Skip to contentSkip to conversation

blk-cgroup: use group allocation/free of per-cpu counters API

PATCH Applied Kefeng Wang 2 participants 3 messages Mar 25, 2024 – Apr 3, 2024 Block layer

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 blk-cgroup: use group allocation/free of per-cpu counters API

Use group allocation/free of per-cpu counters api to accelerate blkg_rwstat_init/exit() and simplify code.

---
 block/blk-cgroup-rwstat.c | 18 ++++++------------
 1 file changed, 6 insertions(+), 12 deletions(-)
block/blk-cgroup-rwstat.c +6 -12
index 3304e841df7c..a55fb0c53558 100644
@@ -9,25 +9,19 @@ int blkg_rwstat_init(struct blkg_rwstat *rwstat, gfp_t gfp)
 {
 	int i, ret;
 
-	for (i = 0; i < BLKG_RWSTAT_NR; i++) {
-		ret = percpu_counter_init(&rwstat->cpu_cnt[i], 0, gfp);
-		if (ret) {
-			while (--i >= 0)
-				percpu_counter_destroy(&rwstat->cpu_cnt[i]);
-			return ret;
-		}
+	ret = percpu_counter_init_many(rwstat->cpu_cnt, 0, gfp, BLKG_RWSTAT_NR);
+	if (ret)
+		return ret;
+
+	for (i = 0; i < BLKG_RWSTAT_NR; i++)
 		atomic64_set(&rwstat->aux_cnt[i], 0);
-	}
 	return 0;
 }
 EXPORT_SYMBOL_GPL(blkg_rwstat_init);
 
 void blkg_rwstat_exit(struct blkg_rwstat *rwstat)
 {
-	int i;
-
-	for (i = 0; i < BLKG_RWSTAT_NR; i++)
-		percpu_counter_destroy(&rwstat->cpu_cnt[i]);
+	percpu_counter_destroy_many(rwstat->cpu_cnt, BLKG_RWSTAT_NR);
 }
 EXPORT_SYMBOL_GPL(blkg_rwstat_exit);
 
Signature · 1 line
2.41.0
#1 lore raw

Hi Jens, kindly ping...

Quoted 44 lines · Kefeng Wang

Use group allocation/free of per-cpu counters api to accelerate blkg_rwstat_init/exit() and simplify code.

---
  block/blk-cgroup-rwstat.c | 18 ++++++------------
  1 file changed, 6 insertions(+), 12 deletions(-)
block/blk-cgroup-rwstat.c +6 -12
index 3304e841df7c..a55fb0c53558 100644
@@ -9,25 +9,19 @@ int blkg_rwstat_init(struct blkg_rwstat *rwstat, gfp_t gfp)
  {
  	int i, ret;
 
-	for (i = 0; i < BLKG_RWSTAT_NR; i++) {
-		ret = percpu_counter_init(&rwstat->cpu_cnt[i], 0, gfp);
-		if (ret) {
-			while (--i >= 0)
-				percpu_counter_destroy(&rwstat->cpu_cnt[i]);
-			return ret;
-		}
+	ret = percpu_counter_init_many(rwstat->cpu_cnt, 0, gfp, BLKG_RWSTAT_NR);
+	if (ret)
+		return ret;
+
+	for (i = 0; i < BLKG_RWSTAT_NR; i++)
  		atomic64_set(&rwstat->aux_cnt[i], 0);
-	}
  	return 0;
  }
  EXPORT_SYMBOL_GPL(blkg_rwstat_init);
 
  void blkg_rwstat_exit(struct blkg_rwstat *rwstat)
  {
-	int i;
-
-	for (i = 0; i < BLKG_RWSTAT_NR; i++)
-		percpu_counter_destroy(&rwstat->cpu_cnt[i]);
+	percpu_counter_destroy_many(rwstat->cpu_cnt, BLKG_RWSTAT_NR);
  }
  EXPORT_SYMBOL_GPL(blkg_rwstat_exit);
 
maintainer Applied
#2 lore raw
In reply to Kefeng Wang
Quoted 4 lines · Kefeng Wang

Use group allocation/free of per-cpu counters api to accelerate blkg_rwstat_init/exit() and simplify code.

Applied, thanks!

[1/1] blk-cgroup: use group allocation/free of per-cpu counters API

      commit: 688c8b9208356eb5c3fa8047f3e35666f3049a4d

Best regards,

Signature · 1 line
Jens Axboe