[PATCH v7 02/19] mm/memcontrol: allow update of LRU statistic without holding LRU lock

From: Kairui Song via B4 Relay

Date: Tue Dec 01 2026 - 15:19:52 EST


From: Kairui Song <kasong@xxxxxxxxxxx>

To enable moving file pages in folio_mark_accessed directly and lazily
for MGLRU, allow updating the LRU statistic atomically without holding a
lock. It may cause temporary counter underflow, which should be fine as
the counter is eventually consistent and only serves as an estimate.

Use a standalone helper and leaves __update_lru_size() with its lockdep
assertion to the lock holders, which may batch the updates [1].

Link: https://lore.kernel.org/20261029204157.117879-1-joannelkoong@xxxxxxxxx [1]
Link: https://lore.kernel.org/linux-mm/387237c3-c2f8-4782-9ba6-481f459cf7f2@xxxxxxxxx/
Reviewed-by: Barry Song <baohua@xxxxxxxxxx>
Reviewed-by: Kunwu Chan <kunwu.chan@xxxxxxxxx>
Tested-by: Andrew Morton <akpm@xxxxxxxxxxxxxxxxxxxx>
Reviewed-by: Lian Wang <lianux.mm@xxxxxxxxx>
Reviewed-by: SJ Park <sj@xxxxxxxxxx>
Reviewed-by: Ridong Chen <ridong.chen@xxxxxxxxx>
Signed-off-by: Kairui Song <kasong@xxxxxxxxxxx>
---
include/linux/mm_inline.h | 17 +++++++++++++++++
1 file changed, 17 insertions(+)

diff --git a/include/linux/mm_inline.h b/include/linux/mm_inline.h
index c6aa1d4b69fa..b68b971d5a25 100644
--- a/include/linux/mm_inline.h
+++ b/include/linux/mm_inline.h
@@ -55,6 +55,23 @@ static __always_inline void __update_lru_size(struct lruvec *lruvec,
NR_ZONE_LRU_BASE + lru, nr_pages);
}

+/*
+ * __update_lru_size() for callers that don't hold lru_lock, so can't rely
+ * on it disabling IRQs.
+ */
+static __always_inline void __update_lru_size_lockless(struct lruvec *lruvec,
+ enum lru_list lru, enum zone_type zid,
+ long nr_pages)
+{
+ struct pglist_data *pgdat = lruvec_pgdat(lruvec);
+
+ WARN_ON_ONCE(nr_pages != (int)nr_pages);
+
+ mod_lruvec_state(lruvec, NR_LRU_BASE + lru, nr_pages);
+ mod_zone_page_state(&pgdat->node_zones[zid],
+ NR_ZONE_LRU_BASE + lru, nr_pages);
+}
+
static __always_inline void update_lru_size(struct lruvec *lruvec,
enum lru_list lru, enum zone_type zid,
long nr_pages)

--
2.56.1