blk-mq: misc changes
cover blk-mq: misc changes
Hi,
Three are fixes, and another one is cleanup.
Thanks,
--
Ming Lei
PATCH 1/4 blk-mq: free hctx->ctx_map when init failed
Avoid memory leak in the failure path.
--- block/blk-mq.c | 1 + 1 file changed, 1 insertion(+)
block/blk-mq.c +1 -0
@@ -1289,6 +1289,7 @@ static int blk_mq_init_hw_queues(struct request_queue *q,blk_mq_unregister_cpu_notifier (&hctx->cpu_notifier);kfree (hctx->ctxs); +kfree (hctx->ctx_map); }return 1 ;
Signature · 1 line
1.7.9.5
Re: [PATCH next 1/4] blk-mq: free hctx->ctx_map when init failed
Quoted 1 line · Ming Lei
Avoid memory leak in the failure path.
Looks good,
PATCH 2/4 blk-mq: fix allocation of set->tags
In reply to Ming Leitype of set->tags is struct blk_mq_tags **.
--- block/blk-mq.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
block/blk-mq.c +1 -1
@@ -1537,7 +1537,7 @@ int blk_mq_alloc_tag_set(struct blk_mq_tag_set *set)return -EINVAL ; - set->tags =kmalloc_node (set->nr_hw_queues *sizeof (struct blk_mq_tags ), + set->tags =kmalloc_node (set->nr_hw_queues *sizeof (struct blk_mq_tags *),GFP_KERNEL , set->numa_node);if (!set->tags) goto out;
Signature · 1 line
1.7.9.5
Re: [PATCH next 2/4] blk-mq: fix allocation of set->tags
Quoted 3 lines · Ming Lei
type of
set->tagsis structblk_mq_tags**.Signed-off-by Ming Lei <[email protected]>
Looks good, but you're now overflowing 80 character per line and need a line break.
PATCH 3/4 blk-mq: user (1 << order) to implement order_to_size()
In reply to Ming Lei--- block/blk-mq.c | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-)
block/blk-mq.c +1 -6
@@ -1130,12 +1130,7 @@ static void blk_mq_free_rq_map(struct blk_mq_tag_set *set,static size_t order_to_size (unsigned int order) { -size_t ret =PAGE_SIZE ; - -while (order--) - ret *=2 ; - -return ret; +return (1 << order) *PAGE_SIZE ; } static struct blk_mq_tags *blk_mq_init_rq_map(struct blk_mq_tag_set *set,
Signature · 1 line
1.7.9.5
Re: [PATCH next 3/4] blk-mq: user (1 << order) to implement order_to_size()
Ming Lei wrote, on 04/17/2014 17:49:
Quoted 10 lines
Signed-off-by Ming Lei <[email protected]>--- block/blk-mq.c | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-)block/blk-mq.c +0
-0
block/blk-mq.c static void blk_mq_free_rq_map(struct blk_mq_tag_set *set, · line 1133
Quoted 10 lines
block/blk-mq.c +1
-6@@ -1130,12 +1130,7 @@ static void blk_mq_free_rq_map(struct blk_mq_tag_set *set,static size_t order_to_size (unsigned int order) { -size_t ret =PAGE_SIZE ; - -while (order--) - ret *=2 ; - -return ret; +return (1 << order) *PAGE_SIZE ;
Shouldn't this be
return ((size_t)1 << order) * PAGE_SIZE;
?
block/blk-mq.c static void blk_mq_free_rq_map(struct blk_mq_tag_set *set, · line 1136
Quoted 4 lines
block/blk-mq.c +0
-0} static struct blk_mq_tags *blk_mq_init_rq_map(struct blk_mq_tag_set *set,
Regards,
jvp.
Re: [PATCH next 3/4] blk-mq: user (1 << order) to implement order_to_size()
Quoted 24 lines · Jörg-Volker Peetz
Ming Lei wrote, on 04/17/2014 17:49:
Quoted 10 lines
Signed-off-by Ming Lei <[email protected]>--- block/blk-mq.c | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-)block/blk-mq.c +0
-0block/blk-mq.c static void blk_mq_free_rq_map(struct blk_mq_tag_set *set, · line 1133
Quoted 10 lines
block/blk-mq.c +1
-6@@ -1130,12 +1130,7 @@ static void blk_mq_free_rq_map(struct blk_mq_tag_set *set,static size_t order_to_size (unsigned int order) { -size_t ret =PAGE_SIZE ; - -while (order--) - ret *=2 ; - -return ret; +return (1 << order) *PAGE_SIZE ;Shouldn't this be
Quoted 3 lines
return ((size_t)1 << order) * PAGE_SIZE;?
Maybe even
return (size_t)PAGE_SIZE << order;
?
Signature · 2 lines
Thanks. -- Max
Re: [PATCH next 3/4] blk-mq: user (1 << order) to implement order_to_size()
In reply to Jörg-Volker PeetzQuoted 24 lines · Jörg-Volker Peetz
Ming Lei wrote, on 04/17/2014 17:49:
Quoted 10 lines
Signed-off-by Ming Lei <[email protected]>--- block/blk-mq.c | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-)block/blk-mq.c +0
-0block/blk-mq.c static void blk_mq_free_rq_map(struct blk_mq_tag_set *set, · line 1133
Quoted 10 lines
block/blk-mq.c +1
-6@@ -1130,12 +1130,7 @@ static void blk_mq_free_rq_map(struct blk_mq_tag_set *set,static size_t order_to_size (unsigned int order) { -size_t ret =PAGE_SIZE ; - -while (order--) - ret *=2 ; - -return ret; +return (1 << order) *PAGE_SIZE ;Shouldn't this be
Quoted 3 lines
return ((size_t)1 << order) * PAGE_SIZE;?
IMO, it isn't necessary since compiler will cast type of 1 and the expression to size_t automatically.
Thanks,
Signature · 1 line
Ming Lei
Re: [PATCH next 3/4] blk-mq: user (1 << order) to implement order_to_size()
Ming Lei wrote, on 04/18/2014 17:47:
Quoted 27 lines · Jörg-Volker Peetz
Quoted 26 lines
Ming Lei wrote, on 04/17/2014 17:49:
Quoted 10 lines
Signed-off-by Ming Lei <[email protected]>--- block/blk-mq.c | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-)block/blk-mq.c +0
-0block/blk-mq.c static void blk_mq_free_rq_map(struct blk_mq_tag_set *set, · line 1133
Quoted 10 lines
block/blk-mq.c +1
-6@@ -1130,12 +1130,7 @@ static void blk_mq_free_rq_map(struct blk_mq_tag_set *set,static size_t order_to_size (unsigned int order) { -size_t ret =PAGE_SIZE ; - -while (order--) - ret *=2 ; - -return ret; +return (1 << order) *PAGE_SIZE ;Shouldn't this be
return ((size_t)1 << order) * PAGE_SIZE;
Quoted 7 lines
Quoted 1 line
?
IMO, it isn't necessary since compiler will cast type of 1 and the expression to
size_tautomatically.Thanks,
Testing this with gcc 4.8.2 with order > 30 confirms that the automatic casting is done operator-wise and the explicit casting is necessary.
Regards,
jvp.
Re: [PATCH next 3/4] blk-mq: user (1 << order) to implement order_to_size()
Quoted 3 lines · Jörg-Volker Peetz
Testing this with gcc 4.8.2 with order > 30 confirms that the automatic casting is done operator-wise and the explicit casting is necessary.
My gcc 4.8.2 doesn't complain the change, see below:
ming@ming:~/ming/linux$ gcc --version gcc (Ubuntu/Linaro 4.8.2-19ubuntu1) 4.8.2
ming@ming:~/ming/linux$
ming@ming:~/ming/linux$ vim block/blk-mq.c ming@ming:~/ming/linux$ ./build CHK include/config/kernel.release CHK include/generated/uapi/linux/version.h CHK include/generated/utsrelease.h CALL scripts/checksyscalls.sh CHK include/generated/compile.h CC block/blk-mq.o CHK kernel/config_data.h LD block/built-in.o LINK vmlinux LD vmlinux.o MODPOST vmlinux.o
Thanks,
Signature · 1 line
Ming Lei
Jens Axboe
maintainerRe: [PATCH next 3/4] blk-mq: user (1 << order) to implement order_to_size()
Quoted 7 lines · Ming Lei
Quoted 5 lines · Jörg-Volker Peetz
Testing this with gcc 4.8.2 with order > 30 confirms that the automatic casting is done operator-wise and the explicit casting is necessary.
My gcc 4.8.2 doesn't complain the change, see below:
It won't complain, but that doesn't mean that it won't get it wrong. The cast is necessary.
PATCH 4/4 blk-mq: initialize req->q in allocation
In reply to Ming LeiThe patch basically reverts the patch of(blk-mq:
initialize request on allocation) in Jens's tree(already in -next), and only initialize req->q in allocation for two reasons:
- presumed cache hotness on completion
- blk_rq_tagged(rq) depends on reset of req->mq_ctx
--- block/blk-mq.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)
block/blk-mq.c +3 -1
@@ -82,7 +82,6 @@ static struct request *__blk_mq_alloc_request(struct blk_mq_hw_ctx *hctx, tag =blk_mq_get_tag (hctx->tags, gfp, reserved);if (tag !=BLK_MQ_TAG_FAIL ) { rq = hctx->tags->rqs[tag]; -blk_rq_init (hctx->queue, rq); rq->tag = tag;return rq;
@@ -187,6 +186,7 @@ static void blk_mq_rq_ctx_init(struct request_queue *q, struct blk_mq_ctx *ctx,if (blk_queue_io_stat (q)) rw_flags |=REQ_IO_STAT ; + rq->q = q; rq->mq_ctx = ctx; rq->cmd_flags = rw_flags; rq->start_time = jiffies;
@@ -258,6 +258,7 @@ static void __blk_mq_free_request(struct blk_mq_hw_ctx *hctx,const int tag = rq->tag;struct request_queue *q = rq->q; +blk_rq_init (hctx->queue, rq);blk_mq_put_tag (hctx->tags, tag);blk_mq_queue_exit (q); }
@@ -1194,6 +1195,7 @@ static struct blk_mq_tags *blk_mq_init_rq_map(struct blk_mq_tag_set *set, left -= to_do * rq_size;for (j =0 ; j < to_do; j++) { tags->rqs[i] = p; +blk_rq_init (NULL , tags->rqs[i]);if (set->ops->init_request) { if (set->ops->init_request(set->driver_data, tags->rqs[i], hctx_idx, i,
Signature · 1 line
1.7.9.5