Virtual Memory Management
Virtual Memory Management
Background
Demand Paging
Copy-on-Write
Page Replacement
Allocation of Frames
Thrashing
1. Background
• Virtual memory – separates user logical memory from physical memory.
• Only part of the program needs to be in memory for execution
• Logical address space can be much larger than physical address space
Procedure for
handling the page
fault
1. OS looks at
another table to
decide:
– Invalid reference
abort
– Just not in
memory
2. Get empty frame
3. Swap page into
frame
4. Reset tables
5. Set validation bit =
v
6. Restart the
instruction that
caused the page Steps in Handling a Page Fault
fault Loganathan R, CSE, HKBKCE 7
2. Demand Paging Cntd…
Performance of Demand Paging
• Let p is the probability of a page fault (0 p 1.0)
if p = 0 no page faults and if p = 1, every reference is a fault
• Effective Access Time EAT = (1 – p) x ma(memory access) + p x page fault time
• Page fault causes
1. Trap to the operating system
2. Save the user registers and process state
3. Determine that the interrupt was a page fault
4. Check that the page reference was legal and determine the location of the page on
the disk.
5. Issue a read from the disk to a free frame:
Wait in a queue for this device until the read request is serviced.
Wait for the device seek and /or latency time.
Begin the transfer of the page to a free frame.
6. While waiting, allocate the CPU to some other user (CPU scheduling, optional).
7. Receive an interrupt from the disk I/O subsystem (I/O completed).
8. Save the registers and process state for the other user (if step 6 is executed).
9. Determine that the interrupt was from the disk.
10. Correct page table &other tables to show the desired page is now in memory.
11. Wait for the CPU to be allocated to this process again.
12. Restore the user registers, process state, and new page table, and then resume the
interrupted instruction.
8
Loganathan R, CSE, HKBKCE
2. Demand Paging Cntd…
12
Loganathan R, CSE, HKBKCE
4. Page Replacement Cntd…
• 4 frames example
1, 2, 3, 4, 1, 2, 5, 1, 2, 3, 4, 5
1 4
2 6 page faults
3
4 5
Loganathan R, CSE, HKBKCE 17
4. Page Replacement Cntd…
Total 12 faults
• Reference string: 1, 2, 3, 4, 1, 2, 5, 1, 2, 3, 4, 5
1 1 1 1 5
2 2 2 2 2
3 5 5 4 4
4 4 3 3 3
Thrashing Prevention
• Why does thrashing occur?
A locality is a set of pages that are actively used together
size of locality > total memory size
– Process migrates from one locality to another
– Localities may overlap
Working-Set Model
• working-set window a fixed number of page references
Example: 10,000 instruction
• WSSi (Working Set Size of Process Pi) =
total number of pages referenced in the most recent (varies
in time)
– if too small will not include entire locality
– if too large will include several localities
– if = will include entire program
26
6. Thrashing Cntd…