From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from out-184.mta0.migadu.com (out-184.mta0.migadu.com [91.218.175.184]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 915303BED7F for ; Tue, 26 May 2026 05:54:15 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=91.218.175.184 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1779774858; cv=none; b=SpI5gWQw63gPNup+H9Mixdx6nuc/Px+QwS2/NkFIgzD9y5slEGmhv7G+uQVHlSaGh6k4MsJNd9yU+C+uVOPp205rHgqy93m+Ta3agsSK0lPBpwqDz2UOjqR2rX6MBpW7lyHiAe7ccOT6gCKyqkeoCfrr4Hh4YrYs5OgXMNbF9+w= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1779774858; c=relaxed/simple; bh=HK4T4+JFfdOANbvHmHiDJ6s1xVc9aXJFcOV0u2o0SK4=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=n8wKntRa5nZUayV591YDEgLpZcK3VOYmuFSW9iJpdEtscD2HUMQh1NDdl2qOBfc+DXSWAkY5/rPqUPfE4pEhF1sE5yJiKPny6OJlFsUmlCBy6FWufyee3N+Nedx1Py1ucqmpm1KK9yANZ6YhbFi7TtJ726VEN6Uvf0bB+bpVPJo= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.dev; spf=pass smtp.mailfrom=linux.dev; dkim=pass (1024-bit key) header.d=linux.dev header.i=@linux.dev header.b=LbOk6sh8; arc=none smtp.client-ip=91.218.175.184 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.dev Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linux.dev Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linux.dev header.i=@linux.dev header.b="LbOk6sh8" Date: Tue, 26 May 2026 13:53:55 +0800 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.dev; s=key1; t=1779774853; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=AF1oquPwv5FzXd+tdEAqTJUpMqePbrEeg9P+1wtdYRk=; b=LbOk6sh8NNbZjFfzXfJQy5OXuntmVBvRutLEo3yfkz8OegUbuo4znzNYUL3939pJdpd5cc ryZU3Aw99YUFK+sBPMAmvCAc4CTOD/GflW99KxDGJw7WxnfC83AG4hFKbvIonmyRG840f7 Lm5prQ9As5KeiUMe6/ue70BIzzWt7UQ= X-Report-Abuse: Please report any abuse attempt to abuse@migadu.com and include these headers. From: Hao Li To: hu.shengming@zte.com.cn Cc: vbabka@kernel.org, harry@kernel.org, akpm@linux-foundation.org, cl@gentwo.org, rientjes@google.com, roman.gushchin@linux.dev, linux-mm@kvack.org, linux-kernel@vger.kernel.org, zhang.run@zte.com.cn, cai.qu@zte.com.cn Subject: Re: [PATCH v3] mm/slub: free prefilled empty sheaves consistently Message-ID: References: <20260525211000387LYqTHmxYL900XIB8qwV3h@zte.com.cn> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20260525211000387LYqTHmxYL900XIB8qwV3h@zte.com.cn> X-Migadu-Flow: FLOW_OUT On Mon, May 25, 2026 at 09:10:00PM +0800, hu.shengming@zte.com.cn wrote: > From: Shengming Hu > > Empty sheaves allocated by alloc_empty_sheaf() should be released with > free_empty_sheaf(). > > Move the empty-sheaf capacity initialization into __alloc_empty_sheaf() > and use it for oversized prefilled sheaves as well. > > This keeps the prefill paths consistent: after flushing an oversized or > pfmemalloc sheaf, release the now-empty sheaf through free_empty_sheaf() > instead of kfree(). > > Signed-off-by: Shengming Hu > --- > Changes in v2: > - Rework the change as suggested by Harry. > - Teach __alloc_empty_sheaf() to initialize capacity and pfmemalloc. > - Allocate oversized prefilled sheaves through __alloc_empty_sheaf(). > - Free flushed oversized and pfmemalloc sheaves through free_empty_sheaf(). > - Link to v1: https://lore.kernel.org/all/20260521195015105Y4zvKHj0TfPZEujixy9Vo@zte.com.cn/ > > Changes in v3: > - Address Hao's comments: > - Drop the redundant `pfmemalloc` initialization in > __alloc_empty_sheaf(). > - Keep initializing `capacity` and `pfmemalloc` in the normal-sized > prefill path, since the sheaf may be reused rather than freshly > allocated. > - Link to v2: https://lore.kernel.org/all/20260522145900248m-nBcy07_SCDk2ATDWfmg@zte.com.cn/ > > --- > mm/slub.c | 13 ++++--------- > 1 file changed, 4 insertions(+), 9 deletions(-) > > diff --git a/mm/slub.c b/mm/slub.c > index 04692a6f9128..f4c06bf43f2d 100644 > --- a/mm/slub.c > +++ b/mm/slub.c > @@ -2782,6 +2782,7 @@ static struct slab_sheaf *__alloc_empty_sheaf(struct kmem_cache *s, gfp_t gfp, > return NULL; > > sheaf->cache = s; > + sheaf->capacity = capacity; > > stat(s, SHEAF_ALLOC); > > @@ -5015,21 +5016,15 @@ kmem_cache_prefill_sheaf(struct kmem_cache *s, gfp_t gfp, unsigned int size) > > if (unlikely(size > s->sheaf_capacity)) { > > - sheaf = kzalloc_flex(*sheaf, objects, size, gfp); > + sheaf = __alloc_empty_sheaf(s, gfp, size); > if (!sheaf) > return NULL; > > stat(s, SHEAF_PREFILL_OVERSIZE); > - sheaf->cache = s; > - sheaf->capacity = size; > > - /* > - * we do not need to care about pfmemalloc here because oversize > - * sheaves area always flushed and freed when returned > - */ just a bit curious, why did you decide to delete these comments? > if (!__kmem_cache_alloc_bulk(s, gfp, size, > &sheaf->objects[0])) { > - kfree(sheaf); > + free_empty_sheaf(s, sheaf); > return NULL; > } > > @@ -5097,7 +5092,7 @@ void kmem_cache_return_sheaf(struct kmem_cache *s, gfp_t gfp, > if (unlikely((sheaf->capacity != s->sheaf_capacity) > || sheaf->pfmemalloc)) { > sheaf_flush_unused(s, sheaf); > - kfree(sheaf); > + free_empty_sheaf(s, sheaf); > return; > } > > -- > 2.25.1