Swapping Flashcards
Why do we need to swap memory?
Address spaces are virtual, so may be larger than actual memory. Thus, we will have to store some of the address space in the hard disk, and swap it into main memory when it is needed.
What is a swap space? Why is the present bit in the page table entry important in this regard?
A swap space is an area on the disk where we can move things back and forth between memory and the disk easily.
The present bit will indicate whether a page is loaded into main memory or if it is still on the disk.
What will happen if we try to access a page that has the present bit set to 0?
This will cause a page fault. The OS handles this by swapping in the page from the hard disk (the location where it is stored on disk is given in the page table entry).
While this is all happening, the process will be blocked.
Why do we need page replacement policies? What is the aim?
If memory is full and we want to swap in a page from the disk, we must know which page to swap out to make space.
The aim is to reduce the number of times which we are required to read from the disk.
What is a low watermark and high watermark?
When deciding when to start evicting pages from memory, we check how many there are. If there are lower than LW spaces left, we start evicting, but if there are more than HW left we stop evicting.
What is the optimal page replacement policy?
When you know exactly which page will be access furthest in the future. You choose to evict that one. This is not really practical, but is good for benchmarking other policies.
What is FIFO page replacement policy?
First in First Out. Simple to implement, but does not take into account importance of certain pages.
What is random page replacement policy?
Pick a random page to evict. Simple, but depends on how lucky you are.
What is LRU page replacement policy?
Least Recently Used. The idea is that if we used a page a while ago, we may not need it again so soon.
This is similar to Least Frequently Used.
How can we approximate LRU page replacement policy?
If we use a reference bit in page table entries, to tell us whether a page has been used recently. If the bit is set to 1, then this entry has been used recently. We must have a way of periodically clearing the reference bit.
Why might it be preferable to evict “clean” pages, which do not have the dirty bit set?
The dirty bit means that a page has been modified. If we evict one of these pages from the TLB, then we must also write it back into memory, which is costly. It is cheaper to evict a page which does not need to be written.