[Devel] [PATCH vz10 v3 1/2] mm/memcontrol: fix cache counter imbalance in mem_cgroup_replace_folio()
Pavel Tikhomirov
ptikhomirov at virtuozzo.com
Tue Jul 29 06:00:19 MSK 2025
On 7/29/25 00:46, Konstantin Khorenko wrote:
> The function was checking cache flag on the new folio instead of the old one,
> causing cache counter imbalance when replacing cache pages.
> The new folio is freshly allocated and never has the cache flag set, so
> we need to copy the flag from the old folio and charge the cache counter
> accordingly.
>
> This fixes potential cache accounting issues during page cache replacement
> operations like page migration between NUMA nodes.
>
> Another possible cause of the imbalance is the commit_charge() function
> which unconditionally drops MEMCG_DATA_PGCACHE flag on
> folio->memcg_data, so enhance commit_charge() to preserve the flag.
>
> The way of adding a new arguments was chosen in order not to miss the
> appearance of new commit_charge() calls on rebases.
>
> Fixes: 6a2ca4d515c5 ("mm: Memory cgroup page cache limit")
> https://virtuozzo.atlassian.net/browse/VSTOR-111756
>
> Signed-off-by: Konstantin Khorenko <khorenko at virtuozzo.com>
>
> Feature: mm: Memory cgroup page cache limit
> ---
> v3:
> * enhance mem_cgroup_commit_charge() with cache parameter as well
> * in mem_cgroup_replace_folio() put cache counter handling under
> !mem_cgroup_is_root() condition like other memory counters
I get why limiting memory in root memcg is kinda useless (as if allowed
it will lead to unused memory). But limiting cache in root memcg looks
like a completely valid operation. So I believe, we should not put cache
accounting under !is_root.
--
Best regards, Pavel Tikhomirov
Senior Software Developer, Virtuozzo.
More information about the Devel
mailing list