From: Jens Axboe <axboe-tSWWG44O7X1aa/9Udqfwiw@public.gmane.org>
To: Christoph Hellwig <hch-jcswGhMUV9g@public.gmane.org>
Cc: Dave Kleikamp <shaggy-DgEjT+Ai2ygdnm+yROfE0A@public.gmane.org>,
jfs-discussion-5NWGOfrQmneRv+LV9MX5uipxlwaOVQ5f@public.gmane.org,
Mike Snitzer <snitzer-H+wXaHxf7aLQT0dZR+AlfA@public.gmane.org>,
linux-nvme-IAPFreCvJWM7uuMidbF8XUB+6BGkLq7r@public.gmane.org,
Konstantin Komarov
<almaz.alexandrovich-m5I1DM4ARimttCpgsWEBFlaTQe2KTcn/@public.gmane.org>,
Song Liu <song-DgEjT+Ai2ygdnm+yROfE0A@public.gmane.org>,
dm-devel-H+wXaHxf7aLQT0dZR+AlfA@public.gmane.org,
target-devel-u79uwXL29TY76Z2rM5mHXA@public.gmane.org,
reiserfs-devel-u79uwXL29TY76Z2rM5mHXA@public.gmane.org,
drbd-dev-cunTk1MwBs8qoQakbn7OcQ@public.gmane.org,
linux-nilfs-u79uwXL29TY76Z2rM5mHXA@public.gmane.org,
linux-scsi-u79uwXL29TY76Z2rM5mHXA@public.gmane.org,
OGAWA Hirofumi
<hirofumi-UIVanBePwB70ZhReMnHkpc8NsWr+9BEh@public.gmane.org>,
linux-ext4-u79uwXL29TY76Z2rM5mHXA@public.gmane.org,
Kees Cook <keescook-F7+t8E8rja9g9hUCZPvPmw@public.gmane.org>,
Josef Bacik <josef-DigfWCa+lFGyeJad7bwFQA@public.gmane.org>,
Coly Li <colyli-l3A5Bk7waGM@public.gmane.org>,
linux-raid-u79uwXL29TY76Z2rM5mHXA@public.gmane.org,
linux-bcache-u79uwXL29TY76Z2rM5mHXA@public.gmane.org,
David Sterba <dsterba-IBi9RG/b67k@public.gmane.org>,
Ryusuke Konishi
<konishi.ryusuke-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>,
Anton Altaparmakov
<anton-yrGDUoBaLx3QT0dZR+AlfA@public.gmane.org>,
linux-block-u79uwXL29TY76Z2rM5mHXA@public.gmane.org,
linux-nfs-u79uwXL29TY76Z2rM5mHXA@public.gmane.org,
Theodore Ts'o <tytso-3s7WtUTddSA@public.gmane.org>,
linux-ntfs-dev-5NWGOfrQmneRv+LV9MX5uipxlwaOVQ5f@public.gmane.org,
Jan Kara <ja>
Subject: Re: don't use ->bd_inode to access the block device size v3
Date: Mon, 18 Oct 2021 11:40:51 -0600 [thread overview]
Message-ID: <2f5dcf79-8419-45ff-c27c-68d43242ccfe@kernel.dk> (raw)
In-Reply-To: <20211018171843.GA3338-jcswGhMUV9g@public.gmane.org>
On 10/18/21 11:18 AM, Christoph Hellwig wrote:
> On Mon, Oct 18, 2021 at 11:16:08AM -0600, Jens Axboe wrote:
>> This looks good to me. Followup question, as it's related - I've got a
>> hacky patch that caches the inode size in the bdev:
>>
>> https://git.kernel.dk/cgit/linux-block/commit/?h=perf-wip&id=c754951eb7193258c35a574bd1ccccb7c4946ee4
>>
>> so we don't have to dip into the inode itself for the fast path. While
>> it's obviously not something being proposed for inclusion right now, is
>> there a world in which we can make something like that work?
>
> There's just two places that update i_size for block devices:
> set_capacity and bdev_set_nr_sectors. So you just need to update
> bd_nr_sectors there and you're done.
This on top of your patches should do the trick, then.
commit eebb7c5048163985fb21d6cb740ebac78cb46051
Author: Jens Axboe <axboe-tSWWG44O7X1aa/9Udqfwiw@public.gmane.org>
Date: Mon Oct 18 11:39:45 2021 -0600
block: cache inode size in bdev
Reading the inode size brings in a new cacheline for IO submit, and
it's in the hot path being checked for every single IO. When doing
millions of IOs per core per second, this is noticeable overhead.
Cache the nr_sectors in the bdev itself.
Signed-off-by: Jens Axboe <axboe-tSWWG44O7X1aa/9Udqfwiw@public.gmane.org>
diff --git a/block/genhd.c b/block/genhd.c
index 759bc06810f8..53495e3391e3 100644
--- a/block/genhd.c
+++ b/block/genhd.c
@@ -58,6 +58,7 @@ void set_capacity(struct gendisk *disk, sector_t sectors)
spin_lock(&bdev->bd_size_lock);
i_size_write(bdev->bd_inode, (loff_t)sectors << SECTOR_SHIFT);
+ bdev->bd_nr_sectors = sectors;
spin_unlock(&bdev->bd_size_lock);
}
EXPORT_SYMBOL(set_capacity);
diff --git a/block/partitions/core.c b/block/partitions/core.c
index 9dbddc355b40..66ef9bc6d6a1 100644
--- a/block/partitions/core.c
+++ b/block/partitions/core.c
@@ -91,6 +91,7 @@ static void bdev_set_nr_sectors(struct block_device *bdev, sector_t sectors)
{
spin_lock(&bdev->bd_size_lock);
i_size_write(bdev->bd_inode, (loff_t)sectors << SECTOR_SHIFT);
+ bdev->bd_nr_sectors = sectors;
spin_unlock(&bdev->bd_size_lock);
}
diff --git a/include/linux/blk_types.h b/include/linux/blk_types.h
index 472e55e0e94f..fe065c394fff 100644
--- a/include/linux/blk_types.h
+++ b/include/linux/blk_types.h
@@ -39,6 +39,7 @@ struct bio_crypt_ctx;
struct block_device {
sector_t bd_start_sect;
+ sector_t bd_nr_sectors;
struct disk_stats __percpu *bd_stats;
unsigned long bd_stamp;
bool bd_read_only; /* read-only policy */
diff --git a/include/linux/genhd.h b/include/linux/genhd.h
index 7b0326661a1e..001f617f82da 100644
--- a/include/linux/genhd.h
+++ b/include/linux/genhd.h
@@ -238,7 +238,7 @@ static inline sector_t get_start_sect(struct block_device *bdev)
static inline loff_t bdev_nr_bytes(struct block_device *bdev)
{
- return i_size_read(bdev->bd_inode);
+ return bdev->bd_nr_sectors;
}
static inline sector_t bdev_nr_sectors(struct block_device *bdev)
--
Jens Axboe
next prev parent reply other threads:[~2021-10-18 17:40 UTC|newest]
Thread overview: 40+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-10-18 10:11 don't use ->bd_inode to access the block device size v3 Christoph Hellwig
2021-10-18 10:11 ` [PATCH 01/30] block: move the SECTOR_SIZE related definitions to blk_types.h Christoph Hellwig
2021-10-18 10:11 ` [PATCH 02/30] block: add a bdev_nr_bytes helper Christoph Hellwig
2021-10-18 10:11 ` [PATCH 03/30] bcache: remove bdev_sectors Christoph Hellwig
2021-10-18 10:11 ` [PATCH 04/30] drbd: use bdev_nr_sectors instead of open coding it Christoph Hellwig
2021-10-18 10:11 ` [PATCH 05/30] dm: use bdev_nr_sectors and bdev_nr_bytes instead of open coding them Christoph Hellwig
2021-10-18 10:11 ` [PATCH 06/30] md: use bdev_nr_sectors instead of open coding it Christoph Hellwig
2021-10-18 10:11 ` [PATCH 07/30] nvmet: use bdev_nr_bytes " Christoph Hellwig
2021-10-18 10:11 ` [PATCH 08/30] target/iblock: " Christoph Hellwig
2021-10-18 10:11 ` [PATCH 09/30] fs: use bdev_nr_bytes instead of open coding it in blkdev_max_block Christoph Hellwig
2021-10-18 10:11 ` [PATCH 10/30] fs: simplify init_page_buffers Christoph Hellwig
2021-10-18 10:11 ` [PATCH 11/30] affs: use bdev_nr_sectors instead of open coding it Christoph Hellwig
2021-10-18 10:11 ` [PATCH 12/30] btrfs: use bdev_nr_bytes " Christoph Hellwig
2021-10-18 10:11 ` [PATCH 13/30] cramfs: " Christoph Hellwig
2021-10-18 10:11 ` [PATCH 14/30] fat: use bdev_nr_sectors " Christoph Hellwig
2021-10-18 10:11 ` [PATCH 15/30] hfs: " Christoph Hellwig
2021-10-18 10:11 ` [PATCH 16/30] hfsplus: " Christoph Hellwig
2021-10-18 10:11 ` [PATCH 17/30] jfs: use bdev_nr_bytes " Christoph Hellwig
2021-10-18 10:11 ` [PATCH 18/30] nfs/blocklayout: " Christoph Hellwig
2021-10-18 10:11 ` [PATCH 19/30] nilfs2: " Christoph Hellwig
2021-10-18 10:11 ` [PATCH 20/30] ntfs3: " Christoph Hellwig
2021-10-18 10:11 ` [PATCH 21/30] pstore/blk: " Christoph Hellwig
2021-10-18 10:11 ` [PATCH 22/30] reiserfs: " Christoph Hellwig
2021-10-18 10:11 ` [PATCH 23/30] squashfs: " Christoph Hellwig
2021-10-18 10:11 ` [PATCH 24/30] block: use bdev_nr_bytes instead of open coding it in blkdev_fallocate Christoph Hellwig
2021-10-18 10:11 ` [PATCH 25/30] block: add a sb_bdev_nr_blocks helper Christoph Hellwig
2021-10-18 10:11 ` [PATCH 26/30] ext4: use sb_bdev_nr_blocks Christoph Hellwig
2021-10-18 10:11 ` [PATCH 27/30] jfs: " Christoph Hellwig
2021-10-18 10:11 ` [PATCH 28/30] ntfs: " Christoph Hellwig
2021-10-18 10:11 ` [PATCH 29/30] reiserfs: " Christoph Hellwig
2021-10-18 10:11 ` [PATCH 30/30] udf: " Christoph Hellwig
[not found] ` <20211018101130.1838532-1-hch-jcswGhMUV9g@public.gmane.org>
2021-10-18 17:16 ` don't use ->bd_inode to access the block device size v3 Jens Axboe
[not found] ` <4a8c3a39-9cd3-5b2f-6d0f-a16e689755e6-tSWWG44O7X1aa/9Udqfwiw@public.gmane.org>
2021-10-18 17:18 ` Christoph Hellwig
[not found] ` <20211018171843.GA3338-jcswGhMUV9g@public.gmane.org>
2021-10-18 17:40 ` Jens Axboe [this message]
2021-10-18 17:49 ` Christoph Hellwig
[not found] ` <20211018174901.GA3990-jcswGhMUV9g@public.gmane.org>
2021-10-18 17:53 ` Jens Axboe
[not found] ` <e0784f3e-46c8-c90c-870b-60cc2ed7a2da-tSWWG44O7X1aa/9Udqfwiw@public.gmane.org>
2021-10-18 17:56 ` Christoph Hellwig
2021-10-19 1:04 ` Kari Argillander
2021-10-19 1:04 ` Jens Axboe
2021-10-18 17:41 ` 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=2f5dcf79-8419-45ff-c27c-68d43242ccfe@kernel.dk \
--to=axboe-tswwg44o7x1aa/9udqfwiw@public.gmane.org \
--cc=almaz.alexandrovich-m5I1DM4ARimttCpgsWEBFlaTQe2KTcn/@public.gmane.org \
--cc=anton-yrGDUoBaLx3QT0dZR+AlfA@public.gmane.org \
--cc=colyli-l3A5Bk7waGM@public.gmane.org \
--cc=dm-devel-H+wXaHxf7aLQT0dZR+AlfA@public.gmane.org \
--cc=drbd-dev-cunTk1MwBs8qoQakbn7OcQ@public.gmane.org \
--cc=dsterba-IBi9RG/b67k@public.gmane.org \
--cc=hch-jcswGhMUV9g@public.gmane.org \
--cc=hirofumi-UIVanBePwB70ZhReMnHkpc8NsWr+9BEh@public.gmane.org \
--cc=jfs-discussion-5NWGOfrQmneRv+LV9MX5uipxlwaOVQ5f@public.gmane.org \
--cc=josef-DigfWCa+lFGyeJad7bwFQA@public.gmane.org \
--cc=keescook-F7+t8E8rja9g9hUCZPvPmw@public.gmane.org \
--cc=konishi.ryusuke-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org \
--cc=linux-bcache-u79uwXL29TY76Z2rM5mHXA@public.gmane.org \
--cc=linux-block-u79uwXL29TY76Z2rM5mHXA@public.gmane.org \
--cc=linux-ext4-u79uwXL29TY76Z2rM5mHXA@public.gmane.org \
--cc=linux-nfs-u79uwXL29TY76Z2rM5mHXA@public.gmane.org \
--cc=linux-nilfs-u79uwXL29TY76Z2rM5mHXA@public.gmane.org \
--cc=linux-ntfs-dev-5NWGOfrQmneRv+LV9MX5uipxlwaOVQ5f@public.gmane.org \
--cc=linux-nvme-IAPFreCvJWM7uuMidbF8XUB+6BGkLq7r@public.gmane.org \
--cc=linux-raid-u79uwXL29TY76Z2rM5mHXA@public.gmane.org \
--cc=linux-scsi-u79uwXL29TY76Z2rM5mHXA@public.gmane.org \
--cc=reiserfs-devel-u79uwXL29TY76Z2rM5mHXA@public.gmane.org \
--cc=shaggy-DgEjT+Ai2ygdnm+yROfE0A@public.gmane.org \
--cc=snitzer-H+wXaHxf7aLQT0dZR+AlfA@public.gmane.org \
--cc=song-DgEjT+Ai2ygdnm+yROfE0A@public.gmane.org \
--cc=target-devel-u79uwXL29TY76Z2rM5mHXA@public.gmane.org \
--cc=tytso-3s7WtUTddSA@public.gmane.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).