Re: [PATCH v3 3/5] mm/mglru: cache the last memcg node, make tail insertion constant time
From: Baolin Wang
Date: Mon Nov 23 2026 - 05:01:00 EST
On 11/16/26 4:14 PM, Max Kellermann wrote:
Rotating or onlining a memcg currently uses hlist_nulls_add_tail_rcu()
which walks the destination bin to find its tail while holding
`memcg_lru.lock` with interrupts disabled. With thousands of cgroups,
this takes a long time and causes severe lock contention.
Cache a pointer to each bin's last node, making tail insertion O(1).
This requires remembering the bin number (but the new struct field
occupies a hole, so it does not grow).
In a micro benchmark that creates 1500 cgroups and repeatedly writes
`1024M swappiness=0` to `memory.reclaim` in 8 threads, the request
rate increases by a factor of 9.5 and the average duration of each
write request is reduced by 89%.
All writes return EAGAIN in both runs; the benchmark measures the cost
of reclaim attempts that cannot meet their requested target, not
reclaimed throughput.
Fixes: e4dde56cd208 ("mm: multi-gen LRU: per-node lru_gen_folio lists")
I don't think this fixes anything, right?
Signed-off-by: Max Kellermann <max.kellermann@xxxxxxxxx>
---
Thanks. We hit the same issue in our stress tests and confirmed that this optimization works.
Reviewed-by: Baolin Wang <baolin.wang@xxxxxxxxxxxxxxxxx>