Re: [PATCH] memcg: sink mem_cgroup_uncharge_folios() into free_unref_folios()
From: Ridong Chen
Date: Thu Aug 27 2026 - 22:08:27 EST
On 8/27/2026 10:52 PM, Johannes Weiner wrote:
On Thu, Aug 27, 2026 at 11:05:16AM +0800, Ridong Chen wrote:
From: Ridong Chen <chenridong@xxxxxxxxxx>
Every caller of free_unref_folios() invokes mem_cgroup_uncharge_folios()
on the same batch immediately beforehand. This pattern is duplicated
across shrink_folio_list(), move_folios_to_lru(), folio_batch_move_lru()
and folios_put_refs().
Move the uncharge into free_unref_folios() itself so the batch is
uncharged in one place before the folios are freed. This removes the
repeated boilerplate at every call site and makes it impossible to free
a batch without uncharging it first. No functional change intended.
Hm, IMO this is confusing. You're making uncharging an included
service in a subset of the page allocator freeing API. Batch freeing
uncharges, but single page freeing does not.
I don't think saving 7 lines is worth that API caveat.
Thanks Johannes.
I thought this could improve cohesion, since we have to uncharge the batch when freeing unreferenced folios. However, I didn't consider the symmetry with single folio freeing.
I'll just drop the patch if it's causing confusion.
--
Best regards
Ridong