From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from out-181.mta0.migadu.com (out-181.mta0.migadu.com [91.218.175.181]) (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 1599D313532 for ; Mon, 25 May 2026 06:38:28 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=91.218.175.181 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1779691111; cv=none; b=fdZI4No5mIc2h1vOwV3A24EzfoPJYQswFB3gTkNk4wl2qnzdO/jjDS6mcByLlkYkjZTjqcbcIKGVeIOHMeFMtfkzDpZ6hi98Xb0ibbKG1X4rqrs3J22JzRK2Q3ty3OeFAiIcwrO6TO2WcU8zTiEQz1/SDnUo2Ry8gUHpDVQpIe4= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1779691111; c=relaxed/simple; bh=e54XGPl+4C8wfUWHc69SbupsjlgbampTzToSinIU4H0=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=tsR9MoglKpIfXNqhtwbOIt0RPPde+T5GfVq0K1+tlylV0vofh8SWO9PwqAEJdKBX/1rGKlYN1yFUGAH8XvHwbsHsiTPcZ/YlH5h0SEkN+nSRbG7cbZnsseavt8a2MFN3IXb3EDyGfxVNct2X4BBRSFUrIa5f49/InKMpMqUA2Eg= 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=xeMJRRkA; arc=none smtp.client-ip=91.218.175.181 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="xeMJRRkA" Date: Mon, 25 May 2026 14:38:17 +0800 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.dev; s=key1; t=1779691106; 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=uKyMuUK0WLqhGS8J8WKRVk1Ij1jSm2kKaV+KU4tQLDs=; b=xeMJRRkAwktnwIFZICXEUBp7PiKdDbRB3GpmgBDp7SkDRY2vk9TQzw02iqAp4x4JalpcOu V4EZaKCFTKR6r/3o1SG/4AHAeu1dNfXXXhHove+R9Q0uNf4HUcuSeTB+4wyFJpUkxKWu47 a1uKlX81yht7R6VdeToJZdUwwG9EJOQ= 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 v2] mm/slub: free prefilled empty sheaves consistently Message-ID: References: <20260522145900248m-nBcy07_SCDk2ATDWfmg@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: <20260522145900248m-nBcy07_SCDk2ATDWfmg@zte.com.cn> X-Migadu-Flow: FLOW_OUT On Fri, May 22, 2026 at 02:59: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 common empty-sheaf initialization into __alloc_empty_sheaf(), > including the capacity and default pfmemalloc state, 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/ > > --- > mm/slub.c | 17 +++++------------ > 1 file changed, 5 insertions(+), 12 deletions(-) > > diff --git a/mm/slub.c b/mm/slub.c > index 04692a6f9128..bbe8351f1bfa 100644 > --- a/mm/slub.c > +++ b/mm/slub.c > @@ -2782,6 +2782,8 @@ static struct slab_sheaf *__alloc_empty_sheaf(struct kmem_cache *s, gfp_t gfp, > return NULL; > > sheaf->cache = s; > + sheaf->capacity = capacity; > + sheaf->pfmemalloc = false; we could eliminate `sheaf->pfmemalloc = false;` because the allocation use kzalloc. > > stat(s, SHEAF_ALLOC); > > @@ -5015,21 +5017,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 > - */ > if (!__kmem_cache_alloc_bulk(s, gfp, size, > &sheaf->objects[0])) { > - kfree(sheaf); > + free_empty_sheaf(s, sheaf); > return NULL; > } > > @@ -5064,9 +5060,6 @@ kmem_cache_prefill_sheaf(struct kmem_cache *s, gfp_t gfp, unsigned int size) > sheaf = alloc_empty_sheaf(s, gfp); > > if (sheaf) { > - sheaf->capacity = s->sheaf_capacity; > - sheaf->pfmemalloc = false; I think we couldn't delete 'sheaf->pfmemalloc = false;', because the 'sheaf' pointer here could points to a normal size sheaf via the `if (pcs->spare) {} else {}` statements above. > - > if (sheaf->size < size && > __prefill_sheaf_pfmemalloc(s, sheaf, gfp)) { > sheaf_flush_unused(s, sheaf); > @@ -5097,7 +5090,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 -- Thanks, Hao