Swapping Flashcards
What is swapping?
Swap inactive pages out of memory temporarily on another level of storage (most of the time HDD) to gain memory.
- What is the swap space?
- Where is the swap space stored?
- The level of storage defined for swapping
- Mostly a swap partition (linux) or swap file (windows)
Paging:
- What is the present bit?
- What happens if it is not set?
- The present bit belong to the PTE. If set the page is in physical memory.
- HW makes a trap with page fault
A page fault gets started by the HW if pages are not in physical memory. This gives the control to the OS.
- Why does the HW not handle this? (3 reasons)
- How is the control given?
- HW would have to know how swapping and swap space works
- Swapping to HDD is slow, we gain no benefit of using the HW
- HW would need to know disk driver and different HW types (SATA, SCSI)
- HW trap into OS, where the page fault handler gets into action
Describe how the OS handles the page fault from start until memory access.
- How does the process work during handling the page fault?
- What if there is no free space in physical memory?
- Use PFN from PTE, which holds the disk address where the page is stored (if present bit is not set)
- I/O to load page from swap space
- Update PFN in PTE (using the physical memory address)
- The process is in state “blocked”. OS can schedule other processes
- Other pages have to be swapped out first
How does the OS swap out pages? page-by-page?
No, there is a minimum of free pages in physical memory. If it is below that, the OS swaps out as much pages until it is above this minimum. This is for optimization of workload.
What is a “cold-start miss”? (Often also called compulsory miss)
When pages have to be loaded in the memory, those are TLB misses, but are compulsory.
What is the problem with simple swapping policies like FIFO or random?
They don’t make use of the past and maybe evict important pages. Locality of reference!
How does the Linux replacement policy work?
2 lists are used: active and inactive
- On first page access the page goes into inactive list
- If it is used again it gets into active list
- If a page needs to be swapped those from inactive are swapped
- Periodically pages from active get into inactive
- Approximation to LRU similar to clock policy is made.