linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
From: Matthew Wilcox <willy@infradead.org>
To: linux-mm@kvack.org
Cc: Johannes Weiner <hannes@cmpxchg.org>,
	Michal Hocko <mhocko@kernel.org>,
	Roman Gushchin <roman.gushchin@linux.dev>,
	Shakeel Butt <shakeel.butt@linux.dev>,
	Muchun Song <muchun.song@linux.dev>, Zi Yan <ziy@nvidia.com>,
	David Hildenbrand <david@redhat.com>
Subject: memcg_data and the page/folio/slab split
Date: Thu, 13 Mar 2025 14:48:44 +0000	[thread overview]
Message-ID: <Z9LwTOudOlCGny3f@casper.infradead.org> (raw)

I started working on 'struct acctmem' as hinted at in
https://kernelnewbies.org/MatthewWilcox/Memdescs

However, as I did so, I became aware of two things.  First, we don't
need acctmem until (unless?) we remove page->flags, which is not
on the cards for 2025.  Second, we actually have distinct things stored
in memcg_data and those things line up perfectly with page/slab/folio.

That is, alloc_page(GFP_ACCOUNT) always stores an obj_cgroup pointer there
(with the KMEM flag set).  Slab always stores an slabobj_ext pointer (with
the OBJEXTS flag set) and folios always store a mem_cgroup pointer there.
Maybe that's obvious to those who work on memcg, but I didn't know that;
I just saw code that could handle all three kinds of accounting.

So, new plan.  For 2025, we have struct slab directly pointing
to slabobj_ext (with no flag, because we know anything that is a
slab has this pointer).  struct folio directly points to mem_cgroup.
And alloc_page(GFP_ACCOUNT) uses page->memdesc with a type in the bottom
four bits to say that this is a pointer to an obj_cgroup.

Obviously we don't have a page->memdesc yet, so we'll keep storing
pointers in page->memcg_data until we're ready to switch over.  But I
do have a few patches to separate out GFP_ACCOUNT allocations from
folio allocations that I think are worth merging now, and I'll send
those imminently (think of this as a [-1/n] email).  We can't get
rid of all the "handle any kind of accounting" code today because we
lose information about whether this memory is a file/anon folio vs a
GFP_ACCOUNT allocation in the freeing path.  That's a today problem that
will get solved, but not in this patchset.



             reply	other threads:[~2025-03-13 14:48 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-03-13 14:48 Matthew Wilcox [this message]
2025-03-13 17:06 ` Shakeel Butt

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=Z9LwTOudOlCGny3f@casper.infradead.org \
    --to=willy@infradead.org \
    --cc=david@redhat.com \
    --cc=hannes@cmpxchg.org \
    --cc=linux-mm@kvack.org \
    --cc=mhocko@kernel.org \
    --cc=muchun.song@linux.dev \
    --cc=roman.gushchin@linux.dev \
    --cc=shakeel.butt@linux.dev \
    --cc=ziy@nvidia.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