swap file — used for replacements

demand paging:

  • use memory as a Cache for the filesystem

  • map memory pages to filesystem blocks

  • only load them into memory when they’re used through the page fault

  • if the page doesn’t represent a file, we map it to swap space

  • move it to disk if we need to use more physical memory

  • number of pages used by a Process is called its working set

  • if we can’t fit the working set into physical memory, the process will thrash, i.e., move entries in and out of cache. performance will suffer

page replacement algorithms

  • optimal — replace the page that won’t be used for the longest
    • looks into future, so not implementable in practice.
    • tries to maximise page hits
  • random - randomly replace
  • FIFO — replace oldest page first
    • more page frames (memory) can cause more page faults: Bélády’s anomaly
    • only for FIFOs. paper that proves this FIFO anomaly is unbounded
    • for other algorithms, adding more memory means less page faults
  • LRU replacement

swap files

  • used for replacements
  • memory is pretty cheap and has high capacity. we might want to know when we need more memory than to just let a process run slowly (if more than available memory, we need to keep swapping. this is not performant. if we disable swapping, linux will OOM kill the process and we know we just need more memory in system)
  • larger page sizes allow for speedups (2 MB, 1 GB)
    • trade off: more fragmentation for more TLB coverage