All of lore.kernel.org
 help / color / mirror / Atom feed
From: Chengming Zhou <chengming.zhou@linux.dev>
To: "Christoph Lameter (Ampere)" <cl@linux.com>
Cc: Vlastimil Babka <vbabka@suse.cz>,
	David Rientjes <rientjes@google.com>,
	Jianfeng Wang <jianfeng.w.wang@oracle.com>,
	penberg@kernel.org, iamjoonsoo.kim@lge.com,
	akpm@linux-foundation.org, roman.gushchin@linux.dev,
	42.hyeyoo@gmail.com, linux-mm@kvack.org,
	linux-kernel@vger.kernel.org,
	Chengming Zhou <zhouchengming@bytedance.com>
Subject: Re: [PATCH] slub: avoid scanning all partial slabs in get_slabinfo()
Date: Wed, 28 Feb 2024 17:51:49 +0800	[thread overview]
Message-ID: <0aa3ce20-438f-49fb-8f04-4fc1dbf49728@linux.dev> (raw)
In-Reply-To: <1eeb84d4-42b1-d204-ece1-b76bfbc548bf@linux.com>

On 2024/2/28 06:55, Christoph Lameter (Ampere) wrote:
> On Tue, 27 Feb 2024, Chengming Zhou wrote:
> 
>>> We could mark the state change (list ownership) in the slab metadata and then abort the scan if the state mismatches the list.
>>
>> It seems feasible, maybe something like below?
>>
>> But this way needs all kmem_caches have SLAB_TYPESAFE_BY_RCU, right?
> 
> No.
> 
> If a slab is freed to the page allocator and the fields are reused in a different way then we would have to wait till the end of the RCU period. This could be done with a deferred free. Otherwise we have the type checking to ensure that nothing untoward happens in the RCU period.
> 
> The usually shuffle of the pages between freelists/cpulists/cpuslab and fully used slabs would not require that.

IIUC, your method doesn't need the slab struct (page) to be delay freed by RCU.

So that page struct maybe reused to anything by buddy, even maybe freed, right?

Not sure the RCU read lock protection is enough here, do we need to hold other
lock, like memory hotplug lock?

> 
>> Not sure if this is acceptable? Which may cause random delay of memory free.
>>
>> ```
>> retry:
>>     rcu_read_lock();
>>
>>     h = rcu_dereference(list_next_rcu(&n->partial));
>>
>>     while (h != &n->partial) {
> 
> Hmm... a linked list that forms a circle? Linked lists usually terminate in a NULL pointer.

I think the node partial list should be a double-linked list? Since we need to
add slab to its head or tail.

> 
> So this would be
> 
> 
> redo:
> 
>     <zap counters>
>     rcu_read_lock();
>     h = <first>;
> 
>     while (h && h->type == <our type>) {
>           <count h somethings>
> 
>           /* Maybe check h->type again */
>           if (h->type != <our_type>)
>             break;

Another problem of this lockless recheck is that we may get a very false value:
say a slab removed from the node list, then be added to our list in another position,
so passed our recheck conditions here. Which may cause our counting is very mistaken?

Thanks!

> 
>           h = <next>;
>     }
> 
>     rcu_read_unlock();
> 
> 
>     if (!h) /* Type of list changed under us */
>         goto redo;
> 
> 
> The check for type == <our_type> is racy. Maybe we can ignore that or we could do something additional.
> 
> Using RCU does not make sense if you add locking in the inner loop. Then it gets too complicated and causes delay. This must be a simple fast lockless loop in order to do what we need.
> 
> Presumably the type and list pointers are in the same cacheline and thus could made to be updated in a coherent way if properly sequenced with fences etc.

  reply	other threads:[~2024-02-28  9:52 UTC|newest]

Thread overview: 23+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-02-15 21:14 [PATCH] slub: avoid scanning all partial slabs in get_slabinfo() Jianfeng Wang
2024-02-18 19:25 ` David Rientjes
2024-02-19  8:30   ` Vlastimil Babka
2024-02-19  9:29     ` Chengming Zhou
2024-02-19 10:17       ` Vlastimil Babka
2024-02-22 13:20     ` Chengming Zhou
2024-02-23  3:02       ` Christoph Lameter (Ampere)
2024-02-23  3:36         ` Chengming Zhou
2024-02-23  3:50           ` Christoph Lameter (Ampere)
2024-02-23  5:00             ` Chengming Zhou
2024-02-23  9:24               ` Vlastimil Babka
2024-02-23  9:37                 ` Chengming Zhou
2024-02-23  9:46                   ` Chengming Zhou
2024-02-23  9:51                   ` Vlastimil Babka
2024-02-26 17:38                     ` Christoph Lameter (Ampere)
2024-02-27  9:30                       ` Chengming Zhou
2024-02-27 22:55                         ` Christoph Lameter (Ampere)
2024-02-28  9:51                           ` Chengming Zhou [this message]
2024-03-14  0:38                             ` Jianfeng Wang
2024-03-14 23:45                               ` Christoph Lameter (Ampere)
2024-02-23  7:36         ` Jianfeng Wang
2024-02-23  9:17           ` Vlastimil Babka
2024-02-20 18:41   ` Jianfeng Wang

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=0aa3ce20-438f-49fb-8f04-4fc1dbf49728@linux.dev \
    --to=chengming.zhou@linux.dev \
    --cc=42.hyeyoo@gmail.com \
    --cc=akpm@linux-foundation.org \
    --cc=cl@linux.com \
    --cc=iamjoonsoo.kim@lge.com \
    --cc=jianfeng.w.wang@oracle.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mm@kvack.org \
    --cc=penberg@kernel.org \
    --cc=rientjes@google.com \
    --cc=roman.gushchin@linux.dev \
    --cc=vbabka@suse.cz \
    --cc=zhouchengming@bytedance.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.