Skip to content

Commit 9f4107b

Browse files
committed
block: store bdev->bd_disk->fops->submit_bio state in bdev
We have a long chain of memory dereferencing just to whether or not this disk has a special submit_bio helper. As that's not necessarily the common case, add a bd_has_submit_bio state in the bdev to avoid traversing this memory dependency chain if we don't need to. Signed-off-by: Jens Axboe <[email protected]>
1 parent 3838c40 commit 9f4107b

File tree

4 files changed

+9
-4
lines changed

4 files changed

+9
-4
lines changed

block/bdev.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -419,6 +419,7 @@ struct block_device *bdev_alloc(struct gendisk *disk, u8 partno)
419419
bdev->bd_inode = inode;
420420
bdev->bd_queue = disk->queue;
421421
bdev->bd_stats = alloc_percpu(struct disk_stats);
422+
bdev->bd_has_submit_bio = false;
422423
if (!bdev->bd_stats) {
423424
iput(inode);
424425
return NULL;

block/blk-core.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -587,14 +587,14 @@ static inline blk_status_t blk_check_zone_append(struct request_queue *q,
587587

588588
static void __submit_bio(struct bio *bio)
589589
{
590-
struct gendisk *disk = bio->bi_bdev->bd_disk;
591-
592590
if (unlikely(!blk_crypto_bio_prep(&bio)))
593591
return;
594592

595-
if (!disk->fops->submit_bio) {
593+
if (!bio->bi_bdev->bd_has_submit_bio) {
596594
blk_mq_submit_bio(bio);
597595
} else if (likely(bio_queue_enter(bio) == 0)) {
596+
struct gendisk *disk = bio->bi_bdev->bd_disk;
597+
598598
disk->fops->submit_bio(bio);
599599
blk_queue_exit(disk->queue);
600600
}
@@ -698,7 +698,7 @@ void submit_bio_noacct_nocheck(struct bio *bio)
698698
*/
699699
if (current->bio_list)
700700
bio_list_add(&current->bio_list[0], bio);
701-
else if (!bio->bi_bdev->bd_disk->fops->submit_bio)
701+
else if (!bio->bi_bdev->bd_has_submit_bio)
702702
__submit_bio_noacct_mq(bio);
703703
else
704704
__submit_bio_noacct(bio);

block/genhd.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -420,6 +420,9 @@ int __must_check device_add_disk(struct device *parent, struct gendisk *disk,
420420
*/
421421
elevator_init_mq(disk->queue);
422422

423+
/* Mark bdev as having a submit_bio, if needed */
424+
disk->part0->bd_has_submit_bio = disk->fops->submit_bio != NULL;
425+
423426
/*
424427
* If the driver provides an explicit major number it also must provide
425428
* the number of minors numbers supported, and those will be used to

include/linux/blk_types.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ struct block_device {
4747
bool bd_read_only; /* read-only policy */
4848
u8 bd_partno;
4949
bool bd_write_holder;
50+
bool bd_has_submit_bio;
5051
dev_t bd_dev;
5152
atomic_t bd_openers;
5253
spinlock_t bd_size_lock; /* for bd_inode->i_size updates */

0 commit comments

Comments
 (0)