← Interview Prep

Linux Kernel — Page Frame Reclaiming

Taking pages back under pressure: what's reclaimable (clean file first, dirty writeback, anon needs swap, slab shrinkers), the active/inactive LRU lists & second-chance/refault, watermarks with kswapd vs direct reclaim, swappiness & thrashing, and the OOM killer (incl. cgroup OOM).

When memory runs low, the kernel has to take pages back — deciding what to evict, writing out what's dirty, and doing it without stalling everyone. How reclaim works, and why "high memory use" is usually fine. Original, interview-focused notes; the pressure side of Memory Management.

Reclaim frees the easy pages first: clean file-cache pages can be dropped instantly (they're on disk already); dirty pages must be written back first; anonymous pages need swap. It runs in the background (kswapd) and, when that's not fast enough, synchronously in the allocating task (direct reclaim).

What's reclaimable

Page typeTo reclaim
Clean file (page cache)Just drop it — the cheapest, reclaimed first.
Dirty fileWrite back to disk, then drop.
Anonymous (heap/stack)Write to swap, then drop. No swap → can't reclaim → OOM.
Reclaimable slabFreed via shrinkers (dentry/inode caches).
Locked / kernel / mlock'dNot reclaimable.

The LRU lists

kswapd, direct reclaim & watermarks

Swap & swappiness

Last resort: the OOM killer

When reclaim can't free enough and there's no swap headroom, the OOM killer picks a victim by oom_score (roughly memory footprint, tunable with oom_score_adj) and kills it — logged in dmesg. Per-cgroup limits (memory.max) trigger a cgroup OOM scoped to that group, which is how containers get killed. See the troubleshooting angle.

Likely interview questions

Kernel Internals series. Related: Memory Management · Page Cache · Linux Troubleshooting.