Re: [PATCH v5 7/7] mm/memcontrol: add stock to the memsw page_counter
From: Joshua Hahn
Date: Tue Sep 01 2026 - 10:34:37 EST
On Tue, 1 Sep 2026 11:40:31 +0200 Michal Koutný <mkoutny@xxxxxxxx> wrote:
> Hello Joshua.
>
> On Mon, Aug 31, 2026 at 09:37:51AM -0700, Joshua Hahn <joshua.hahnjy@xxxxxxxxx> wrote:
> > Before this series, each memcg had one stock shared by all its
> > page_counters (memory + memsw). Now that the memcg stock was folded
> > into the page_counter level, give memsw its own page_counter_stock
> > so that it can benefit from caching charges as well.
> >
> > Note that while the allocation is conditional on do_memsw_account(),
> > the freeing is not; the freer will only free non-NULL stocks. This
> > matters because do_memsw_account() could have changed in between the
> > allocation and the free.
>
> (Just a passerby comment, I have no remarks to the overhaul.)
Hi Michal! Thanks for taking a look at the series.
> The change of do_memsw_account() is because of re-attaching the memory
> controller between v1 and v2 trees. That's not so common operation (but
> not ruled out), pre-condition for that is that there's only a single
> online memcg, namely the root memcg. So it needs treatment especially at
> memcg offlining (which is what drain_all_stock() (also) does).
Wow, that's good to know. To be completely honest I dont have much
experience with cgroup v1. I didn't realize it wasn't a "switch whenever
you want" type of operation. Good to know that there is some more
guarding there.
> I don't know how expensive page_counter_drain_stock_async() is going to
> be [1] but the v1 parts here could could be guarded with
> !cgroup_on_dfl(memcg->css.cgroup).
The function itself should be pretty quick. It just frees one CPU's
stock, but the rest is just scheduling a job item.
> Regards,
> Michal
>
> [1] Now, I see in 5/7 that there's the counter->stock check which should
> be quick bailout on v2 (maybe quicker than the cgroup_on_dfl()
> I proposed above).
I'm not entirely sure, it's probably similar : -)
I think they should achieve the same goal, and hopefully it wasn't too
difficult to understand why we don't have the cgroup_on_dfl() there.
Hopefully the rest of the code looks good to you too. Thanks again for
taking a look Michal, I hope you have a great day!
Joshua