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=1796050703; b=y6PZCVBiB04XOK5WwxzkjaoYKo97js2K9YFQiv3jHKz19epIUnVxC9JXi8pCzvgrp98g nZ0zbIEB9R9j/LFCAi63RyUSUd/VUY7Er2YJkaeHNhI1EQBSgsZDatN0jJQoVcZQ3WPsh dKqOFofl7eX0om/a3jeoUWeCiJmh4raB7I9NMKXO07vJYLKplwSkCroIJb2g4rpivkwv4 mzNGACUsp6Lq89ytlYWU4qBpzsOnkpaOkpGiCurw3U7fcLsZHFlVkFQJrEnlzyRAhY/Uh B/GL966Vl2dnH7dUFV9y/4Zm8MXGOtObbpbJPUIitlmpdGVa6MUlWzMb657fcr2WN+Q== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796050703; h=Received:DKIM-Signature:Date:From:To:Cc:Subject:Message-ID: References:MIME-Version:Content-Type:Content-Disposition:In-Reply-To; bh=q7wo853ldcRjtuE10cOilFu+8lA4kjNHA/mmh+uFsmI=; b=JwbqGTVYax7uXOnit81dYlikio3Im8kSQZWJ1jSLmKF4sT2iCNuidG3ZJo8lI1M2h8Gi APUhwDtYoTL4oLlIJ+H6ZOnxVBP9MD4nTxG0PmXP98+C0UcmPzOmtokPjWK20QxKesZNn DfxxeAFeGEQdJt2POqdhd+jjdK2ePLA47Z5qOJ7F6fDY2lJTNQeMuA800aKPibJMcozTh WtswCIzMPN85qOUDgg5DeePfAItK5AnWkSYm4/lhXvYlIX1d7YFlsPv00lwLKtm23S/vY WFcuPbh8m/KzIGCpGD9PlCc6eG1xPTHItBlVBy+cf3Go0TCVlH6HIRGO1NGmo25VHjw== 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=VmLCKwtE; 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 763C0606A339; Mon, 30 Nov 2026 14:58:23 +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=VmLCKwtE Received: by smtp.kernel.org (Postfix) with ESMTPSA id 73BF31F00897; Mon, 30 Nov 2026 14:58:22 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1796050702; bh=q7wo853ldcRjtuE10cOilFu+8lA4kjNHA/mmh+uFsmI=; h=Date:From:To:Cc:Subject:References:In-Reply-To; b=VmLCKwtE3JMQevmwo20lknkKZRvbqh7rlQpLpnJKWvb24dZ5dLvRpCgA6ud42yAVz maHRzrJBgmaxXrLWg59doeSNrUOmMPOOQJxlsgYQRaVJs/fYWAuCJGjZGK2Euh30PP QM7T86vtcmQPuU5LvP+UUk1zJX3XGo2OD/ijjX9kcOFeir+ufYE41htjSBh5j+DvVC qFL1LMshn3ZEJTnV8HiW3Jj6nPgyFeL/C2xtTlTCPT5TmagsXsaAoB3xU5NYzQO/sm hrkwr5QduWpGyaBP+i1rLq780RIqmZ9nCHBXC4sgLZTRTnSb/ikzBfkocYEOP69MtF Sl6/yK3Wqdsww== Date: Mon, 30 Nov 2026 14:58:20 +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 2/4] mm/slab: handle __GFP_NOFAIL better with prefilled sheaves Message-ID: References: <20261127-slab-ai-fixes-v1-0-cf13b6be6692@kernel.org> <20261127-slab-ai-fixes-v1-2-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-2-cf13b6be6692@kernel.org> On Fri, Nov 27, 2026 at 09:12:31PM +0100, Vlastimil Babka (SUSE) wrote: > If a prefilled sheaf is requested with __GFP_NOFAIL in a > gfp_pfmemalloc_allowed() context, the following can happen in the > initial __GFP_NOMEMALOC attempt. > > refill_objects() __GFP_NOFAIL | __GFP_NOMEMALLOC > new_slab() > __alloc_pages_may_oom() > if (gfp_mask & __GFP_NOFAIL) > ALLOC_NO_WATERMARKS the slab is pfmemalloc > alloc_from_new_slab() its objects go into the sheaf > > So the sheaf should be marked pfmemalloc, but isn't. Fix this by > removing __GFP_NOFAIL from the __GFP_NOMEMALLOC attempt. Hmm the underlying problem here is that slab can't tell if it might be allocated from memory reserves or not just by looking at the GFP flags? We should probably set sheaf->pfmemalloc to true in refill_objects() when it ended up allocating a pfmemalloc slab and refilled objects from it. > For consistency, also adjust kmem_cache_return_sheaf() in case somebody > would hypothetically call it with __GFP_NOFAIL. Just drop it > unconditionally and also add __GFP_NORETRY there to make returns > cheaper - in a low memory situation, keeping the sheaf from being > flushed isn't a priority. > > Reported-by: Chris Mason > Fixes: 1ce20c28eafd ("slab: handle pfmemalloc slabs properly with sheaves") > Cc: > Signed-off-by: Vlastimil Babka (SUSE) > --- > mm/slub.c | 12 ++++++++++-- > 1 file changed, 10 insertions(+), 2 deletions(-) > > diff --git a/mm/slub.c b/mm/slub.c > index 5fd148f11efd..20570e4f1795 100644 > --- a/mm/slub.c > +++ b/mm/slub.c > @@ -5204,8 +5204,10 @@ static int __prefill_sheaf_pfmemalloc(struct kmem_cache *s, > return 0; > > gfp_nomemalloc = gfp | __GFP_NOMEMALLOC; > - if (gfp_pfmemalloc_allowed(gfp)) > + if (gfp_pfmemalloc_allowed(gfp)) { As pointed out by Sashiko gfp_pfmemalloc_allowed could still return false with __GFP_NOFAIL. __GFP_NOFAIL is not included in __gfp_pfmemalloc_flags() but it _may_ end up setting ALLOC_NO_WATERMARKS. > + gfp_nomemalloc &= ~__GFP_NOFAIL; > gfp_nomemalloc |= __GFP_NOWARN; > + } > > ret = refill_sheaf(s, sheaf, gfp_nomemalloc); > > @@ -5345,12 +5347,18 @@ void kmem_cache_return_sheaf(struct kmem_cache *s, gfp_t gfp, > > stat(s, SHEAF_RETURN_SLOW); > > + /* > + * If we end up refilling the sheaf, don't try too hard. > + */ > + gfp &= ~__GFP_NOFAIL; > + gfp |= __GFP_NOMEMALLOC | __GFP_NORETRY | __GFP_NOWARN; > + > /* > * If the barn has too many full sheaves or we fail to refill the sheaf, > * simply flush and free it. > */ > if (!barn || data_race(barn->nr_full) >= MAX_FULL_SHEAVES || > - refill_sheaf(s, sheaf, gfp | __GFP_NOMEMALLOC | __GFP_NOWARN)) { > + refill_sheaf(s, sheaf, gfp)) { > sheaf_flush_unused(s, sheaf); > free_empty_sheaf(s, sheaf); > return; > > -- > 2.56.1 > -- Cheers, Harry / Hyeonggon