[PATCH 1/2] mm: list_lru: fix XArray node leak at destroy
From: Johannes Weiner
Date: Fri Dec 04 2026 - 12:39:42 EST
From: Chris Mason <mason@xxxxxxxxxx>
memcg_destroy_list_lru() tears down lru->xa by erasing its entries,
and relies on the XArray to free each node once its last entry is
gone. That is not how an XArray is torn down. A node can exist
without entries, and nothing frees that one; it also keeps the count
of its parent up, so the parent and everything above it stay
allocated as well. The API has xa_destroy() for this: free the
entries, then call it to free the nodes.
Empty nodes come from a store that gave up partway. xas_create()
builds the path to a new index one level at a time, and links each
node into the tree before it allocates the next. If that allocation
fails, the linked node stays. This is by design: once xas_nomem()
has refilled the cache, the retry descends into the node and
completes the path, and later stores reuse it too. But if the retry
cannot allocate either, the store returns -ENOMEM and the node stays
empty. __memcg_list_lru_alloc() gets there with GFP_NOWAIT when the
page cache allocates a node under memory pressure.
The leak is small, a few nodes per list_lru, and shows at umount.
Fix it by calling xa_destroy() once the entries are freed.
Fixes: bbca91cca9a9 ("mm: list_lru: replace linear array with xarray")
Cc: Dave Chinner <david@xxxxxxxxxxxxx>
Cc: Kairui Song <kasong@xxxxxxxxxxx>
Cc: Michal Hocko <mhocko@xxxxxxxxxx>
Cc: Muchun Song <muchun.song@xxxxxxxxx>
Cc: Qi Zheng <qi.zheng@xxxxxxxxx>
Cc: Roman Gushchin <roman.gushchin@xxxxxxxxx>
Cc: Shakeel Butt <shakeel.butt@xxxxxxxxx>
Signed-off-by: Chris Mason <mason@xxxxxxxxxx>
Signed-off-by: David Hildenbrand (Arm) <david@xxxxxxxxxx>
Signed-off-by: Johannes Weiner <hannes@xxxxxxxxxxx>
---
mm/list_lru.c | 3 +++
1 file changed, 3 insertions(+)
diff --git a/mm/list_lru.c b/mm/list_lru.c
index 651983d0bf8b..5d4b660f9fe4 100644
--- a/mm/list_lru.c
+++ b/mm/list_lru.c
@@ -499,6 +499,9 @@ static void memcg_destroy_list_lru(struct list_lru *lru)
xas_store(&xas, NULL);
}
xas_unlock_irq(&xas);
+
+ /* Erasing the entries leaves nodes that never held one; free those too. */
+ xa_destroy(&lru->xa);
}
static void memcg_reparent_list_lru_one(struct list_lru *lru, int nid,
--
2.56.1