Re: [PATCH 1/4] memcg: keep swap charging under RCU protection

From: Muchun Song

Date: Fri Sep 18 2026 - 08:18:33 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 unbinding memcgid from memcg. No
> functional change.
>
> The swap charging path currently drops its RCU read lock after acquiring
> a private ID reference. This is safe because the ID reference pins the
> memcg's CSS.
>
> Moving private ID references to objcgs will remove that lifetime
> guarantee. Keep the RCU read lock held while accessing the memcg for
> counter charging, statistics and failure handling. (This matches what
> __memcg1_swapout() already does.).
>
> Save the private ID before dropping the RCU read lock, and use the saved
> value when recording the swap entry. The swap cluster locking remains
> outside the RCU read-side critical section.
>
> Signed-off-by: Bingfang Guo <bingfangguo@xxxxxxxxxxx>

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

Thanks.