Re: [PATCH] mm: memcontrol: fix memsw uncharge for root_mem_cgroup

From: Michal Hocko
Date: Tue Mar 23 2021 - 12:11:48 EST


On Tue 23-03-21 22:56:53, Muchun Song wrote:
> The pages aren't accounted at the root level, so we cannot uncharge the
> page to the memsw counter for the root memcg. Fix this.

The patch is correct but I do wonder whether this matters much in the
end. We shouldn't really rely on a correct page counter for the root
memcg AFAICS in the kernel. We do not display the value
(mem_cgroup_usage) so there shouldn't be any actual problem. Unless I am
missing something make sure to spell that out in the changelog.

> Fixes: 1f47b61fb407 ("mm: memcontrol: fix swap counter leak on swapout from offline cgroup")
> Signed-off-by: Muchun Song <songmuchun@xxxxxxxxxxxxx>

Acked-by: Michal Hocko <mhocko@xxxxxxxx>
> ---
> mm/memcontrol.c | 3 ++-
> 1 file changed, 2 insertions(+), 1 deletion(-)
>
> diff --git a/mm/memcontrol.c b/mm/memcontrol.c
> index 533b4b31b464..7d765a106684 100644
> --- a/mm/memcontrol.c
> +++ b/mm/memcontrol.c
> @@ -7155,7 +7155,8 @@ void mem_cgroup_swapout(struct page *page, swp_entry_t entry)
> if (!cgroup_memory_noswap && memcg != swap_memcg) {
> if (!mem_cgroup_is_root(swap_memcg))
> page_counter_charge(&swap_memcg->memsw, nr_entries);
> - page_counter_uncharge(&memcg->memsw, nr_entries);
> + if (!mem_cgroup_is_root(memcg))
> + page_counter_uncharge(&memcg->memsw, nr_entries);
> }
>
> /*
> --
> 2.11.0

--
Michal Hocko
SUSE Labs