6.memory Management
6.memory Management
Straetegies
Background
Program must be brought (from disk) into memory and placed within
a process for it to be run
Main memory and registers are only storage, CPU can access directly
Logical and physical addresses are the same in compile-time and load-
time address-binding schemes; logical (virtual) and physical addresses
differ in execution-time address-binding scheme
Logical address space is the set of all logical addresses generated by
a program
Physical address space is the set of all physical addresses generated
by a program
Memory-Management Unit (MMU)
MMU is a hardware device that at run time maps virtual address to
physical address
The user program deals with logical addresses; it never sees the
real physical addresses
Execution-time binding occurs when reference is made to
location in memory
Logical address bound to physical addresses
Dynamic relocation using a relocation register
Routine is not loaded until it is called
Other programs linked before the new library will continue using
the older library.
Does the swapped out process need to swap back in to same physical
addresses?
partitions:
◦ Resident operating system, usually held in low
memory with interrupt vector
◦ User processes then held in high memory
◦ Each process contained in single contiguous
section of memory
Contiguous Allocation (Cont.)
Relocation registers used to protect
user processes from each other, and
from changing operating-system code
and data
◦ Base register contains value of smallest
physical address
◦ Limit register contains range of logical
addresses – each logical address must be
less than the limit register
◦ MMU maps logical address dynamically
◦ Can then allow actions such as kernel code
being transient and kernel changing size
Hardware Support for Relocation and Limit
Registers
Multiple-partition allocation
Multiple-partition allocation
◦ Degree of multiprogramming limited by number of partitions
◦ Variable-partition sizes for efficiency (sized to a given process’
needs)
◦ Hole – block of available memory; holes of various size are scattered
throughout memory
◦ When a process arrives, it is allocated memory from a hole large
enough to accommodate it
◦ Process exiting frees its partition, adjacent free partitions combined
◦ Operating system maintains information about:
a) allocated partitions b) free partitions (hole)
Dynamic Storage-Allocation Problem
First-fit and best-fit better than worst-fit in terms of speed and storage utilization
Fragmentation
External Fragmentation – total
memory space exists to satisfy a
request, but it is not contiguous
Internal Fragmentation – allocated
4
1
3 2
4
4
Structure of the Page Table
Memory structures for paging can get
huge using straight-forward methods
◦ Consider a 32-bit logical address space as on
modern computers
◦ Page size of 4 KB (212)
◦ Page table would have 1 million entries (232 /
212)
◦ If each entry is 4 bytes -> 4 MB of physical
address space / memory for page table alone
That amount of memory used to cost a lot
Don’t want to allocate that contiguously in main
memory
Structure of the Page Table
Hierarchical Paging