Skip to content

Commit fa72b90

Browse files
htejunLinus Torvalds
authored andcommitted
[PATCH] blk: remove blk_queue_tag->real_max_depth optimization
blk_queue_tag->real_max_depth was used to optimize out unnecessary allocations/frees on tag resize. However, the whole thing was very broken - tag_map was never allocated to real_max_depth resulting in access beyond the end of the map, bits in [max_depth..real_max_depth] were set when initializing a map and copied when resizing resulting in pre-occupied tags. As the gain of the optimization is very small, well, almost nill, remove the whole thing. Signed-off-by: Tejun Heo <htejun@gmail.com> Acked-by: Jens Axboe <axboe@suse.de> Signed-off-by: Andrew Morton <akpm@osdl.org> Signed-off-by: Linus Torvalds <torvalds@osdl.org>
1 parent 2bf0fda commit fa72b90

2 files changed

Lines changed: 10 additions & 26 deletions

File tree

‎drivers/block/ll_rw_blk.c‎

Lines changed: 10 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -717,7 +717,7 @@ struct request *blk_queue_find_tag(request_queue_t *q, int tag)
717717
{
718718
struct blk_queue_tag *bqt = q->queue_tags;
719719

720-
if (unlikely(bqt == NULL || tag >= bqt->real_max_depth))
720+
if (unlikely(bqt == NULL || tag >= bqt->max_depth))
721721
return NULL;
722722

723723
return bqt->tag_index[tag];
@@ -775,9 +775,9 @@ EXPORT_SYMBOL(blk_queue_free_tags);
775775
static int
776776
init_tag_map(request_queue_t *q, struct blk_queue_tag *tags, int depth)
777777
{
778-
int bits, i;
779778
struct request **tag_index;
780779
unsigned long *tag_map;
780+
int nr_ulongs;
781781

782782
if (depth > q->nr_requests * 2) {
783783
depth = q->nr_requests * 2;
@@ -789,24 +789,17 @@ init_tag_map(request_queue_t *q, struct blk_queue_tag *tags, int depth)
789789
if (!tag_index)
790790
goto fail;
791791

792-
bits = (depth / BLK_TAGS_PER_LONG) + 1;
793-
tag_map = kmalloc(bits * sizeof(unsigned long), GFP_ATOMIC);
792+
nr_ulongs = ALIGN(depth, BLK_TAGS_PER_LONG) / BLK_TAGS_PER_LONG;
793+
tag_map = kmalloc(nr_ulongs * sizeof(unsigned long), GFP_ATOMIC);
794794
if (!tag_map)
795795
goto fail;
796796

797797
memset(tag_index, 0, depth * sizeof(struct request *));
798-
memset(tag_map, 0, bits * sizeof(unsigned long));
798+
memset(tag_map, 0, nr_ulongs * sizeof(unsigned long));
799799
tags->max_depth = depth;
800-
tags->real_max_depth = bits * BITS_PER_LONG;
801800
tags->tag_index = tag_index;
802801
tags->tag_map = tag_map;
803802

804-
/*
805-
* set the upper bits if the depth isn't a multiple of the word size
806-
*/
807-
for (i = depth; i < bits * BLK_TAGS_PER_LONG; i++)
808-
__set_bit(i, tag_map);
809-
810803
return 0;
811804
fail:
812805
kfree(tag_index);
@@ -871,32 +864,24 @@ int blk_queue_resize_tags(request_queue_t *q, int new_depth)
871864
struct blk_queue_tag *bqt = q->queue_tags;
872865
struct request **tag_index;
873866
unsigned long *tag_map;
874-
int bits, max_depth;
867+
int max_depth, nr_ulongs;
875868

876869
if (!bqt)
877870
return -ENXIO;
878871

879-
/*
880-
* don't bother sizing down
881-
*/
882-
if (new_depth <= bqt->real_max_depth) {
883-
bqt->max_depth = new_depth;
884-
return 0;
885-
}
886-
887872
/*
888873
* save the old state info, so we can copy it back
889874
*/
890875
tag_index = bqt->tag_index;
891876
tag_map = bqt->tag_map;
892-
max_depth = bqt->real_max_depth;
877+
max_depth = bqt->max_depth;
893878

894879
if (init_tag_map(q, bqt, new_depth))
895880
return -ENOMEM;
896881

897882
memcpy(bqt->tag_index, tag_index, max_depth * sizeof(struct request *));
898-
bits = max_depth / BLK_TAGS_PER_LONG;
899-
memcpy(bqt->tag_map, tag_map, bits * sizeof(unsigned long));
883+
nr_ulongs = ALIGN(max_depth, BLK_TAGS_PER_LONG) / BLK_TAGS_PER_LONG;
884+
memcpy(bqt->tag_map, tag_map, nr_ulongs * sizeof(unsigned long));
900885

901886
kfree(tag_index);
902887
kfree(tag_map);
@@ -926,7 +911,7 @@ void blk_queue_end_tag(request_queue_t *q, struct request *rq)
926911

927912
BUG_ON(tag == -1);
928913

929-
if (unlikely(tag >= bqt->real_max_depth))
914+
if (unlikely(tag >= bqt->max_depth))
930915
return;
931916

932917
if (unlikely(!__test_and_clear_bit(tag, bqt->tag_map))) {

‎include/linux/blkdev.h‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -294,7 +294,6 @@ struct blk_queue_tag {
294294
struct list_head busy_list; /* fifo list of busy tags */
295295
int busy; /* current depth */
296296
int max_depth; /* what we will send to device */
297-
int real_max_depth; /* what the array can hold */
298297
atomic_t refcnt; /* map can be shared */
299298
};
300299

0 commit comments

Comments
 (0)