All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH 1/2] mm: list_lru: fix XArray node leak at destroy
@ 2026-12-04 17:39 Johannes Weiner
  2026-12-04 17:39 ` [PATCH 2/2] mm: list_lru: charge per-memcg lists and XArray nodes Johannes Weiner
  2026-12-06  2:57 ` [PATCH 1/2] mm: list_lru: fix XArray node leak at destroy Muchun Song
  0 siblings, 2 replies; 4+ messages in thread
From: Johannes Weiner @ 2026-12-04 17:39 UTC (permalink / raw)
  To: Andrew Morton
  Cc: Chris Mason, David Hildenbrand, Michal Hocko, Roman Gushchin,
	Shakeel Butt, linux-mm, cgroups, linux-kernel, Dave Chinner,
	Kairui Song, Muchun Song, Qi Zheng

From: Chris Mason <mason@kernel.org>

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@fromorbit.com>
Cc: Kairui Song <kasong@tencent.com>
Cc: Michal Hocko <mhocko@kernel.org>
Cc: Muchun Song <muchun.song@linux.dev>
Cc: Qi Zheng <qi.zheng@linux.dev>
Cc: Roman Gushchin <roman.gushchin@linux.dev>
Cc: Shakeel Butt <shakeel.butt@linux.dev>
Signed-off-by: Chris Mason <mason@kernel.org>
Signed-off-by: David Hildenbrand (Arm) <david@kernel.org>
Signed-off-by: Johannes Weiner <hannes@cmpxchg.org>
---
 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



^ permalink raw reply related	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2026-12-06  2:58 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-12-04 17:39 [PATCH 1/2] mm: list_lru: fix XArray node leak at destroy Johannes Weiner
2026-12-04 17:39 ` [PATCH 2/2] mm: list_lru: charge per-memcg lists and XArray nodes Johannes Weiner
2026-12-04 20:33   ` sashiko-bot
2026-12-06  2:57 ` [PATCH 1/2] mm: list_lru: fix XArray node leak at destroy Muchun Song

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.