2.01k likes | 5.14k Views
Memory Management. Memory management is the art and the process of coordinating and controlling the use of memory in a computer system Why memory management? Multiple processing Relocation Protection Sharing Logical Organization Physical Organization. Three areas of memory management.
E N D
Memory Management • Memory management is the art and the process of coordinating and controlling the use of memory in a computer system • Why memory management? • Multiple processing • Relocation • Protection • Sharing • Logical Organization • Physical Organization
Three areas of memory management • Memory management hardware • MMUs (Memory Management Unit), RAM, etc. • Operating system memory management: • Virtual memory, protection, etc. • Application memory management: • Allocation, garbage collection, etc.
Memory Management Hardware • Memory management devices include RAM, MMUs, caches, disks, and processor registers • Ex. MMU • a hardware device responsible for handling memory(2) accesses requested by the main processor • translates virtual addresses to physical addresses
Operating System Memory Management • Virtual Memory • Operating systems simulates having more memory than is available as main memory, by storing part of the data in backing store, typically on disk. • If the page referenced by the virtual address is not currently in main memory, a page fault occurs, triggering an operating system handler that swaps in the page. • Some other page might be swapped out to make room • Benefits
Operating System Memory Management • Protection (also known as memory protection, page protection) • Operating systems can protect memory pages against a combination of read, write or execute accesses by a process. • A process which attempts a protected access will trigger a protection fault.
Application Memory Management: Allocation • When the program requests a block of memory, the memory manager must allocate that blockout of the larger blocks it has received from the operating system. • The part of the memory manager that does this is known as the allocator. • Allocation techniques: • First fit • Buddy system • Suballocators
Application Memory Management: Recycling • When memory blocks have been allocated, but the data they contain is no longer required by the program, then the blocks can be recycled for reuse. • There are two approaches to recycling memory: • either the programmer must decide when memory can be reused (known as manual memory management); • or the memory manager must be able to work it out (known as automatic memory management).
Application memory manager constraints • CPU overhead • The additional time taken by the memory manager while the program is running • Interactive pause times • How much delay an interactive user observes • Memory overhead • How much space is wasted for administration, rounding (known as internal fragmentation), and poor layout (known as external fragmentation).
Memory management problems • Premature free or dangling pointer • Memory leak • External fragmentation • Poor locality of reference • Inflexible design • Interface complexity