From b28acdf9042c803e1e79cf93bc2417a3431fa0ac Mon Sep 17 00:00:00 2001 From: Zach Brown Date: Fri, 21 Aug 2020 15:40:02 -0700 Subject: [PATCH] scoutfs: use larger percpu_counter batch The percpu_counter library merges the per-cpu counters with a shared count when the per-cpu counter gets larger than a certain value. The default is very small, so we often end up taking a shared lock to update the count. Use a larger batch so that we take the lock less often. Signed-off-by: Zach Brown --- kmod/src/counters.h | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/kmod/src/counters.h b/kmod/src/counters.h index 82d34e46..a9658bf3 100644 --- a/kmod/src/counters.h +++ b/kmod/src/counters.h @@ -201,11 +201,21 @@ struct scoutfs_counters { pcpu <= &SCOUTFS_SB(sb)->counters->LAST_COUNTER; \ pcpu++) -#define scoutfs_inc_counter(sb, which) \ - percpu_counter_inc(&SCOUTFS_SB(sb)->counters->which) +/* + * We always read with _sum, we have no use for the shared count and + * certainly don't want to pay the cost of a shared lock to update it. + * The default batch of 32 make counter increments show up significantly + * in profiles. + */ +#define SCOUTFS_PCPU_COUNTER_BATCH (1 << 30) -#define scoutfs_add_counter(sb, which, cnt) \ - percpu_counter_add(&SCOUTFS_SB(sb)->counters->which, cnt) +#define scoutfs_inc_counter(sb, which) \ + __percpu_counter_add(&SCOUTFS_SB(sb)->counters->which, 1, \ + SCOUTFS_PCPU_COUNTER_BATCH) + +#define scoutfs_add_counter(sb, which, cnt) \ + __percpu_counter_add(&SCOUTFS_SB(sb)->counters->which, cnt, \ + SCOUTFS_PCPU_COUNTER_BATCH) void __init scoutfs_init_counters(void); int scoutfs_setup_counters(struct super_block *sb);