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

From: Jiebin Sun

Date: Wed Nov 18 2026 - 05:12:38 EST


Hi Andrew and Sebastian,

Thanks for the comments and the RT review.

I'll replace the macros with static inline helpers, add the RT comment,
and clarify the practical callers, including percpu_counter_sum_positive(),
in v2.

Interrupt readers can bypass a WAITING writer and delay it if they keep
overlapping. I'm considering the impact this could have on counter
updates. If this needs addressing, we might take the write lock in
__percpu_counter_sum() when called from interrupt context, while keeping
the read lock for ordinary sums.

I also tested buffered writes with fio.

Fio (64 jobs, 3 iterations, 60s each):

+------+------------+-----------------+---------+
| Test | Throughput | CPU utilization | Cycles |
+------+------------+-----------------+---------+
| Fio | +6.91% | -40.41% | -40.80% |
+------+------------+-----------------+---------+

Test configuration: ext4, 32 GiB cgroup memory limit.

Commands:

sysctl -w vm.dirty_bytes=67108864 \
vm.dirty_background_bytes=33554432

fio --name=buffered-write --directory="$TEST_DIR" \
--ioengine=sync --rw=write --bs=64k --size=256m --numjobs=64 \
--direct=0 --fallocate=none --time_based=1 --runtime=60 \
--cpus_allowed=0-31,86-117 --cpus_allowed_policy=split \
--group_reporting --output-format=json

Thanks,
Jiebin