mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Vlastimil Babka <vbabka@suse.cz>
To: Suren Baghdasaryan <surenb@google.com>
Cc: "Liam R. Howlett" <Liam.Howlett@oracle.com>,
	Christoph Lameter <cl@linux.com>,
	David Rientjes <rientjes@google.com>,
	Roman Gushchin <roman.gushchin@linux.dev>,
	Harry Yoo <harry.yoo@oracle.com>,
	Uladzislau Rezki <urezki@gmail.com>,
	linux-mm@kvack.org, linux-kernel@vger.kernel.org,
	rcu@vger.kernel.org, maple-tree@lists.infradead.org
Subject: Re: [PATCH v4 2/9] slab: add sheaf support for batching kfree_rcu() operations
Date: Wed, 14 May 2025 16:01:17 +0200	[thread overview]
Message-ID: <f181285e-4167-4581-a712-8e444a0ab2bb@suse.cz> (raw)
In-Reply-To: <CAJuCfpGVx2jG+S2ch2hqK=sAdmTcs9dW0kOdopxgLtH4V_wNXQ@mail.gmail.com>

On 5/6/25 23:34, Suren Baghdasaryan wrote:
> On Fri, Apr 25, 2025 at 1:27 AM Vlastimil Babka <vbabka@suse.cz> wrote:
>> @@ -2631,6 +2637,24 @@ static void sheaf_flush_unused(struct kmem_cache *s, struct slab_sheaf *sheaf)
>>         sheaf->size = 0;
>>  }
>>
>> +static void __rcu_free_sheaf_prepare(struct kmem_cache *s,
>> +                                    struct slab_sheaf *sheaf);
> 
> I think you could safely move __rcu_free_sheaf_prepare() here and
> avoid the above forward declaration.

Right, done.

>> @@ -5304,6 +5340,140 @@ bool free_to_pcs(struct kmem_cache *s, void *object)
>>         return true;
>>  }
>>
>> +static void __rcu_free_sheaf_prepare(struct kmem_cache *s,
>> +                                    struct slab_sheaf *sheaf)
> 
> This function seems to be an almost exact copy of free_to_pcs_bulk()
> from your previous patch. Maybe they can be consolidated?

True, I've extracted it to __kmem_cache_free_bulk_prepare().

>> +{
>> +       bool init = slab_want_init_on_free(s);
>> +       void **p = &sheaf->objects[0];
>> +       unsigned int i = 0;
>> +
>> +       while (i < sheaf->size) {
>> +               struct slab *slab = virt_to_slab(p[i]);
>> +
>> +               memcg_slab_free_hook(s, slab, p + i, 1);
>> +               alloc_tagging_slab_free_hook(s, slab, p + i, 1);
>> +
>> +               if (unlikely(!slab_free_hook(s, p[i], init, true))) {
>> +                       p[i] = p[--sheaf->size];
>> +                       continue;
>> +               }
>> +
>> +               i++;
>> +       }
>> +}
>> +
>> +static void rcu_free_sheaf(struct rcu_head *head)
>> +{
>> +       struct slab_sheaf *sheaf;
>> +       struct node_barn *barn;
>> +       struct kmem_cache *s;
>> +
>> +       sheaf = container_of(head, struct slab_sheaf, rcu_head);
>> +
>> +       s = sheaf->cache;
>> +
>> +       /*
>> +        * This may reduce the number of objects that the sheaf is no longer
>> +        * technically full, but it's easier to treat it that way (unless it's
> 
> I don't understand the sentence above. Could you please clarify and
> maybe reword it?

Is this more clear?

/*
 * This may remove some objects due to slab_free_hook() returning false,
 * so that the sheaf might no longer be completely full. But it's easier
 * to handle it as full (unless it became completely empty), as the code
 * handles it fine. The only downside is that sheaf will serve fewer
 * allocations when reused. It only happens due to debugging, which is a
 * performance hit anyway.
 */

>> +
>> +               if (!local_trylock(&s->cpu_sheaves->lock))
> 
> Aren't you leaking `empty` sheaf on this failure?

Right! Fixed, thanks.

>> +                       goto fail;
>> +
>> +               pcs = this_cpu_ptr(s->cpu_sheaves);
>> +
>> +               if (unlikely(pcs->rcu_free))
>> +                       barn_put_empty_sheaf(pcs->barn, empty);
>> +               else
>> +                       pcs->rcu_free = empty;
>> +       }
>> +
>> +do_free:
>> +
>> +       rcu_sheaf = pcs->rcu_free;
>> +
>> +       rcu_sheaf->objects[rcu_sheaf->size++] = obj;
>> +
>> +       if (likely(rcu_sheaf->size < s->sheaf_capacity))
>> +               rcu_sheaf = NULL;
>> +       else
>> +               pcs->rcu_free = NULL;
>> +
>> +       local_unlock(&s->cpu_sheaves->lock);
>> +
>> +       if (rcu_sheaf)
>> +               call_rcu(&rcu_sheaf->rcu_head, rcu_free_sheaf);
>> +
>> +       stat(s, FREE_RCU_SHEAF);
>> +       return true;
>> +
>> +fail:
>> +       stat(s, FREE_RCU_SHEAF_FAIL);
>> +       return false;
>> +}
>> +
>>  /*
>>   * Bulk free objects to the percpu sheaves.
>>   * Unlike free_to_pcs() this includes the calls to all necessary hooks
>> @@ -6802,6 +6972,11 @@ int __kmem_cache_shutdown(struct kmem_cache *s)
>>         struct kmem_cache_node *n;
>>
>>         flush_all_cpus_locked(s);
>> +
>> +       /* we might have rcu sheaves in flight */
>> +       if (s->cpu_sheaves)
>> +               rcu_barrier();
>> +
>>         /* Attempt to free all objects */
>>         for_each_kmem_cache_node(s, node, n) {
>>                 if (n->barn)
>> @@ -8214,6 +8389,8 @@ STAT_ATTR(ALLOC_PCS, alloc_cpu_sheaf);
>>  STAT_ATTR(ALLOC_FASTPATH, alloc_fastpath);
>>  STAT_ATTR(ALLOC_SLOWPATH, alloc_slowpath);
>>  STAT_ATTR(FREE_PCS, free_cpu_sheaf);
>> +STAT_ATTR(FREE_RCU_SHEAF, free_rcu_sheaf);
>> +STAT_ATTR(FREE_RCU_SHEAF_FAIL, free_rcu_sheaf_fail);
>>  STAT_ATTR(FREE_FASTPATH, free_fastpath);
>>  STAT_ATTR(FREE_SLOWPATH, free_slowpath);
>>  STAT_ATTR(FREE_FROZEN, free_frozen);
>> @@ -8312,6 +8489,8 @@ static struct attribute *slab_attrs[] = {
>>         &alloc_fastpath_attr.attr,
>>         &alloc_slowpath_attr.attr,
>>         &free_cpu_sheaf_attr.attr,
>> +       &free_rcu_sheaf_attr.attr,
>> +       &free_rcu_sheaf_fail_attr.attr,
>>         &free_fastpath_attr.attr,
>>         &free_slowpath_attr.attr,
>>         &free_frozen_attr.attr,
>>
>> --
>> 2.49.0
>>


  reply	other threads:[~2025-05-14 14:01 UTC|newest]

Thread overview: 35+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-04-25  8:27 [PATCH v4 0/9] SLUB percpu sheaves Vlastimil Babka
2025-04-25  8:27 ` [PATCH v4 1/9] slab: add opt-in caching layer of " Vlastimil Babka
2025-04-25 17:31   ` Christoph Lameter (Ampere)
2025-04-28  7:01     ` Vlastimil Babka
2025-05-06 17:32       ` Suren Baghdasaryan
2025-05-06 23:11         ` Suren Baghdasaryan
2025-04-29  1:08   ` Harry Yoo
2025-05-13 16:08     ` Vlastimil Babka
2025-05-06 23:14   ` Suren Baghdasaryan
2025-05-14 13:06     ` Vlastimil Babka
2025-04-25  8:27 ` [PATCH v4 2/9] slab: add sheaf support for batching kfree_rcu() operations Vlastimil Babka
2025-04-29  7:36   ` Harry Yoo
2025-05-14 13:07     ` Vlastimil Babka
2025-05-06 21:34   ` Suren Baghdasaryan
2025-05-14 14:01     ` Vlastimil Babka [this message]
2025-05-15  8:45       ` Vlastimil Babka
2025-05-15 15:03         ` Suren Baghdasaryan
2025-04-25  8:27 ` [PATCH v4 3/9] slab: sheaf prefilling for guaranteed allocations Vlastimil Babka
2025-05-06 22:54   ` Suren Baghdasaryan
2025-05-07  9:15   ` Harry Yoo
2025-05-07  9:20     ` Harry Yoo
2025-05-15  8:41     ` Vlastimil Babka
2025-04-25  8:27 ` [PATCH v4 4/9] slab: determine barn status racily outside of lock Vlastimil Babka
2025-04-25  8:27 ` [PATCH v4 5/9] tools: Add testing support for changes to rcu and slab for sheaves Vlastimil Babka
2025-04-25  8:27 ` [PATCH v4 6/9] tools: Add sheaves support to testing infrastructure Vlastimil Babka
2025-04-25  8:27 ` [PATCH v4 7/9] maple_tree: use percpu sheaves for maple_node_cache Vlastimil Babka
2025-04-25  8:27 ` [PATCH v4 8/9] mm, vma: use percpu sheaves for vm_area_struct cache Vlastimil Babka
2025-05-06 23:08   ` Suren Baghdasaryan
2025-04-25  8:27 ` [PATCH v4 9/9] mm, slub: skip percpu sheaves for remote object freeing Vlastimil Babka
2025-04-25 17:35   ` Christoph Lameter (Ampere)
2025-04-28  7:08     ` Vlastimil Babka
2025-05-07 10:39   ` Harry Yoo
2025-05-15  8:59     ` Vlastimil Babka
2025-05-15 12:46 ` [PATCH v4 0/9] SLUB percpu sheaves Vlastimil Babka
2025-05-15 15:01   ` Suren Baghdasaryan

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=f181285e-4167-4581-a712-8e444a0ab2bb@suse.cz \
    --to=vbabka@suse.cz \
    --cc=Liam.Howlett@oracle.com \
    --cc=cl@linux.com \
    --cc=harry.yoo@oracle.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mm@kvack.org \
    --cc=maple-tree@lists.infradead.org \
    --cc=rcu@vger.kernel.org \
    --cc=rientjes@google.com \
    --cc=roman.gushchin@linux.dev \
    --cc=surenb@google.com \
    --cc=urezki@gmail.com \
    /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®