OS Spring ‘04
Paging and Virtual Memory
Operating Systems Spring 2004
OS Spring ‘04
The memory of a program
Source-code is compiled into linkable object
modules
Memory addresses given as relative offsets Libraries contain object modules
Object modules are linked together into a
loadable module
Leave unresolved references to dynamic libraries
Loadable modules are loaded into memory and
execute in a process
The OS + hardware map from logical address space to physical memory
OS Spring ‘04
Physical to logical address mapping
Every memory access is handled by the
memory management unit (MMU)
Example: C = A+ B
four memory accesses (why?)
Simple scheme:
Physical addr = base register + logical addr
Logical addressing allows
Multiple programs to co-exist in memory Use overlays to increase the available address space beyond physical limitation Use shared libraries and dynamic library loading
OS Spring ‘04
Swapping
Use secondary storage to store running
processes
Swap-out: suspend a process, copy its memory from main memory to disk Swap-in: copy a stored process from disk to main memory and resume running state
Logical addressing: allow swapping back to a
different location in memory
Caution: DMA and asynchronous I/O to
swapped processes must take care
OS Spring ‘04
Memory management: Review
Fixed partitioning, dynamic partitioning Problems
Internal/external fragmentation A process can be loaded only if a contiguous memory chunk is available to accommodate the process Process size is limited by the main memory size
Advantage: simplicity
OS Spring ‘04