Re: [PATCH 0/6 v3] mm/memcontrol, page_counter: move stock from mem_cgroup to page_counter
From: Joshua Hahn
Date: Fri Jun 05 2026 - 11:51:56 EST
On Fri, 5 Jun 2026 08:35:56 -0700 Joshua Hahn <joshua.hahnjy@xxxxxxxxx> wrote:
> Memcg currently keeps a "stock" of 64 pages per-cpu to cache pre-charged
> allocations, allowing small allocations to avoid walking the expensive
> mem_cgroup hierarchy traversal and atomic operations on each charge.
> This design introduces a fastpath, but there is room for improvement:
>
> 1. Currently, each CPU tracks up to 7 (NR_MEMCG_STOCK) mem_cgroups. When
> more than 7 mem_cgroups are actively charging on a single CPU, a
> random victim is evicted and its associated stock is drained.
>
> 2. Stock management is tightly coupled to struct mem_cgroup, which makes
> it difficult to add a new page_counter to mem_cgroup and have
> multiple sources of stock management, which is required when trying
> to introduce fastpaths to multiple hard limit checks.
>
> This series moves the per-cpu stock down into the page_counter which
> consolidates stock limit checking and page_counter limit checking into
> page_counter_try_charge. This eliminates the 7-memcg-per-cpu slot limit,
> the random evictions (drain & refill), and slot traversal.
Sorry, two things that I forgot to add as reviewers' notes:
- There was a previous v3, but that was just a rebase, so I wasn't sure
how to name that / this. I decided to name this one v3, since the
last one didn't have any changes at all. I apologize in case there are
any confusions.
- I think it is quite late in the merge cycle, this is intended for the
next cycle, not this one.
Thank you!