]> www.infradead.org Git - users/jedix/linux-maple.git/commitdiff
mm: backing-dev: use group allocation/free of per-cpu counters API
authorKefeng Wang <wangkefeng.wang@huawei.com>
Mon, 25 Mar 2024 03:56:35 +0000 (11:56 +0800)
committerAndrew Morton <akpm@linux-foundation.org>
Fri, 26 Apr 2024 03:56:12 +0000 (20:56 -0700)
Use group allocation/free of per-cpu counters api to accelerate
wb_init/exit() and simplify code.

Link: https://lkml.kernel.org/r/20240325035635.49342-1-wangkefeng.wang@huawei.com
Signed-off-by: Kefeng Wang <wangkefeng.wang@huawei.com>
Cc: Dennis Zhou <dennis@kernel.org>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
mm/backing-dev.c

index 5f2be8c8df11f1ba31a1c2ea78be76651eb98747..5fa3666356f957f532f3358b5059427d36ab028e 100644 (file)
@@ -388,7 +388,7 @@ static void wb_update_bandwidth_workfn(struct work_struct *work)
 static int wb_init(struct bdi_writeback *wb, struct backing_dev_info *bdi,
                   gfp_t gfp)
 {
-       int i, err;
+       int err;
 
        memset(wb, 0, sizeof(*wb));
 
@@ -416,18 +416,10 @@ static int wb_init(struct bdi_writeback *wb, struct backing_dev_info *bdi,
        if (err)
                return err;
 
-       for (i = 0; i < NR_WB_STAT_ITEMS; i++) {
-               err = percpu_counter_init(&wb->stat[i], 0, gfp);
-               if (err)
-                       goto out_destroy_stat;
-       }
-
-       return 0;
+       err = percpu_counter_init_many(wb->stat, 0, gfp, NR_WB_STAT_ITEMS);
+       if (err)
+               fprop_local_destroy_percpu(&wb->completions);
 
-out_destroy_stat:
-       while (i--)
-               percpu_counter_destroy(&wb->stat[i]);
-       fprop_local_destroy_percpu(&wb->completions);
        return err;
 }
 
@@ -460,13 +452,8 @@ static void wb_shutdown(struct bdi_writeback *wb)
 
 static void wb_exit(struct bdi_writeback *wb)
 {
-       int i;
-
        WARN_ON(delayed_work_pending(&wb->dwork));
-
-       for (i = 0; i < NR_WB_STAT_ITEMS; i++)
-               percpu_counter_destroy(&wb->stat[i]);
-
+       percpu_counter_destroy_many(wb->stat, NR_WB_STAT_ITEMS);
        fprop_local_destroy_percpu(&wb->completions);
 }