Re: [PATCH 2/4] memcg: base swap charge accounting on memcgid root status
From: Muchun Song
Date: Fri Sep 18 2026 - 22:56:50 EST
> On Sep 18, 2026, at 17:18, Bingfang Guo via B4 Relay <devnull+bingfangguo.tencent.com@xxxxxxxxxx> wrote:
>
> From: Bingfang Guo <bingfangguo@xxxxxxxxxxx>
>
> A private ID currently pins its original memcg, so testing whether the
> ID belongs to root is equivalent to testing whether the resolved memcg
> is root.
>
> That equivalence will no longer hold when IDs refer to objcgs. A
> non-root ID may resolve to root after reparenting, but its swap entries
> still carry counter charges inherited by root. Skipping their uncharge
> based on the resolved memcg would leave those charges behind.
>
> Use the private ID's root status to decide whether a swap entry carries
> a counter charge. A root-ID entry carries none, while a non-root-ID
> entry must release its charge even if its current accounting memcg has
> become root.
>
> This patch adds a new helper to check if the memcgid equals to that of
> the root memcg. For swap uncharging and v2 swap charging, simply decide
> whether to charge/uncharge memsw or swap counter based on the swap
> memcgid is root or not. For v1 swapout, don't recharge the memsw
> counter, just cancel the charge if the swap memcg ID refers to the root
> memcg.
>
> This makes memory and swap charging have similar semantics: one relys on
> the objcg's root status, and the other relys on the memcgid's root
> status.
>
> Signed-off-by: Bingfang Guo <bingfangguo@xxxxxxxxxxx>
Acked-by: Muchun Song <muchun.song@xxxxxxxxx>