Documentation/admin-guide/cgroup-v2.rst | 17 +++ include/linux/mmzone.h | 16 +++ mm/memcontrol.c | 31 +++++ mm/vmscan.c | 176 +++++++++++++++++++----- 4 files changed, 206 insertions(+), 34 deletions(-)
This patchset adds a memory.lru_gen interface to cgroup v2, allowing users
to interact with MGLRU directly on a specific cgroup without needing to
know the internal memcg_id.
Motivation
==========
Currently, the only way to perform aging or eviction on a specific memcg
is through the debugfs interface (/sys/kernel/debug/lru_gen), which
requires the memcg_id. However, there's no straightforward way to get the
memcg_id for a given cgroup path. This makes it difficult for users to
leverage MGLRU's proactive reclaim capabilities on specific cgroups.
Solution
========
The new memory.lru_gen interface operates directly on the cgroup:
# Show lru_gen info for this cgroup
cat /sys/fs/cgroup/mygroup/memory.lru_gen
# Run aging on node 0
echo '+ 0 <seq>' > /sys/fs/cgroup/mygroup/memory.lru_gen
# Evict cold pages on node 0
echo '- 0 <seq> <swappiness> <nr_to_reclaim>' > \
/sys/fs/cgroup/mygroup/memory.lru_gen
This interface is available on all cgroups including root, providing the
same functionality as the debugfs lru_gen interface.
Testing
=======
Create 1GB page cache, loop access 200MB as hot pages.
After aging twice, 200MB hot pages are in young generation,
800MB cold pages remain in oldest generation.
Eviction with seq=min_seq only reclaims cold pages, hot pages preserved.
Patches
=======
Patch 1 refactors the existing debugfs code to extract helper functions.
Patch 2 adds the memory.lru_gen interface using these helpers.
Patch 3 adds documentation for the new interface.
Jiayuan Chen (3):
mm/lru_gen: refactor to extract helper functions
mm/lru_gen: add memory.lru_gen interface for cgroup v2
docs/cgroup: document memory.lru_gen interface
Documentation/admin-guide/cgroup-v2.rst | 17 +++
include/linux/mmzone.h | 16 +++
mm/memcontrol.c | 31 +++++
mm/vmscan.c | 176 +++++++++++++++++++-----
4 files changed, 206 insertions(+), 34 deletions(-)
--
2.43.0
On Wed, Jan 21, 2026 at 08:39:46PM +0800, Jiayuan Chen wrote: > This patchset adds a memory.lru_gen interface to cgroup v2, allowing users > to interact with MGLRU directly on a specific cgroup without needing to > know the internal memcg_id. Unfortunetely we don't want to expose reclaim implementation specific interface to a cgroup. > > Motivation > ========== > Currently, the only way to perform aging or eviction on a specific memcg > is through the debugfs interface (/sys/kernel/debug/lru_gen), which > requires the memcg_id. However, there's no straightforward way to get the > memcg_id for a given cgroup path. This makes it difficult for users to > leverage MGLRU's proactive reclaim capabilities on specific cgroups. From the next kernel version, this memcg_id will be inode number of the cgroup for this interface. So, a simple 'ls -id cgroup_path' would be sufficient for your use-case. The relevant series [1] is in mm-tree at the moment and if you want, you can backport it to your kernels. [1] https://lkml.kernel.org/r/20251225232116.294540-1-shakeel.butt@linux.dev
January 22, 2026 at 06:19, "Shakeel Butt" <shakeel.butt@linux.dev mailto:shakeel.butt@linux.dev?to=%22Shakeel%20Butt%22%20%3Cshakeel.butt%40linux.dev%3E > wrote: > > On Wed, Jan 21, 2026 at 08:39:46PM +0800, Jiayuan Chen wrote: > > > > > This patchset adds a memory.lru_gen interface to cgroup v2, allowing users > > to interact with MGLRU directly on a specific cgroup without needing to > > know the internal memcg_id. > > > Unfortunetely we don't want to expose reclaim implementation specific > interface to a cgroup. > > > > > Motivation > > ========== > > Currently, the only way to perform aging or eviction on a specific memcg > > is through the debugfs interface (/sys/kernel/debug/lru_gen), which > > requires the memcg_id. However, there's no straightforward way to get the > > memcg_id for a given cgroup path. This makes it difficult for users to > > leverage MGLRU's proactive reclaim capabilities on specific cgroups. > > > From the next kernel version, this memcg_id will be inode number of the > cgroup for this interface. So, a simple 'ls -id cgroup_path' would be > sufficient for your use-case. > > The relevant series [1] is in mm-tree at the moment and if you want, you > can backport it to your kernels. > > [1] https://lkml.kernel.org/r/20251225232116.294540-1-shakeel.butt@linux.dev > Hi Shakeel, Thanks for the review and the pointer to the inode-based memcg_id series. I agree that using the cgroup inode number as memcg_id will simplify the write operations (aging/eviction) through the debugfs interface. However, I'd like to point out that the read operation (viewing lru_gen info for a specific cgroup) is still not convenient. Currently, users would need to parse the full debugfs output and grep for the specific memcg_id, which can be cumbersome especially on systems with many cgroups. Would it be acceptable to add a read-only command to /lru_gen that only displays the lru_gen information for the specified cgroup? Alternatively, if exposing any lru_gen info in cgroup is not desired, I understand and will use the debugfs approach with scripting. Thanks, chenjiayuan
© 2016 - 2026 Red Hat, Inc.