Professional Documents
Culture Documents
Memory Management
Memory Management
Memory Management
1
Memory Management
• Background
• Logical/Virtual Address Space vs Physical
Address Space
• Swapping
• Contiguous MemoryAllocation
• Segmentation
Goals and Tools of memory management
3
Background
no no
7
Logical/Virtual Address Space
• 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
– Exam 2 approaches
• Fixed partition
• Variable partition
Old technique #1: Fixed partitions
21
Mechanics of fixed partitions
physical memory
0
limit register base register partition 0
2K
2K P2’s base: 6K
partition 1
6K
yes
offset <? + partition 2
virtual address 8K
no
partition 3
raise
protection fault
12K
22
Old technique #2: Variable partitions
23
Mechanics of variable partitions
physical memory
partition 2
yes
offset <? + partition 3
virtual address
no
raise
protection fault partition 4
24
Multiple-partition allocation
• Multiple-partition allocation
– 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, 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
How to satisfy a request of size n from a list of free holes?
• Worst-fit: Allocate the largest hole; must also search entire list
– Produces the largest leftover hole
• Compact memory by
copying
– Swap a program out partition 0 partition 0
– Re-load it, adjacent to partition 1 partition 1
another
partition 2
– Adjust its base register partition 2 partition 3
– Compaction is possible
only if relocation is dynamic partition 3 partition 4
– I/O problem
• Latch job in memory
while it is involved in I/O partition 4
• Do I/O only into OS
buffers
28
Segmentation
29
User’s View of a Program
Logical View of Segmentation
4
1
3 2
4
• Segment table
– multiple base/limit pairs, one per segment
– segments named by segment #, used as index into table
• a virtual address is <segment #, offset>
– offset of virtual address added to base address of segment to yield
physical address
32
Segment lookups
segment table
physical memory
limit base
segment 0
segment # offset
segment 1
virtual address
segment 2
yes
<? + segment 3
no
raise
protection fault segment 4
33
Pros and cons
34