Operating Systems Level 9
PART 3 • MEMORY & STORAGE

Give Every Process a Larger, Protected View of Memory

Follow a nonresident page from CPU reference to disk and back, compare replacement decisions, and diagnose when excessive paging destroys useful execution.

Level 09 of 15 Intermediate 110–140 minutes Two interactive traces
BY THE END, YOU CAN

Reason about residency

  • Explain demand paging and valid bits.
  • Trace a page fault safely.
  • Run FIFO, LRU and Optimal.
  • Identify Belady’s anomaly.
  • Explain working sets and thrashing.
01 • SEPARATE ADDRESS SPACE FROM RAM

Virtual Memory Loads Only the Pages Needed Now

A process sees a private virtual address space. Page-table entries map resident pages to frames; a valid/present bit tells hardware whether translation can continue.

DEMAND PAGING

Load on first use

Executable and data pages remain on secondary storage until referenced, reducing initial load and allowing more processes to coexist.

COPY-ON-WRITE

Delay private copying

Processes initially share read-only frames. A write fault creates a private copy, making fork() cheaper.

MEMORY-MAPPED FILE

File bytes become pages

Reads and writes use ordinary memory references while the OS handles caching, loading and eventual persistence.

page = ⌊virtual address / page size⌋ offset = virtual address mod page size EAT depends on TLB hit and fault rate

A TLB miss and a page fault are different. On a TLB miss the mapping may already exist in the page table; on a page fault the page is not resident and OS intervention is required.

02 • HANDLE A FAULT WITHOUT CORRUPTING STATE

A Page Fault Is a Controlled Exception

1

Trap and validate

Hardware traps to the kernel. The OS checks whether the address is legal; illegal references terminate or signal the process.

2

Obtain a frame

Use a free frame or select a victim. If the victim is dirty, schedule its write-back before reuse.

3

Read and block

Issue storage I/O and block the faulting process so another ready process can run.

4

Update translation

Record frame number and protection bits; invalidate stale TLB state.

5

Restart instruction

Return to user mode and repeat the faulting instruction as though the page had been present.

03 • INTERACTIVE PAGE-REPLACEMENT LAB

Run Every Reference against the Same Frames

FIFO removes the oldest loaded page; LRU removes the least recently used; Optimal removes the page used farthest in the known future and is an offline benchmark.

READY

Choose policy and run

The complete hit/fault and victim trace will appear here.

Policy Information Strength Limitation
FIFO Load order Small metadata Belady anomaly possible
LRU Past recency Uses temporal locality Exact tracking costly
Optimal Future references Minimum faults for trace Not online implementable
04 • CONTROL MEMORY PRESSURE

Thrashing Means the System Is Moving Pages More Than Doing Work

LOCALITY

Working set

The pages referenced in a recent window approximate the process’s active locality. Enough frames keep that locality resident.

SYMPTOM

High faults, low CPU use

Processes block for paging; a naive scheduler may admit more processes and make pressure worse.

CONTROL

Reduce degree

Suspend processes, use working-set or page-fault-frequency control, and allocate frames according to locality.

Global replacement may take frames from another process; local replacement restricts victims to the faulting process. Global policies can improve utilization but couple processes and weaken performance isolation.

05 • PROGRAM TRACING

Trace One Fault from Instruction to Restart

FAULT PATH · 0 / 0

Ready to trace

Press Next step to begin.

06 • CHECK YOUR UNDERSTANDING

Ten Misconception-Specific Checks

Answered correctly: 0 of 10
07 • EXAM & INTERVIEW PREPARATION

Explain Mechanism and Trade-off

2-MARK
  1. Define demand paging.
  2. TLB miss versus page fault?
  3. What is a dirty bit?
  4. Define thrashing.
  5. What is locality?
5-MARK
  1. Trace page-fault service.
  2. Compare FIFO, LRU and Optimal.
  3. Explain Belady’s anomaly.
  4. Explain working-set control.
  5. Calculate effective access time.
INTERVIEW
  1. Why can more frames hurt FIFO?
  2. Why is Optimal useful?
  3. How is LRU approximated?
  4. Global versus local replacement?
  5. What triggers copy-on-write?
Strong answer: “Explain a page fault”

Start with present-bit failure, validate the address, obtain a frame, write dirty victim if necessary, read the page, update page table/TLB, unblock and restart. Mention that disk latency dominates and another process can run meanwhile.

LEVEL 9 SUMMARY

You Can Explain Why a Page Is Present—or Missing

  • Demand paging separates virtual size from current residency.
  • A legal nonresident reference causes a recoverable page fault.
  • Replacement policy selects a victim only when no free frame exists.
  • Optimal is a benchmark; practical systems approximate locality.
  • Working-set pressure can cause thrashing.
COURSE CHECKPOINT

Mark complete after you can trace one fault and manually run LRU.

Saved only in this browser.