Received: by 2002:a05:6a10:5bc5:0:0:0:0 with SMTP id os5csp3228221pxb; Mon, 18 Oct 2021 10:41:40 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzHXv35kgmhTZTdTkq4xU91/gWct3SeV4PxKbUdUSQ1EWlC2+/w/d9HjRCcmISXkLOzn3Ce X-Received: by 2002:a63:ab02:: with SMTP id p2mr1816032pgf.209.1634578899913; Mon, 18 Oct 2021 10:41:39 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1634578899; cv=none; d=google.com; s=arc-20160816; b=X0sM1Yc48UM5r94s0MBjylmRDGqKUfNX1VdO6IIp2kJQJVZrxSX64xM8jnfaPfqmOe HucBaQRjcILXwrYZS5rC76xoOtqUNTGuj74YgzMbSa2l9Av3sPn1lYrknXZzl5DDM4PR hBbr5ENiYXxfeN5TGH1FSPHUasCP8n+kRuEpX1mxeN9KJMr73GTiG1+8AMqWyf+NtqyT dMmt94BzTohMhPRzGsvyDWx+DgLa+adjyJLlL20wmq++5wi82CsViZY5nXzMLr8x79T6 5WH/m0HPRlp8btT7N1HNm+wjbG+4Gq6yIbgiV9DsnTh3UKPP2HW/DGUVa93G2kDwAWbA 8hoQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:content-language :in-reply-to:mime-version:user-agent:date:message-id:from:references :cc:to:subject:dkim-signature; bh=8eHyIh60ZUzo3JWH2PHiHe4cTmG/UJai+TUUoRo1bPo=; b=jchd1AegEFujJ+3FwyNzC79HFbxUmUw1OAc2HWjR0RZfvaCW6sktSycNKShkMKl+SC lwRNeCInagZa1hPvrcoccciYfwT5iEh7sAR5+zdLhRltPF64uKrhGV+f7DanHlOQD6h9 SoxEOT4y+NZuF60v9NAjHzTJmyr5AToI51sWxZroJTSQf34B28LwQMlwtRtsADbiHE9+ YYE+wbwfOU05IEWwxbSRFLvjzXBt/nzvx0+J6RsjAaQdHME1dktCEBnL7piMuq/pbQuW ai80ByfAPf1qr2jjBmg1Xfr5vbKmC+EbyCDVz+gYzMssmbN5G9BzYgUgPpDlWI3ws/I0 gJnA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel-dk.20210112.gappssmtp.com header.s=20210112 header.b=FxDre2hj; spf=pass (google.com: domain of linux-ext4-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-ext4-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id me4si210806pjb.34.2021.10.18.10.41.18; Mon, 18 Oct 2021 10:41:39 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-ext4-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel-dk.20210112.gappssmtp.com header.s=20210112 header.b=FxDre2hj; spf=pass (google.com: domain of linux-ext4-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-ext4-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234163AbhJRRnG (ORCPT + 99 others); Mon, 18 Oct 2021 13:43:06 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36852 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234152AbhJRRnF (ORCPT ); Mon, 18 Oct 2021 13:43:05 -0400 Received: from mail-il1-x12c.google.com (mail-il1-x12c.google.com [IPv6:2607:f8b0:4864:20::12c]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 2FB22C061769 for ; Mon, 18 Oct 2021 10:40:54 -0700 (PDT) Received: by mail-il1-x12c.google.com with SMTP id h27so9985318ila.5 for ; Mon, 18 Oct 2021 10:40:54 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel-dk.20210112.gappssmtp.com; s=20210112; h=subject:to:cc:references:from:message-id:date:user-agent :mime-version:in-reply-to:content-language:content-transfer-encoding; bh=8eHyIh60ZUzo3JWH2PHiHe4cTmG/UJai+TUUoRo1bPo=; b=FxDre2hjyoHZ64BANF3MmORptiQUy9H6AZXx6LsuyaBb3BcaZC0U/QrU21BtTujGBo 8pKXev+INoMpwpLRfH86fYXpprj4xYaVKSen9V7xFxUy/Adi3YagOWpZv1TCL1fYRKF4 KJjdISFmhkQQ0L4EmrQXCfcR5w3Zzj3aqn6DzOl13eefz8vxGa1vYg1bewxzJ9VB28da 3UiILqBGRheOtvSI5gJ9xtk7xHUS/Gucotz2TgqyyRfnlasGRztSAeszEgY1u2mV13ER EMsST0UXfQiH71wz4IGsonA4VDgwXa5gnJGRFiHsgHIEksPy/aZTeVCzAUrIhmXl9xQs p/ag== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:subject:to:cc:references:from:message-id:date :user-agent:mime-version:in-reply-to:content-language :content-transfer-encoding; bh=8eHyIh60ZUzo3JWH2PHiHe4cTmG/UJai+TUUoRo1bPo=; b=DGoUJ7Lli30hwOLbb+r5JGnVUXPl/Y4db1qe+JLKLnT7vgs1CI4QucM9s3ujrRH6T8 7QHoz11sf9Kh3rV98vCscA0lSpUg2qkfXd5uG8RN2fOhqyTc8pPwSfxiYcrsgoUWNFkU /MauT6z2DR1+O0BIjf9whYKdMvlAlIS6dsVTwuCHV/fWVQvT4gqi9jORPSXu1xUgj5/c xv9bU6eWeezO9/STTbQpXWJiXBypZgZg2HVGImwnmQWddDU94vqm70ncoohrXvcz3E+/ f+6QpVGdtDSomqg/PtnxUwDfWyrE/sp0IrRPGmpWY2KvBUHXgXW1bE+/4uK8z7K2vBTf 3rIA== X-Gm-Message-State: AOAM533TTFQNW4K/dTqz1dHDUxiduAvFke/c5P/KFsNuu9WO01n9RnX3 GlFq7RbPS/Rx9eNYeW6kyovCgg== X-Received: by 2002:a05:6e02:14d3:: with SMTP id o19mr15105521ilk.257.1634578853304; Mon, 18 Oct 2021 10:40:53 -0700 (PDT) Received: from [192.168.1.30] ([207.135.234.126]) by smtp.gmail.com with ESMTPSA id s6sm3131684ilv.18.2021.10.18.10.40.51 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Mon, 18 Oct 2021 10:40:52 -0700 (PDT) Subject: Re: don't use ->bd_inode to access the block device size v3 To: Christoph Hellwig Cc: Coly Li , Mike Snitzer , Song Liu , David Sterba , Josef Bacik , Theodore Ts'o , OGAWA Hirofumi , Dave Kleikamp , Ryusuke Konishi , Anton Altaparmakov , Konstantin Komarov , Kees Cook , Phillip Lougher , Jan Kara , 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 References: <20211018101130.1838532-1-hch@lst.de> <4a8c3a39-9cd3-5b2f-6d0f-a16e689755e6@kernel.dk> <20211018171843.GA3338@lst.de> From: Jens Axboe Message-ID: <2f5dcf79-8419-45ff-c27c-68d43242ccfe@kernel.dk> Date: Mon, 18 Oct 2021 11:40:51 -0600 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:68.0) Gecko/20100101 Thunderbird/68.10.0 MIME-Version: 1.0 In-Reply-To: <20211018171843.GA3338@lst.de> Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: 7bit Precedence: bulk List-ID: X-Mailing-List: linux-ext4@vger.kernel.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 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 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