1 of 24

CSE 451

Operating Systems

L19 - Page Replacement,

Storage

Slides by: Tom Anderson

Rohan Kadekodi

2 of 24

MIN, LRU, LFU

  • MIN (optimal for page faults)
    • Replace the cache entry that will not be used for the longest time into the future
    • Optimality proof: if evict an entry used sooner, that will trigger an earlier cache miss
  • Least Recently Used (LRU)
    • Replace the cache entry that has not been used for the longest time in the past
    • Approximation of MIN
  • Least Frequently Used (LFU)
    • Replace the cache entry used the least often (recently)
    • Better than LRU when usage pattern is based on popularity, not history

3 of 24

Belady’s Anomaly

4 of 24

Question

  • How accurately do we need to track the least recently/least frequently used page?
    • If miss cost is low, any approximation will do
      • Hardware caches
    • If miss cost is high but number of pages is large, any not recently used page will do
      • Main memory paging with small pages
    • If miss cost is high and number of pages is small, need to be precise
      • Main memory paging with superpages

5 of 24

Clock Algorithm: Estimating LRU

  • Hardware sets use bit
  • Periodically, kernel sweeps through all physical page frames
  • If page is unused (by any process), reclaim
    • After flushing changes to disk
  • If page is used, mark as unused
  • Downside: modern servers can have 100M+ physical page frames

6 of 24

Second Chance List

  • Periodically sweep through all page frames

if (page is dirty) {

flush to disk, mark page as clean, unused

} else if (page is used) { mark page as unused

} else {

mark as invalid; put at end of “second chance” list

if page is referenced, pull off “second chance” list, mark

page as valid

}

  • If need page, pull off front of second chance list

7 of 24

Recap

  • MIN is optimal
    • replace the page or cache entry that will be used farthest into the future
  • LRU is an approximation of MIN
    • For programs that exhibit spatial and temporal locality
  • Clock/Second Chance is an approximation of LRU
    • Bin pages into sets of “not recently used”

8 of 24

Working Set Model

  • Working Set: set of memory locations that need to be cached for reasonable cache hit rate
  • Thrashing: when system has too small a cache

9 of 24

Phase change behavior

10 of 24

Question

  • What happens to system performance as we increase the number of processes?
    • If the sum of the working sets > physical memory?

# progs

Hit rate

11 of 24

Storage and File Systems

12 of 24

Main Points

  • Survey of physical storage hardware devices
    • SRAM, DRAM, Flash, magnetic disk
  • File systems
    • Useful abstraction on top of physical devices
  • File system usage patterns
    • Small files and large files are both commonplace

13 of 24

Volatile Memory: SRAM and DRAM

  • Individual word (8 byte) and cache line (64 byte) access
  • Data degrades without power; power proportional to storage capacity
  • Bit density scales with Moore’s Law
  • Static RAM (SRAM)
    • Typical uses: CPU registers, on chip cache, I/O device caches
    • Data stored in a transistor flip/flop
    • Access latency range: 1 – 20ns (smaller caches => faster)
  • Dynamic RAM (DRAM)
    • Typical use: main memory (8GB/chip with DDR5, usually sold as an array of chips)
    • Data stored in a capacitor, 2D/3D array for dense packing
    • Data degrades even when powered; bits need periodic refresh
    • Access latency: 50 - 100 ns
  • Tiered DRAM (CXL)
    • Rack-level extension to server DRAM (cache coherent, PCI)
    • Access latency: 300 ns

14 of 24

Persistent Memory: Flash and Magnetic Disk

  • Block level (4KB) access (or larger); asynchronous request queues
  • Data valid even when unpowered
  • NAND Flash/Solid State Drive (SSD)
    • Bits stored in special silicon gate, densely packed in 2-D or 3-D array
    • 10-50 us block level random read/write
    • Each block can only be written once, but can be erased
    • Limited number of erasures per physical block (10K depending on type)
    • Typical use: smartphones, laptops, servers, data centers
  • Magnetic “hard” disk drive (HDD)
    • Bits stored on magnetic surface: 1.5 Tbit per square inch
    • Physical motion (spinning disk) needed to read bits off surface
    • 10 ms random access latency; 250MB/s max throughput
    • Typical use: data center bulk storage, backup

15 of 24

5

[J. McCallum, jcmit.org]

DRAM

Flash

Disk

16 of 24

Flash Memory

17 of 24

Flash Memory Challenge

  • Writes must be to “clean” cells
    • Erasure required before block can be rewritten
    • Erasure is 20x slower than single block read/write
    • Erasure needs empty guard regions to avoid erasing useful data in nearby blocks
    • Limited number of erasures per physical block (10-35K for MLC, 1K for QLC)

  • Solutions?

18 of 24

Managing Wearout

  • Each flash block can only be written limited number of times
    • Depends on encoding: 1000 (QLC), 10-35K (MLC), 100K (SLC)
  • What if app repeatedly updates the same physical block?
    • 1ms per write/erase cycle
    • Assume 10K write/erase cycles before wearout

Wearout (of one block) in 10 seconds !

Disk keeps getting smaller over time…

=> Can’t allow update in place

19 of 24

Flash Translation Layer (FTL)

  • Disk firmware exports a virtual block interface
    • Read/Write/Trim (block delete)
  • Firmware relocates each virtual block to physical location as needed
    • Overwrite to a previously written block goes to new empty location
    • Reads to the newly written block are redirected to its new location
    • Previous block is stale, unused, ready for erasure (reuse for other block writes)
      • Like putting the block into the trash - device firmware can still read the old data (until erasure)
  • FTL needs a map from virtual block # to physical location
    • Stored in SRAM for fast lookup
    • Written back to SSD on power failure (battery, capacitor)

20 of 24

FTL in Picture Form

Eventually we’ll run out of space…

21 of 24

Erasures

  • Erase many blocks at a time (erasure region)
    • Multi-block erasure region is always erased together at same time
    • Minimizes wasted area/density due to guard regions
      • Guard per multi-block erasure region
    • Prorate time spent erasing over more blocks
  • Device still appears to read/write individual 4KB blocks
    • Number of blocks in erasure region is an internal value, not visible to customers
    • Tens to hundreds 4KB blocks per erasure region
  • What if some of the data in the erasure region is still live?
    • Where do we put that data during the erasure?

22 of 24

FTL Compaction

23 of 24

Efficient Compaction

24 of 24

Wear Levelling

  • Each block can only be written a maximum number of times
    • FTL tracks # of erase/write cycles for each block
    • Unmap blocks if they can’t hold new data
  • To keep from losing blocks due to wear out
    • Write new data into regions with fewer update cycles
    • Put data that won’t change in blocks that are near the end of their lifetime