Memory Management

Lesson, slides, and applied problem sets.

View Slides

Lesson

Memory Management

Why this module exists

The OS provides the illusion of a large, contiguous memory space. Under the hood, it is a complex mapping between virtual addresses and physical frames. Mistakes here are catastrophic: wrong translation means reading or writing the wrong data.


1) Paging basics

Virtual memory is split into pages. Physical memory is split into frames. A page table maps pages to frames.

With 4KB pages on a 32-bit address:

  • 10 bits page directory
  • 10 bits page table
  • 12 bits offset

2) Multi-level page tables

Multi-level tables reduce memory overhead by only allocating lower levels when needed. Translation walks levels, checking present bits at each step.


3) Page replacement

Physical memory is finite. When full, the OS must evict a page. Algorithms:

  • LRU: evict least recently used
  • Clock: approximate LRU with a reference bit

Replacement policies are about the long-term access pattern, not a single event.


What you will build

  • A two-level page table translator
  • A clock (second-chance) replacement simulator

Key takeaways

  • Address translation is a deterministic walk with strict invariants.
  • Page replacement is policy with real performance impact.

Module Items