From: Hao Li <hao.li@linux.dev>
To: Harry Yoo <harry.yoo@oracle.com>
Cc: vbabka@suse.cz, cl@gentwo.org, rientjes@google.com,
roman.gushchin@linux.dev, linux-mm@kvack.org,
linux-kernel@vger.kernel.org
Subject: Re: [PATCH] slub: clarify kmem_cache_refill_sheaf() failure behavior
Date: Sat, 14 Mar 2026 17:23:58 +0800 [thread overview]
Message-ID: <dbkgniglboyu5m65vlr4uygfhhjv75vgtutg7lky73tyabrxez@vnz3x7fhclli> (raw)
In-Reply-To: <abQExi4z2mhCzKPw@hyeyoo>
On Fri, Mar 13, 2026 at 09:36:22PM +0900, Harry Yoo wrote:
> On Thu, Mar 12, 2026 at 07:42:25PM +0800, Hao Li wrote:
> > kmem_cache_refill_sheaf() can fail in two slightly different ways.
> > During an in-place refill, some objects may already have been added
> > before the function returns -ENOMEM. On the other hand, if allocation of
> > a larger replacement sheaf fails, the original sheaf remains unchanged.
> >
> > Update the comment to spell out both cases explicitly for clarity.
> >
> > Signed-off-by: Hao Li <hao.li@linux.dev>
> > ---
> >
> > mm/slub.c | 21 +++++++++++++++------
> > 1 file changed, 15 insertions(+), 6 deletions(-)
> >
> > diff --git a/mm/slub.c b/mm/slub.c
> > index 11a99bd06ac7..8ae248b5b384 100644
> > --- a/mm/slub.c
> > +++ b/mm/slub.c
> > @@ -5005,14 +5005,23 @@ void kmem_cache_return_sheaf(struct kmem_cache *s, gfp_t gfp,
> > }
> >
> > /*
> > - * refill a sheaf previously returned by kmem_cache_prefill_sheaf to at least
> > - * the given size
> > + * Refill a sheaf previously returned by kmem_cache_prefill_sheaf to at least
> > + * the given size.
> > *
> > - * the sheaf might be replaced by a new one when requesting more than
> > - * s->sheaf_capacity objects if such replacement is necessary, but the refill
> > - * fails (returning -ENOMEM), the existing sheaf is left intact
> > + * On success, the sheaf will contain at least @size objects.
> > *
> > - * In practice we always refill to full sheaf's capacity.
> > + * On failure, there are two cases:
> > + *
> > + * 1. If the requested size fits within the current sheaf's capacity, the
> > + * refill is done in place. In that case, a failed refill may still fill
> > + * some additional objects into the existing sheaf before returning -ENOMEM.
> > + *
> > + * 2. If the requested size exceeds the current sheaf's capacity, a new
> > + * larger sheaf may be allocated to replace the original one. In that case,
> > + * if allocation of the replacement sheaf fails, the original sheaf is left
> > + * unchanged.
>
> This is correct, but users of this API probably don't need to know the
> implementation in detail.
>
> I think it's fine to simply say the sheaf may have additional objects even
> on failure?
That makes sense.
Too much explanation could actually distract users.
Thanks!
>
> > + *
> > + * In practice we usually refill to the sheaf's full capacity.
> > */
> > int kmem_cache_refill_sheaf(struct kmem_cache *s, gfp_t gfp,
> > struct slab_sheaf **sheafp, unsigned int size)
> > --
> > 2.50.1
> >
>
> --
> Cheers,
> Harry / Hyeonggon
prev parent reply other threads:[~2026-03-14 9:24 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-03-12 11:42 Hao Li
2026-03-13 12:36 ` Harry Yoo
2026-03-14 9:23 ` Hao Li [this message]
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=dbkgniglboyu5m65vlr4uygfhhjv75vgtutg7lky73tyabrxez@vnz3x7fhclli \
--to=hao.li@linux.dev \
--cc=cl@gentwo.org \
--cc=harry.yoo@oracle.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mm@kvack.org \
--cc=rientjes@google.com \
--cc=roman.gushchin@linux.dev \
--cc=vbabka@suse.cz \
/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