From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=209.85.128.171 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796405976; b=CdDeLQnp6WoeN+BeN0B6BtjkieeNLjJeNMoKfEpCzFZwUra5Hn5Exe+qgNEdFULH1x3+ JIc0OUfL51d2t3amtVFWytMV8kcSkd4ZVt101fHUyLG33aqo8WiE0MErmVSgn76Qgn+jt /TFFh1LD/j1iBF8t6q8rlJ9kcs9m2DD6cxEnXJtl/TDqikaIBbxVZYo8DlrRh9eHsFUq9 thmHSv01YCIPM4EMbZ+ICdwkHGzd90URYQNrFqimagSZBP1cxytT0hb1p8cGxF7xrTUpc RaP2oDug8S/9T0R6clsOLwnLqRRfvGQOEk/kea93ouaUMDrZIkW2/IfrmyrHIhSvc1A== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796405976; h=DMARC-Filter:Received:DKIM-Signature:X-Google-DKIM-Signature: X-Forwarded-Encrypted:X-Gm-Message-State:X-Gm-Gg:X-Received:Received: From:To:Cc:Subject:Date:Message-ID:X-Mailer:MIME-Version: Content-Transfer-Encoding; bh=TlZWSjtcPH52jQ4z7m8jdDHOGZAMg6/H7YFuBE5Hk7M=; b=sxYkHX690Nts5cURmq65U3OS/rCaiu7UVSUzjyhRKlY4OrcXSnI1Vy3bJrcbueO3f0nc RgPVmhTs/vZ3b+QMek2Biqc//Y4DrWEiaLIeuNK57laf/fOlwC1gvtxIExvN87XdienIx Gi6JkqylNybfyG1MVA3ERZjAsqiODYEekpbFUcIJwVLynZ/w8QSm0Uc7PfMaOiutMIMNW w6uRYetMxmWUqARtoTocWpzVivrMRs4WpDRdiuJn33bWYXLAdDZPZKBciTKJiY797J6dH 7U51rM1SYWD32Hm+txN5A8TVj/sG2g+E6K1UsH0iUPyjX7x8bQduDQveRFGEh6iDeNg== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass header.from=cmpxchg.org; spf=pass smtp.mailfrom=cmpxchg.org; dkim=pass header.d=cmpxchg.org header.i=@cmpxchg.org header.a=rsa-sha256 header.s=google header.b=rsHkRPrx; arc=none smtp.remote-ip=209.85.128.171 Received: from mail-yw1-f171.google.com (mail-yw1-f171.google.com [209.85.128.171]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id C59ED606A32C for ; Fri, 4 Dec 2026 17:39:35 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org C59ED606A32C Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=cmpxchg.org Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=cmpxchg.org Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key, unprotected) header.d=cmpxchg.org header.i=@cmpxchg.org header.a=rsa-sha256 header.s=google header.b=rsHkRPrx Received: by mail-yw1-f171.google.com with SMTP id 00721157ae682-8b503e2a87bso12277647b3.3 for ; Fri, 04 Dec 2026 09:39:35 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=cmpxchg.org; s=google; t=1796405974; x=1797010774; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to:content-type; bh=TlZWSjtcPH52jQ4z7m8jdDHOGZAMg6/H7YFuBE5Hk7M=; b=rsHkRPrxyZMV7xWy4qJSfM+9OMXUxIlMlhgfXpAcpmFOGMUvZ8xsRarbtTO6GER7D6 Wqg1LhMZ1QIa21BJPvDxy9LrSys8S1+qqRGRDEGoQUwGo5EAcjqxph9RaSko/uiae+oL k4l3iimivx5GtSEs07ciN8RCOBBcEFbDL2RqQSheof1Hk0ZAiceKbTsNYhJDMxEyStQo TuGBYPKzhrVBkNFAUUP/ZV0vgDkY0b5evsup2LKNJgpnejWF/PZO6b6MW54TkdarN5dx NoRy2oi1dcVKOxhmOqzYWjaWqEdDPqwHR0Iw7xu4V+E3sqTX02kPALdo+qRs7yHWLl6l 7zgQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1796405974; x=1797010774; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-gg:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to:content-type; bh=TlZWSjtcPH52jQ4z7m8jdDHOGZAMg6/H7YFuBE5Hk7M=; b=qHdXPLFU9YzWAkvNVSUd2oDbkpcKg1nKlzSq+lYOjlIpl15EXRxY6PTKpWD7a2Jh56 izj3Jzm6pvx57l7X6HDHQwQ77s0/nDhM4nXk2ubr9US+trPioDL8FB99L4aD+OA9dbVv XEQGE2ai4WE2n2lMPi20n8hI6QGzOGTEICblkKdc4+fJhX/AiSMcHG4y4eY1rO1vpyHN F0SvajpG9TFzvU/uPTWrJkkr5ollbMqVl5QBcGWgBwNaAjiOBbdPTRKTG6S4I/woN8z9 fuDSAi6eXue/SJeXll8sfSN4zHuBusDXPQQFdjHHUGG/Cyhqax9uxMu6RS3GIBjVR6GV lJ7g== X-Forwarded-Encrypted: i=1; AL+hErEpXN+IjTperHhlDlHFLMZ0MCL4jI4JbftVMo/hyPm5rVR5UaW2bgetV5JusokpN4o6vtCI/3JNkVhl2II=@vger.kernel.org X-Gm-Message-State: AB4q+uHAqx0j18K7ZNlXFAn8696bog1hFk4ZWnKsvvj6dYkSdsewhTrg U77ffmy2KUSnOTbutKFZmSmXVBugjQKOFYBhQqqyRHPZ5ZSHIC4Svkx1SwNj64JdLm8= X-Gm-Gg: AZFdTZe9lgZuHlo/FUrQufgjuM99KTR4x+hiJXysK5g45Jw15NdjLK9PyxRz7mjyQ4L cpLu7waDfbaLjSeM0+YHMxZqC14SaTim2yIiP9rsfsK3Jt2TsIeSkbWJLgjSs70vy6l1xeFS7jD pCOai3kV/3g3tjXEwPxLajFMbz7eHZcmQp8r3Rld4sOb3DHeLlyxWbJmAjVexk4okLcX6fVI3yK GORBq0ns1TLW3rq0+wp9YTzKGWjet88+u3WJfvrTEdGs2psdQPNmwYf5i2CdgADaVFTwEV15fIT 5ABmqH51q2I+gYwMRT3rAuOQSNsz0BpNsUnv/X89TucAa7b1RgRMsOwIfUaWswST34aL5zK+q9E 1hZSl9f+t6LOpn8KsJ7/earxqD42MoJTO9ka+w5Y1oAibnQ/KNHTWwEt//iJY82Syt+QUSLQu6y YQDOZu7amJqmtkAYCzmuPDhBYzbOz2IdIDw14+YzlNOAHxUce5e2EeUBuBQpHwrbqVPi8XNRpi3 p7GgivcmHcLywv90LZbR/kdDzkQmMy2VFPYRfaNi4ue1nRqmoMMuEyaS3xrOXAiGBuGmE0eVK2y lpq1EbEsdljeJsG3FzNvn+zAn87K5lSTn5wTNvOxxLJTToN7 X-Received: by 2002:a05:690c:586:b0:8b1:88ad:1fce with SMTP id 00721157ae682-8b660d93039mr16786237b3.42.1796405974628; Fri, 04 Dec 2026 09:39:34 -0800 (PST) Received: from localhost ([2605:8600:200:dc6:365a:60ff:fe62:ff29]) by smtp.gmail.com with ESMTPSA id 00721157ae682-8b6604050d7sm12609547b3.5.2026.12.04.09.39.33 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 04 Dec 2026 09:39:34 -0800 (PST) From: Johannes Weiner To: Andrew Morton Cc: Chris Mason , David Hildenbrand , Michal Hocko , Roman Gushchin , Shakeel Butt , linux-mm@kvack.org, cgroups@vger.kernel.org, linux-kernel@vger.kernel.org, Dave Chinner , Kairui Song , Muchun Song , Qi Zheng Subject: [PATCH 1/2] mm: list_lru: fix XArray node leak at destroy Date: Fri, 4 Dec 2026 12:39:28 -0500 Message-ID: <20261204173929.2355221-1-hannes@cmpxchg.org> X-Mailer: git-send-email 2.56.1 X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Transfer-Encoding: 8bit From: Chris Mason 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 Cc: Kairui Song Cc: Michal Hocko Cc: Muchun Song Cc: Qi Zheng Cc: Roman Gushchin Cc: Shakeel Butt Signed-off-by: Chris Mason Signed-off-by: David Hildenbrand (Arm) Signed-off-by: Johannes Weiner --- 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