Memory Management Policies: Unix: The Design of The Unix Operating System Maurice J. Bach Prentice Hall
Memory Management Policies: Unix: The Design of The Unix Operating System Maurice J. Bach Prentice Hall
2
Data Structures for Process
Kernel Process Kernel Region
Table A Process Table
Text
Stack
U Area
3
Data Structure for Process (contd.)
per process
region table Kernel region table
u area
main memory
Kernel
process table
4
UNIX Memory Management
Policies
• Swapping
– Easy to implement
– Less system overhead
• Demand Paging
– Greater flexibility
5
Swapping
• The swap device is a block device in a configurable
section of a disk
• Kernel allocates contiguous space on the swap device
without fragmentation
• It maintains free space of the swap device in an in-
core table, called map
• The kernel treats each unit of the swap map as group
of disk blocks
• As kernel allocates and frees resources, it updates the
map accordingly
6
Allocating Swap Space
Address Unit
Allocate 100 unit
1 10000 101 9900
Map
Allocate 50 unit
7
Freeing Swap Space
Address Unit 101 50
50 unit free at 101
251 9750 251 9750
Map
8
Freeing Swap Space
Address Unit 101 50
50 unit free at 101
251 9750 251 9750
Map
100 unit free at 1
1 150
251 9750
11
Swapping Process Out
• Memory Swap device
• Kernel swap out when it needs memory
1. When fork() called for allocate child process
2. When called for increase the size of process
3. When process become larger by growth of its
stack
4. Previously swapped out process want to swap
in but not enough memory
12
Swapping Process Out
• The kernel must gather the page addresses of
data at primary memory to be swapped out
• Kernel copies the physical memory assigned to
a process to the allocated space on the swap
device
• The mapping between physical memory and
swap device is kept in page table entry
13
Swapping Process Out
16
Expansion Swap
17
Demand Paging
18
Data Structure for Demand Paging
21
Disk Block Descriptor
22