Logical/Virtual Address Space: Isolated addresses for a running program
- Translation to physical address done by MMU (Memory Management Unit)
Memory Management Goals
- Support as many processes as possible, reduce waste
- Small overhead
Requirements
- Relocation: Programmers shouldn’t worry about physical memory constraint
(address translation, swapping)
- Protection: Prevent reading of another process’ memory
- Sharing: Control permission for shared blocks (e.g. glibc)
- Logical Organization: Map different sections (e.g. text, stack, heap, mmap files, libraries)
- Physical Organization: Manage flow of info between memory and disk
Address Binding
Address Binding: Linking variable names to physical address
- Compile time binding: Compiler assign each program absolute addresses
(Relocation not possible, single instance, different programs override)
- Load time binding: Compiler bind variables to (relative) local address in object file (.o)
- Linker takes .o, resolve dependencies, translate to logical address with relocation table
- Loader translate logical addresses to physical addresses when program load
- Cannot relocate after loading (pointer variables will misplace when relocated)
- Dynamic Relocation: Each instruction translated during execution
(Requires special hardware)
Partitioning
Fixed Partitioning: Divide memory into fixed blocks, one process each block (e.g. 8MB each)
- Internal Fragmentation: Wasted space for processes using less memory
- Overlays: Manually swapping data from RAM to disk on a program
- Unequal Partition Sizes: Fixed blocks but different sizes (e.g. 4, 4, 8, 16 MB)
- Support larger programs, but still result in internal fragmentation
- Limits the number of processes, not adjustable after boot
Dynamic Partitioning: When a program loads, a partition of the exact size needed is created
- Hard to predict program RAM usage
- External Fragmentation: Gaps from exited processes are too small to run new processes
- Compaction: Move processes to reduce external fragmentation (require dynamic relocation)
- Still used in malloc! (without relocation)
- Placement Algorithms:
- First Fit: First large-enough block
(irl: fastest and most efficient, but leaves small fragments)
- Next Fit: First fit but search from previous end
(irl: free space fragmented more rapidly)
- Best Fit: Choose block closest to requested size
(irl: similar utilization to first-fit)
- Worst Fit: Choose largest block
(irl: free space fragmented more rapidly)
- Quick Fit: Multiple free lists for common block sizes
(irl: harder to coalesce)