Towards Unified and Extensible Memory Reclaim (reclaim_ext)
Subsystems (2)
The Problem
-----------
Memory reclaim in the kernel is a mess. We ship two completely separate eviction algorithms -- traditional LRU and MGLRU -- in the same file. mm/vmscan.c is over 8,000 lines. 40% of it is MGLRU-specific code that duplicates functionality already present in the traditional path. Every bug fix, every optimization, every feature has to be done twice or it only works for half the users. This is not sustainable. It has to stop.
We should unify both algorithms into a single code path. In this path, both algorithms are a set of hooks called from that path. Everyone maintains, understands, and evolves a single codebase. Optimizations are now evaluated against -- and available to -- both algorithms. And the next time someone develops a new LRU algorithm, they can do so in a way that does not add churn to existing code.
How We Got Here
---------------
MGLRU brought interesting ideas -- multi-generation aging, page table scanning, Bloom filters, spatial lookaround. But we never tried to refactor the existing reclaim code or integrate these mechanisms into the traditional path. 3,300 lines of code were dumped as a completely parallel implementation with a runtime toggle to switch between the two. No attempt to evolve the existing code or share mechanisms between the two paths -- just a second reclaim system bolted on next to the first.
To be fair, traditional reclaim is not easy to refactor. It has accumulated decades of heuristics trying to work for every workload, and touching any of it risks regressions. But difficulty is not an excuse. There was no justification for not even trying -- not attempting to generalize the existing scanning path, not proposing shared abstractions, not offering the new mechanisms as improvements to the code that was already there. Hard does not mean impossible, and the cost of not trying is what we are living with now.
The Differences That Matter
---------------------------
The two algorithms differ in how they classify pages, detect access, and decide what to evict. But most of these differences are not fundamental -- they are mechanisms that got trapped inside one implementation when they could benefit both. Not making those mechanisms shareable leaves potential free performance gains on the table.
Access detection: Traditional LRU walks reverse mappings (RMAP) from the page back to its page table entries. MGLRU walks page tables forward, scanning process address spaces directly. Neither approach is inherently tied to its eviction policy. Page table scanning would benefit traditional LRU just as much -- it is cache-friendly, batches updates without the LRU lock, and naturally exploits spatial locality. There is no reason this should be MGLRU-only.
Bloom filters and lookaround: MGLRU uses Bloom filters to skip cold page table regions and a lookaround optimization to scan adjacent PTEs during eviction. These are general-purpose optimizations for any scanning path. They are locked inside MGLRU today for no good reason.
Lock-free age updates: MGLRU updates folio age using atomic flag operations, avoiding the LRU lock during scanning. Traditional reclaim can use the same technique to reduce lock contention.
Page classification: Traditional LRU uses two buckets (active/inactive). MGLRU uses four generations with timestamps and reference frequency tiers. This is the policy difference -- how many age buckets and how pages move between them. Every other mechanism is shareable.
Both systems already share the core reclaim mechanics -- writeback, unmapping, swap, NUMA demotion, and working set tracking. The shareable mechanisms listed above should join that common core. What remains after that is a thin policy layer -- and that is all that should differ between algorithms.
The Fix: One Reclaim, Pluggable and Extensible
-----------------------------------------------
We need one reclaim system, not two. One code path that everyone maintains, everyone tests, and everyone benefits from. But it needs to be pluggable as there will always be cases where someone wants some customization for their specialized workload or wants to explore some new techniques/ideas, and we do not want to get into the current mess again.
The unified reclaim must separate mechanism from policy. The mechanisms -- writeback, unmapping, swap, NUMA demotion, workingset tracking -- are shared today and should stay shared. The policy decisions -- how to detect access, how to classify pages, which pages to evict, when to protect a page -- are where the two algorithms differ, and where future algorithms will differ too. Make those pluggable.
This gives us one maintained code path with the flexibility to evolve. New ideas get implemented as new policies, not as 3,000-line forks. Good mechanisms from MGLRU (page table scanning, Bloom filters, lookaround) become shared infrastructure available to any policy. And if someone comes up with a better eviction algorithm tomorrow, they plug it in without touching the core.
Making reclaim pluggable implies we define it as a set of function methods (let's call them reclaim_ops) hooking into a stable codebase we rarely modify. We then have two big questions to answer: how do these reclaim ops look, and how do we move the existing code to the new model?
How Do We Get There
-------------------
Do we merge the two mechanisms feature by feature, or do we prioritize moving MGLRU to the pluggable model then follow with LRU once we are happy with the result?
Whichever option we choose, we do the work in small, self-contained phases. Each phase ships independently, each phase makes the code better, each phase is bisectable. No big bang. No disruption. No excuses.
Option A: Factor and Merge
MGLRU is already pretty modular. However, we do not know which optimizations are actually generic and which ones are only useful for MGLRU itself.
Phase 1 -- Factor out just MGLRU into reclaim_ops. We make no functional changes to MGLRU. Traditional LRU code is left completely untouched at this stage.
Phase 2 -- Merge the two paths one method at a time. Right now the code diverts control to MGLRU from the very top of the high-level hooks. We instead unify the algorithms starting from the very beginning of LRU and deciding what to keep in common code and what to move into a traditional LRU path.
Advantages:
- We do not touch LRU until Phase 2, avoiding churn.
- Makes it easy to experiment with combining MGLRU features into traditional LRU. We do not actually know which optimizations are useful and which should stay in MGLRU hooks.
Disadvantages:
- We will not find out whether reclaim_ops exposes the right methods until we merge the paths at the end. We will have to change the ops if it turns out we need a different split. The reclaim_ops API will be private and have a single user so it is not that bad, but it may require additional changes.
Option B: Merge and Factor
Phase 1 -- Extract MGLRU mechanisms into shared infrastructure. Page table scanning, Bloom filter PMD skipping, lookaround, lock-free folio age updates. These are independently useful. Make them available to both algorithms. Stop hoarding good ideas inside one code path.
Phase 2 -- Collapse the remaining differences. Generalize list infrastructure to N classifications (trad=2, MGLRU=4). Unify eviction entry points. Common classification/promotion interface. At this point the two "algorithms" are thin wrappers over shared code.
Phase 3 -- Define the hook interface. Define reclaim_ops around the remaining policy differences. Layer BPF on top (reclaim_ext). Traditional LRU and MGLRU become two instances of the same interface. Adding a third algorithm means writing a new set of hooks, not forking 3,000 lines.
Advantages:
- We get signals on what should be shared earlier. We know every shared method to be useful because we use it for both algorithms.
- Can test LRU optimizations on MGLRU early.
Disadvantages:
- Slower, as we factor out both algorithms and expand reclaim_ops all at once.
Open Questions
--------------
- Policy granularity: system-wide, per-node, or per-cgroup?
- Mechanism/policy boundary: needs iteration; get it wrong and we either constrain policies or duplicate code.
- Validation: reclaim quality is hard to measure; we need agreed-upon benchmarks.
- Simplicity: the end result must be simpler than what we have today, not more complex. If it is not simpler, we failed.
Signature · 1 line
2.52.0
Quoted 176 lines · Shakeel Butt
The Problem
-----------Memory reclaim in the kernel is a mess. We ship two completely separate eviction algorithms -- traditional LRU and MGLRU -- in the same file.
mm/vmscan.cis over 8,000 lines. 40% of it is MGLRU-specific code that duplicates functionality already present in the traditional path. Every bug fix, every optimization, every feature has to be done twice or it only works for half the users. This is not sustainable. It has to stop.We should unify both algorithms into a single code path. In this path, both algorithms are a set of hooks called from that path. Everyone maintains, understands, and evolves a single codebase. Optimizations are now evaluated against -- and available to -- both algorithms. And the next time someone develops a new LRU algorithm, they can do so in a way that does not add churn to existing code.
How We Got Here
---------------MGLRU brought interesting ideas -- multi-generation aging, page table scanning, Bloom filters, spatial lookaround. But we never tried to refactor the existing reclaim code or integrate these mechanisms into the traditional path. 3,300 lines of code were dumped as a completely parallel implementation with a runtime toggle to switch between the two. No attempt to evolve the existing code or share mechanisms between the two paths -- just a second reclaim system bolted on next to the first.
To be fair, traditional reclaim is not easy to refactor. It has accumulated decades of heuristics trying to work for every workload, and touching any of it risks regressions. But difficulty is not an excuse. There was no justification for not even trying -- not attempting to generalize the existing scanning path, not proposing shared abstractions, not offering the new mechanisms as improvements to the code that was already there. Hard does not mean impossible, and the cost of not trying is what we are living with now.
The Differences That Matter
---------------------------The two algorithms differ in how they classify pages, detect access, and decide what to evict. But most of these differences are not fundamental -- they are mechanisms that got trapped inside one implementation when they could benefit both. Not making those mechanisms shareable leaves potential free performance gains on the table.
Access detection: Traditional LRU walks reverse mappings (RMAP) from the page back to its page table entries. MGLRU walks page tables forward, scanning process address spaces directly. Neither approach is inherently tied to its eviction policy. Page table scanning would benefit traditional LRU just as much -- it is cache-friendly, batches updates without the LRU lock, and naturally exploits spatial locality. There is no reason this should be MGLRU-only.
Bloom filters and lookaround: MGLRU uses Bloom filters to skip cold page table regions and a lookaround optimization to scan adjacent PTEs during eviction. These are general-purpose optimizations for any scanning path. They are locked inside MGLRU today for no good reason.
Lock-free age updates: MGLRU updates folio age using atomic flag operations, avoiding the LRU lock during scanning. Traditional reclaim can use the same technique to reduce lock contention.
Page classification: Traditional LRU uses two buckets (active/inactive). MGLRU uses four generations with timestamps and reference frequency tiers. This is the policy difference -- how many age buckets and how pages move between them. Every other mechanism is shareable.
Both systems already share the core reclaim mechanics -- writeback, unmapping, swap, NUMA demotion, and working set tracking. The shareable mechanisms listed above should join that common core. What remains after that is a thin policy layer -- and that is all that should differ between algorithms.
The Fix: One Reclaim, Pluggable and Extensible
-----------------------------------------------We need one reclaim system, not two. One code path that everyone maintains, everyone tests, and everyone benefits from. But it needs to be pluggable as there will always be cases where someone wants some customization for their specialized workload or wants to explore some new techniques/ideas, and we do not want to get into the current mess again.
The unified reclaim must separate mechanism from policy. The mechanisms -- writeback, unmapping, swap, NUMA demotion, workingset tracking -- are shared today and should stay shared. The policy decisions -- how to detect access, how to classify pages, which pages to evict, when to protect a page -- are where the two algorithms differ, and where future algorithms will differ too. Make those pluggable.
This gives us one maintained code path with the flexibility to evolve. New ideas get implemented as new policies, not as 3,000-line forks. Good mechanisms from MGLRU (page table scanning, Bloom filters, lookaround) become shared infrastructure available to any policy. And if someone comes up with a better eviction algorithm tomorrow, they plug it in without touching the core.
Making reclaim pluggable implies we define it as a set of function methods (let's call them
reclaim_ops) hooking into a stable codebase we rarely modify. We then have two big questions to answer: how do these reclaim ops look, and how do we move the existing code to the new model?How Do We Get There
-------------------Do we merge the two mechanisms feature by feature, or do we prioritize moving MGLRU to the pluggable model then follow with LRU once we are happy with the result?
Whichever option we choose, we do the work in small, self-contained phases. Each phase ships independently, each phase makes the code better, each phase is bisectable. No big bang. No disruption. No excuses.
Option A: Factor and Merge
MGLRU is already pretty modular. However, we do not know which optimizations are actually generic and which ones are only useful for MGLRU itself.
Phase 1 -- Factor out just MGLRU into
reclaim_ops. We make no functional changes to MGLRU. Traditional LRU code is left completely untouched at this stage.Phase 2 -- Merge the two paths one method at a time. Right now the code diverts control to MGLRU from the very top of the high-level hooks. We instead unify the algorithms starting from the very beginning of LRU and deciding what to keep in common code and what to move into a traditional LRU path.
Advantages:
- We do not touch LRU until Phase 2, avoiding churn.
- Makes it easy to experiment with combining MGLRU features into traditional LRU. We do not actually know which optimizations are useful and which should stay in MGLRU hooks.Disadvantages:
- We will not find out whetherreclaim_opsexposes the right methods until we merge the paths at the end. We will have to change the ops if it turns out we need a different split. Thereclaim_opsAPI will be private and have a single user so it is not that bad, but it may require additional changes.Option B: Merge and Factor
Phase 1 -- Extract MGLRU mechanisms into shared infrastructure. Page table scanning, Bloom filter PMD skipping, lookaround, lock-free folio age updates. These are independently useful. Make them available to both algorithms. Stop hoarding good ideas inside one code path.
Phase 2 -- Collapse the remaining differences. Generalize list infrastructure to N classifications (trad=2, MGLRU=4). Unify eviction entry points. Common classification/promotion interface. At this point the two "algorithms" are thin wrappers over shared code.
Phase 3 -- Define the hook interface. Define
reclaim_opsaround the remaining policy differences. Layer BPF on top (reclaim_ext). Traditional LRU and MGLRU become two instances of the same interface. Adding a third algorithm means writing a new set of hooks, not forking 3,000 lines.Advantages:
- We get signals on what should be shared earlier. We know every shared method to be useful because we use it for both algorithms.
- Can test LRU optimizations on MGLRU early.Disadvantages:
- Slower, as we factor out both algorithms and expandreclaim_opsall at once.Open Questions
--------------
Quoted 10 lines
- Policy granularity: system-wide, per-node, or per-cgroup?
- Mechanism/policy boundary: needs iteration; get it wrong and we either constrain policies or duplicate code.
- Validation: reclaim quality is hard to measure; we need agreed-upon benchmarks.
- Simplicity: the end result must be simpler than what we have today, not more complex. If it is not simpler, we failed.
--
2.52.0
Hi Shakeel,
Nice outline, I'd be quite interested in this discussion. It's a little difficult for me to imagine a reclaim_ops getting us to complete convergence, but it seems like a good way to start making progress.
Unfortuantely I got an LSFMM Invitation Decline, so I won't be there. Take good notes. :)
-T.J.
Andrew Morton
maintainerQuoted 1 line · On Wed, 25 Mar 2026 14:06:37 -0700 Shakeel Butt <[email protected]> wrote:
We should unify both algorithms into a single code path.
I'm here to ask the questions which others fear will sound dumb.
Is it indeed the plan to maintain both implementations? I thought the long-term ambition was to knock MGLRU into shape and to drop the legacy LRU?
And that Linus has expressed such a desire, but my googling fails me.
Quoted 5 lines · Andrew Morton
Quoted 1 line · On Wed, 25 Mar 2026 14:06:37 -0700 Shakeel Butt <[email protected]> wrote:
We should unify both algorithms into a single code path.
I'm here to ask the questions which others fear will sound dumb.
Not dumb at all and recently discussed here https://lore.kernel.org/all/CAMgjq7AkYOtUL2HuZjBu5dJw=RTL7W2L1+zVv=SCOyHKYwc3AA@mail.gmail.com/T/#u
Quoted 2 lines
Is it indeed the plan to maintain both implementations? I thought the long-term ambition was to knock MGLRU into shape and to drop the legacy LRU?
Yes, but MGLRU is not there yet and with development pace last year or so we are not much closer than at the time MGLRU has been merged unfortunatelly.
Signature · 2 lines
Michal Hocko SUSE Labs
Quoted 9 lines · Shakeel Butt
The Problem
-----------Memory reclaim in the kernel is a mess. We ship two completely separate eviction algorithms -- traditional LRU and MGLRU -- in the same file.
mm/vmscan.cis over 8,000 lines. 40% of it is MGLRU-specific code that duplicates functionality already present in the traditional path. Every bug fix, every optimization, every feature has to be done twice or it only works for half the users. This is not sustainable. It has to stop.
While I do agree that having 2 implementations available and to maintain them is not long term sustainable I would disagree with your above line of argumentation. We are not aiming to have the two in feature parity nor they are overlapping in bug space all that much.
Quoted 2 lines
We should unify both algorithms into a single code path. In this path, both algorithms are a set of hooks called from that path.
Isn't this the case from a large part? MGRLU tends to have couple of entry points in the shared code base (node/memcg scanning code).
Quoted 5 lines
Everyone
maintains, understands, and evolves a single codebase. Optimizations are now evaluated against -- and available to -- both algorithms. And the next time someone develops a new LRU algorithm, they can do so in a way that does not add churn to existing code.
I think we should focus to make a single canonical reclaim implementation work well. I.e. we deal with most (or ideally all) known regressions of MGLRU. In the initial presentation of the MGRLU framework we were told that the implemenation should be extensible to provide more creative aging algorithms etc.
Quoted 9 lines
The Fix: One Reclaim, Pluggable and Extensible
-----------------------------------------------We need one reclaim system, not two. One code path that everyone maintains, everyone tests, and everyone benefits from. But it needs to be pluggable as there will always be cases where someone wants some customization for their specialized workload or wants to explore some new techniques/ideas, and we do not want to get into the current mess again.
I would go that way only if/after we are done with MGLRU unification and after we will have depleted the potential of that approach and hit cases where we cannot implement new extensions without going $foo_ext way. TBH I am not convinced "make it pluginable to solve hard problems" is the best way forward.
Signature · 2 lines
Michal Hocko SUSE Labs
Quoted 199 lines
-----Original Message-----
From: [email protected] <[email protected]> On Behalf Of Shakeel Butt
Sent: Thursday, March 26, 2026 5:07 AM
To: [email protected]
Cc: Andrew Morton <[email protected]>; Johannes Weiner <[email protected]>; David Hildenbrand <[email protected]>; Michal Hocko <[email protected]>; Qi Zheng <[email protected]>; Lorenzo Stoakes <[email protected]>; Chen Ridong <[email protected]>; Emil Tsalapatis <[email protected]>; Alexei Starovoitov <[email protected]>; Axel Rasmussen <[email protected]>; Yuanchu Xie <[email protected]>; Wei Xu <[email protected]>; Kairui Song <[email protected]>; Matthew Wilcox <[email protected]>; Nhat Pham <[email protected]>; Gregory Price <[email protected]>; Barry Song <[email protected]>; David Stevens <[email protected]>; Vernon Yang <[email protected]>; David Rientjes <[email protected]>; Kalesh Singh <[email protected]>; wangzicheng <[email protected]>; T . J . Mercier <[email protected]>; Baolin Wang <[email protected]>; Suren Baghdasaryan <[email protected]>; Meta kernel team <[email protected]>; [email protected]; [email protected]; [email protected]
Subject: [LSF/MM/BPF TOPIC] Towards Unified and Extensible Memory Reclaim (reclaim_ext)The Problem
-----------Memory reclaim in the kernel is a mess. We ship two completely separate eviction algorithms -- traditional LRU and MGLRU -- in the same file.
mm/vmscan.cis over 8,000 lines. 40% of it is MGLRU-specific code that duplicates functionality already present in the traditional path. Every bug fix, every optimization, every feature has to be done twice or it only works for half the users. This is not sustainable. It has to stop.We should unify both algorithms into a single code path. In this path, both algorithms are a set of hooks called from that path. Everyone maintains, understands, and evolves a single codebase. Optimizations are now evaluated against -- and available to -- both algorithms. And the next time someone develops a new LRU algorithm, they can do so in a way that does not add churn to existing code.
How We Got Here
---------------MGLRU brought interesting ideas -- multi-generation aging, page table scanning, Bloom filters, spatial lookaround. But we never tried to refactor the existing reclaim code or integrate these mechanisms into the traditional path. 3,300 lines of code were dumped as a completely parallel implementation with a runtime toggle to switch between the two.
No attempt to evolve the existing code or share mechanisms between the two paths -- just a second reclaim system bolted on next to the first.To be fair, traditional reclaim is not easy to refactor. It has accumulated decades of heuristics trying to work for every workload, and touching any of it risks regressions. But difficulty is not an excuse.
There was no justification for not even trying -- not attempting to generalize the existing scanning path, not proposing shared abstractions, not offering the new mechanisms as improvements to the code that was already there. Hard does not mean impossible, and the cost of not trying is what we are living with now.The Differences That Matter
---------------------------The two algorithms differ in how they classify pages, detect access, and decide what to evict. But most of these differences are not fundamental -- they are mechanisms that got trapped inside one implementation when they could benefit both. Not making those mechanisms shareable leaves potential free performance gains on the table.
Access detection: Traditional LRU walks reverse mappings (RMAP) from the page back to its page table entries. MGLRU walks page tables forward, scanning process address spaces directly. Neither approach is inherently tied to its eviction policy. Page table scanning would benefit traditional LRU just as much -- it is cache-friendly, batches updates without the LRU lock, and naturally exploits spatial locality. There is no reason this should be MGLRU- only.
Bloom filters and lookaround: MGLRU uses Bloom filters to skip cold page table regions and a lookaround optimization to scan adjacent PTEs during eviction. These are general-purpose optimizations for any scanning path. They are locked inside MGLRU today for no good reason.
Lock-free age updates: MGLRU updates folio age using atomic flag operations, avoiding the LRU lock during scanning. Traditional reclaim can use the same technique to reduce lock contention.
Page classification: Traditional LRU uses two buckets (active/inactive). MGLRU uses four generations with timestamps and reference frequency tiers. This is the policy difference -- how many age buckets and how pages move between them. Every other mechanism is shareable.
Both systems already share the core reclaim mechanics -- writeback, unmapping, swap, NUMA demotion, and working set tracking. The shareable mechanisms listed above should join that common core. What remains after that is a thin policy layer -- and that is all that should differ between algorithms.
The Fix: One Reclaim, Pluggable and Extensible
-----------------------------------------------We need one reclaim system, not two. One code path that everyone maintains, everyone tests, and everyone benefits from. But it needs to be pluggable as there will always be cases where someone wants some customization for their specialized workload or wants to explore some new techniques/ideas, and we do not want to get into the current mess again.
The unified reclaim must separate mechanism from policy. The mechanisms -- writeback, unmapping, swap, NUMA demotion, workingset tracking -- are shared today and should stay shared. The policy decisions -- how to detect access, how to classify pages, which pages to evict, when to protect a page -- are where the two algorithms differ, and where future algorithms will differ too. Make those pluggable.
This gives us one maintained code path with the flexibility to evolve. New ideas get implemented as new policies, not as 3,000-line forks. Good mechanisms from MGLRU (page table scanning, Bloom filters, lookaround) become shared infrastructure available to any policy. And if someone comes up with a better eviction algorithm tomorrow, they plug it in without touching the core.
Making reclaim pluggable implies we define it as a set of function methods (let's call them
reclaim_ops) hooking into a stable codebase we rarely modify. We then have two big questions to answer: how do these reclaim ops look, and how do we move the existing code to the new model?How Do We Get There
-------------------Do we merge the two mechanisms feature by feature, or do we prioritize moving MGLRU to the pluggable model then follow with LRU once we are happy with the result?
Whichever option we choose, we do the work in small, self-contained phases. Each phase ships independently, each phase makes the code better, each phase is bisectable. No big bang. No disruption. No excuses.
Option A: Factor and Merge
MGLRU is already pretty modular. However, we do not know which optimizations are actually generic and which ones are only useful for MGLRU itself.
Phase 1 -- Factor out just MGLRU into
reclaim_ops. We make no functional changes to MGLRU. Traditional LRU code is left completely untouched at this stage.Phase 2 -- Merge the two paths one method at a time. Right now the code diverts control to MGLRU from the very top of the high-level hooks. We instead unify the algorithms starting from the very beginning of LRU and deciding what to keep in common code and what to move into a traditional LRU path.
Advantages:
- We do not touch LRU until Phase 2, avoiding churn.
- Makes it easy to experiment with combining MGLRU features into traditional LRU. We do not actually know which optimizations are useful and which should stay in MGLRU hooks.Disadvantages:
- We will not find out whetherreclaim_opsexposes the right methods until we merge the paths at the end. We will have to change the ops if it turns out we need a different split. Thereclaim_opsAPI will be private and have a single user so it is not that bad, but it may require additional changes.Option B: Merge and Factor
Phase 1 -- Extract MGLRU mechanisms into shared infrastructure. Page table scanning, Bloom filter PMD skipping, lookaround, lock-free folio age updates. These are independently useful. Make them available to both algorithms. Stop hoarding good ideas inside one code path.
Phase 2 -- Collapse the remaining differences. Generalize list infrastructure to N classifications (trad=2, MGLRU=4). Unify eviction entry points. Common classification/promotion interface. At this point the two "algorithms" are thin wrappers over shared code.
Phase 3 -- Define the hook interface. Define
reclaim_opsaround the remaining policy differences. Layer BPF on top (reclaim_ext). Traditional LRU and MGLRU become two instances of the same interface. Adding a third algorithm means writing a new set of hooks, not forking 3,000 lines.Advantages:
- We get signals on what should be shared earlier. We know every shared method to be useful because we use it for both algorithms.
- Can test LRU optimizations on MGLRU early.Disadvantages:
- Slower, as we factor out both algorithms and expandreclaim_opsall at once.Open Questions
--------------
Quoted 10 lines
- Policy granularity: system-wide, per-node, or per-cgroup?
- Mechanism/policy boundary: needs iteration; get it wrong and we either constrain policies or duplicate code.
- Validation: reclaim quality is hard to measure; we need agreed-upon benchmarks.
- Simplicity: the end result must be simpler than what we have today, not more complex. If it is not simpler, we failed.
--
2.52.0
Hi Shakeel,
The reclaim_ops direction looks very promising. I'd be interested in the discussion.
We are particularly interested in the individual effects of several mechanisms currently bundled in MGLRU. reclaim_ops would provide a great opportunity to run ablation experiments, e.g. testing traditional LRU with page table scanning.
On policy granularity, it would also be interesting to see something like ``reclaim_ext''[1,2] taking control at different levels, similar to what sched_ext does for scheduling policies.
Best,
Zicheng
[1] cache_ext: Customizing the Page Cache with eBPF
[2] PageFlex: Flexible and Efficient User-space Delegation of Linux Paging Policies with eBPF
Quoted 7 lines · Michal Hocko
Quoted 5 lines · Andrew Morton
Quoted 1 line · On Wed, 25 Mar 2026 14:06:37 -0700 Shakeel Butt <[email protected]> wrote:
We should unify both algorithms into a single code path.
I'm here to ask the questions which others fear will sound dumb.
Quoted 8 lines
Not dumb at all and recently discussed here https://lore.kernel.org/all/CAMgjq7AkYOtUL2HuZjBu5dJw=RTL7W2L1+zVv=SCOyHKYwc3AA@mail.gmail.com/T/#u
Quoted 2 lines
Is it indeed the plan to maintain both implementations? I thought the long-term ambition was to knock MGLRU into shape and to drop the legacy LRU?
Yes, but MGLRU is not there yet and with development pace last year or so we are not much closer than at the time MGLRU has been merged unfortunatelly.
I'm quite concerned about maintainership, as it seems the MGLRU maintainers have not been all that active, and the MGLRU to me at least is currently a black box.
I'm not the only one who's raised this (see [0]).
That'd very much have to be resolved and the community reassured that MGLRU is _actively_ maintained before we could even contemplate it replacing the 'classic' reclaim approach IMO.
I hope that Kairu, Barry, Zicheng and others who are interested int it resolve this, however!
Thanks, Lorenzo
[0]:https://lore.kernel.org/linux-mm/[email protected]/
Quoted 3 lines
--
Michal Hocko
SUSE Labs
Quoted 5 lines · Shakeel Butt
The Problem
-----------Memory reclaim in the kernel is a mess. We ship two completely separate eviction algorithms -- traditional LRU and MGLRU -- in the same file.
Agreed :)
Quoted 4 lines
mm/vmscan.cis over 8,000 lines. 40% of it is MGLRU-specific code that duplicates functionality already present in the traditional path. Every bug fix, every optimization, every feature has to be done twice or it only works for half the users. This is not sustainable. It has to stop.
Yup.
Quoted 7 lines
We should unify both algorithms into a single code path. In this path, both algorithms are a set of hooks called from that path. Everyone maintains, understands, and evolves a single codebase. Optimizations are now evaluated against -- and available to -- both algorithms. And the next time someone develops a new LRU algorithm, they can do so in a way that does not add churn to existing code.
Yup. I mean it's less churn more duplication which is a lot worse.
Quoted 11 lines
How We Got Here
---------------MGLRU brought interesting ideas -- multi-generation aging, page table scanning, Bloom filters, spatial lookaround. But we never tried to refactor the existing reclaim code or integrate these mechanisms into the traditional path. 3,300 lines of code were dumped as a completely parallel implementation with a runtime toggle to switch between the two. No attempt to evolve the existing code or share mechanisms between the two paths -- just a second reclaim system bolted on next to the first.
Yeah, I don't love that we accepted it in this form.
With review far sharper now I would hope in future there'd be pushback in at least having better separation in future.
Quoted 9 lines
To be fair, traditional reclaim is not easy to refactor. It has accumulated decades of heuristics trying to work for every workload, and touching any of it risks regressions. But difficulty is not an excuse. There was no justification for not even trying -- not attempting to generalize the existing scanning path, not proposing shared abstractions, not offering the new mechanisms as improvements to the code that was already there. Hard does not mean impossible, and the cost of not trying is what we are living with now.
Yes. Agreed very much so.
Quoted 10 lines
The Differences That Matter
---------------------------The two algorithms differ in how they classify pages, detect access, and decide what to evict. But most of these differences are not fundamental -- they are mechanisms that got trapped inside one implementation when they could benefit both. Not making those mechanisms shareable leaves potential free performance gains on the table.
Quoted 7 lines
Access detection: Traditional LRU walks reverse mappings (RMAP) from the page back to its page table entries. MGLRU walks page tables forward, scanning process address spaces directly. Neither approach is inherently tied to its eviction policy. Page table scanning would benefit traditional LRU just as much -- it is cache-friendly, batches updates without the LRU lock, and naturally exploits spatial locality. There is no reason this should be MGLRU-only.
Right.
Quoted 16 lines
Bloom filters and lookaround: MGLRU uses Bloom filters to skip cold page table regions and a lookaround optimization to scan adjacent PTEs during eviction. These are general-purpose optimizations for any scanning path. They are locked inside MGLRU today for no good reason.
Lock-free age updates: MGLRU updates folio age using atomic flag operations, avoiding the LRU lock during scanning. Traditional reclaim can use the same technique to reduce lock contention.
Page classification: Traditional LRU uses two buckets (active/inactive). MGLRU uses four generations with timestamps and reference frequency tiers. This is the policy difference -- how many age buckets and how pages move between them. Every other mechanism is shareable.
Quoted 5 lines
Both systems already share the core reclaim mechanics -- writeback, unmapping, swap, NUMA demotion, and working set tracking. The shareable mechanisms listed above should join that common core. What remains after that is a thin policy layer -- and that is all that should differ between algorithms.
Yeah, this all really speaks to the review simply not being sufficient at the time.
Given the data given by Mike at [0], it suggests the recent sub-M changes have made a really big difference to this (I'm genuinely pleasantly surprised by that!) so hopefully this is something we'll avoid in future.
[0]:https://lore.kernel.org/linux-mm/[email protected]/
Quoted 10 lines
The Fix: One Reclaim, Pluggable and Extensible
-----------------------------------------------We need one reclaim system, not two. One code path that everyone maintains, everyone tests, and everyone benefits from. But it needs to be pluggable as there will always be cases where someone wants some customization for their specialized workload or wants to explore some new techniques/ideas, and we do not want to get into the current mess again.
OK so I was with you up until the pluggable bit :) it's like you're combining two things here, obviously - unification and pluggability.
I think we should consider both separately.
I also hope that as a result of this those who are involved in unification gain understanding and some at least are able to perhaps become _active_ co-maintainers/reviewers? As this is a major concern see [1].
[1]:https://lore.kernel.org/linux-mm/[email protected]/
Quoted 7 lines
The unified reclaim must separate mechanism from policy. The mechanisms -- writeback, unmapping, swap, NUMA demotion, workingset tracking -- are shared today and should stay shared. The policy decisions -- how to detect access, how to classify pages, which pages to evict, when to protect a page -- are where the two algorithms differ, and where future algorithms will differ too. Make those pluggable.
Again you're saying sane things than adding on 'pluggable' :)
Let me address pluggability concerns further down I guess.
Quoted 2 lines
This gives us one maintained code path with the flexibility to evolve.
I like 'maintained' here :)
Quoted 10 lines
New ideas get implemented as new policies, not as 3,000-line forks. Good mechanisms from MGLRU (page table scanning, Bloom filters, lookaround) become shared infrastructure available to any policy. And if someone comes up with a better eviction algorithm tomorrow, they plug it in without touching the core.
Making reclaim pluggable implies we define it as a set of function methods (let's call them
reclaim_ops) hooking into a stable codebase we rarely modify. We then have two big questions to answer: how do these reclaim ops look, and how do we move the existing code to the new model?
Hmm, I'm not so sure about that. But it depends really on who has access to these operations.
The issue with operations in general is that they eliminate the possibility of the general code being able to make assumptions about what's happening.
For instance, the .mmap f_op callback meant that we had to account for any possible thing being done by a driver. You couldn't make assumptions about vma state, page table state, etc. and of course things happened that we didn't anticipate, leading to bugs.
So I guess it's less 'no ops' more so 'what do we actually expose to the ops', 'what assumptions do we bake in about how the ops are used' and very importantly - 'who gets to populate them'.
If they're _exclusively_ mm-internal then that's fine.
Reclaim is a _very_ _very_ sensitive part of mm. At the point it's being activated you may be under extreme memory pressure, so a hook even allocating at all may either fail or enter infinite loops.
We are also very sensitive on things like rmap locks and also, of course, - timing.
It's not just a perf concern, if we are too slow, we might end up thrashing when we could otherwise not have.
Also there ends up being a question of how much now-internal functionality we end up exposing to users.
So we really need a good definition of who we intend should use this stuff, and how any such interface should be designed.
I mean, if sufficiently abstracted, and with very carefully restricted constrainst perhaps we could work around a lot of this but we have to tread _very_ carefully here.
Quoted 7 lines
How Do We Get There
-------------------Do we merge the two mechanisms feature by feature, or do we prioritize moving MGLRU to the pluggable model then follow with LRU once we are happy with the result?
Absolutely by a distance the first is preferable. The pluggability is controversial here and needs careful consideration.
Eliminating redundancy and ensuring broader community maintainership is easily more important.
Quoted 28 lines
Whichever option we choose, we do the work in small, self-contained phases. Each phase ships independently, each phase makes the code better, each phase is bisectable. No big bang. No disruption. No excuses.
Option A: Factor and Merge
MGLRU is already pretty modular. However, we do not know which optimizations are actually generic and which ones are only useful for MGLRU itself.
Phase 1 -- Factor out just MGLRU into
reclaim_ops. We make no functional changes to MGLRU. Traditional LRU code is left completely untouched at this stage.Phase 2 -- Merge the two paths one method at a time. Right now the code diverts control to MGLRU from the very top of the high-level hooks. We instead unify the algorithms starting from the very beginning of LRU and deciding what to keep in common code and what to move into a traditional LRU path.
Advantages:
- We do not touch LRU until Phase 2, avoiding churn.
- Makes it easy to experiment with combining MGLRU features into traditional LRU. We do not actually know which optimizations are useful and which should stay in MGLRU hooks.
Quoted 6 lines
Disadvantages:
- We will not find out whetherreclaim_opsexposes the right methods until we merge the paths at the end. We will have to change the ops if it turns out we need a different split. Thereclaim_opsAPI will be private and have a single user so it is not that bad, but it may require additional changes.
Yup this to me renders this totally not an option.
Quoted 19 lines
Option B: Merge and Factor
Phase 1 -- Extract MGLRU mechanisms into shared infrastructure. Page table scanning, Bloom filter PMD skipping, lookaround, lock-free folio age updates. These are independently useful. Make them available to both algorithms. Stop hoarding good ideas inside one code path.
Phase 2 -- Collapse the remaining differences. Generalize list infrastructure to N classifications (trad=2, MGLRU=4). Unify eviction entry points. Common classification/promotion interface. At this point the two "algorithms" are thin wrappers over shared code.
Phase 3 -- Define the hook interface. Define
reclaim_opsaround the remaining policy differences. Layer BPF on top (reclaim_ext). Traditional LRU and MGLRU become two instances of the same interface. Adding a third algorithm means writing a new set of hooks, not forking 3,000 lines.
Quoted 8 lines
Advantages:
- We get signals on what should be shared earlier. We know every shared method to be useful because we use it for both algorithms.
- Can test LRU optimizations on MGLRU early.Disadvantages:
- Slower, as we factor out both algorithms and expandreclaim_opsall at once.
Much preferable thanks. I'd rather we deferred the pluggability stuff.
Quoted 5 lines
Open Questions
--------------- Policy granularity: system-wide, per-node, or per-cgroup?
Well, we have varying levers to pull at least per-cgroup/system-wide.
I wonder if we could add improved documentation on this overall by the way :) just a thought.
A general reclaim page that mentions cgroup stuff also (can link back to cgroup pages) so a 'one stop shop' for reclaim/(perhaps also) reclaim-adjacent writeback, etc. controls could be useful.
Quoted 5 lines
- Mechanism/policy boundary: needs iteration; get it wrong and we either constrain policies or duplicate code.
- Validation: reclaim quality is hard to measure; we need agreed-upon benchmarks.
Yes, it'd be great to get some standardised set of tests to ensure correct behaviour, though how we set those up might be tricky.
Perhaps somehow some qemu/libvirt configurations with very tightly specified environments intended to trigger various reclaim behaviours, with some specific measurements (bpf, ftrace, procfs, etc.?) to correctly observe the behaviours in place?
Quoted 2 lines
- Simplicity: the end result must be simpler than what we have today, not more complex. If it is not simpler, we failed.
Yeah that's a nice aim :)
Quoted 3 lines
--
2.52.0
Thanks, Lorenzo
Quoted 9 lines · Andrew Morton
Quoted 1 line · On Wed, 25 Mar 2026 14:06:37 -0700 Shakeel Butt <[email protected]> wrote:
We should unify both algorithms into a single code path.
I'm here to ask the questions which others fear will sound dumb.
Is it indeed the plan to maintain both implementations? I thought the long-term ambition was to knock MGLRU into shape and to drop the legacy LRU?
I personally also agree on that, so far I'm not aware of any major issues with MGLRU except some corner cases that are not hard to fix. Once these are done, I don't see the need for more complexity.
Quoted 1 line
And that Linus has expressed such a desire, but my googling fails me.
+cc Gregory
Quoted 7 lines · Kairui Song
Quoted 5 lines · Andrew Morton
Quoted 1 line · On Wed, 25 Mar 2026 14:06:37 -0700 Shakeel Butt <[email protected]> wrote:
We should unify both algorithms into a single code path.
Quoted 8 lines
Quoted 4 lines
I'm here to ask the questions which others fear will sound dumb.
Is it indeed the plan to maintain both implementations? I thought the long-term ambition was to knock MGLRU into shape and to drop the legacy LRU?
I personally also agree on that, so far I'm not aware of any major issues with MGLRU except some corner cases that are not hard to fix. Once these are done, I don't see the need for more complexity.
Well... :)
What about the issues Gregory raised here?
https://lore.kernel.org/linux-mm/aaXM7xNSJaJBsety@gourry-fedora-PF4VCD3F/
Quoted 3 lines
Quoted 3 lines
And that Linus has expressed such a desire, but my googling fails me.
Yup I know, and it'd be ideal to have a single approach, but we definitely need a little more assurance this time that it's the right choice :)
In any case I do agree with Shakeel that de-duplicating the code and 'stealing' good ideas from it for both flavours of reclaim at least to start with is a good way forwards.
Once we've done that, we can work towards eliminating the 'classic' reclaim if the data supports it.
Thanks, Lorenzo
Quoted 21 lines · Lorenzo Stoakes (Oracle)
Quoted 7 lines · Michal Hocko
Quoted 5 lines · Andrew Morton
Quoted 1 line · On Wed, 25 Mar 2026 14:06:37 -0700 Shakeel Butt <[email protected]> wrote:
We should unify both algorithms into a single code path.
I'm here to ask the questions which others fear will sound dumb.
Quoted 8 lines
Not dumb at all and recently discussed here https://lore.kernel.org/all/CAMgjq7AkYOtUL2HuZjBu5dJw=RTL7W2L1+zVv=SCOyHKYwc3AA@mail.gmail.com/T/#u
Quoted 2 lines
Is it indeed the plan to maintain both implementations? I thought the long-term ambition was to knock MGLRU into shape and to drop the legacy LRU?
Yes, but MGLRU is not there yet and with development pace last year or so we are not much closer than at the time MGLRU has been merged unfortunatelly.
I'm quite concerned about maintainership, as it seems the MGLRU maintainers have not been all that active, and the MGLRU to me at least is currently a black box.
Quoted 8 lines
I'm not the only one who's raised this (see [0]).
That'd very much have to be resolved and the community reassured that MGLRU is _actively_ maintained before we could even contemplate it replacing the 'classic' reclaim approach IMO.
I hope that Kairu, Barry, Zicheng and others who are interested int it resolve this, however!
Hi everyone,
Right, I think we are starting to make good progress on improving MGLRU recently. For the last few years we already have some commits stashed downstream to enable that on our fleet, most of my effort in upstream is spent on other parts like SWAP, really looking forward to making MGLRU better upstreamly.
Yesterday I was still discussing with CachyOS folks about their usage while working on that series for MGLRU cleanup and dirty flush optimization, and got some nice feedback later from their chat server that MGLRU's TTL resolved their thrashing issue very well. With classic LRU they needed a le9 patch downtreamly.
For many other typical workloads under stress, MGLRU performs significantly better too (e.g. database, build kernel could be more than twice as fast), it would be a huge loss to leave it unmaintained.
Barry also provided some really helpful ideas about MGLRU like readahead handling. We are also seeing other vendors and people contributing to MGLRU like Leno and Baolin recently. Things are looking promising.
Quoted 45 lines · Kairui Song
Quoted 21 lines · Lorenzo Stoakes (Oracle)
Quoted 7 lines · Michal Hocko
Quoted 5 lines · Andrew Morton
Quoted 1 line · On Wed, 25 Mar 2026 14:06:37 -0700 Shakeel Butt <[email protected]> wrote:
We should unify both algorithms into a single code path.
I'm here to ask the questions which others fear will sound dumb.
Quoted 8 lines
Not dumb at all and recently discussed here https://lore.kernel.org/all/CAMgjq7AkYOtUL2HuZjBu5dJw=RTL7W2L1+zVv=SCOyHKYwc3AA@mail.gmail.com/T/#u
Quoted 2 lines
Is it indeed the plan to maintain both implementations? I thought the long-term ambition was to knock MGLRU into shape and to drop the legacy LRU?
Yes, but MGLRU is not there yet and with development pace last year or so we are not much closer than at the time MGLRU has been merged unfortunatelly.
I'm quite concerned about maintainership, as it seems the MGLRU maintainers have not been all that active, and the MGLRU to me at least is currently a black box.
Quoted 8 lines
I'm not the only one who's raised this (see [0]).
That'd very much have to be resolved and the community reassured that MGLRU is _actively_ maintained before we could even contemplate it replacing the 'classic' reclaim approach IMO.
I hope that Kairu, Barry, Zicheng and others who are interested int it resolve this, however!
Hi everyone,
Right, I think we are starting to make good progress on improving MGLRU recently. For the last few years we already have some commits stashed downstream to enable that on our fleet, most of my effort in upstream is spent on other parts like SWAP, really looking forward to making MGLRU better upstreamly.
Yesterday I was still discussing with CachyOS folks about their usage while working on that series for MGLRU cleanup and dirty flush optimization, and got some nice feedback later from their chat server that MGLRU's TTL resolved their thrashing issue very well. With classic LRU they needed a le9 patch downtreamly.
Quoted 8 lines
For many other typical workloads under stress, MGLRU performs significantly better too (e.g. database, build kernel could be more than twice as fast), it would be a huge loss to leave it unmaintained.
Barry also provided some really helpful ideas about MGLRU like readahead handling. We are also seeing other vendors and people contributing to MGLRU like Leno and Baolin recently. Things are looking promising.
Guys, can I please make a plea then for you guys to AT LEAST become reviewers in MAINTAINERS please:
MEMORY MANAGEMENT - MGLRU (MULTI-GEN LRU)
M: Andrew Morton <[email protected]>
Well Andrew is Andrew :)
M: Axel Rasmussen <[email protected]>
git log mm/vmscan.c has 0 results.
Axel has however engaged in discussion on
https://lore.kernel.org/linux-mm/[email protected]/
recently for example, but not much in 2025 afaict.
M: Yuanchu Xie <[email protected]>
git log mm/vmscan.c shows 1 result from August 13th 2024.
Yuanchu has engaged in some MGLRU discussion also recently, here and there.
R: Wei Xu <[email protected]>
git log mm/vmscan.c shows 2 results from October 2024.
Wei doesn't look to have engaged in discussion on MGLRU recently.
L: [email protected]
S: Maintained
W: http://www.linux-mm.org
T: git git://git.kernel.org/pub/scm/linux/kernel/git/akpm/mm
F: Documentation/admin-guide/mm/multigen_lru.rst
F: Documentation/mm/multigen_lru.rst
F: include/linux/mm_inline.h
F: include/linux/mmzone.h
F: mm/swap.c
F: mm/vmscan.c
F: mm/workingset.c
It doesn't really feel like MGLRU is currently maintained at all, quite honestly.
So I think we need people to step up here.
Thanks, Lorenzo
Quoted 20 lines · Lorenzo Stoakes (Oracle)
+cc Gregory
Quoted 7 lines · Kairui Song
Quoted 5 lines · Andrew Morton
Quoted 1 line · On Wed, 25 Mar 2026 14:06:37 -0700 Shakeel Butt <[email protected]> wrote:
We should unify both algorithms into a single code path.
Quoted 8 lines
Quoted 4 lines
I'm here to ask the questions which others fear will sound dumb.
Is it indeed the plan to maintain both implementations? I thought the long-term ambition was to knock MGLRU into shape and to drop the legacy LRU?
I personally also agree on that, so far I'm not aware of any major issues with MGLRU except some corner cases that are not hard to fix. Once these are done, I don't see the need for more complexity.
Quoted 5 lines
Well... :)
What about the issues Gregory raised here?
https://lore.kernel.org/linux-mm/aaXM7xNSJaJBsety@gourry-fedora-PF4VCD3F/
Hi,
Thanks for linking Gregory's mail.
I'm not quite sure I fully get what the concern is, I'll try to address the main points I see. Regarding the bi-modal distributions, it's very workload-dependent, and the reclamation still performs well with that distributions. So I think that's not really a problem?
The heuristics are a bit confusing and intertwined (gen number as flags for atomic update and avoid LRU lock, tight coupling with generational aging, etc.), decoupling them cleanly without hurting performance is tricky, and the current approach has worked dramatically well. Cleanup the code structure might be helpful?
Many distros have been running MGLRU by default for years now and the feedback (plus our own production experience) has been very positive. There are indeed some known rough edges, under-protected file cache, ineffective swappiness, flag usage, etc. some of which I listed here [1]. I believe they're all fixable, and once addressed MGLRU should be a solid base.
Right, I realized after re-reading that some of these really are not really easy to fix or improve... sorry for my earlier reply, guess I'm too sleepy today and not thinking clearly :P, my apologies.
[1] https://lore.kernel.org/linux-mm/CAMgjq7BoekNjg-Ra3C8M7=8=75su38w=HD782T5E_cxyeCeH_g@mail.gmail.com/
Quoted 7 lines · Andrew Morton
Quoted 1 line · On Wed, 25 Mar 2026 14:06:37 -0700 Shakeel Butt <[email protected]> wrote:
We should unify both algorithms into a single code path.
I'm here to ask the questions which others fear will sound dumb.
Is it indeed the plan to maintain both implementations?
I think in general the plan/wish was to have one implementation but the current state shows that we are far from where we wish to be.
Quoted 2 lines
I thought the
long-term ambition was to knock MGLRU into shape and to drop the legacy LRU?
That might be the ambition but I don't think there was an agreement and there weren't any efforts to do so. Traditional LRU has been battle tested for decades and thus there were concerns/skepticisms about this ambition as well.
To me, the right way is to take step-by-step approach with clear evaluations and comparison on unifying or selecting a component from one over the other.
Quoted 49 lines · Kairui Song
Quoted 20 lines · Lorenzo Stoakes (Oracle)
+cc Gregory
Quoted 7 lines · Kairui Song
Quoted 5 lines · Andrew Morton
Quoted 1 line · On Wed, 25 Mar 2026 14:06:37 -0700 Shakeel Butt <[email protected]> wrote:
We should unify both algorithms into a single code path.
Quoted 8 lines
Quoted 4 lines
I'm here to ask the questions which others fear will sound dumb.
Is it indeed the plan to maintain both implementations? I thought the long-term ambition was to knock MGLRU into shape and to drop the legacy LRU?
I personally also agree on that, so far I'm not aware of any major issues with MGLRU except some corner cases that are not hard to fix. Once these are done, I don't see the need for more complexity.
Quoted 5 lines
Well... :)
What about the issues Gregory raised here?
https://lore.kernel.org/linux-mm/aaXM7xNSJaJBsety@gourry-fedora-PF4VCD3F/
Hi,
Thanks for linking Gregory's mail.
I'm not quite sure I fully get what the concern is, I'll try to address the main points I see. Regarding the bi-modal distributions, it's very workload-dependent, and the reclamation still performs well with that distributions. So I think that's not really a problem?
The heuristics are a bit confusing and intertwined (gen number as flags for atomic update and avoid LRU lock, tight coupling with generational aging, etc.), decoupling them cleanly without hurting performance is tricky, and the current approach has worked dramatically well. Cleanup the code structure might be helpful?
Many distros have been running MGLRU by default for years now and the feedback (plus our own production experience) has been very positive. There are indeed some known rough edges, under-protected file cache, ineffective swappiness, flag usage, etc. some of which I listed here [1]. I believe they're all fixable, and once addressed MGLRU should be a solid base.
Quoted 5 lines
Right, I realized after re-reading that some of these really are not really easy to fix or improve... sorry for my earlier reply, guess I'm too sleepy today and not thinking clearly :P, my apologies.
[1] https://lore.kernel.org/linux-mm/CAMgjq7BoekNjg-Ra3C8M7=8=75su38w=HD782T5E_cxyeCeH_g@mail.gmail.com/
Thanks, well that's good to hear.
I broadly agree with Shakeel's proposals for the incremental improvement of the LRU code, and I think that and fixing MAINTAINERS (*ahem*) will seriously help move us forwards with this.
I wonder also if we shouldn't have a document on this somewhere in the kernel to lay out the differences, improvements, how the gen numbers work etc.?
Cheers, Lorenzo
Quoted 79 lines · Lorenzo Stoakes (Oracle)
Quoted 29 lines · Kairui Song
Quoted 5 lines · Lorenzo Stoakes (Oracle)
I'm quite concerned about maintainership, as it seems the MGLRU maintainers have not been all that active, and the MGLRU to me at least is currently a black box.
Quoted 8 lines
I'm not the only one who's raised this (see [0]).
That'd very much have to be resolved and the community reassured that MGLRU is _actively_ maintained before we could even contemplate it replacing the 'classic' reclaim approach IMO.
I hope that Kairu, Barry, Zicheng and others who are interested int it resolve this, however!
Hi everyone,
Right, I think we are starting to make good progress on improving MGLRU recently. For the last few years we already have some commits stashed downstream to enable that on our fleet, most of my effort in upstream is spent on other parts like SWAP, really looking forward to making MGLRU better upstreamly.
Yesterday I was still discussing with CachyOS folks about their usage while working on that series for MGLRU cleanup and dirty flush optimization, and got some nice feedback later from their chat server that MGLRU's TTL resolved their thrashing issue very well. With classic LRU they needed a le9 patch downtreamly.
Quoted 8 lines
For many other typical workloads under stress, MGLRU performs significantly better too (e.g. database, build kernel could be more than twice as fast), it would be a huge loss to leave it unmaintained.
Barry also provided some really helpful ideas about MGLRU like readahead handling. We are also seeing other vendors and people contributing to MGLRU like Leno and Baolin recently. Things are looking promising.
Guys, can I please make a plea then for you guys to AT LEAST become reviewers in
MAINTAINERSplease:MEMORY MANAGEMENT - MGLRU (MULTI-GEN LRU)
M: Andrew Morton <[email protected]>Well Andrew is Andrew :)
M: Axel Rasmussen <[email protected]>
git log
mm/vmscan.chas 0 results.Axel has however engaged in discussion on
https://lore.kernel.org/linux-mm/[email protected]/
recently for example, but not much in 2025 afaict.M: Yuanchu Xie <[email protected]>
git log
mm/vmscan.cshows 1 result from August 13th 2024.Yuanchu has engaged in some MGLRU discussion also recently, here and there.
R: Wei Xu <[email protected]>
git log
mm/vmscan.cshows 2 results from October 2024.Wei doesn't look to have engaged in discussion on MGLRU recently.
L: [email protected]
S: Maintained
W: http://www.linux-mm.org
T: gitgit://git.kernel.org/pub/scm/linux/kernel/git/akpm/mm
F:Documentation/admin-guide/mm/multigen_lru.rst
F:Documentation/mm/multigen_lru.rst
F:include/linux/mm_inline.h
F:include/linux/mmzone.h
F:mm/swap.c
F:mm/vmscan.c
F:mm/workingset.c
Quoted 4 lines
It doesn't really feel like MGLRU is currently maintained at all, quite honestly.
So I think we need people to step up here.
Ans some serious cleanup of the entry to reflect who is actually involved nowadays, if at all.
Master of MAINTAINER updates, I assume you'll take care of that?
Signature · 3 lines
Cheers, David
Quoted 11 lines · Michal Hocko
Quoted 9 lines · Shakeel Butt
The Problem
-----------Memory reclaim in the kernel is a mess. We ship two completely separate eviction algorithms -- traditional LRU and MGLRU -- in the same file.
mm/vmscan.cis over 8,000 lines. 40% of it is MGLRU-specific code that duplicates functionality already present in the traditional path. Every bug fix, every optimization, every feature has to be done twice or it only works for half the users. This is not sustainable. It has to stop.
Quoted 4 lines
While I do agree that having 2 implementations available and to maintain them is not long term sustainable I would disagree with your above line of argumentation. We are not aiming to have the two in feature parity nor they are overlapping in bug space all that much.
There is definitely basic set of features which we want from a reclaim mechanism (e.g. writeback and writeback throttling which MGLRU lacked for a long time) and it does not mean we should aim for feature parity.
For the bugs/debugging, we always need to answer if it is impacting one or the other or both.
Quoted 6 lines
Quoted 3 lines
We should unify both algorithms into a single code path. In this path, both algorithms are a set of hooks called from that path.
Isn't this the case from a large part? MGRLU tends to have couple of entry points in the shared code base (node/memcg scanning code).
Most of the code is diverged at the reclaim entry point and from what I see the code at the lowest layer (shrink_folio_list) is shared.
Quoted 10 lines
Quoted 6 lines
Everyone
maintains, understands, and evolves a single codebase. Optimizations are now evaluated against -- and available to -- both algorithms. And the next time someone develops a new LRU algorithm, they can do so in a way that does not add churn to existing code.I think we should focus to make a single canonical reclaim implementation work well. I.e. we deal with most (or ideally all) known regressions of MGLRU.
Here we disagree on the approach or steps to reach the single canonical reclaim implementation. MGLRU is a plethora of different mechanisms and policies and it never went through rigorous evaluation for each of those mechanisms and policies individually. To me that needs to be done to have one solution.
Quoted 14 lines
In the initial presentation of the MGRLU framework
we were told that the implemenation should be extensible to provide more creative aging algorithms etc.Quoted 9 lines
The Fix: One Reclaim, Pluggable and Extensible
-----------------------------------------------We need one reclaim system, not two. One code path that everyone maintains, everyone tests, and everyone benefits from. But it needs to be pluggable as there will always be cases where someone wants some customization for their specialized workload or wants to explore some new techniques/ideas, and we do not want to get into the current mess again.
Quoted 5 lines
I would go that way only if/after we are done with MGLRU unification and after we will have depleted the potential of that approach and hit cases where we cannot implement new extensions without going $foo_ext way. TBH I am not convinced "make it pluginable to solve hard problems" is the best way forward.
The reason I have added pluggable/extensible part in this proposal is that I want to avoid the same scenario all over again in the future. There will always be some users with very specialized workloads needing some fancy/weird heuristic. Rather than polluting the core reclaim, letting such users to do fancy policies should be part of our long term strategy. In addition, we will want to explore different algorithms and techniques, providing a way to easily do that without changing the core is definitely needed for future proofing the reclaim.
Quoted 83 lines · David Hildenbrand (Arm)
Quoted 82 lines · Lorenzo Stoakes (Oracle)
Quoted 29 lines · Kairui Song
Quoted 5 lines · Lorenzo Stoakes (Oracle)
I'm quite concerned about maintainership, as it seems the MGLRU maintainers have not been all that active, and the MGLRU to me at least is currently a black box.
Quoted 8 lines
I'm not the only one who's raised this (see [0]).
That'd very much have to be resolved and the community reassured that MGLRU is _actively_ maintained before we could even contemplate it replacing the 'classic' reclaim approach IMO.
I hope that Kairu, Barry, Zicheng and others who are interested int it resolve this, however!
Hi everyone,
Right, I think we are starting to make good progress on improving MGLRU recently. For the last few years we already have some commits stashed downstream to enable that on our fleet, most of my effort in upstream is spent on other parts like SWAP, really looking forward to making MGLRU better upstreamly.
Yesterday I was still discussing with CachyOS folks about their usage while working on that series for MGLRU cleanup and dirty flush optimization, and got some nice feedback later from their chat server that MGLRU's TTL resolved their thrashing issue very well. With classic LRU they needed a le9 patch downtreamly.
Quoted 8 lines
For many other typical workloads under stress, MGLRU performs significantly better too (e.g. database, build kernel could be more than twice as fast), it would be a huge loss to leave it unmaintained.
Barry also provided some really helpful ideas about MGLRU like readahead handling. We are also seeing other vendors and people contributing to MGLRU like Leno and Baolin recently. Things are looking promising.
Guys, can I please make a plea then for you guys to AT LEAST become reviewers in
MAINTAINERSplease:MEMORY MANAGEMENT - MGLRU (MULTI-GEN LRU)
M: Andrew Morton <[email protected]>Well Andrew is Andrew :)
M: Axel Rasmussen <[email protected]>
git log
mm/vmscan.chas 0 results.Axel has however engaged in discussion on
https://lore.kernel.org/linux-mm/[email protected]/
recently for example, but not much in 2025 afaict.M: Yuanchu Xie <[email protected]>
git log
mm/vmscan.cshows 1 result from August 13th 2024.Yuanchu has engaged in some MGLRU discussion also recently, here and there.
R: Wei Xu <[email protected]>
git log
mm/vmscan.cshows 2 results from October 2024.Wei doesn't look to have engaged in discussion on MGLRU recently.
L: [email protected]
S: Maintained
W: http://www.linux-mm.org
T: gitgit://git.kernel.org/pub/scm/linux/kernel/git/akpm/mm
F:Documentation/admin-guide/mm/multigen_lru.rst
F:Documentation/mm/multigen_lru.rst
F:include/linux/mm_inline.h
F:include/linux/mmzone.h
F:mm/swap.c
F:mm/vmscan.c
F:mm/workingset.cIt doesn't really feel like MGLRU is currently maintained at all, quite honestly.
Quoted 7 lines
Quoted 1 line
So I think we need people to step up here.
Ans some serious cleanup of the entry to reflect who is actually involved nowadays, if at all.
Master of MAINTAINER updates, I assume you'll take care of that?
Ack of course :)
I mean I can suggest a change and cc the various people and we can do it that way :)
Obviously will want some Acked-by's from those invovled on that though! :)
Quoted 5 lines
--
Cheers,David
Cheers, Lorenzo
Quoted 2 lines · Shakeel Butt
Quoted 1 line · Michal Hocko
On Wed 25-03-26 14:06:37, Shakeel Butt wrote:
[...]
Quoted 8 lines
Quoted 3 lines
I think we should focus to make a single canonical reclaim implementation work well. I.e. we deal with most (or ideally all) known regressions of MGLRU.
Here we disagree on the approach or steps to reach the single canonical reclaim implementation. MGLRU is a plethora of different mechanisms and policies and it never went through rigorous evaluation for each of those mechanisms and policies individually. To me that needs to be done to have one solution.
If my recollection is correct from the LSFMM (2022) there was a promise that MGLRU architecture should allow to add extension and eventually supersede traditional LRU. If we do not see that happening then we should re-evaluate current MGRLU approach. I do not think we want to build reclaim_ext architecture on top of the current code. Or are you suggesting to achieve MGLRU through reclaim_ext?
Signature · 2 lines
Michal Hocko SUSE Labs
... snip snip snip ...
Quoted 11 lines
Quoted 7 lines
How Do We Get There
-------------------Do we merge the two mechanisms feature by feature, or do we prioritize moving MGLRU to the pluggable model then follow with LRU once we are happy with the result?
Absolutely by a distance the first is preferable. The pluggability is controversial here and needs careful consideration.
Pluggability asside - I do not think merging these two things "feature by feature" is actually feasible (I would be delighted to be wrong).
Many MGLRU "features" solve problems that MGLRU invents for itself.
Take MGLRU's PID controller - its entire purpose is to try to smooth out refault rates and "learn" from prior mistakes - but it's fundamentally tied to MGLRU's aging system, and the aging systems differ greatly.
- LRU: actual lists - active/inactive - that maintain ordering
- MGLRU: "generations", "inter-generation tiers", aging-in-place
"Merging" this is essentially inventing something completely new - or more reasonably just migrating everyone to MGLRU.
In terms of managing risk, it seems far more reasonable to either split MGLRU off into its own file and formalize the interface (ops), or simply rip it out and let each individual feature fight its way back in.
~Gregory
Quoted 26 lines · Gregory Price
... snip snip snip ...
Quoted 11 lines
Quoted 7 lines
How Do We Get There
-------------------Do we merge the two mechanisms feature by feature, or do we prioritize moving MGLRU to the pluggable model then follow with LRU once we are happy with the result?
Absolutely by a distance the first is preferable. The pluggability is controversial here and needs careful consideration.
Pluggability asside - I do not think merging these two things "feature by feature" is actually feasible (I would be delighted to be wrong).
Many MGLRU "features" solve problems that MGLRU invents for itself.
Take MGLRU's PID controller - its entire purpose is to try to smooth out refault rates and "learn" from prior mistakes - but it's fundamentally tied to MGLRU's aging system, and the aging systems differ greatly.
- LRU: actual lists - active/inactive - that maintain ordering
- MGLRU: "generations", "inter-generation tiers", aging-in-place
Quoted 6 lines
"Merging" this is essentially inventing something completely new - or more reasonably just migrating everyone to MGLRU.
In terms of managing risk, it seems far more reasonable to either split MGLRU off into its own file and formalize the interface (ops), or simply rip it out and let each individual feature fight its way back in.
But _surely_ (and Shakeel can come back on this I guess) there are things that are commonalities.
In any case we can all agree that MGLRU cohabiting with classical reclaim is not a happy household one way or another.
Maybe a stage 1 can be to separate stuff into another file, because that'd actually be pretty easy to do for a fair bit of it, surely?
Can use mm/internal.h to handle stuff that has to link one with other?
Quoted 2 lines
~Gregory
Cheers, Lorenzo
Quoted 3 lines · Kairui Song
For many other typical workloads under stress, MGLRU performs significantly better too (e.g. database, build kernel could be more than twice as fast), it would be a huge loss to leave it unmaintained.
BTW press X to doubt on it doubling kernel build times :)
Cheers, Lorenzo
Quoted 6 lines · Lorenzo Stoakes (Oracle)
Maybe a stage 1 can be to separate stuff into another file, because that'd actually be pretty easy to do for a fair bit of it, surely?
Can use
mm/internal.hto handle stuff that has to link one with other?
Yeah i don't think we absolutely need to jump all the way to ops right away, and splitting into a new file would at least give our eyes a rest from the ifdef spaghetti.
~Gregory
Quoted 11 lines · Gregory Price
Quoted 6 lines · Lorenzo Stoakes (Oracle)
Maybe a stage 1 can be to separate stuff into another file, because that'd actually be pretty easy to do for a fair bit of it, surely?
Can use
mm/internal.hto handle stuff that has to link one with other?Yeah i don't think we absolutely need to jump all the way to ops right away, and splitting into a new file would at least give our eyes a rest from the ifdef spaghetti.
Yeah as I said in my reply here, I'm if(def?)fy about the ops tbh.
But we can defer thinking about that until last anyway.
Quoted 2 lines
~Gregory
Cheers, Lorenzo
Quoted 13 lines · Michal Hocko
Quoted 2 lines · Shakeel Butt
Quoted 1 line · Michal Hocko
On Wed 25-03-26 14:06:37, Shakeel Butt wrote:
[...]
Quoted 8 lines
Quoted 3 lines
I think we should focus to make a single canonical reclaim implementation work well. I.e. we deal with most (or ideally all) known regressions of MGLRU.
Here we disagree on the approach or steps to reach the single canonical reclaim implementation. MGLRU is a plethora of different mechanisms and policies and it never went through rigorous evaluation for each of those mechanisms and policies individually. To me that needs to be done to have one solution.
Quoted 6 lines
If my recollection is correct from the LSFMM (2022) there was a promise that MGLRU architecture should allow to add extension and eventually supersede traditional LRU. If we do not see that happening then we should re-evaluate current MGRLU approach. I do not think we want to build
reclaim_extarchitecture on top of the current code. Or are you suggesting to achieve MGLRU throughreclaim_ext?
My main objective is to unify the reclaim i.e. one reclaim algorithm/mechanism and then (later) provide a framework where folks/kernel-engs/researchers can experiment with new techniques/algorithms without changing the core reclaim.
Regarding MGLRU, after unification something from MGLRU remains which does not makes sense to put in the core reclaim, that can be provided through the framework. For reclaim_ext, I just like the name, looks fancy :).
Quoted 1 line · Lorenzo Stoakes (Oracle)
On Wed, Mar 25, 2026 at 02:06:37PM -0700, Shakeel Butt wrote:
[...]
Quoted 11 lines
Quoted 10 lines
The Fix: One Reclaim, Pluggable and Extensible
-----------------------------------------------We need one reclaim system, not two. One code path that everyone maintains, everyone tests, and everyone benefits from. But it needs to be pluggable as there will always be cases where someone wants some customization for their specialized workload or wants to explore some new techniques/ideas, and we do not want to get into the current mess again.
Quoted 4 lines
OK so I was with you up until the pluggable bit :) it's like you're combining two things here, obviously - unification and pluggability.
I think we should consider both separately.
Yes, I should be more explicit that these are two different steps. First unification and then provide a framework for extensibility.
[...]
Quoted 42 lines
Quoted 11 lines
New ideas get implemented as new policies, not as 3,000-line forks. Good mechanisms from MGLRU (page table scanning, Bloom filters, lookaround) become shared infrastructure available to any policy. And if someone comes up with a better eviction algorithm tomorrow, they plug it in without touching the core.
Making reclaim pluggable implies we define it as a set of function methods (let's call them
reclaim_ops) hooking into a stable codebase we rarely modify. We then have two big questions to answer: how do these reclaim ops look, and how do we move the existing code to the new model?Hmm, I'm not so sure about that. But it depends really on who has access to these operations.
The issue with operations in general is that they eliminate the possibility of the general code being able to make assumptions about what's happening.
For instance, the .mmap
f_opcallback meant that we had to account for any possible thing being done by a driver. You couldn't make assumptions about vma state, page table state, etc. and of course things happened that we didn't anticipate, leading to bugs.So I guess it's less 'no ops' more so 'what do we actually expose to the ops', 'what assumptions do we bake in about how the ops are used' and very importantly - 'who gets to populate them'.
If they're _exclusively_ mm-internal then that's fine.
Reclaim is a _very_ _very_ sensitive part of mm. At the point it's being activated you may be under extreme memory pressure, so a hook even allocating at all may either fail or enter infinite loops.
We are also very sensitive on things like rmap locks and also, of course, - timing.
It's not just a perf concern, if we are too slow, we might end up thrashing when we could otherwise not have.
Also there ends up being a question of how much now-internal functionality we end up exposing to users.
Quoted 6 lines
So we really need a good definition of who we intend should use this stuff, and how any such interface should be designed.
I mean, if sufficiently abstracted, and with very carefully restricted constrainst perhaps we could work around a lot of this but we have to tread _very_ carefully here.
Good points and I think we are still at the early stage of defining what operations these would be. One of the complain during MGLRU upstream effort was that the traditional LRU is too rigid and is very hard to experiment new ideas. I want to eliminate such future complains. If you want to experiment some new algorithm or new heuristic, experiment using the new framework.
I think once we start unifying the reclaim mechanisms, these operations will start becoming more clear.
Quoted 5 lines · Lorenzo Stoakes (Oracle)
Quoted 3 lines · Michal Hocko
Quoted 2 lines · Andrew Morton
On Wed, 25 Mar 2026 14:06:37 -0700 Shakeel Butt <[email protected]> wrote:
Quoted 8 lines
Quoted 8 lines
Quoted 3 lines
Quoted 1 line
We should unify both algorithms into a single code path.
I'm here to ask the questions which others fear will sound dumb.
Not dumb at all and recently discussed here https://lore.kernel.org/all/CAMgjq7AkYOtUL2HuZjBu5dJw=RTL7W2L1+zVv=SCOyHKYwc3AA@mail.gmail.com/T/#u
Quoted 2 lines
Is it indeed the plan to maintain both implementations? I thought the long-term ambition was to knock MGLRU into shape and to drop the legacy LRU?
I think one thing we all agree on at least is, long term, there isn't really a good argument for having > 1 LRU implementation. E.g., we don't believe there are just irreconcilable differences, where one impl is better for some workloads, and another is better for others, and there is no way the two can be converged.
On that basis, I would be hesitant to add some complex abstraction layer / reclaim_ops to facilitate having two. It seems ilke it may make things a bit cleaner in the short term, but long term might make that end goal harder (because we'd add the task of cleaning up this abstraction at some point).
My preferred way would be more like:
- Look for opportunities where we can deduplicate code, but without adding abstraction (e.g., factor out common operations into common functions both impls can call).
- Identify gaps where MGLRU performs worse than classic LRU, and close them.
We could go the other direction, where we identify places classic LRU can be improved, and port particular MGLRU features over to it. I prefer the other way for a couple of reasons;
- My sense is MGLRU is "close", meaning as Kairui said in "average" cases it is substantially better, and the gaps are both fairly narrow / edge-casey, and very solveable.
- Leaving classic LRU alone leaves the option for existing users to maintain the status quo. If we start porting MGLRU features over to classic LRU, we may introduce new regressions and break existing users. Using MGLRU as our working base means we can iterate on it without as much risk.
Quoted 5 lines
Quoted 4 lines
Yes, but MGLRU is not there yet and with development pace last year or so we are not much closer than at the time MGLRU has been merged unfortunatelly.
Quoted 8 lines
I'm quite concerned about maintainership, as it seems the MGLRU maintainers have not been all that active, and the MGLRU to me at least is currently a black box.
I'm not the only one who's raised this (see [0]).
That'd very much have to be resolved and the community reassured that MGLRU is _actively_ maintained before we could even contemplate it replacing the 'classic' reclaim approach IMO.
Very fair concern. Time will tell but I think things are on a much better trajectory now.
Barry's and Kairui's work here has been great. Suren's team (Android) is dedicating a full time engineer to MGLRU this year, as I understand it. I'm planning to do the same myself. I started by spending some time reviewing some patches last week, and I'm hoping to send some patches of my own in the next month or two.
I realize just talking about it doesn't mean much, action is needed. I'm hoping in a few months' time everyone feels much better about the state of things. :)
Quoted 11 lines
I hope that Kairu, Barry, Zicheng and others who are interested int it resolve this, however!
Thanks, Lorenzo
[0]:https://lore.kernel.org/linux-mm/[email protected]/
Quoted 3 lines
--
Michal Hocko
SUSE Labs
Quoted 7 lines · Axel Rasmussen
I think one thing we all agree on at least is, long term, there isn't really a good argument for having > 1 LRU implementation. E.g., we don't believe there are just irreconcilable differences, where one impl is better for some workloads, and another is better for others, and there is no way the two can be converged.
I absolutely believe there are irreconcilable differences - but not in the sense that one is better or worse, but in the sense that features from one cannot work in the other.
Quoted 4 lines
- My sense is MGLRU is "close", meaning as Kairui said in "average" cases it is substantially better, and the gaps are both fairly narrow / edge-casey, and very solveable.
This is a really, really bold claim. So much of this is workload dependent, and LRU has decades of battle-testing while MGLRU has barely been around 4 years.
~Gregory
Quoted 10 lines · Gregory Price
Quoted 7 lines · Axel Rasmussen
I think one thing we all agree on at least is, long term, there isn't really a good argument for having > 1 LRU implementation. E.g., we don't believe there are just irreconcilable differences, where one impl is better for some workloads, and another is better for others, and there is no way the two can be converged.
Quoted 3 lines
I absolutely believe there are irreconcilable differences - but not in the sense that one is better or worse, but in the sense that features from one cannot work in the other.
Right, agreed. I mean a case where we have workloads A and B, such that there does not exist an implementation that can serve both well. If such workloads were "common" to me that would justify a reclaim_ops / pluggable abstraction layer. My thesis is that they are "not common", so I'm a bit skeptical the abstraction is worth it.
Quoted 9 lines
Quoted 5 lines
- My sense is MGLRU is "close", meaning as Kairui said in "average" cases it is substantially better, and the gaps are both fairly narrow / edge-casey, and very solveable.
This is a really, really bold claim. So much of this is workload dependent, and LRU has decades of battle-testing while MGLRU has barely been around 4 years.
Fair. My basic thinking is, MGLRU is enabled by default in some (admittedly, not all) major distros like Fedora or Arch. From that, we have some various regression reports on the mailing list, but to Kairui's point, nothing that looks super hard to resolve.
Then again we can always be surprised later / as the footprint expands. :)
Quoted 2 lines
~Gregory
Quoted 15 lines · Axel Rasmussen
Quoted 10 lines · Gregory Price
Quoted 7 lines · Axel Rasmussen
I think one thing we all agree on at least is, long term, there isn't really a good argument for having > 1 LRU implementation. E.g., we don't believe there are just irreconcilable differences, where one impl is better for some workloads, and another is better for others, and there is no way the two can be converged.
Quoted 3 lines
I absolutely believe there are irreconcilable differences - but not in the sense that one is better or worse, but in the sense that features from one cannot work in the other.
Quoted 5 lines
Right, agreed. I mean a case where we have workloads A and B, such that there does not exist an implementation that can serve both well. If such workloads were "common" to me that would justify a
reclaim_ops/ pluggable abstraction layer. My thesis is that they are "not common", so I'm a bit skeptical the abstraction is worth it.
That isn't what Tal was telling me at Plumbers. Adding him to cc so he can dispute you in his own words, rather than my clumsy paraphrasing of what he said.
Quoted 27 lines · Axel Rasmussen via Lsf-pc
Quoted 5 lines · Lorenzo Stoakes (Oracle)
Quoted 3 lines · Michal Hocko
Quoted 2 lines · Andrew Morton
On Wed, 25 Mar 2026 14:06:37 -0700 Shakeel Butt <[email protected]> wrote:
Quoted 8 lines
Quoted 8 lines
Quoted 3 lines
Quoted 1 line
We should unify both algorithms into a single code path.
I'm here to ask the questions which others fear will sound dumb.
Not dumb at all and recently discussed here https://lore.kernel.org/all/CAMgjq7AkYOtUL2HuZjBu5dJw=RTL7W2L1+zVv=SCOyHKYwc3AA@mail.gmail.com/T/#u
Quoted 2 lines
Is it indeed the plan to maintain both implementations? I thought the long-term ambition was to knock MGLRU into shape and to drop the legacy LRU?
I think one thing we all agree on at least is, long term, there isn't really a good argument for having > 1 LRU implementation. E.g., we don't believe there are just irreconcilable differences, where one impl is better for some workloads, and another is better for others, and there is no way the two can be converged.
On that basis, I would be hesitant to add some complex abstraction layer /
reclaim_opsto facilitate having two. It seems ilke it may make things a bit cleaner in the short term, but long term might make that end goal harder (because we'd add the task of cleaning up this abstraction at some point).
Quoted 6 lines
My preferred way would be more like:
- Look for opportunities where we can deduplicate code, but without adding abstraction (e.g., factor out common operations into common functions both impls can call).
- Identify gaps where MGLRU performs worse than classic LRU, and close them.
I'm afraid to identify these gaps we'd have to indeed split the MGLRU differences (as listed in Shakeel's proposal) in a way that they can be tried separately. I recall when MGLRU was proposed, we did argue that it's a combination of several things done differently and they should be introduced to the existing reclaim and validated separately. But the author refused to go that way.
Quoted 56 lines
We could go the other direction, where we identify places classic LRU can be improved, and port particular MGLRU features over to it. I prefer the other way for a couple of reasons;
- My sense is MGLRU is "close", meaning as Kairui said in "average" cases it is substantially better, and the gaps are both fairly narrow / edge-casey, and very solveable.
- Leaving classic LRU alone leaves the option for existing users to maintain the status quo. If we start porting MGLRU features over to classic LRU, we may introduce new regressions and break existing users. Using MGLRU as our working base means we can iterate on it without as much risk.
Quoted 5 lines
Quoted 4 lines
Yes, but MGLRU is not there yet and with development pace last year or so we are not much closer than at the time MGLRU has been merged unfortunatelly.
Quoted 8 lines
I'm quite concerned about maintainership, as it seems the MGLRU maintainers have not been all that active, and the MGLRU to me at least is currently a black box.
I'm not the only one who's raised this (see [0]).
That'd very much have to be resolved and the community reassured that MGLRU is _actively_ maintained before we could even contemplate it replacing the 'classic' reclaim approach IMO.
Very fair concern. Time will tell but I think things are on a much better trajectory now.
Barry's and Kairui's work here has been great. Suren's team (Android) is dedicating a full time engineer to MGLRU this year, as I understand it. I'm planning to do the same myself. I started by spending some time reviewing some patches last week, and I'm hoping to send some patches of my own in the next month or two.
I realize just talking about it doesn't mean much, action is needed. I'm hoping in a few months' time everyone feels much better about the state of things. :)
Quoted 11 lines
I hope that Kairu, Barry, Zicheng and others who are interested int it resolve this, however!
Thanks, Lorenzo
[0]:https://lore.kernel.org/linux-mm/[email protected]/
Quoted 3 lines
--
Michal Hocko
SUSE Labs_______________________________________________
Lsf-pc mailing list
[email protected]
https://lists.linuxfoundation.org/mailman/listinfo/lsf-pc
Quoted 35 lines · Vlastimil Babka
Quoted 27 lines · Axel Rasmussen via Lsf-pc
Quoted 5 lines · Lorenzo Stoakes (Oracle)
Quoted 3 lines · Michal Hocko
Quoted 2 lines · Andrew Morton
On Wed, 25 Mar 2026 14:06:37 -0700 Shakeel Butt <[email protected]> wrote:
Quoted 8 lines
Quoted 8 lines
Quoted 3 lines
Quoted 1 line
We should unify both algorithms into a single code path.
I'm here to ask the questions which others fear will sound dumb.
Not dumb at all and recently discussed here https://lore.kernel.org/all/CAMgjq7AkYOtUL2HuZjBu5dJw=RTL7W2L1+zVv=SCOyHKYwc3AA@mail.gmail.com/T/#u
Quoted 2 lines
Is it indeed the plan to maintain both implementations? I thought the long-term ambition was to knock MGLRU into shape and to drop the legacy LRU?
I think one thing we all agree on at least is, long term, there isn't really a good argument for having > 1 LRU implementation. E.g., we don't believe there are just irreconcilable differences, where one impl is better for some workloads, and another is better for others, and there is no way the two can be converged.
On that basis, I would be hesitant to add some complex abstraction layer /
reclaim_opsto facilitate having two. It seems ilke it may make things a bit cleaner in the short term, but long term might make that end goal harder (because we'd add the task of cleaning up this abstraction at some point).Quoted 6 lines
My preferred way would be more like:
- Look for opportunities where we can deduplicate code, but without adding abstraction (e.g., factor out common operations into common functions both impls can call).
- Identify gaps where MGLRU performs worse than classic LRU, and close them.
Quoted 6 lines
I'm afraid to identify these gaps we'd have to indeed split the MGLRU differences (as listed in Shakeel's proposal) in a way that they can be tried separately. I recall when MGLRU was proposed, we did argue that it's a combination of several things done differently and they should be introduced to the existing reclaim and validated separately. But the author refused to go that way.
It's unfortunate we were ok with going ahead with this anyway, I hope in the current mm culture we'd simply say 'ok series doesn't land then'.
It feels like the 'merge by default' stuff has been both a process _and_ a culture fail for a while honestly.
We are managing arguably _the_ most core part of the kernel (I know people will argue on that but at it's at least up there :) and almost certainly _the_ subsystem with the most direct route to exploitable security bugs, but we've been running it with some of the loosest merge criteria in the entire kernel.
It's patently insane.
Things are changing however!
Cheers, Lorenzo
Quoted 22 lines · Matthew Wilcox
Quoted 15 lines · Axel Rasmussen
Quoted 10 lines · Gregory Price
Quoted 7 lines · Axel Rasmussen
I think one thing we all agree on at least is, long term, there isn't really a good argument for having > 1 LRU implementation. E.g., we don't believe there are just irreconcilable differences, where one impl is better for some workloads, and another is better for others, and there is no way the two can be converged.
Quoted 3 lines
I absolutely believe there are irreconcilable differences - but not in the sense that one is better or worse, but in the sense that features from one cannot work in the other.
Quoted 5 lines
Right, agreed. I mean a case where we have workloads A and B, such that there does not exist an implementation that can serve both well. If such workloads were "common" to me that would justify a
reclaim_ops/ pluggable abstraction layer. My thesis is that they are "not common", so I'm a bit skeptical the abstraction is worth it.
Quoted 4 lines
That isn't what Tal was telling me at Plumbers. Adding him to cc so he can dispute you in his own words, rather than my clumsy paraphrasing of what he said.
Yeah, unfortunately it's not so straightforward. As a simple illustrative example, consider a file-search workload, where you search through a large number of files over and over again (e.g., a poor kernel developer trying to understand how the page cache works). This follows an MRU, rather than LRU, pattern, and readahead doesn't help much, leading the active/inactive and MGLRU policies to have similar performance (~40s runtime in a specific benchmark we ran). In comparison, using cache_ext (our eBPF-based caching framework), we can run an MRU policy and it goes down to 20s.
This is also true for more complex workloads, like an HTAP-like database workload, where we have lots of small GET-like requests and a few large SCAN requests. We find that the SCAN requests pollute the cache for both policies, leading to eviction of the (small) GET data and degrading performance. fadvise() doesn't help much, but using a custom policy that separates the GET and SCAN data into two different queues can yield a 70% throughput increase for GET requests. This was tested on Linux v6.6, so it's possible that various MGLRU behaviors have been improved, but the underlying structure remains.
It's been well-known in the academic realm for a while that there isn't really a "one-size-fits-all" policy that works *best* for all workloads. Yes, you can make a general policy that works *well*, but if you really care about a workload's performance and want to squeeze out the last 10-20% (or more) of performance, you need to be able to (1) experiment and (2) take advantage of application-level insights. Being able to extend reclaim (in our case with eBPF) enables that.
We wrote a paper about this that was published a few months ago [1]. Happy to answer any questions and continue the discussion!
Thanks,
Tal
Quoted 9 lines · Tal Zussman
It's been well-known in the academic realm for a while that there isn't really a "one-size-fits-all" policy that works *best* for all workloads. Yes, you can make a general policy that works *well*, but if you really care about a workload's performance and want to squeeze out the last 10-20% (or more) of performance, you need to be able to (1) experiment and (2) take advantage of application-level insights. Being able to extend reclaim (in our case with eBPF) enables that.
This just makes me think going all the way to reclaim_ext and re-writing MGLRU as an eBPF extension in an effort to simplify the code/maintenance and keep what works working is the least-worst option.
But this is a naive take, i'm sure making that interface stable would be even worse than just maintaining both LRU/MGLRU.
~Gregory
Quoted 30 lines · Lorenzo Stoakes (Oracle)
Quoted 29 lines · Gregory Price
... snip snip snip ...
Quoted 11 lines
Quoted 7 lines
How Do We Get There
-------------------Do we merge the two mechanisms feature by feature, or do we prioritize moving MGLRU to the pluggable model then follow with LRU once we are happy with the result?
Absolutely by a distance the first is preferable. The pluggability is controversial here and needs careful consideration.
Pluggability asside - I do not think merging these two things "feature by feature" is actually feasible (I would be delighted to be wrong).
Many MGLRU "features" solve problems that MGLRU invents for itself.
Take MGLRU's PID controller - its entire purpose is to try to smooth out refault rates and "learn" from prior mistakes - but it's fundamentally tied to MGLRU's aging system, and the aging systems differ greatly.
- LRU: actual lists - active/inactive - that maintain ordering
- MGLRU: "generations", "inter-generation tiers", aging-in-place"Merging" this is essentially inventing something completely new - or more reasonably just migrating everyone to MGLRU.
Quoted 6 lines
Quoted 3 lines
In terms of managing risk, it seems far more reasonable to either split MGLRU off into its own file and formalize the interface (ops), or simply rip it out and let each individual feature fight its way back in.
But _surely_ (and Shakeel can come back on this I guess) there are things that are commonalities.
There are some commonalities, but MGLRU was almost maximalist in its approach to finding parallel solutions and reinventing various wheels with little commentary, explanations or isolated testing.
For example, MGLRU took a totally different, ad-hoc approach to dealing with dirty and writeback pages. It's been converging on the LRU mechanism. This process has been stretching out for years, with users eventually running into all the same problems that shaped the LRU implementation to begin with. Yes, you need to wake flushers from reclaim. Yes, you will OOM if you don't throttle on writeback.
There are many other divergences like this that complicate the picture:
- Cgroup tree iteration, per-zone lists to implement node reclaim.
- Divergent anon/file balancing policies.
- A notably different approach to scan resistance.
Many of these were not part of the main pitch at the time, but they’ve created sizable technical debt that we’re now forced to reconcile.
I think MGLRU's NIH-attitude towards the problem space set it up for running into past lessons again and learning the hard way, just like with writeback.
The good thing is that there are some integration efforts now, even if they don't come from the people that promised them. And some of them do exactly the targeted, rigorous tests on a per-component basis that is needed to sort it out (and was asked for back then).
But there are many workloads, many hardware configurations, and many cornercases to cover, so this will take time. The end result doesn't just need to be fast for some workloads, it also needs to be universal, robust, easy to reason about and predictable.
Based on the current differences and how unification has been going so far, I think it's premature to claim that we're close to deleting one.
And the current code structure makes it difficult to whittle down the differences methodically.
IMO modularization is the best path forward. Giving people the ability to experiment with a la carte combinations of features would make it much easier to actually production test and prove individual ideas.
A nice side effect of this is that entirely new ideas would also be easier to try out.
I think a good start would be to keep the common bits - "library" code like shrink_folio_list() list and shared facilities like kswapd - in vmscan.c. Move LRU and MGLRU specifics to their own files.
Then as much as possible extract and generalize functionality into the common code so it can plug into both. For example, collecting accessed bits from page tables instead of rmap chains should really not have to be specific to one. Nor how the cgroup tree is iterated.
It might be possible to make N lists a natural extension of 2 lists, so that the tracking datastructures themselves can be shared. With minimal parameterization from the policy engines.
If we can get to a place where the only difference is how reference data is interpreted and causes the lists to be sorted - you know, the actual replacement policy - that is a much more manageable gap to evaluate and argue about. Or swap out to try entirely new ones.
(sorry my mail is a disaster totally missed this)
Quoted 42 lines · Johannes Weiner
Quoted 30 lines · Lorenzo Stoakes (Oracle)
Quoted 29 lines · Gregory Price
... snip snip snip ...
Quoted 11 lines
Quoted 7 lines
How Do We Get There
-------------------Do we merge the two mechanisms feature by feature, or do we prioritize moving MGLRU to the pluggable model then follow with LRU once we are happy with the result?
Absolutely by a distance the first is preferable. The pluggability is controversial here and needs careful consideration.
Pluggability asside - I do not think merging these two things "feature by feature" is actually feasible (I would be delighted to be wrong).
Many MGLRU "features" solve problems that MGLRU invents for itself.
Take MGLRU's PID controller - its entire purpose is to try to smooth out refault rates and "learn" from prior mistakes - but it's fundamentally tied to MGLRU's aging system, and the aging systems differ greatly.
- LRU: actual lists - active/inactive - that maintain ordering
- MGLRU: "generations", "inter-generation tiers", aging-in-place"Merging" this is essentially inventing something completely new - or more reasonably just migrating everyone to MGLRU.
Quoted 6 lines
Quoted 3 lines
In terms of managing risk, it seems far more reasonable to either split MGLRU off into its own file and formalize the interface (ops), or simply rip it out and let each individual feature fight its way back in.
But _surely_ (and Shakeel can come back on this I guess) there are things that are commonalities.
There are some commonalities, but MGLRU was almost maximalist in its approach to finding parallel solutions and reinventing various wheels with little commentary, explanations or isolated testing.
Quoted 6 lines
For example, MGLRU took a totally different, ad-hoc approach to dealing with dirty and writeback pages. It's been converging on the LRU mechanism. This process has been stretching out for years, with users eventually running into all the same problems that shaped the LRU implementation to begin with. Yes, you need to wake flushers from reclaim. Yes, you will OOM if you don't throttle on writeback.
Yeah this is a real concern. And it's a pity we put ourselves in this position.
Quoted 6 lines
There are many other divergences like this that complicate the picture:
- Cgroup tree iteration, per-zone lists to implement node reclaim.
- Divergent anon/file balancing policies.
- A notably different approach to scan resistance.
Quoted 6 lines
Many of these were not part of the main pitch at the time, but they’ve created sizable technical debt that we’re now forced to reconcile.
I think MGLRU's NIH-attitude towards the problem space set it up for running into past lessons again and learning the hard way, just like with writeback.
Yeah :( we should never have allowed this series to land the way it did, it's an important lesson in how mm should address changes like this moving forwards.
But, given the great response on the thread here, and around the recent MGLRU entry update in MAINTAINERS, I think this is widely recognised.
Quoted 5 lines
The good thing is that there are some integration efforts now, even if they don't come from the people that promised them. And some of them do exactly the targeted, rigorous tests on a per-component basis that is needed to sort it out (and was asked for back then).
And this is exactly what we need, and it's the ability to do this kind of thing (minus the BPF, minus the pluggable bits, of which I have concerns, perhaps not _fatal_ concerns but concerns anyway) that made me rather pleased with Shakeel's proposal here :)
Quoted 5 lines
But there are many workloads, many hardware configurations, and many cornercases to cover, so this will take time. The end result doesn't just need to be fast for some workloads, it also needs to be universal, robust, easy to reason about and predictable.
Yes, we shouldn't rush this, and should be conservative in how we approach this.
Quoted 3 lines
Based on the current differences and how unification has been going so far, I think it's premature to claim that we're close to deleting one.
Yeah. I think people _really want_ this to be true, but it doesn't make it so.
Reclaim is a really difficult problem I think simply because there are so many corner cases and so many ways in which things can be broken in different circumstances.
I've recently heard complaints about really poor reclaim behaviour on laptops + firefox-eating-all-my-ram which makes me think in general, it'd be good to see a broader improvement in testing, code quality and documentation and separation of the various heuristics.
When writing the book it did strike me just how heuristic so much of it is, which makes the code necessarily delicate. I think we can do better in separating out these bits in general.
But that kind of steps outside of the scope of the proposed changes here.
Quoted 7 lines
And the current code structure makes it difficult to whittle down the differences methodically.
IMO modularization is the best path forward. Giving people the ability to experiment with a la carte combinations of features would make it much easier to actually production test and prove individual ideas.
Yes agreed.
I guess one aspect of testing that's tricky here is that it's _so_ dependent on workload and hardware and software and etc. etc. that writing a bunch of self-tests or similar would possibly be semi-useless.
I wonder if we need some way of storing specific test results/having specific tests for specific workloads within the kernel tree?
I know, super nebulous, but if we had some way of expressing 'we expect behaviour X in setup Y' it'd be super helpful. But I realise that quickly becomes a combinatorial explosion.
In a possibly, fantasy ideal world scenario *puffs on dream pipe*, it'd be amazing to somehow isolate the reclaim code in such a way that we could instrument it for testing purposes.
E.g. if it could be invoked from userland, or UML, or _something_ and then faked out to have a certain configuration of X NUMA nodes and Y GB of RAM with Z processes competing with total observability of what's happening in the algorithm that could allow for really robust controllable testing and regression tests, as well as possibly some form of fuzzing for broken reclaim scenarios.
*Puts dream pipe down*
Quoted 7 lines
A nice side effect of this is that entirely new ideas would also be easier to try out.
I think a good start would be to keep the common bits - "library" code like
shrink_folio_list()list and shared facilities like kswapd - invmscan.c. Move LRU and MGLRU specifics to their own files.
Yes this would be a great (and simple) start!
Maybe worth keeping the mglru.c file or whatever-it-will-be also under the reclaim entry in MAINTAINERS while we're figuring out who should eventually maintain MGLRU however.
Quoted 5 lines
Then as much as possible extract and generalize functionality into the common code so it can plug into both. For example, collecting accessed bits from page tables instead of rmap chains should really not have to be specific to one. Nor how the cgroup tree is iterated.
Yes, we should aggressively reduce duplication. Since this is a lot more 'obvious' in terms of value and correctness, maybe also a good starting point?
Quoted 4 lines
It might be possible to make N lists a natural extension of 2 lists, so that the tracking datastructures themselves can be shared. With minimal parameterization from the policy engines.
That'd be nice!
Quoted 5 lines
If we can get to a place where the only difference is how reference data is interpreted and causes the lists to be sorted - you know, the actual replacement policy - that is a much more manageable gap to evaluate and argue about. Or swap out to try entirely new ones.
Yes absolutely agreed.
This is a fantastic reply, am annoyed my not knowing how to do mail (apparently) prevented me from seeing it earlier!
Cheers, Lorenzo
Quoted 8 lines · Lorenzo Stoakes
Quoted 7 lines
And the current code structure makes it difficult to whittle down the differences methodically.
IMO modularization is the best path forward. Giving people the ability to experiment with a la carte combinations of features would make it much easier to actually production test and prove individual ideas.
...
Quoted 5 lines
In a possibly, fantasy ideal world scenario *puffs on dream pipe*, it'd be amazing to somehow isolate the reclaim code in such a way that we could instrument it for testing purposes.
Quoted 8 lines
E.g. if it could be invoked from userland, or UML, or _something_ and then faked out to have a certain configuration of X NUMA nodes and Y GB of RAM with Z processes competing with total observability of what's happening in the algorithm that could allow for really robust controllable testing and regression tests, as well as possibly some form of fuzzing for broken reclaim scenarios.
*Puts dream pipe down*
*picks up the pipe*
At risk of being shot - this kind of stubbing / functional testing is somewhat trivial work these days via <pick your favorite LLM> with reasonably well designed interfaces.
( read: probably not with the current api n_n;; ).
So to get there, we'd need to agree on the refactor work and interfaces that make it possible to model the scenarios outside a running kernel.
If we do actually want to move the core to look like:
- vmscan.c : core library - lru.c : standard lru - mglru.c : mglru
Might as well consider the functional testing question as well as we decide what those interfaces look like anyway.
*throws the pipe into the bikeshed*
~Gregory
Quoted 24 lines · Gregory Price
Quoted 8 lines · Lorenzo Stoakes
Quoted 7 lines
And the current code structure makes it difficult to whittle down the differences methodically.
IMO modularization is the best path forward. Giving people the ability to experiment with a la carte combinations of features would make it much easier to actually production test and prove individual ideas.
...
Quoted 12 lines
In a possibly, fantasy ideal world scenario *puffs on dream pipe*, it'd be amazing to somehow isolate the reclaim code in such a way that we could instrument it for testing purposes.
E.g. if it could be invoked from userland, or UML, or _something_ and then faked out to have a certain configuration of X NUMA nodes and Y GB of RAM with Z processes competing with total observability of what's happening in the algorithm that could allow for really robust controllable testing and regression tests, as well as possibly some form of fuzzing for broken reclaim scenarios.
Quoted 5 lines
Quoted 1 line
*Puts dream pipe down*
*picks up the pipe*
At risk of being shot - this kind of stubbing / functional testing is
*nukes entire site from orbit, it's the only way to be sure*
Quoted 2 lines
somewhat trivial work these days via <pick your favorite LLM> with reasonably well designed interfaces.
Though to be honest, I did ask Claude to do this with some code before and was really impressed with how quickly it came up with something.
Buuut I've generally found the code LLMs produce... terrible? Really terrible? So I think you'd want there to be some level of human improvement there.
And in any case, maybe doing things this way will struggle to really represent real world cases (lock contention etc.) but OTOH, being able to simulate a high memory pressure environment with certain parameters even without [the rest of the kernel] interacting might still be super super useful for diagnosing issues.x
Quoted 2 lines
( read: probably not with the current api
n_n;; ).
*gasp*! But yeah, also yes.
Quoted 11 lines
So to get there, we'd need to agree on the refactor work and interfaces that make it possible to model the scenarios outside a running kernel.
If we do actually want to move the core to look like:
- vmscan.c : core library - lru.c : standard lru - mglru.c : mglruMight as well consider the functional testing question as well as we decide what those interfaces look like anyway.
Yes, adding unit-level tests would be hugely useful.
Quoted 2 lines
*throws the pipe into the bikeshed*
*Dives in bikeshed to rescue*
Quoted 2 lines
~Gregory
Cheers, Lorenzo
Quoted 5 lines · Lorenzo Stoakes
Quoted 2 lines · Gregory Price
Might as well consider the functional testing question as well as we decide what those interfaces look like anyway.
Yes, adding unit-level tests would be hugely useful.
Do I know just the tool for generating these...
Quoted 7 lines · Lorenzo Stoakes
Quoted 3 lines
somewhat trivial work these days via <pick your favorite LLM> with reasonably well designed interfaces.
Though to be honest, I did ask Claude to do this with some code before and was really impressed with how quickly it came up with something.
Quoted 8 lines
Buuut I've generally found the code LLMs produce... terrible? Really terrible? So I think you'd want there to be some level of human improvement there.
And in any case, maybe doing things this way will struggle to really represent real world cases (lock contention etc.) but OTOH, being able to simulate a high memory pressure environment with certain parameters even without [the rest of the kernel] interacting might still be super super useful for diagnosing issues.x
There is a concern people start looking at these tests as signal for performance regressions - which is neither meaningful nor useful (unless you fundamentally break list iteration or something).
But for trivial cases, you'd at least like to know under strongly controlled aging and reclaim scenarios that anon/file memory is reclaimed in a balanced manner - just as an example.
If something breaks THAT assumption, you know there's a logic issue.
Likewise with comparisons between LRU and MGLRU. It might be easier to identify the behavioral divergences that way.
But i fear the whole page-table walk thing makes all of this a non-starter. That's turns into stubbing out like rmap and such.
~Gregory
Quoted 21 lines · Gregory Price
Quoted 7 lines · Lorenzo Stoakes
Quoted 3 lines
somewhat trivial work these days via <pick your favorite LLM> with reasonably well designed interfaces.
Though to be honest, I did ask Claude to do this with some code before and was really impressed with how quickly it came up with something.
Quoted 8 lines
Buuut I've generally found the code LLMs produce... terrible? Really terrible? So I think you'd want there to be some level of human improvement there.
And in any case, maybe doing things this way will struggle to really represent real world cases (lock contention etc.) but OTOH, being able to simulate a high memory pressure environment with certain parameters even without [the rest of the kernel] interacting might still be super super useful for diagnosing issues.x
There is a concern people start looking at these tests as signal for performance regressions - which is neither meaningful nor useful (unless you fundamentally break list iteration or something).
Quoted 5 lines
But for trivial cases, you'd at least like to know under strongly controlled aging and reclaim scenarios that anon/file memory is reclaimed in a balanced manner - just as an example.
If something breaks THAT assumption, you know there's a logic issue.
Yeah and you could assert a lot of things like this, for me the real value would be in extreme circumstances which might otherwise be hard to simulate.
But it'd be testing very specific things rather than 'how does an actual kernel behave in this situation?'
Quoted 6 lines
Likewise with comparisons between LRU and MGLRU. It might be easier to identify the behavioral divergences that way.
But i fear the whole page-table walk thing makes all of this a non-starter. That's turns into stubbing out like rmap and such.
It could grow exponentially yes :) it was hard enough isolating the VMA logic...
Quoted 2 lines
~Gregory
Cheers, Lorenzo
Quoted 3 lines · Tal Zussman
Quoted 2 lines · Matthew Wilcox
Quoted 1 line · Axel Rasmussen
On Thu, Mar 26, 2026 at 1:30 PM Gregory Price <[email protected]> wrote:
...
Quoted 8 lines
Yeah, unfortunately it's not so straightforward. As a simple illustrative example, consider a file-search workload, where you search through a large number of files over and over again (e.g., a poor kernel developer trying to understand how the page cache works). This follows an MRU, rather than LRU, pattern, and readahead doesn't help much, leading the active/inactive and MGLRU policies to have similar performance (~40s runtime in a specific benchmark we ran). In comparison, using
cache_ext(our eBPF-based caching framework), we can run an MRU policy and it goes down to 20s.
That's dramatic!
...
Quoted 2 lines
It's been well-known in the academic realm for a while that there isn't really a "one-size-fits-all" policy that works *best* for all workloads.
I think that that point has been less clear, outside of academia. In fact, MGRLU (to the extent that we believed we would eventually get rid of LRU, in favor of MGLRU) doubled down on the idea of one size fits all. So this is interesting.
Quoted 11 lines
Yes, you can make a general policy that works *well*, but if you really care about a workload's performance and want to squeeze out the last 10-20% (or more) of performance, you need to be able to (1) experiment and (2) take advantage of application-level insights. Being able to extend reclaim (in our case with eBPF) enables that.
We wrote a paper about this that was published a few months ago [1]. Happy to answer any questions and continue the discussion!
Excellent work, I was delighted to find a well-balanced description of both older and more recent history of the Linux page cache there.
It's helpful to read this, even if we go with a non-eBPF approach.
thanks,
Signature · 1 line
John Hubbard
Quoted 34 lines · John Hubbard
Quoted 3 lines · Tal Zussman
Quoted 2 lines · Matthew Wilcox
Quoted 1 line · Axel Rasmussen
On Thu, Mar 26, 2026 at 1:30 PM Gregory Price <[email protected]> wrote:
...
Quoted 8 lines
Yeah, unfortunately it's not so straightforward. As a simple illustrative example, consider a file-search workload, where you search through a large number of files over and over again (e.g., a poor kernel developer trying to understand how the page cache works). This follows an MRU, rather than LRU, pattern, and readahead doesn't help much, leading the active/inactive and MGLRU policies to have similar performance (~40s runtime in a specific benchmark we ran). In comparison, using
cache_ext(our eBPF-based caching framework), we can run an MRU policy and it goes down to 20s.That's dramatic!
...
Quoted 2 lines
It's been well-known in the academic realm for a while that there isn't really a "one-size-fits-all" policy that works *best* for all workloads.
I think that that point has been less clear, outside of academia. In fact, MGRLU (to the extent that we believed we would eventually get rid of LRU, in favor of MGLRU) doubled down on the idea of one size fits all. So this is interesting.
Quoted 9 lines
Yes, you can make a general policy that works *well*, but if you really care about a workload's performance and want to squeeze out the last 10-20% (or more) of performance, you need to be able to (1) experiment and (2) take advantage of application-level insights. Being able to extend reclaim (in our case with eBPF) enables that.
We wrote a paper about this that was published a few months ago [1]. Happy to answer any questions and continue the discussion!
Quoted 7 lines
Quoted 2 lines
Excellent work, I was delighted to find a well-balanced description of both older and more recent history of the Linux page cache there.
It's helpful to read this, even if we go with a non-eBPF approach.
Yes, thanks for that, it's interesting!
But I would say for now we need to defer any consideration of bpf being a thing until we actually get things into shape in terms of improving and modularising the existing reclaim mechanisms.
mm has been far too keen to take features without paying down technical debt first and it's been very costly, so before anything else, we must ensure that reclaim is both long-term maintainable and maintained.
In terms of reclaim bpf as a concept in general - reclaim is so very sensitive to even minor changes, and I fear that people might find something that appears to dramatically improve matters in one scenario, but end up with an unusable system in another.
A bad sched_ext implementation might result in poor responsiveness, but a bad reclaim_ext implementation might result in a soft-locked system, and I fear that it might be quite easy to do that.
In any case, we can look at all that once we are in a better place with reclaim, which Shakeel's proposal focuses on and I'm very much in favour of! :)
Quoted 6 lines
thanks,
--
John Hubbard
Cheers, Lorenzo
Quoted 34 lines · John Hubbard
Quoted 3 lines · Tal Zussman
Quoted 2 lines · Matthew Wilcox
Quoted 1 line · Axel Rasmussen
On Thu, Mar 26, 2026 at 1:30 PM Gregory Price <[email protected]> wrote:
...
Quoted 8 lines
Yeah, unfortunately it's not so straightforward. As a simple illustrative example, consider a file-search workload, where you search through a large number of files over and over again (e.g., a poor kernel developer trying to understand how the page cache works). This follows an MRU, rather than LRU, pattern, and readahead doesn't help much, leading the active/inactive and MGLRU policies to have similar performance (~40s runtime in a specific benchmark we ran). In comparison, using
cache_ext(our eBPF-based caching framework), we can run an MRU policy and it goes down to 20s.That's dramatic!
...
Quoted 2 lines
It's been well-known in the academic realm for a while that there isn't really a "one-size-fits-all" policy that works *best* for all workloads.
I think that that point has been less clear, outside of academia. In fact, MGRLU (to the extent that we believed we would eventually get rid of LRU, in favor of MGLRU) doubled down on the idea of one size fits all. So this is interesting.
Quoted 9 lines
Yes, you can make a general policy that works *well*, but if you really care about a workload's performance and want to squeeze out the last 10-20% (or more) of performance, you need to be able to (1) experiment and (2) take advantage of application-level insights. Being able to extend reclaim (in our case with eBPF) enables that.
We wrote a paper about this that was published a few months ago [1]. Happy to answer any questions and continue the discussion!
Quoted 8 lines
Quoted 2 lines
Excellent work, I was delighted to find a well-balanced description of both older and more recent history of the Linux page cache there.
It's helpful to read this, even if we go with a non-eBPF approach.
That's great to hear, thank you!
Quoted 5 lines
thanks,
Signature · 1 line
John Hubbard
Quoted 11 lines · Gregory Price
Quoted 9 lines · Tal Zussman
It's been well-known in the academic realm for a while that there isn't really a "one-size-fits-all" policy that works *best* for all workloads. Yes, you can make a general policy that works *well*, but if you really care about a workload's performance and want to squeeze out the last 10-20% (or more) of performance, you need to be able to (1) experiment and (2) take advantage of application-level insights. Being able to extend reclaim (in our case with eBPF) enables that.
Quoted 3 lines
This just makes me think going all the way to
reclaim_extand re-writing MGLRU as an eBPF extension in an effort to simplify the code/maintenance and keep what works working is the least-worst option.
That may very well be true, at least on the policy side. In fact, we implemented an MGLRU policy in eBPF. The infrastructure side is a different story, as Shakeel has pointed out.
Quoted 2 lines
But this is a naive take, i'm sure making that interface stable would be even worse than just maintaining both LRU/MGLRU.
Putting eBPF aside for a second, I'm of the opinion that separating reclaim policy from infrastructure and creating such an interface would actually be beneficial for maintenance long-term. There's no clean separation between policy and infrastructure right now, making the code less readable and potentially affecting performance. I'm in the process of collecting some instances of such overlap and assessing what their impact is.
Now, once you have such an interface... eBPF falls into place pretty nicely...
Thanks,
Tal
Quoted 10 lines · Lorenzo Stoakes
Yes, thanks for that, it's interesting!
But I would say for now we need to defer any consideration of bpf being a thing until we actually get things into shape in terms of improving and modularising the existing reclaim mechanisms.
mm has been far too keen to take features without paying down technical debt first and it's been very costly, so before anything else, we must ensure that reclaim is both long-term maintainable and maintained.
Completely agreed that cleanup is necessary and modularization is a big step towards that. I do think it makes sense to think about what eBPF would look like as part of that future though. It would be a shame to do all of that modularization work, then decide to integrate eBPF later on and realize that we need major changes to make that happen (but, given a well-designed interface, I think that's unlikely to be a significant issue).
Quoted 4 lines
In terms of reclaim bpf as a concept in general - reclaim is so very sensitive to even minor changes, and I fear that people might find something that appears to dramatically improve matters in one scenario, but end up with an unusable system in another.
That concern is precisely why we implemented per-cgroup policies. We found that running each application with a policy that works best for it yielded greater overall performance. System-wide policies may need something more generic, but if you can make them more granular, you can specialize more without running into such issues. This was simple enough to do given that the LRU lists are already per-memcg, and eBPF (is about to) support per-cgroup struct_ops programs.
Quoted 3 lines
A bad
sched_extimplementation might result in poor responsiveness, but a badreclaim_extimplementation might result in a soft-locked system, and I fear that it might be quite easy to do that.
Anecdotally, having implemented about a dozen policies across dozens of workloads, we never ran into a soft-lockup. That's not a guarantee that it can't happen, but with a properly implemented fallback/watchdog to ensure that pages actually get reclaimed as necessary, this should be manageable. sched_ext actually implements such a watchdog to kick out misbehaving eBPF schedulers.
Quoted 6 lines
In any case, we can look at all that once we are in a better place with reclaim, which Shakeel's proposal focuses on and I'm very much in favour of! :)
Cheers, Lorenzo