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=1796047827; b=fR3/ZTUEN7ywowcQCWwa4VbKqCeMyYv9tfg/JK98jKkgqr2ODPt4LTiQKgCgWjw4P1xj rPKLayTMkxS3BjoBIKG/NOgBK8X4zUb4p+U8/HaIKVzNevZ2lEEIVg0gC9+CCxMADrFyH QzV4+E3tJhRBQAUE+ga4EwKOGkOsMz4m7Vlmrc5Q4jR7kAdW1Ozswrkn+4wnwl3A8oZOR ffXATMgbHtFtr1BTE5oCvMVIQSyLHJkTv6HIrZJEO3dBM7FPM7DGPpFcedJ/D19p5p4OI iM8CEA5XmbfeAx4mNSes9L3/PaQFk2LH2u5iuDHBMqXBEi/+0snL0EyKiqqHlWYgV9w== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796047827; h=Received:DKIM-Signature:Date:From:To:Cc:Subject:Message-ID: References:MIME-Version:Content-Type:Content-Disposition:In-Reply-To; bh=ooIHQe27KOQHTv42nIfdf3Uddrz0K2hyIV56OM2+Mpc=; b=JrFhHIaKcJu5BAzdBh3M1XmaDuDcyUYS2DtK1B4AvWhtYd2z/ibL4vVw7up5yuorV70P a2ERFHjlZu4RTtrXXbzw7XuSywVee4gBWfh1dIlyMTnvTcfxAHjASQ0gZRaDPOTnRzb97 9FuVzNAOC/pWl9X/FZbxciIEA8Byg4ZKQPSGIx7pH+pBgvn6e9mYcaTUn8mL+qHIS7CAp k/GTW410C6v3uQcO9TKT6wPz8bYmEUwSMRcXkbr/raxy1vk16u/NCxGCMrKGiwxiGJU04 Dh/gCrn07O2VZcTWOtZRDmtVKYh+nj6wdgGh+zqN03dt/YTuzD/Cy674yj79BFqv5fw== 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="FAvU8/my"; 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 3C15C606A327; Mon, 30 Nov 2026 14:10:27 +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=FAvU8/my Received: by smtp.kernel.org (Postfix) with ESMTPSA id 5B0231F008A0; Mon, 30 Nov 2026 14:10:26 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1796047826; bh=ooIHQe27KOQHTv42nIfdf3Uddrz0K2hyIV56OM2+Mpc=; h=Date:From:To:Cc:Subject:References:In-Reply-To; b=FAvU8/myAkz9yN6t+U9o4LqqJhsBJ3WwplD57ZOEkD0NxPiTzSXXC9TKv+ycTO772 /bEDZqBLAV0sgrRSB51rbhbzvmqTfdS5zUCLdn2IkBFgzK+JESZYRbdAuhaWyQlJDz YEoj5ZsVCJHA4DszkYTNPexqxvUUzJ1ZhwqLYLpWou85IgDlxawxQ9hBF2MzdGPjjF 3n0A+XVdQ4Mu4AiB5gfZDlFwsN5FVFmjeEjqnqNcuyXTKZVZ2UednsI2Pu+p5HuRLH dXaZQyK9p64cRaK2cxktAFqLyEKaIIFMHfyneLj6CZUJLAxb5J/rCkQEAW9Vy4M+Kl fNIESz2ByR4Pg== Date: Mon, 30 Nov 2026 14:10:24 +0000 From: Harry Yoo To: "Vlastimil Babka (SUSE)" Cc: Hao Li , Christoph Lameter , David Rientjes , Roman Gushchin , "David Hildenbrand (Arm)" , linux-mm@kvack.org, linux-kernel@vger.kernel.org, Chris Mason , stable@vger.kernel.org Subject: Re: [PATCH 1/4] mm/slab: drop __GFP_NOFAIL when refilling sheaves Message-ID: References: <20261127-slab-ai-fixes-v1-0-cf13b6be6692@kernel.org> <20261127-slab-ai-fixes-v1-1-cf13b6be6692@kernel.org> 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=us-ascii Content-Disposition: inline In-Reply-To: <20261127-slab-ai-fixes-v1-1-cf13b6be6692@kernel.org> On Fri, Nov 27, 2026 at 09:12:30PM +0100, Vlastimil Babka (SUSE) wrote: > 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_MEMALLOC for the refill, there are also some s/__GFP_MEMALLOC/__GFP_NOMEMALLOC/ > 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: > Signed-off-by: Vlastimil Babka (SUSE) > --- Looks good to me, Reviewed-by: Harry Yoo (Meta) > 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 > -- Cheers, Harry / Hyeonggon