Skip to content

Commit 17220ca

Browse files
isilenceaxboe
authored andcommitted
block: cache request queue in bdev
There are tons of places where we need to get a request_queue only having bdev, which turns into bdev->bd_disk->queue. There are probably a hundred of such places considering inline helpers, and enough of them are in hot paths. Cache queue pointer in struct block_device and make use of it in bdev_get_queue(). Signed-off-by: Pavel Begunkov <asml.silence@gmail.com> Link: https://lore.kernel.org/r/a3bfaecdd28956f03629d0ca5c63ebc096e1c809.1634219547.git.asml.silence@gmail.com Signed-off-by: Jens Axboe <axboe@kernel.dk>
1 parent abd45c1 commit 17220ca

4 files changed

Lines changed: 6 additions & 2 deletions

File tree

‎block/bdev.c‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -493,6 +493,7 @@ struct block_device *bdev_alloc(struct gendisk *disk, u8 partno)
493493
spin_lock_init(&bdev->bd_size_lock);
494494
bdev->bd_partno = partno;
495495
bdev->bd_inode = inode;
496+
bdev->bd_queue = disk->queue;
496497
bdev->bd_stats = alloc_percpu(struct disk_stats);
497498
if (!bdev->bd_stats) {
498499
iput(inode);

‎block/genhd.c‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1267,6 +1267,9 @@ struct gendisk *__alloc_disk_node(struct request_queue *q, int node_id,
12671267
if (!disk->bdi)
12681268
goto out_free_disk;
12691269

1270+
/* bdev_alloc() might need the queue, set before the first call */
1271+
disk->queue = q;
1272+
12701273
disk->part0 = bdev_alloc(disk, 0);
12711274
if (!disk->part0)
12721275
goto out_free_bdi;
@@ -1282,7 +1285,6 @@ struct gendisk *__alloc_disk_node(struct request_queue *q, int node_id,
12821285
disk_to_dev(disk)->type = &disk_type;
12831286
device_initialize(disk_to_dev(disk));
12841287
inc_diskseq(disk);
1285-
disk->queue = q;
12861288
q->disk = disk;
12871289
lockdep_init_map(&disk->lockdep_map, "(bio completion)", lkclass, 0);
12881290
#ifdef CONFIG_BLOCK_HOLDER_DEPRECATED

‎include/linux/blk_types.h‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ struct block_device {
3838
u8 bd_partno;
3939
spinlock_t bd_size_lock; /* for bd_inode->i_size updates */
4040
struct gendisk * bd_disk;
41+
struct request_queue * bd_queue;
4142

4243
/* The counter of freeze processes */
4344
int bd_fsfreeze_count;

‎include/linux/blkdev.h‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -574,7 +574,7 @@ int iocb_bio_iopoll(struct kiocb *kiocb, unsigned int flags);
574574

575575
static inline struct request_queue *bdev_get_queue(struct block_device *bdev)
576576
{
577-
return bdev->bd_disk->queue; /* this is never NULL */
577+
return bdev->bd_queue; /* this is never NULL */
578578
}
579579

580580
/*

0 commit comments

Comments
 (0)