From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=100.103.45.18 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796148973; b=IdnR9E+euw+CVzg8xIezykxdfbmCAs7JQxBsouEVUuMI/c9TuhlXXABvpTcFJwSI2qvD cTm2TeJftvlmkdG08KOMIVfnAtTgzLSCxIwthO1C5FDJDl/3Bhha/Os7QcQp5DWv0RHgI BxLZojziztw8gTzaI37Ev1VglGkmmCs1Q+jl0O9smHZ9tBEfj59NUTJOJe+mFANNzTGz0 vWByIwkjpLXDWdgmgwceAYueaOE/HjgWtt0H4vIqmES38QzQ4CTKlpaGNeLOYLCP5Tl14 1YifYgsj6RQ4QXFUf/Z46LMD47sSalvBuWBVn3PXKwCQZ8Pji5hVkdXZhYkbQM5vPBQ== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796148973; h=Received:DKIM-Signature:From:Date:Subject:MIME-Version:Content-Type: Content-Transfer-Encoding:Message-Id:References:In-Reply-To:To:Cc: X-Mailer; bh=9bhmaW+0WS0TiV7z+k6eqwIi3DlWuyrS8fLiIiLhu3w=; b=S+O+AsPW5ZOXQNZ9cqA1ytaavYXfny2q20H+4aXv0XOZbAOsInLxC/qBMSlJBTjcHjHe gfWAw6RtxUedZDmdY/EKsuNXQA+vAXcg5OgA1J5m3ss2veCFFq7ExS9HWpM5nzLBHIB1K g/HmLwdx+ffVKkg4DN3EMSkbtySsAb8AWxP6GdxC91gAk0Xoewne6O7LBdLRnY3cUsY/+ v/lRHUaRrxZ2xoEFv0aAxuQ3nXq/iLVt+TRSPw/b8tLH9srQIFTDnaHuRTbLaoCMZKCcn IZJWpxOitZ45bmHLYRcQ1Hrulh6T0Cd2tJEyLU06T6oOCElXsG+lAPBC9hzL/0FP6Kw== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=jAIB2m1+; arc=none smtp.remote-ip=100.103.45.18 Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 5DCA9606A327; Tue, 1 Dec 2026 18:16:13 +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=jAIB2m1+ Received: by smtp.kernel.org (Postfix) with ESMTPSA id D07DF1F00923; Tue, 1 Dec 2026 18:16:10 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1796148973; bh=9bhmaW+0WS0TiV7z+k6eqwIi3DlWuyrS8fLiIiLhu3w=; h=From:Date:Subject:References:In-Reply-To:To:Cc; b=jAIB2m1+F3GdeNS25TcWJPGcKeIwVakm/50YCtapaJPMffA/7xQjEdbe6HJ4K7ziu gppwaO+eqmYslu75l/oCobkKjQyubyvhTM2hWlDeGmwoWLmVlalhNPLsaSAYeikRHy bShz23kyursSLV3cOvmU5/cR+A/HloKteFyKNN+VqoAcJr95/oBTyt/6JyRIJOIPqr r007AoHe0X+XeMYCYIfEt9ZHa5Mfn2czcA510F9KbFWKE8FnAjYndg9QGA9GZwWpVF E65LBcA9sjvSdEDWfXZSMEsI8UvNTwbS+ZhFEI251fCQ2UH6Jgo4qAfsMLRsVdj89x rpPyhIRHPrhJA== From: "Vlastimil Babka (SUSE)" Date: Tue, 01 Dec 2026 19:16:02 +0100 Subject: [PATCH v2 1/4] mm/slab: drop __GFP_NOFAIL when refilling sheaves 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-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit Message-Id: <20261201-slab-ai-fixes-v2-1-7419dfbd3bac@kernel.org> References: <20261201-slab-ai-fixes-v2-0-7419dfbd3bac@kernel.org> In-Reply-To: <20261201-slab-ai-fixes-v2-0-7419dfbd3bac@kernel.org> To: Harry Yoo Cc: Hao Li , Christoph Lameter , David Rientjes , Roman Gushchin , "David Hildenbrand (Arm)" , linux-mm@kvack.org, linux-kernel@vger.kernel.org, "Vlastimil Babka (SUSE)" , Chris Mason , stable@vger.kernel.org X-Mailer: b4 0.16.0 A __GFP_NOFAIL slab allocation in a low memory situation may end up refilling a whole sheaf from slabs (possibly newly allocated), passing the __GFP_NOFAIL to all underlying allocations. This can make the low memory condition worse and it's unnecessary, given there's a fallback. Given how we use __GFP_NOMEMALLOC for the refill, there are also some undesirable corner cases, as reported by Chris Mason. If the allocation happens in a PF_MEMALLOC task (which it should not in the first place, but there's no guarantee), the following can occur: refill_sheaf(gfp | __GFP_NOMEMALLOC) __alloc_pages_slowpath() WARN_ON_ONCE(nofail && PF_MEMALLOC) retry: reserve_flags = 0 /* __GFP_NOMEMALLOC */ goto nopage /* PF_MEMALLOC */ goto retry /* __GFP_NOFAIL */ The allocation will loop without reclaim and no access to memory reserves. Additionally the slab page may be marked pfmemalloc, which the sheaf refill does not expect and handle: refill_objects() __GFP_NOFAIL | __GFP_NOMEMALLOC new_slab() __alloc_pages_may_oom() if (gfp_mask & __GFP_NOFAIL) ALLOC_NO_WATERMARKS the slab is then pfmemalloc alloc_from_new_slab() its objects go into the sheaf Improve or prevent all of the above by dropping __GFP_NOFAIL for the sheaf refill. Also perform all adjustments before potentially calling alloc_empty_sheaf(). While that one already clears __GFP_NOFAIL, it should also get the __GFP_NOMEMALLOC | __GFP_NOWARN flags, since a fallback exists. One consequence is that the WARN_ON_ONCE(nofail && PF_MEMALLOC) in the page allocator will now only be reachable from the fallback and thus in case such a caller is introduced, might lurk undetected for a while. If people think it's an issue, we can duplicate the warning here as well. Reported-by: Chris Mason Fixes: 1ce20c28eafd ("slab: handle pfmemalloc slabs properly with sheaves") Cc: stable@vger.kernel.org Reviewed-by: Harry Yoo (Meta) Signed-off-by: Vlastimil Babka (SUSE) --- mm/slub.c | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/mm/slub.c b/mm/slub.c index 145a32c334cb..5fd148f11efd 100644 --- a/mm/slub.c +++ b/mm/slub.c @@ -4807,13 +4807,20 @@ __pcs_replace_empty_main(struct kmem_cache *s, struct slub_percpu_sheaves *pcs, if (!allow_spin) return NULL; + /* + * We don't want refills to rely on __GFP_NOFAIL or memalloc reserves to + * succeed, nor to warn on failure. Leave that to the fallback. + */ + gfp &= ~__GFP_NOFAIL; + gfp |= __GFP_NOMEMALLOC | __GFP_NOWARN; + if (!empty) { empty = alloc_empty_sheaf(s, gfp, alloc_flags); if (!empty) return NULL; } - if (refill_sheaf(s, empty, gfp | __GFP_NOMEMALLOC | __GFP_NOWARN)) { + if (refill_sheaf(s, empty, gfp)) { /* * we must be very low on memory so don't bother * with the barn -- 2.56.1