Re: [PATCH v2] lib/percpu_counter: allow concurrent sums with an rwlock

From: Sebastian Andrzej Siewior

Date: Wed Nov 25 2026 - 06:37:17 EST


On 2026-11-24 13:19:52 [+0800], Jiebin Sun wrote:
> __percpu_counter_sum() holds a raw spinlock while reading the global
> count and per-CPU deltas, serializing concurrent sums of the same
> counter. Since a sum changes neither the global count nor the per-CPU
> deltas, use rwlock_t on !PREEMPT_RT to allow concurrent sums with a
> read lock. Global updates take the write lock. The per-CPU fast path
> remains lockless, so sums keep their existing snapshot semantics.
>
> stress-ng dentry reaches this path through ext4_statfs():
>
> statfs -> ext4_statfs -> __percpu_counter_sum
> -> native_queued_spin_lock_slowpath

Not sure if `df' is considered high performance.

…
> Suggested-by: Tim Chen <tim.c.chen@xxxxxxxxxxxxxxx>
> Reviewed-by: Tianyou Li <tianyou.li@xxxxxxxxx>
> Reviewed-by: Wangyang Guo <wangyang.guo@xxxxxxxxx>
> Signed-off-by: Jiebin Sun <jiebin.sun@xxxxxxxxx>

This is fine from PREEMPT_RT/ lockdep point of view. So
Reviewed-by: Sebastian Andrzej Siewior <bigeasy@xxxxxxxxxxxxx>

Whether is okay from actual RW-lock vs spinlock point of view is a
different story.

Sebastian