Skip to content

Commit

Permalink
blk-mq: make lifetime consitent between q/ctx and its kobject
Browse files Browse the repository at this point in the history
Currently from kobject view, both q->mq_kobj and ctx->kobj can
be released during one cycle of blk_mq_register_dev() and
blk_mq_unregister_dev(). Actually, sw queue's lifetime is
same with its request queue's, which is covered by request_queue->kobj.

So we don't need to call kobject_put() for the two kinds of
kobject in __blk_mq_unregister_dev(), instead we do that
in release handler of request queue.

Signed-off-by: Ming Lei <[email protected]>
Tested-by: Peter Zijlstra (Intel) <[email protected]>
Signed-off-by: Jens Axboe <[email protected]>
  • Loading branch information
ming1 authored and axboe committed Mar 8, 2017
1 parent 737f98c commit 7ea5fe3
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 8 deletions.
20 changes: 13 additions & 7 deletions block/blk-mq-sysfs.c
Original file line number Diff line number Diff line change
Expand Up @@ -242,24 +242,18 @@ static int blk_mq_register_hctx(struct blk_mq_hw_ctx *hctx)
static void __blk_mq_unregister_dev(struct device *dev, struct request_queue *q)
{
struct blk_mq_hw_ctx *hctx;
struct blk_mq_ctx *ctx;
int i, j;
int i;

queue_for_each_hw_ctx(q, hctx, i) {
blk_mq_unregister_hctx(hctx);

hctx_for_each_ctx(hctx, ctx, j)
kobject_put(&ctx->kobj);

kobject_put(&hctx->kobj);
}

blk_mq_debugfs_unregister_hctxs(q);

kobject_uevent(&q->mq_kobj, KOBJ_REMOVE);
kobject_del(&q->mq_kobj);
kobject_put(&q->mq_kobj);

kobject_put(&dev->kobj);

q->mq_sysfs_init_done = false;
Expand All @@ -277,6 +271,18 @@ void blk_mq_hctx_kobj_init(struct blk_mq_hw_ctx *hctx)
kobject_init(&hctx->kobj, &blk_mq_hw_ktype);
}

void blk_mq_sysfs_deinit(struct request_queue *q)
{
struct blk_mq_ctx *ctx;
int cpu;

for_each_possible_cpu(cpu) {
ctx = per_cpu_ptr(q->queue_ctx, cpu);
kobject_put(&ctx->kobj);
}
kobject_put(&q->mq_kobj);
}

void blk_mq_sysfs_init(struct request_queue *q)
{
struct blk_mq_ctx *ctx;
Expand Down
7 changes: 6 additions & 1 deletion block/blk-mq.c
Original file line number Diff line number Diff line change
Expand Up @@ -2264,7 +2264,12 @@ void blk_mq_release(struct request_queue *q)

kfree(q->queue_hw_ctx);

/* ctx kobj stays in queue_ctx */
/*
* release .mq_kobj and sw queue's kobject now because
* both share lifetime with request queue.
*/
blk_mq_sysfs_deinit(q);

free_percpu(q->queue_ctx);
}

Expand Down
1 change: 1 addition & 0 deletions block/blk-mq.h
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ static inline struct blk_mq_hw_ctx *blk_mq_map_queue(struct request_queue *q,
* sysfs helpers
*/
extern void blk_mq_sysfs_init(struct request_queue *q);
extern void blk_mq_sysfs_deinit(struct request_queue *q);
extern int blk_mq_sysfs_register(struct request_queue *q);
extern void blk_mq_sysfs_unregister(struct request_queue *q);
extern void blk_mq_hctx_kobj_init(struct blk_mq_hw_ctx *hctx);
Expand Down

0 comments on commit 7ea5fe3

Please sign in to comment.