From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 90CC8606A322 for ; Fri, 4 Dec 2026 20:34:02 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=I7U6fg1i Received: by kanga.kvack.org (Postfix) id 654AA6B05B2; Fri, 4 Dec 2026 15:34:01 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 62C1A6B05B3; Fri, 4 Dec 2026 15:34:01 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 569826B05B4; Fri, 4 Dec 2026 15:34:01 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0012.hostedemail.com [216.40.44.12]) by kanga.kvack.org (Postfix) with ESMTP id 29C776B05B2 for ; Fri, 4 Dec 2026 15:34:01 -0500 (EST) Received: from smtpin20.hostedemail.com (lb01a-stub [10.200.18.249]) by unirelay03.hostedemail.com (Postfix) with ESMTP id 0DFACA0579 for ; Fri, 4 Dec 2026 20:34:00 +0000 (UTC) X-FDA: 85507452240.20.18EF956 Received: from sea.source.kernel.org (sea.source.kernel.org [172.234.252.31]) by imf23.hostedemail.com (Postfix) with ESMTP id 512D514000C for ; Fri, 4 Dec 2026 20:33:58 +0000 (UTC) Authentication-Results: imf23.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20260515 header.b=I7U6fg1i; dmarc=pass (policy=quarantine) header.from=kernel.org; spf=pass (imf23.hostedemail.com: domain of sashiko-bot@kernel.org designates 172.234.252.31 as permitted sender) smtp.mailfrom=sashiko-bot@kernel.org ARC-Seal: i=1; a=rsa-sha256; d=hostedemail.com; s=arc-20220608; cv=none; t=1796416438; b=KYUHg7TEZgYsS71YK3yK3Jek+/C9vxLRvyjVgATWD7N4UpAefprk5SgOJOZGJRu1NbXoE4 XGCSFznFx9iBJZO1fkcWM+x1KG2FZv+nVP7yPmOekgPf1V3p3Oz7ibQ4JePPCIVtY9Jkg7 oEuEtgNBwswnlV7jEYxXgdoR9C24T5s= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1796416438; h=from:from:sender:reply-to:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=A2ZBdd7Mz5HxH5vnnUuV2mPiphECjVnefsMpYeQdooA=; b=SnQLmbvRdSbjrjCztC4M+kTDJKtx01hoIQS7++4yWXJ6AnIdR007qhb8CRYHPnfgh47bjh w54nnCqqNTHMyxepM4le6CQ4DUHtQF5GZ4KExtZSphoO6fRqnH3LiPUQ9Ja+yYx1OnMpuf VmXpC/dyZmHrdKZeKC+ivulV1pFs3Ks= ARC-Authentication-Results: i=1; imf23.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20260515 header.b=I7U6fg1i; dmarc=pass (policy=quarantine) header.from=kernel.org; spf=pass (imf23.hostedemail.com: domain of sashiko-bot@kernel.org designates 172.234.252.31 as permitted sender) smtp.mailfrom=sashiko-bot@kernel.org Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18]) by sea.source.kernel.org (Postfix) with ESMTP id 36B8243B83; Fri, 4 Dec 2026 20:33:57 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 358D71F00936; Fri, 4 Dec 2026 20:33:56 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1796416437; bh=A2ZBdd7Mz5HxH5vnnUuV2mPiphECjVnefsMpYeQdooA=; h=From:Subject:Reply-To:To:Cc:In-Reply-To:References:Date; b=I7U6fg1iIheUEV+LcIgf6d1Tbncn/IPnTDjLMN27EvlizDZX0En9Si88e+4jeHf02 y9uwlScspW5pmrGjcD/0IOel7jtxbOZ8c8WaalXKYV+MHT0Dkb2fWeUeUu6I1I0yZ7 NNVuyrX8XUg9dIhFKOrDqzth84jRow6FFAUoxBAETsqEt0Im/hHooBKZSkJP379TP5 NQEH+VFKoGmexjFFCxrOx2QR350XizVo7+yKokVgX72wwyDgR1cHrVvISttv3PsXl/ E1rT6RnSiw/gx6aC621IwJMUpBigkhfeOGhwqPx0XZ0Py3FQSOtCWAMNuWCrlrUBlB yRgMEMZ64VW/Q== Message-ID: From: sashiko-bot@kernel.org Subject: Re: [PATCH 2/2] mm: list_lru: charge per-memcg lists and XArray nodes Reply-To: sashiko-reviews@lists.linux.dev To: "Johannes Weiner" , "Andrew Morton" Cc: "Chris Mason" , "David Hildenbrand" , "Michal Hocko" , "Roman Gushchin" , "Shakeel Butt" , linux-mm@kvack.org, "Baolin Wang" , "Dave Chinner" , "Harry Yoo" , "Hugh Dickins" , "Kairui Song" , "Matthew Wilcox" , "Muchun Song" , "Qi Zheng" , "Qinyun Tan" , "Vlastimil Babka" , "Zi Yan" , tj@kernel.org, mkoutny@suse.com In-Reply-To: <20261204173929.2355221-2-hannes@cmpxchg.org> References: <20261204173929.2355221-1-hannes@cmpxchg.org> <20261204173929.2355221-2-hannes@cmpxchg.org> Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Date: Fri, 04 Dec 2026 20:33:55 +0000 X-Rspamd-Server: rspam04 X-Rspam-User: X-Rspamd-Queue-Id: 512D514000C X-Stat-Signature: pbchn1941h4ykhpuhbjincs34a7tmf4e X-Spam-Status: No, score=-11.2 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_PASS,SPF_PASS autolearn=ham autolearn_force=no version=4.0.1 X-HE-Tag: 1796416438-782287 X-HE-Meta: U2FsdGVkX19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PYGovoU4dsU3KvP27wcIvFh4x+nrDM9QGPgXKsSKN5sGiw1hcKPFk4xgllvJlNvrspif8xmbZvzyDzR2zJQDpQmtwC2NHh91FGtMS6hcx/7HMYG3BDUQ5KOYKZTnPHAz3aPSNwMJsQNPnJRr6Ioq5dKkjwUWSIUuM+Oz4Lvm3RKXOOtCFbztkzUbayOsOveT0bBsL9HxDdBHgJuhqe4Pl9rrc9vukrRWICr34TK695ae2sb2Kn58vjSV7aJS6RgYY4jU6cB2eDXJDb+QhDfOes5658UfLguEbqb9aS4xR2Tmed7q59uDb6XAbbguGV9QeF0tzgbm5YspsvLYWz3K6xHwzN/OTexkgihhXYH5Vsrb5z6jXIzl/UjZ2ZuYZMyZxvtGTwNqCAQtgKHeewuSgGWdMfU94rgzYZmmOFzUb7IKrpTnNiLr+LaxH5oGxj0a+QescrjUUVT7tIXA616RSpdXp74ZV5yPuNDYt5DM+hlvQyjhsc7uYBp7hInxOMLyKGH0L1M8RCgYe4vwO/+yQjutKm9abRk/7P9xHAgsidwasJsrMc4qUbIgegslj7ZFIq0vEb0miWsN2Zj5eK8SnhEadmD0cjreb3q8xXAhoRnONRTZp2VLwTIr+4CyZrlOVGGUwWY8dDmNn8xY/aAmFxEDiA6xYWKzZK5q93U9UzlwvE6C2GxDPdVpBaNsILZwjdeHnGYMtkhIuHfIkYIdS9B/tz5QDWeqGI92uE9uap7rP/YhBp/BtTMZSyE9tlygYKd+XKr1kxaCGYS3wSlwaDmHXbhv2PGz8+E3D3PfyZdshEBJRT0v4mvkanuvd4hJbYXy2AZI= Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: X-Spam-Checker-Version: SpamAssassin 4.0.1 (2024-03-26) on aws-us-west-2-korg-listserv-alma10-1 X-Archived-By: Thank you for your contribution! Sashiko AI review found 4 potential issues to consider: - [Critical] mm: list_lru: infinite loop in __memcg_list_lru_alloc() on XArray -ENOMEM - [High] mm: huge_memory: folio_memcg_alloc_deferred() still triggers memcg OOM - [Medium] mm: shmem_unused_huge_add() can trigger memcg OOM after charging list_lru - [Medium] mm: zswap_store() GFP_KERNEL list_lru charge can deadlock on oom_lock -- commit 6f3d882240ba7c4819b5952c2c4c0480a5d5931b Author: Chris Mason mm: list_lru: charge per-memcg lists and XArray nodes This commit charges per-memcg list_lru_memcg allocations and lru->xa XArray nodes to the target memcg, and passes the folio's gfp mask into folio_memcg_alloc_deferred() instead of GFP_KERNEL. > diff --git a/mm/huge_memory.c b/mm/huge_memory.c > index d065b26a94dfa..329da86c388ef 100644 > --- a/mm/huge_memory.c > +++ b/mm/huge_memory.c > @@ -1048,11 +1048,12 @@ static inline void hugepage_exit_sysfs(struct kob= ject *hugepage_kobj) > } > #endif /* CONFIG_SYSFS */ > =20 > -int folio_memcg_alloc_deferred(struct folio *folio) > +int folio_memcg_alloc_deferred(struct folio *folio, gfp_t gfp) > { > if (mem_cgroup_disabled()) > return 0; > - return folio_memcg_list_lru_alloc(folio, &deferred_split_lru, GFP_KERNE= L); > + /* The folio's gfp: a failed charge falls back the way the folio's does= . */ > + return folio_memcg_list_lru_alloc(folio, &deferred_split_lru, gfp); > } [Severity: High] Can folio_memcg_alloc_deferred() still invoke the memcg OOM killer when called with GFP_TRANSHUGE? GFP_TRANSHUGE includes __GFP_DIRECT_RECLAIM | __GFP_IO | __GFP_FS and sets neither __GFP_NORETRY nor __GFP_RETRY_MAYFAIL. A large folio charge with GFP_TRANSHUGE (for example from collapse_huge_page() or an MADV_HUGEPAGE fault) avoids mem_cgroup_oom() only because its order exceeds PAGE_ALLOC_COSTLY_ORDER. Here, __memcg_list_lru_alloc() charges order-0 slab and XArray nodes, so that order check does not apply. If the just-charged folio pushed the cgroup to memory.max, this can OOM-kill a task in the cgroup (even from khugepaged) instead of falling back. Adding __GFP_NORETRY avoids this. [ ... ] > diff --git a/mm/list_lru.c b/mm/list_lru.c > index 5d4b660f9fe42..a00cd1f4ceeca 100644 > --- a/mm/list_lru.c > +++ b/mm/list_lru.c > @@ -481,7 +481,7 @@ static struct list_lru_memcg *memcg_init_list_lru_one= (struct list_lru *lru, gfp_ > static inline void memcg_init_list_lru(struct list_lru *lru, bool memcg_= aware) > { > if (memcg_aware) > - xa_init_flags(&lru->xa, XA_FLAGS_LOCK_IRQ); > + xa_init_flags(&lru->xa, XA_FLAGS_LOCK_IRQ | XA_FLAGS_ACCOUNT); > lru->memcg_aware =3D memcg_aware; > } > =20 > @@ -591,10 +591,13 @@ static int __memcg_list_lru_alloc(struct mem_cgroup= *memcg, > { > unsigned long flags; > struct list_lru_memcg *mlru =3D NULL; > - struct mem_cgroup *pos, *parent; > + struct mem_cgroup *pos, *parent, *old_memcg; > XA_STATE(xas, &lru->xa, 0); > + int ret; > =20 > - gfp &=3D GFP_RECLAIM_MASK; > + /* Charge the heads and the XArray nodes to @memcg, not to current. */ > + gfp =3D (gfp & GFP_RECLAIM_MASK) | __GFP_ACCOUNT; > + old_memcg =3D set_active_memcg(memcg); [Severity: Medium] Does charging list_lru allocations here also allow shmem_unused_huge_add() to trigger a memcg OOM kill? In shmem_get_folio_gfp(), right after charging a large folio with a tail past i_size, shmem_unused_huge_add() passes the base GFP_HIGHUSER_MOVABLE mask into folio_memcg_list_lru_alloc() while holding folio_lock(folio). Because shmem_unused_huge_add() treats shrinklist allocation failure as non-fatal, hitting memory.max on this order-0 charge can spuriously OOM-kill a task in the cgroup. Adding __GFP_NORETRY in shmem_unused_huge_alloc_lru() would avoid invoking the OOM killer. [Severity: Medium] Can zswap_store()'s GFP_KERNEL call to memcg_list_lru_alloc() now self-deadlock on oom_lock? During a global OOM (or SysRq-f via moom_callback()), out_of_memory() runs under oom_lock without PF_MEMALLOC and invokes the i915 OOM notifier: __alloc_pages_may_oom() (holds oom_lock, no PF_MEMALLOC) out_of_memory() i915_gem_shrinker_oom() ... -> __shmem_writeback() (holds folio_lock) shmem_write_folio() -> swap_writeout() -> zswap_store() memcg_list_lru_alloc(..., &zswap_list_lru, GFP_KERNEL) try_charge_memcg() mem_cgroup_out_of_memory() mutex_lock_killable(&oom_lock) <-- self-deadlock Because PF_MEMALLOC is clear, try_charge_memcg() enters reclaim and OOM when the folio's memcg is at its limit; from moom_callback() (an unkillable kworker), oom_lock deadlocks permanently. Passing GFP_NOWAIT or __GFP_NORETRY in zswap_store() falls back to swap writeout. [ ... ] > @@ -631,10 +636,12 @@ static int __memcg_list_lru_alloc(struct mem_cgroup= *memcg, > } while (xas_nomem(&xas, gfp)); > } while (pos !=3D memcg && !css_is_dying(&pos->css)); > =20 > + ret =3D xas_error(&xas); > if (unlikely(mlru)) > kfree(mlru); > - > - return xas_error(&xas); > +out: > + set_active_memcg(old_memcg); > + return ret; > } [Severity: Critical] Will this outer loop spin forever if xas_nomem() fails with -ENOMEM while populating an ancestor cgroup? In a nested hierarchy (root -> A -> B) where ancestor A is not yet in lru->xa and B is at memory.max, memcg_init_list_lru_one() can succeed while xas_store() and xas_nomem() fail to charge a radix_tree_node with GFP_NOWAIT (e.g. __filemap_add_folio() -> xas_store() for shadow_nodes). Because the outer while condition omits !xas_error(&xas) and pos !=3D memcg, the loop restarts on the same ancestor A with mlru still non-NULL and calls xas_set(&xas, pos->kmemcg_id), clearing XA_ERROR(-ENOMEM). It then retries and fails forever without sleeping. When reached from __filemap_add_folio() under mapping->i_pages.xa_lock with IRQs disabled, this causes an immediate hard lockup (and an unkillable soft lockup on blocking paths like THP faults). Checking !xas_error(&xas) in the outer while condition exits the loop on error. --=20 Sashiko AI review =C2=B7 https://sashiko.dev/#/patchset/20261204173929.2355= 221-1-hannes@cmpxchg.org?part=3D2