Please enable JavaScript.
Coggle requires JavaScript to display documents.
Chapter 9: Virtual Memory (Demand Paging (Stages in demand paging (Trap to…
Chapter 9: Virtual Memory
Virtual memory
separation of user logical memory from physical memory
Virtual address space
logical view of how process is stored in memory
Usually design logical address space for stack to start at Max logical address and grow “down” while heap grows “up”
Can be implemented via
Demand paging
Demand segmentation
Demand Paging
Could bring entire process into memory at load time or bring a page into memory only when it is needed
Similar to paging system with swapping
Lazy sweeper
never swaps a page into memory unless page will be needed
Steps in handling page fault
If there is a reference to a page, first reference to that page will trap to operating system
Operating system looks at another table to decide
find a free frame
Swap page into frame via scheduled disk operation
Reset tables to indicate page now in memory set validation bit = v
Restart the instruction that caused the page fault
Demand paging aspects
Hardware support needed for demand paging
Page table with valid / invalid bit
Secondary memory
Instruction restart
Stages in demand paging
Trap to the OS
Save the user registers and process state
Determine that the interrupt was a page fault
Check that the page reference was legal and determine the location of the page on the disk
Issue a read from the disk to a free frame
while waiting, allocate the CPU to some other user
Receive an interrupt from the disk I/O subsystem
Save the registers and process state for the other user
Determine that the interrupt was from the disk
Correct the page table and other tables to show page is now in memory
Wait for the CPU to be allocated to this process again
Restore the user registers, process state, and new page table and then resume the interrupted instruction
Performance of demand paging
3 major activities
Service the interrupt
Read the page
Restart the process
Demand paging optimizations
Swap space I/O faster than file system I/O even if on the same device
Copy entire process image to swap space at process load time
Demand page in from program binary on disk, but discard rather than paging out when freeing frame
Page replacement
Prevent over-allocation of memory by modifying page-fault service routine to include page replacement and completes separation between logical memory and physical memory
Basic page replacement
1.Find the location of the desired page on disk
Find a free frame
Bring the desired page into the (newly) free frame; update the page and frame tables
Continue the process by restarting the instruction that caused the trap
Algorithms
Frame-allocation
Determines how many frames to give each process and which frames to replace
Page-replacement
want loset page-fault rate on both first access and re-access
Allocation of frames
Each process needs minimum number of frames
Two major allocation schemes
fixed allocation
priority allocation
Global vs local allocation
Global replacement
process selects a replacement frame from the set of all frames; one process can take a frame from another
Local replacement
each process selects from only its own set of allocated frames
Thrashing
A process is busy swapping pages in and out
If a process does not have “enough” pages, the page-fault rate is very high
Leads to
Low CPU utilization
OS thinks that it needs to increase the degree of multiprogramming
another process added to the system