mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: "Vlastimil Babka (SUSE)" <vbabka@kernel.org>
To: hu.shengming@zte.com.cn, harry@kernel.org, akpm@linux-foundation.org
Cc: hao.li@linux.dev, 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 v4] mm/slub: use empty sheaf helpers for oversized sheaves
Date: Wed, 27 May 2026 10:06:13 +0200	[thread overview]
Message-ID: <8c5bf213-399b-4fa1-835a-36d906061e88@kernel.org> (raw)
In-Reply-To: <20260526232429176aHA6oZjTYdhXcZVHc2ZQ-@zte.com.cn>

On 5/26/26 17:24, hu.shengming@zte.com.cn wrote:
> From: Shengming Hu <hu.shengming@zte.com.cn>
> 
> Oversized prefilled sheaves are allocated separately, but after they are
> flushed they are empty sheaves as well. Release them through
> free_empty_sheaf() instead of calling kfree() directly.
> 
> Use __alloc_empty_sheaf() for oversized prefilled sheaves as well, so
> that they are allocated through the same helper as regular empty sheaves
> and released through the matching helper.
> 
> Since oversized sheaves are now allocated and freed through the empty
> sheaf helpers, SHEAF_ALLOC and SHEAF_FREE also account for oversized
> sheaves. Update the stat comments accordingly.
> 
> This keeps the oversized and pfmemalloc prefill paths consistent after
> flushing.
> 
> Signed-off-by: Shengming Hu <hu.shengming@zte.com.cn>

Hmm, __alloc_empty_sheaf() does "gfp &= ~OBJCGS_CLEAR_MASK" which includes
__GFP_NOFAIL. A caller of kmem_cache_prefill_sheaf() with __GFP_NOFAIL might
not expect failure. The __GFP_NO_OBJ_EXT handling is also not necessary for
prefilled sheaves.

Well maybe all the gfp handling could be simply moved to
alloc_empty_sheaf()? The other caller of __alloc_empty_sheaf() is
bootstrap_cache_sheaves() and I think it doesn't need it either.

> ---
> 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/
> 
> Changes in v4:
> - Address comments from Hao and Harry:
> - Keep capacity initialization in the oversized prefill path.
> - Update SHEAF_ALLOC and SHEAF_FREE comments to mention oversized sheaves.
> - Restore the oversized sheaf pfmemalloc comment.
> - Link to v3: https://lore.kernel.org/all/20260525211000387LYqTHmxYL900XIB8qwV3h@zte.com.cn/
> 
> ---
>  mm/slub.c | 11 +++++------
>  1 file changed, 5 insertions(+), 6 deletions(-)
> 
> diff --git a/mm/slub.c b/mm/slub.c
> index 04692a6f9128..08812de7a8b5 100644
> --- a/mm/slub.c
> +++ b/mm/slub.c
> @@ -362,8 +362,8 @@ enum stat_item {
>  	CMPXCHG_DOUBLE_FAIL,	/* Failures of slab freelist update */
>  	SHEAF_FLUSH,		/* Objects flushed from a sheaf */
>  	SHEAF_REFILL,		/* Objects refilled to a sheaf */
> -	SHEAF_ALLOC,		/* Allocation of an empty sheaf */
> -	SHEAF_FREE,		/* Freeing of an empty sheaf */
> +	SHEAF_ALLOC,		/* Allocation of an empty sheaf including oversized ones */
> +	SHEAF_FREE,		/* Freeing of an empty sheaf including oversized ones */
>  	BARN_GET,		/* Got full sheaf from barn */
>  	BARN_GET_FAIL,		/* Failed to get full sheaf from barn */
>  	BARN_PUT,		/* Put full sheaf to barn */
> @@ -5015,12 +5015,11 @@ 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;
> 
>  		/*
> @@ -5029,7 +5028,7 @@ kmem_cache_prefill_sheaf(struct kmem_cache *s, gfp_t gfp, unsigned int size)
>  		 */
>  		if (!__kmem_cache_alloc_bulk(s, gfp, size,
>  					     &sheaf->objects[0])) {
> -			kfree(sheaf);
> +			free_empty_sheaf(s, sheaf);
>  			return NULL;
>  		}
> 
> @@ -5097,7 +5096,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;
>  	}
> 


  reply	other threads:[~2026-05-27  8:06 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-05-26 15:24 hu.shengming
2026-05-27  8:06 ` Vlastimil Babka (SUSE) [this message]
2026-05-27 13:48   ` hu.shengming
2026-05-27 15:47     ` Vlastimil Babka (SUSE)
2026-05-28  6:37       ` hu.shengming
2026-05-28  7:26         ` Vlastimil Babka (SUSE)

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=8c5bf213-399b-4fa1-835a-36d906061e88@kernel.org \
    --to=vbabka@kernel.org \
    --cc=akpm@linux-foundation.org \
    --cc=cai.qu@zte.com.cn \
    --cc=cl@gentwo.org \
    --cc=hao.li@linux.dev \
    --cc=harry@kernel.org \
    --cc=hu.shengming@zte.com.cn \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mm@kvack.org \
    --cc=rientjes@google.com \
    --cc=roman.gushchin@linux.dev \
    --cc=zhang.run@zte.com.cn \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®