Re: [PATCH v2 3/3] mm: memcg: skip the RCU lock when the memcg is not dying

From: Shakeel Butt

Date: Thu Sep 03 2026 - 13:59:02 EST


On Mon, Aug 31, 2026 at 05:46:11PM +0800, Hui Zhu wrote:
> From: Hui Zhu <zhuhui@xxxxxxxxxx>
>
> get_non_dying_memcg_start() takes rcu_read_lock() on every stat update, but
> the lock only protects the upward walk to a non-dying ancestor, which
> happens solely while a memcg is being offlined. The dying check itself
> reads the CSS_DYING flag of a memcg the caller already holds a reference
> to, so it is safe without the lock.
>
> Check memcg_is_dying() first and return immediately when the memcg is
> alive, taking the RCU lock only on the rare dying path. On an anon
> fault/charge churn workload in a memcg this recovers the ~0.6% overhead
> added by the previous patch (4368077 vs 4343159 pages/s before, back to
> ~4377000 pages/s after).
>
> Signed-off-by: Hui Zhu <zhuhui@xxxxxxxxxx>

Acked-by: Shakeel Butt <shakeel.butt@xxxxxxxxx>