From: Ming Lei <ming.lei@redhat.com>
To: Jens Axboe <axboe@kernel.dk>
Cc: linux-block@vger.kernel.org, Ming Lei <ming.lei@redhat.com>,
Guenter Roeck <linux@roeck-us.net>,
Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Subject: [PATCH 2/2] blk-mq: alloc q->queue_ctx as normal array
Date: Fri, 16 Nov 2018 11:28:26 +0800 [thread overview]
Message-ID: <20181116032826.11901-3-ming.lei@redhat.com> (raw)
In-Reply-To: <20181116032826.11901-1-ming.lei@redhat.com>
Now q->queue_ctx is just one read-mostly table for query the
'blk_mq_ctx' instance from one cpu index, it isn't necessary
to allocate it as percpu variable. One simple array may be
more efficient.
Cc: Guenter Roeck <linux@roeck-us.net>
Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Signed-off-by: Ming Lei <ming.lei@redhat.com>
---
block/blk-mq-sysfs.c | 6 +++---
block/blk-mq.c | 12 +++++++-----
block/blk-mq.h | 2 +-
include/linux/blkdev.h | 2 +-
4 files changed, 12 insertions(+), 10 deletions(-)
diff --git a/block/blk-mq-sysfs.c b/block/blk-mq-sysfs.c
index bab236955f56..dc4ac733a125 100644
--- a/block/blk-mq-sysfs.c
+++ b/block/blk-mq-sysfs.c
@@ -300,7 +300,7 @@ void blk_mq_sysfs_deinit(struct request_queue *q)
int cpu;
for_each_possible_cpu(cpu) {
- ctx = *per_cpu_ptr(q->queue_ctx, cpu);
+ ctx = q->queue_ctx[cpu];
kobject_put(&ctx->kobj);
}
kobject_put(q->mq_kobj);
@@ -322,7 +322,7 @@ int blk_mq_sysfs_init(struct request_queue *q)
ctx = kzalloc_node(sizeof(*ctx), GFP_KERNEL, cpu_to_node(cpu));
if (!ctx)
goto fail;
- *per_cpu_ptr(q->queue_ctx, cpu) = ctx;
+ q->queue_ctx[cpu] = ctx;
kobject_init(&ctx->kobj, &blk_mq_ctx_ktype);
}
q->mq_kobj = &mq_kobj->kobj;
@@ -330,7 +330,7 @@ int blk_mq_sysfs_init(struct request_queue *q)
fail:
for_each_possible_cpu(cpu) {
- ctx = *per_cpu_ptr(q->queue_ctx, cpu);
+ ctx = q->queue_ctx[cpu];
if (ctx)
kobject_put(&ctx->kobj);
}
diff --git a/block/blk-mq.c b/block/blk-mq.c
index 3589ee601f37..20c485e1817a 100644
--- a/block/blk-mq.c
+++ b/block/blk-mq.c
@@ -2299,7 +2299,7 @@ static void blk_mq_init_cpu_queues(struct request_queue *q,
unsigned int i, j;
for_each_possible_cpu(i) {
- struct blk_mq_ctx *__ctx = *per_cpu_ptr(q->queue_ctx, i);
+ struct blk_mq_ctx *__ctx = q->queue_ctx[i];
struct blk_mq_hw_ctx *hctx;
__ctx->cpu = i;
@@ -2385,7 +2385,7 @@ static void blk_mq_map_swqueue(struct request_queue *q)
set->map[0].mq_map[i] = 0;
}
- ctx = *per_cpu_ptr(q->queue_ctx, i);
+ ctx = q->queue_ctx[i];
for (j = 0; j < set->nr_maps; j++) {
hctx = blk_mq_map_queue_type(q, j, i);
@@ -2541,7 +2541,7 @@ void blk_mq_release(struct request_queue *q)
*/
blk_mq_sysfs_deinit(q);
- free_percpu(q->queue_ctx);
+ kfree(q->queue_ctx);
}
struct request_queue *blk_mq_init_queue(struct blk_mq_tag_set *set)
@@ -2731,7 +2731,9 @@ struct request_queue *blk_mq_init_allocated_queue(struct blk_mq_tag_set *set,
if (!q->poll_cb)
goto err_exit;
- q->queue_ctx = alloc_percpu(struct blk_mq_ctx *);
+ q->queue_ctx = kmalloc_array_node(nr_cpu_ids,
+ sizeof(struct blk_mq_ctx *),
+ GFP_KERNEL, set->numa_node);
if (!q->queue_ctx)
goto err_exit;
@@ -2798,7 +2800,7 @@ struct request_queue *blk_mq_init_allocated_queue(struct blk_mq_tag_set *set,
err_sys_init:
blk_mq_sysfs_deinit(q);
err_percpu:
- free_percpu(q->queue_ctx);
+ kfree(q->queue_ctx);
err_exit:
q->mq_ops = NULL;
return ERR_PTR(-ENOMEM);
diff --git a/block/blk-mq.h b/block/blk-mq.h
index 84898793c230..97829388e1db 100644
--- a/block/blk-mq.h
+++ b/block/blk-mq.h
@@ -129,7 +129,7 @@ static inline enum mq_rq_state blk_mq_rq_state(struct request *rq)
static inline struct blk_mq_ctx *__blk_mq_get_ctx(struct request_queue *q,
unsigned int cpu)
{
- return *per_cpu_ptr(q->queue_ctx, cpu);
+ return q->queue_ctx[cpu];
}
/*
diff --git a/include/linux/blkdev.h b/include/linux/blkdev.h
index 9e3892bd67fd..9b6ddc5c7a40 100644
--- a/include/linux/blkdev.h
+++ b/include/linux/blkdev.h
@@ -407,7 +407,7 @@ struct request_queue {
const struct blk_mq_ops *mq_ops;
/* sw queues */
- struct blk_mq_ctx __percpu **queue_ctx;
+ struct blk_mq_ctx **queue_ctx;
unsigned int nr_queues;
unsigned int queue_depth;
--
2.9.5
prev parent reply other threads:[~2018-11-16 3:28 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-11-16 3:28 [PATCH 0/2] blk-mq: fix kobject lifetime issue Ming Lei
2018-11-16 3:28 ` [PATCH 1/2] blk-mq: not embed .mq_kobj and ctx->kobj into queue instance Ming Lei
2018-11-16 6:11 ` jianchao.wang
2018-11-16 7:52 ` Ming Lei
2018-11-16 6:52 ` Sasha Levin
2018-11-16 7:49 ` Ming Lei
2018-11-16 16:07 ` Sasha Levin
2018-11-16 3:28 ` Ming Lei [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20181116032826.11901-3-ming.lei@redhat.com \
--to=ming.lei@redhat.com \
--cc=axboe@kernel.dk \
--cc=gregkh@linuxfoundation.org \
--cc=linux-block@vger.kernel.org \
--cc=linux@roeck-us.net \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox