Beyond Physical Memory: Mechanisms
- Until now, we have assumed that memory used by every process fits in physical memory (all at once).
That’s not realistic.
- Key idea: If no frame is available, move an unused frame to physical memory.
- This is more or less the same idea as cache: Keep what you are using “close”
and put other stuff “far away”.
- Differences?
- Cache is small relative to main memory (8KB for L1 compared to 10s of GB).
- Today, we only swap out a small percentage of RAM (e.g., 3GB out of 16GB).
- RAM is about 100x slower than cache.
- Disk is about 10,000 times slower than RAM.
- Compare “single address space” system to old-school Overlays that the
programmer had to manage by hand.
- Swap space: Space on disk for vm pages.
- Idea: Instead of swapping code pages out to the specific swap space, just dump
them and reload them from disk if necessary.
- Caveat?
- You can’t delete a program while it is running.
- Add a present bit to the page table.
- Set the present bit to 0 if the page is not in a page frame, but on disk instead.
- A page fault happens when a page is not present.
- A page fault is handled by the operating system, not hardware
- There are a lot of steps involved in doing the disk I/O and loading the
resulting data into RAM.
- Often the page table entry can contain the location on disk if page isn’t present.
- Process is blocked while page fault is handled. (Let’s other processes get work done.)
- What are the three possibilities with TLB miss:
- Present and valid (Just grab frame number from the page table)
- Valid and not present (Need to fetch page from swap space)
- Invalid
Optimization: Keep some page frames free
- Waiting until memory is full makes page faults really slow:
We’d need to wait for page to be written out, then new page read in.
- Idea: Preemptively write pages out.
- When number of free pages goes below the low water mark, start writing pages out to disk.
- (This can even be done when the disk isn’t otherwise busy, giving priority to I/O from running processes).
- Stop writing pages out when a high water mark is reached.
- To improve efficiency, write out a group of related pages
- Likely to be evicted around the same time
- Larger disk writes are more efficient.
- Key idea: Just because a page is written out, does not mean it is no longer present.
- If the page is referenced before the page frame is needed, it is “saved”. No page fault.
- This is the idea of “major” and “minor” page faults from recent lab.