freenode
Kernel & Low-Level

Linux memory reclaim patch aims to make MGLRU usable on Kubernetes

Kairui Song's frequency-guided promotion series claims double-digit gains and a fix for the working-set numbers clusters use to evict pods.

A proposed rework of the Linux kernel's multi-generational LRU (MGLRU) would promote pages by how often they are touched, not only by when they were last seen, and would repair the working-set numbers that have kept the feature off many production systems.

Kairui Song of Tencent posted a 19-patch series, MGLRU-FG, following an idea raised at this year's LSF/MM/BPF summit. Depending on the workload, he reports roughly 10% to more than 50% better performance or less I/O, from the reclaim code doing a better job of telling a hot working set from cold pages. The series has been run on desktops, large servers, an Android phone, and x86_64 and arm64 virtual machines, covering databases and ordinary applications, with reports from other testers as well. Gains vary from flat to dramatic.

The change that matters for deployment is the metric, not the benchmark. MGLRU has long under-counted pressure-stall information and produced unstable readings of the active working set. Cloud platforms such as Kubernetes derive a pod's working set from that figure and use it to decide what to evict. Operators have turned MGLRU off to get a number they can trust. Song calls that a major blocker to rolling the feature out widely, and the series redefines the active working-set metric so those readings stop flickering.

The design borrows from least-frequently-used caching without abandoning generation-based reclaim. Accesses raise a bounded reference count; once that count crosses a threshold the page moves into a newer generation and the count is capped again. A page in a newer generation with a lower count is treated as hotter than an older page with a higher count, so aging the generations cools everything without rewriting every page. Page-table accesses and file-descriptor accesses are balanced by a defined rule. Song describes most of this as reconnecting mechanisms MGLRU already had, including a softer tier-protection ratio now that promotion happens at access time rather than only after pages have already been evicted and faulted back in.

The same series also stops treating the referenced and working-set page flags as independent bits. Under MGLRU they are the low bits of the reference count, and writing them directly has been corrupting that count in DAMON page-out, huge-page collapse, madvise cold and page-out hints, and the per-process memory stats in procfs. Those paths now read and clear the count through helpers, and one page flag is dropped. Classical LRU behavior is left alone.

The series is rebased on the memory-management tree that already includes a separate swappiness rework. It is a proposal, not a merged change.