All of lore.kernel.org
 help / color / mirror / Atom feed
From: Vlastimil Babka <vbabka@suse.cz>
To: Jianfeng Wang <jianfeng.w.wang@oracle.com>,
	"Christoph Lameter (Ampere)" <cl@linux.com>,
	Chengming Zhou <chengming.zhou@linux.dev>
Cc: David Rientjes <rientjes@google.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: Fri, 23 Feb 2024 10:17:34 +0100	[thread overview]
Message-ID: <4a8aa758-175e-471c-9c22-bb61dbb956e8@suse.cz> (raw)
In-Reply-To: <93497e03-1acf-483e-8695-e103fd1bc044@oracle.com>

On 2/23/24 08:36, Jianfeng Wang wrote:
> 
> On 2/22/24 7:02 PM, Christoph Lameter (Ampere) wrote:
>> On Thu, 22 Feb 2024, Chengming Zhou wrote:
>> 
>>> Anyway, I put the code below for discussion...
>> 
>> Can we guestimate the free objects based on the number of partial slabs. That number is available.
>> 
> 
> Yes.
> I've thought about calculating the average number of free objects in a
> partial slab (through sampling) and then estimating the total number of
> free objects as (avg * n->nr_partial).
> 
> See the following.
> 
> ---
>  mm/slub.c | 20 ++++++++++++++++++--
>  1 file changed, 18 insertions(+), 2 deletions(-)
> 
> diff --git a/mm/slub.c b/mm/slub.c
> index 63d281dfacdb..13385761049c 100644
> --- a/mm/slub.c
> +++ b/mm/slub.c
> @@ -2963,6 +2963,8 @@ static inline bool free_debug_processing(struct kmem_cache *s,
>  #endif /* CONFIG_SLUB_DEBUG */
>  
>  #if defined(CONFIG_SLUB_DEBUG) || defined(SLAB_SUPPORTS_SYSFS)
> +#define MAX_PARTIAL_TO_SCAN 10000
> +
>  static unsigned long count_partial(struct kmem_cache_node *n,
>  					int (*get_count)(struct slab *))
>  {
> @@ -2971,8 +2973,22 @@ static unsigned long count_partial(struct kmem_cache_node *n,
>  	struct slab *slab;
>  
>  	spin_lock_irqsave(&n->list_lock, flags);
> -	list_for_each_entry(slab, &n->partial, slab_list)
> -		x += get_count(slab);
> +	if (n->nr_partial > MAX_PARTIAL_TO_SCAN) {
> +		/* Estimate total count of objects via sampling */
> +		unsigned long sample_rate = n->nr_partial / MAX_PARTIAL_TO_SCAN;
> +		unsigned long scanned = 0;
> +		unsigned long counted = 0;
> +		list_for_each_entry(slab, &n->partial, slab_list) {

Unfortunately this is still going through the whole list.

> +			if (++scanned % sample_rate == 0) {
> +				x += get_count(slab);

The get_count() itself is trivial, so this won't help much.
(except saving a function call which can be noticeable with all the
retpolines and other unfortunate stuff these days; we could refactor the
code to be inline, but processing the whole long list would still be an issue).

So this would have to instead count first up to MAX_PARTIAL_TO_SCAN slabs
and then terminate the loop. This can make the sampling biased, unfortunately.

> +				counted++;
> +			}
> +		}
> +		x = mult_frac(x, n->nr_partial, counted);
> +	} else {
> +		list_for_each_entry(slab, &n->partial, slab_list)
> +			x += get_count(slab);
> +	}
>  	spin_unlock_irqrestore(&n->list_lock, flags);
>  	return x;
>  }


  reply	other threads:[~2024-02-23  9:17 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
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 [this message]
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=4a8aa758-175e-471c-9c22-bb61dbb956e8@suse.cz \
    --to=vbabka@suse.cz \
    --cc=42.hyeyoo@gmail.com \
    --cc=akpm@linux-foundation.org \
    --cc=chengming.zhou@linux.dev \
    --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=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.