Virtual Memory & Demand Paging

page-out

Picture clearing a spot on your crowded desk to make room for a new document. If the paper you remove has fresh handwriting on it that exists nowhere else, you must first file it away safely; if it is just a printout you can reprint any time, you can simply toss it. Page-out is the OS doing this when RAM is full: it removes a page from a frame to free that frame, saving the page first if and only if saving is necessary.

Concretely, page-out is the act of evicting a page from physical memory. When the OS needs a free frame and none is available, page replacement selects a victim page, and paging that victim out frees its frame. Whether the page-out involves a disk write depends on the page. If the victim's dirty bit is set (the page was modified since it was loaded), its only up-to-date copy is in RAM, so the OS must write it to the backing store before reusing the frame. If the page is clean (unmodified) and file-backed, a good copy already exists on disk, so the OS can free the frame immediately with no write at all. After page-out, the OS marks the corresponding page-table entry invalid, records where the page now lives (if it was written out), and the freed frame is ready for the page being faulted in.

Why it matters: page-out is the counterpart of paging-in that makes demand paging sustainable — RAM stays full of useful pages because stale or idle ones are pushed out to make room. The big performance lever here is the dirty bit: writing a dirty page out costs a slow disk transfer, so a fault that must first page out a dirty victim can be twice as expensive as one that finds a clean victim or a free frame. This is why replacement policies prefer to evict clean pages, and why systems sometimes write dirty pages out in the background ahead of time, so a frame is clean and instantly reusable when the moment of need arrives.

The OS needs a frame and picks page A as victim. A is clean (file-backed code), so it is dropped instantly and its frame reused — zero disk writes. Next time it picks page B, which is dirty, so B must be written to swap first, then its frame is reused.

A dirty victim costs a write-out; a clean victim is free to evict.

Page-out is not the same as page replacement. Replacement is the policy that decides which page to evict; page-out is the mechanical act of evicting it (and writing it back if dirty). A page-out only causes a disk write when the victim is dirty.

Also called
page evictionwriting back a page頁換出頁寫出