linux-bcache.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Jens Axboe <axboe@kernel.dk>
To: Christoph Hellwig <hch@lst.de>
Cc: Coly Li <colyli@suse.de>, Mike Snitzer <snitzer@redhat.com>,
	Song Liu <song@kernel.org>, David Sterba <dsterba@suse.com>,
	Josef Bacik <josef@toxicpanda.com>, Theodore Ts'o <tytso@mit.edu>,
	OGAWA Hirofumi <hirofumi@mail.parknet.co.jp>,
	Dave Kleikamp <shaggy@kernel.org>,
	Ryusuke Konishi <konishi.ryusuke@gmail.com>,
	Anton Altaparmakov <anton@tuxera.com>,
	Konstantin Komarov <almaz.alexandrovich@paragon-software.com>,
	Kees Cook <keescook@chromium.org>,
	Phillip Lougher <phillip@squashfs.org.uk>,
	Jan Kara <jack@suse.com>,
	linux-block@vger.kernel.org, dm-devel@redhat.com,
	drbd-dev@lists.linbit.com, linux-bcache@vger.kernel.org,
	linux-raid@vger.kernel.org, linux-nvme@lists.infradead.org,
	linux-scsi@vger.kernel.org, target-devel@vger.kernel.org,
	linux-fsdevel@vger.kernel.org, linux-btrfs@vger.kernel.org,
	linux-ext4@vger.kernel.org, jfs-discussion@lists.sourceforge.net,
	linux-nfs@vger.kernel.org, linux-nilfs@vger.kernel.org,
	linux-ntfs-dev@lists.sourceforge.net, ntfs3@lists.linux.dev,
	reiserfs-devel@vger.kernel.org
Subject: Re: don't use ->bd_inode to access the block device size v3
Date: Mon, 18 Oct 2021 11:53:08 -0600	[thread overview]
Message-ID: <e0784f3e-46c8-c90c-870b-60cc2ed7a2da@kernel.dk> (raw)
In-Reply-To: <20211018174901.GA3990@lst.de>

On 10/18/21 11:49 AM, Christoph Hellwig wrote:
> On Mon, Oct 18, 2021 at 11:40:51AM -0600, Jens Axboe wrote:
>>  static inline loff_t bdev_nr_bytes(struct block_device *bdev)
>>  {
>> -	return i_size_read(bdev->bd_inode);
>> +	return bdev->bd_nr_sectors;
> 
> This hunk needs to go into bdev_nr_sectors, and the bdev_nr_bytes
> probably wants to call bdev_nr_sectors and do the shifting.

Makes sense.

commit dd018a580d0037f65d7dd801cbf3e053f36283de
Author: Jens Axboe <axboe@kernel.dk>
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@kernel.dk>

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..a967b3fb3c71 100644
--- a/include/linux/genhd.h
+++ b/include/linux/genhd.h
@@ -236,14 +236,14 @@ static inline sector_t get_start_sect(struct block_device *bdev)
 	return bdev->bd_start_sect;
 }
 
-static inline loff_t bdev_nr_bytes(struct block_device *bdev)
+static inline sector_t bdev_nr_sectors(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)
+static inline loff_t bdev_nr_bytes(struct block_device *bdev)
 {
-	return bdev_nr_bytes(bdev) >> SECTOR_SHIFT;
+	return bdev_nr_setors(bdev) << SECTOR_SHIFT;
 }
 
 static inline sector_t get_capacity(struct gendisk *disk)

-- 
Jens Axboe


  reply	other threads:[~2021-10-18 17:53 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
2021-10-18 17:16 ` don't use ->bd_inode to access the block device size v3 Jens Axboe
2021-10-18 17:18   ` Christoph Hellwig
2021-10-18 17:40     ` Jens Axboe
2021-10-18 17:49       ` Christoph Hellwig
2021-10-18 17:53         ` Jens Axboe [this message]
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=e0784f3e-46c8-c90c-870b-60cc2ed7a2da@kernel.dk \
    --to=axboe@kernel.dk \
    --cc=almaz.alexandrovich@paragon-software.com \
    --cc=anton@tuxera.com \
    --cc=colyli@suse.de \
    --cc=dm-devel@redhat.com \
    --cc=drbd-dev@lists.linbit.com \
    --cc=dsterba@suse.com \
    --cc=hch@lst.de \
    --cc=hirofumi@mail.parknet.co.jp \
    --cc=jack@suse.com \
    --cc=jfs-discussion@lists.sourceforge.net \
    --cc=josef@toxicpanda.com \
    --cc=keescook@chromium.org \
    --cc=konishi.ryusuke@gmail.com \
    --cc=linux-bcache@vger.kernel.org \
    --cc=linux-block@vger.kernel.org \
    --cc=linux-btrfs@vger.kernel.org \
    --cc=linux-ext4@vger.kernel.org \
    --cc=linux-fsdevel@vger.kernel.org \
    --cc=linux-nfs@vger.kernel.org \
    --cc=linux-nilfs@vger.kernel.org \
    --cc=linux-ntfs-dev@lists.sourceforge.net \
    --cc=linux-nvme@lists.infradead.org \
    --cc=linux-raid@vger.kernel.org \
    --cc=linux-scsi@vger.kernel.org \
    --cc=ntfs3@lists.linux.dev \
    --cc=phillip@squashfs.org.uk \
    --cc=reiserfs-devel@vger.kernel.org \
    --cc=shaggy@kernel.org \
    --cc=snitzer@redhat.com \
    --cc=song@kernel.org \
    --cc=target-devel@vger.kernel.org \
    --cc=tytso@mit.edu \
    /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).