mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Johannes Weiner <hannes@cmpxchg.org>
To: Andrew Morton <akpm@linux-foundation.org>
Cc: Chris Mason <mason@kernel.org>,
	David Hildenbrand <david@kernel.org>,
	Michal Hocko <mhocko@kernel.org>,
	Roman Gushchin <roman.gushchin@linux.dev>,
	Shakeel Butt <shakeel.butt@linux.dev>,
	linux-mm@kvack.org, cgroups@vger.kernel.org,
	linux-kernel@vger.kernel.org, Dave Chinner <david@fromorbit.com>,
	Kairui Song <kasong@tencent.com>,
	Muchun Song <muchun.song@linux.dev>,
	Qi Zheng <qi.zheng@linux.dev>
Subject: [PATCH 1/2] mm: list_lru: fix XArray node leak at destroy
Date: Fri,  4 Dec 2026 12:39:28 -0500	[thread overview]
Message-ID: <20261204173929.2355221-1-hannes@cmpxchg.org> (raw)

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


             reply	other threads:[~2026-12-04 17:39 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-12-04 17:39 Johannes Weiner [this message]
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

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20261204173929.2355221-1-hannes@cmpxchg.org \
    --to=hannes@cmpxchg.org \
    --cc=akpm@linux-foundation.org \
    --cc=cgroups@vger.kernel.org \
    --cc=david@fromorbit.com \
    --cc=david@kernel.org \
    --cc=kasong@tencent.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mm@kvack.org \
    --cc=mason@kernel.org \
    --cc=mhocko@kernel.org \
    --cc=muchun.song@linux.dev \
    --cc=qi.zheng@linux.dev \
    --cc=roman.gushchin@linux.dev \
    --cc=shakeel.butt@linux.dev \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®