Re: [PATCH 3/4] memcg: manipulate memcg private ID references by ID

From: Muchun Song

Date: Fri Sep 18 2026 - 23:08:06 EST




> On Sep 18, 2026, at 17:18, Bingfang Guo via B4 Relay <devnull+bingfangguo.tencent.com@xxxxxxxxxx> wrote:
>
> From: Bingfang Guo <bingfangguo@xxxxxxxxxxx>
>
> This is a preparatory work for moving memcgid from memcg to objcg.
>
> Swap entries retain a private ID rather than a memcg pointer. Once
> private ID references are moved to objcgs, the ID can also outlive the
> memcg to which it was originally assigned. So it's better to make the
> get and put functions accept the ID itself instead of the memcg.
>
> Rename mem_cgroup_private_id_get_online() to
> mem_cgroup_private_id_get(), and make it return the ID only. If the
> memcg is already dying, the dying memcg will still be used for charging
> and stats accounting in v2 swap charging path. But they are hierarchical
> and will be reparented after offlining so it doesn't matter.
>
> Make mem_cgroup_private_id_put() take the ID and resolve the reference
> holder internally. Convert swap uncharge and charge rollback to release
> the reference using that ID. This introduces an extra xarray lookup for
> now, which will be removed in the final patch.
>
> Separate the online-state reference release into
> mem_cgroup_private_id_kill(). The offline path already has the memcg
> pointer and can call the underlying put helper directly.
>
> Signed-off-by: Bingfang Guo <bingfangguo@xxxxxxxxxxx>

With Shakeel's suggestion.

Acked-by: Muchun Song <muchun.song@xxxxxxxxx>