* memcg_data and the page/folio/slab split
@ 2025-03-13 14:48 Matthew Wilcox
2025-03-13 17:06 ` Shakeel Butt
0 siblings, 1 reply; 2+ messages in thread
From: Matthew Wilcox @ 2025-03-13 14:48 UTC (permalink / raw)
To: linux-mm
Cc: Johannes Weiner, Michal Hocko, Roman Gushchin, Shakeel Butt,
Muchun Song, Zi Yan, David Hildenbrand
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.
^ permalink raw reply [flat|nested] 2+ messages in thread
* Re: memcg_data and the page/folio/slab split
2025-03-13 14:48 memcg_data and the page/folio/slab split Matthew Wilcox
@ 2025-03-13 17:06 ` Shakeel Butt
0 siblings, 0 replies; 2+ messages in thread
From: Shakeel Butt @ 2025-03-13 17:06 UTC (permalink / raw)
To: Matthew Wilcox
Cc: linux-mm, Johannes Weiner, Michal Hocko, Roman Gushchin,
Muchun Song, Zi Yan, David Hildenbrand
On Thu, Mar 13, 2025 at 02:48:44PM +0000, Matthew Wilcox wrote:
> 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.
To be fair I often get confused on page vs folio distinction which your
new following plan and the series will make much more clear.
>
> 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.
>
>
Thanks a lot of this awesome work.
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2025-03-13 17:06 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2025-03-13 14:48 memcg_data and the page/folio/slab split Matthew Wilcox
2025-03-13 17:06 ` Shakeel Butt
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox