Skip to content

Glossary

Page-replacement clock

XNU's two-handed clock algorithm for aging pages from active to inactive, identifying reclaim candidates under memory pressure.

The page-replacement clock is XNU's algorithm for deciding which physical pages to reclaim under memory pressure. A "two-handed clock" — a variant of the classic CLOCK algorithm widely used in Unix-family kernels.

How it works:

  • The active hand walks the active page queue, checking each page's recently-referenced bit (set by hardware on access).
  • Pages without a recent reference get demoted from active to inactive.
  • The inactive hand walks the inactive queue, picking pages to reclaim — hand them to the compressor, write back dirty file-backed pages, or simply unmap clean file-backed pages.
  • Both hands move continuously under the pageout daemon; the speed scales with memory pressure.
apple-oss-distributions/xnuosfmk/vm/vm_pageout.cThe pageout daemon — implements the two-handed clock.View on GitHub(line )

The "two hands" let the algorithm separate aging (active → inactive) from reclaim (inactive → free), giving each its own pace. A page that's just been demoted to inactive has some grace time to be re-referenced and rescued back to active before the inactive hand catches up and reclaims it.

The clock is the workhorse algorithm behind XNU's memory pressure response — every reclamation decision ultimately bottoms out in the clock's verdicts.

See also: pageout daemon, VM compressor, working set.