How Linux Reclaims Memory: Inside the Page Frame Reclaim Algorithm
This article explains how Linux's Page Frame Reclaim Algorithm categorizes pages, uses kswapd and pdflush threads, and relies on vmstat parameters to manage virtual memory, illustrating the process with examples and key configuration settings.
Page Frame Reclaim Algorithm (PFRA)
Virtual memory is managed in pages, typically 4 KB, or 2 MB when using huge pages. PFRA reclaims memory based on page types.
1. Page Types
Non‑reclaimable pages: locked pages, kernel pages, reserved pages.
Swappable pages: anonymous memory pages.
Sync pages: pages that have a corresponding disk file.
Discardable pages: static or discarded pages.
All types except the first can be reclaimed by PFRA.
2. PFRA Mechanisms
kswapd kernel thread.
pdflush kernel thread.
3. kswapd
The kswapd daemon ensures enough free memory is available. When free memory falls below pages_low, kswapd releases pages in batches of 32 until free memory reaches pages_high. It uses a double‑LRU list: unmodified pages are moved to the free list; modified pages with a backing file are written back to disk; modified anonymous pages are written to swap.
4. pdflush
pdflush writes dirty pages belonging to files back to disk. When about 10 % of pages become dirty, pdflush starts syncing them; the threshold can be tuned via vm.dirty_background_ratio.
5. vmstat‑related Parameters
Key vmstat parameters that influence memory reclamation include pages_low, pages_high, and vm.dirty_background_ratio.
6. Example
An analysis of an I/O spike shows massive virtual‑memory usage: many disk blocks are mapped to pages, free memory stays around 17 MB, kswapd pulls memory from buffers to keep the free list, and dirty pages are written to swap.
7. Summary
Page faults occur.
Heavy swap usage indicates memory shortage.
Signed-in readers can open the original source through BestHub's protected redirect.
This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactand we will review it promptly.
MaGe Linux Operations
Founded in 2009, MaGe Education is a top Chinese high‑end IT training brand. Its graduates earn 12K+ RMB salaries, and the school has trained tens of thousands of students. It offers high‑pay courses in Linux cloud operations, Python full‑stack, automation, data analysis, AI, and Go high‑concurrency architecture. Thanks to quality courses and a solid reputation, it has talent partnerships with numerous internet firms.
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.
