Re: [PATCH v5 2/7] mm/page_counter: report the number of pages charged

From: Shakeel Butt

Date: Fri Sep 04 2026 - 21:48:05 EST


On Mon, Aug 31, 2026 at 09:37:46AM -0700, Joshua Hahn wrote:
> Add an optional @nr_charged parameter to page_counter_try_charge.
> On success, it will be set to the number of pages actually charged to
> the hierarchy. Today this number is always @nr_pages, so there is no
> functional change.
>
> Of the 6 callsites, only one user (try_charge_memcg) uses that
> information. The number of charged pages is added to
> current->memcg_nr_pages_over_high to indicate how many pages it charged
> to the hierarchy while over high.
>
> Today, try_charge_memcg requests "batch" from page_counter_try_charge
> and adds that same amount to memcg_nr_pages_over_high on success, since
> page_counter_try_charge's only source of charges is the hierarchy.
> However, this invariant changes later in the series when stock is pushed
> down from the memcg level to the page_counter level, and a page_counter
> charge can be successful without growing the hierarchy size.
>
> Plumb the new parameter to all callsites, passing NULL where the source
> of charge does not matter to the caller, and passing &nr_charged in
> try_charge_memcg to account the hierarchy size growth.

The terminology of "growing the hierarchy size" and "hierarchy size growth" is
confusing.

The code looks fine.