From: Jens Axboe <axboe@kernel.dk>
To: linux-block@vger.kernel.org
Cc: Jens Axboe <axboe@kernel.dk>
Subject: [PATCH 2/2] block: store bdev->bd_disk->fops->submit_bio state in bdev
Date: Fri, 14 Apr 2023 07:48:48 -0600 [thread overview]
Message-ID: <20230414134848.91563-3-axboe@kernel.dk> (raw)
In-Reply-To: <20230414134848.91563-1-axboe@kernel.dk>
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_submit_bio state in the bdev to avoid
traversing this memory dependency chain if we don't need to.
Signed-off-by: Jens Axboe <axboe@kernel.dk>
---
block/bdev.c | 1 +
block/blk-core.c | 8 ++++----
block/genhd.c | 4 ++++
include/linux/blk_types.h | 1 +
4 files changed, 10 insertions(+), 4 deletions(-)
diff --git a/block/bdev.c b/block/bdev.c
index 1795c7d4b99e..31a5d25b2b44 100644
--- a/block/bdev.c
+++ b/block/bdev.c
@@ -419,6 +419,7 @@ struct block_device *bdev_alloc(struct gendisk *disk, u8 partno)
bdev->bd_inode = inode;
bdev->bd_queue = disk->queue;
bdev->bd_stats = alloc_percpu(struct disk_stats);
+ bdev->bd_submit_bio = 0;
if (!bdev->bd_stats) {
iput(inode);
return NULL;
diff --git a/block/blk-core.c b/block/blk-core.c
index 269765d16cfd..ae7953539dc0 100644
--- a/block/blk-core.c
+++ b/block/blk-core.c
@@ -587,14 +587,14 @@ static inline blk_status_t blk_check_zone_append(struct request_queue *q,
static void __submit_bio(struct bio *bio)
{
- struct gendisk *disk = bio->bi_bdev->bd_disk;
-
if (unlikely(!blk_crypto_bio_prep(&bio)))
return;
- if (!disk->fops->submit_bio) {
+ if (!bio->bi_bdev->bd_submit_bio) {
blk_mq_submit_bio(bio);
} else if (likely(bio_queue_enter(bio) == 0)) {
+ struct gendisk *disk = bio->bi_bdev->bd_disk;
+
disk->fops->submit_bio(bio);
blk_queue_exit(disk->queue);
}
@@ -698,7 +698,7 @@ void submit_bio_noacct_nocheck(struct bio *bio)
*/
if (current->bio_list)
bio_list_add(¤t->bio_list[0], bio);
- else if (!bio->bi_bdev->bd_disk->fops->submit_bio)
+ else if (!bio->bi_bdev->bd_submit_bio)
__submit_bio_noacct_mq(bio);
else
__submit_bio_noacct(bio);
diff --git a/block/genhd.c b/block/genhd.c
index 02d9cfb9e077..07736c5db988 100644
--- a/block/genhd.c
+++ b/block/genhd.c
@@ -420,6 +420,10 @@ int __must_check device_add_disk(struct device *parent, struct gendisk *disk,
*/
elevator_init_mq(disk->queue);
+ /* Mark bdev as having a submit_bio, if needed */
+ if (disk->fops->submit_bio)
+ disk->part0->bd_submit_bio = 1;
+
/*
* If the driver provides an explicit major number it also must provide
* the number of minors numbers supported, and those will be used to
diff --git a/include/linux/blk_types.h b/include/linux/blk_types.h
index d68d6e951fad..c08e1c08b7ba 100644
--- a/include/linux/blk_types.h
+++ b/include/linux/blk_types.h
@@ -47,6 +47,7 @@ struct block_device {
bool bd_read_only; /* read-only policy */
u8 bd_partno;
bool bd_write_holder;
+ bool bd_submit_bio;
dev_t bd_dev;
atomic_t bd_openers;
spinlock_t bd_size_lock; /* for bd_inode->i_size updates */
--
2.39.2
next prev parent reply other threads:[~2023-04-14 13:49 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-04-14 13:48 [PATCHSET 0/2] Optimize block_device utilization Jens Axboe
2023-04-14 13:48 ` [PATCH 1/2] block: re-arrange the struct block_device fields for better layout Jens Axboe
2023-04-16 5:51 ` Christoph Hellwig
2023-04-16 19:01 ` Jens Axboe
2023-04-14 13:48 ` Jens Axboe [this message]
2023-04-15 2:43 ` [PATCH 2/2] block: store bdev->bd_disk->fops->submit_bio state in bdev Damien Le Moal
2023-04-15 3:41 ` Jens Axboe
2023-04-16 5:53 ` Christoph Hellwig
2023-04-16 18:59 ` Jens Axboe
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20230414134848.91563-3-axboe@kernel.dk \
--to=axboe@kernel.dk \
--cc=linux-block@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).