Skip to content

Commit 688c8b9

Browse files
Kefeng Wangaxboe
authored andcommitted
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. Signed-off-by: Kefeng Wang <wangkefeng.wang@huawei.com> Link: https://lore.kernel.org/r/20240325035955.50019-1-wangkefeng.wang@huawei.com Signed-off-by: Jens Axboe <axboe@kernel.dk>
1 parent fa1af65 commit 688c8b9

1 file changed

Lines changed: 6 additions & 12 deletions

File tree

block/blk-cgroup-rwstat.c

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -9,25 +9,19 @@ int blkg_rwstat_init(struct blkg_rwstat *rwstat, gfp_t gfp)
99
{
1010
int i, ret;
1111

12-
for (i = 0; i < BLKG_RWSTAT_NR; i++) {
13-
ret = percpu_counter_init(&rwstat->cpu_cnt[i], 0, gfp);
14-
if (ret) {
15-
while (--i >= 0)
16-
percpu_counter_destroy(&rwstat->cpu_cnt[i]);
17-
return ret;
18-
}
12+
ret = percpu_counter_init_many(rwstat->cpu_cnt, 0, gfp, BLKG_RWSTAT_NR);
13+
if (ret)
14+
return ret;
15+
16+
for (i = 0; i < BLKG_RWSTAT_NR; i++)
1917
atomic64_set(&rwstat->aux_cnt[i], 0);
20-
}
2118
return 0;
2219
}
2320
EXPORT_SYMBOL_GPL(blkg_rwstat_init);
2421

2522
void blkg_rwstat_exit(struct blkg_rwstat *rwstat)
2623
{
27-
int i;
28-
29-
for (i = 0; i < BLKG_RWSTAT_NR; i++)
30-
percpu_counter_destroy(&rwstat->cpu_cnt[i]);
24+
percpu_counter_destroy_many(rwstat->cpu_cnt, BLKG_RWSTAT_NR);
3125
}
3226
EXPORT_SYMBOL_GPL(blkg_rwstat_exit);
3327

0 commit comments

Comments
 (0)