Operating Systems: Three Easy Pieces Ch. 21
Beyound Physical Memory: Mechanisms
- Memory Hierarchy → additional level, if OS needs to support large address space, it needs to keep every portion of address spaces even if it is not currently using
- Hard Disk Drive
- Why do we want to support a single large space? It is convenient to use
- Memory overlays → programmers to manually move pieces of code or data in and out
- Swap space → swap the spaces, pages out of memory to it and swap pages into memory from it
- Need to remember disk address
- We should note that swap space is not the only on-disk location for swapping traffic.
- Safely re-use the memory space for the file that is in the disk storage
- Present Bit
- Running process generates virtual memory references → the hardware translates them into physical addresses before fetching the desired data from memory
- TLB hit, TLB miss
- PTE
- If we need to allow pages to be swapped to disk → need to indicate the page is present in the physical memory or not
- it is set to zero, the page is not in memory but rather on disk somewhere. The act of accessing a page that is not in physical memory is commonly referred to as a page fault
- Running process generates virtual memory references → the hardware translates them into physical addresses before fetching the desired data from memory
- Page fault
- OS is in charge to handle the page fault → page-fault handler
- Hardware page-fault handler
- Software page-fault handler
- OS needs to swap the page into memory → how?
- the page table is a natural place to store such information. Thus, the OS could use the bits in the PTE normally used for data such as the PFN of the page for a disk address.
- Disk I/O → update the page table → TLB Miss → Bring up the page to TLB
- The process will be blocked state so OS will be free to run
- Overlap of I/O of one process and execution of another way to the effective usage of its hardware
- OS is in charge to handle the page fault → page-fault handler
- Page-replacement policy
- Page in, Page out
- Replacing, cost a lot
- Three cases
- Page was both present and valid → TLB miss handler grap PFN from PTE, retry the instruction
- Page is valid but not present, Page fault handler → when the page is legitimate
- Invalid page access → bug, trap the invalid access, terminating
- OS to keep a small portion of memory free more proactively
- High watermark
- Low watermark
- OS notice fewer than LW page available, the background thread is responsible for freeing memory runs
- evicts the page until there are HW pages available
- Swap daemon
- Many systems cluster or group a number of pages and write them out at once to the swap partition
- these actions all take place transparently to the process
- Replacement occurs
- high watermark (HW ) and low watermark (LW ) to help decide when to start evicting pages from memory
- systems will cluster or group a number of pages and write them out at once to the swap partition