linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
From: Roman Gushchin <roman.gushchin@linux.dev>
To: Yosry Ahmed <yosryahmed@google.com>
Cc: guro@fb.com, vvs@virtuozzo.com, Michal Hocko <mhocko@kernel.org>,
	Andrew Morton <akpm@linux-foundation.org>,
	Shakeel Butt <shakeelb@google.com>,
	Johannes Weiner <hannes@cmpxchg.org>,
	cl@linux.com, linux-mm@kvack.org
Subject: Re: Questions about memcg_slabinfo.py drgn script
Date: Thu, 10 Mar 2022 15:40:55 -0800	[thread overview]
Message-ID: <YiqMh4VMglqU+Z4J@carbon.dhcp.thefacebook.com> (raw)
In-Reply-To: <CAJD7tkb2N0twLTCZRxj78wquF47mdVqTKqvy=PtmZrAn7jndDg@mail.gmail.com>

On Thu, Mar 10, 2022 at 12:21:44PM -0800, Yosry Ahmed wrote:
> Hi everyone,
> 
> I was looking at the memcg_slabinfo.py drgn script that offers a
> replacement to the deprecated memory.kmem.slabinfo. I had some
> questions about how it collects the memcg slab stats:

Hi Yosry!

First, I have to admit that I haven't spent too much time optimizing
this script for speed. So, there are almost certainly available opportunities
to enhance it and patches are highly welcome.

> 
> 1. Why does the script loop through all struct pages on the system?
> Wouldn't it be more efficient to loop for every kmem_cache, for every
> online kmem_cache_node, then loop through slabs_free, slabs_full, and
> slabs_partial lists?

It's somewhat tricky with SLUB because of per-cpu partial pages (I'm less
familiar with SLAB). In theory, we have a single-linked list of such pages,
but idk if we can reliably traverse it (given that it will be changed
concurrently). We also will be way more dependent on SLUB internals.
However it still might be a good optimization.

> 
> This seems more consistent with how /proc/slabinfo works, and more
> efficient. I tested this on SLAB using a crash script as I am unable
> to run drgn on my current setup. I am not sure how correct this would
> be for SLUB though.

/proc/slabinfo has its own weaknesses, e.g. it shows systematically wrong
numbers for slab utilization because of how it handles per-cpu partial pages
(on SLUB).

> 
> 2. Before looping through pages, why does the script collect all
> objcgs belonging to the desired memcg in a set, and then test every
> objcg in a slab page to see whether it belongs to that memcg. Wouldn't
> it be easier to just check objcg->memcg? AFAICT this gets updated as
> well when the objcg is reparented.

I can't think of any good reason now, however it's not obviously faster
(I guess dereferencing of a pointer in drgn can be more expensive than doing
few "local" comparison, something to measure).
If it is faster, it will be a good enhancement.

> 
> Sorry for my ignorance if any of the assumptions I made are incorrect.
> I just wanted to get more understanding of the implementation
> decisions taken while writing the script.

You're welcome!


  reply	other threads:[~2022-03-10 23:41 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-03-10 20:21 Yosry Ahmed
2022-03-10 23:40 ` Roman Gushchin [this message]
2022-03-16 21:16   ` Yosry Ahmed

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=YiqMh4VMglqU+Z4J@carbon.dhcp.thefacebook.com \
    --to=roman.gushchin@linux.dev \
    --cc=akpm@linux-foundation.org \
    --cc=cl@linux.com \
    --cc=guro@fb.com \
    --cc=hannes@cmpxchg.org \
    --cc=linux-mm@kvack.org \
    --cc=mhocko@kernel.org \
    --cc=shakeelb@google.com \
    --cc=vvs@virtuozzo.com \
    --cc=yosryahmed@google.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