[PATCH 2/2] blk-iocost: Use alloc_percpu_gfp() to simplify the code
From: Baolin Wang
Date: Thu Dec 10 2020 - 05:59:24 EST
Use alloc_percpu_gfp() with __GFP_ZERO flag, which can remove
some explicit initialization code.
Signed-off-by: Baolin Wang <baolin.wang@xxxxxxxxxxxxxxxxx>
---
block/blk-iocost.c | 15 +++------------
1 file changed, 3 insertions(+), 12 deletions(-)
diff --git a/block/blk-iocost.c b/block/blk-iocost.c
index ac6078a..52ce2e3 100644
--- a/block/blk-iocost.c
+++ b/block/blk-iocost.c
@@ -2819,28 +2819,19 @@ static int blk_iocost_init(struct request_queue *q)
{
struct ioc *ioc;
struct rq_qos *rqos;
- int i, cpu, ret;
+ int ret;
+ gfp_t gfp = GFP_KERNEL | __GFP_ZERO;
ioc = kzalloc(sizeof(*ioc), GFP_KERNEL);
if (!ioc)
return -ENOMEM;
- ioc->pcpu_stat = alloc_percpu(struct ioc_pcpu_stat);
+ ioc->pcpu_stat = alloc_percpu_gfp(struct ioc_pcpu_stat, gfp);
if (!ioc->pcpu_stat) {
kfree(ioc);
return -ENOMEM;
}
- for_each_possible_cpu(cpu) {
- struct ioc_pcpu_stat *ccs = per_cpu_ptr(ioc->pcpu_stat, cpu);
-
- for (i = 0; i < ARRAY_SIZE(ccs->missed); i++) {
- local_set(&ccs->missed[i].nr_met, 0);
- local_set(&ccs->missed[i].nr_missed, 0);
- }
- local64_set(&ccs->rq_wait_ns, 0);
- }
-
rqos = &ioc->rqos;
rqos->id = RQ_QOS_COST;
rqos->ops = &ioc_rqos_ops;
--
1.8.3.1