From patchwork Tue Feb 21 20:56:58 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christoph Hellwig X-Patchwork-Id: 13148396 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 22AF0C61DA3 for ; Tue, 21 Feb 2023 20:57:09 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229918AbjBUU5I (ORCPT ); Tue, 21 Feb 2023 15:57:08 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35600 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229660AbjBUU5G (ORCPT ); Tue, 21 Feb 2023 15:57:06 -0500 Received: from bombadil.infradead.org (bombadil.infradead.org [IPv6:2607:7c80:54:3::133]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 307971ABC2 for ; Tue, 21 Feb 2023 12:57:05 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=bombadil.20210309; h=Content-Transfer-Encoding: MIME-Version:References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From:Sender :Reply-To:Content-Type:Content-ID:Content-Description; bh=qcCUOn22+pSdhqmwIeijfNzthK1ki/rm6LHNGlFR+VM=; b=NdTrkv7em4yx1LKyNyfcyLRGbj 5EQPk/o8Ok5UUyXozkqJZKs/mux7RQi/TdCHvKESm+hmN5Uue8bh/3lTp+cx+NXsCq5gKgUzzHLNK MUOWgPtNMQbEHe7RFtg4G7PdMPOp07blasE8D4+uZSyURB5PVBnaqsI60gQMoGIvg2JEYn36zPDgo uxHeEZ2Gw1a5k9Ql+8iFpaU4MqeWS+qXhpPJo8zZHVYfJUJMnvrfdgf3nAXcjIBPIviaU33+aA6PD L1c+0OQSWos0uCpPrGv3wGERG+28CkWrP2udZ8TB0iCXtNo70D3E3zFPhGJ3zX+mPfFJrazJ4W8qo WJHKFklA==; Received: from [4.28.11.157] (helo=localhost) by bombadil.infradead.org with esmtpsa (Exim 4.94.2 #2 (Red Hat Linux)) id 1pUZh7-009lKO-SZ; Tue, 21 Feb 2023 20:57:01 +0000 From: Christoph Hellwig To: Chris Mason , Josef Bacik , David Sterba Cc: linux-btrfs@vger.kernel.org Subject: [PATCH 1/2] btrfs: remove search_file_offset_in_bio Date: Tue, 21 Feb 2023 12:56:58 -0800 Message-Id: <20230221205659.530284-2-hch@lst.de> X-Mailer: git-send-email 2.39.1 In-Reply-To: <20230221205659.530284-1-hch@lst.de> References: <20230221205659.530284-1-hch@lst.de> MIME-Version: 1.0 X-SRS-Rewrite: SMTP reverse-path rewritten from by bombadil.infradead.org. See http://www.infradead.org/rpr.html Precedence: bulk List-ID: X-Mailing-List: linux-btrfs@vger.kernel.org There is no need to search for a file offset in a bio, it is now always provided in bbio->file_offset. Just use that adjusted to the offset into the bio. Signed-off-by: Christoph Hellwig Reviewed-by: Johannes Thumshirn Reviewed-by: Anand Jain --- fs/btrfs/file-item.c | 52 +++----------------------------------------- 1 file changed, 3 insertions(+), 49 deletions(-) diff --git a/fs/btrfs/file-item.c b/fs/btrfs/file-item.c index fff09e5635e5f2..9df9b91dbc6463 100644 --- a/fs/btrfs/file-item.c +++ b/fs/btrfs/file-item.c @@ -335,48 +335,6 @@ static int search_csum_tree(struct btrfs_fs_info *fs_info, return ret; } -/* - * Locate the file_offset of @cur_disk_bytenr of a @bio. - * - * Bio of btrfs represents read range of - * [bi_sector << 9, bi_sector << 9 + bi_size). - * Knowing this, we can iterate through each bvec to locate the page belong to - * @cur_disk_bytenr and get the file offset. - * - * @inode is used to determine if the bvec page really belongs to @inode. - * - * Return false if we can't find the file offset - * Return true if we find the file offset and restore it to @file_offset_ret - */ -static int search_file_offset_in_bio(struct bio *bio, struct inode *inode, - u64 disk_bytenr, u64 *file_offset_ret) -{ - struct bvec_iter iter; - struct bio_vec bvec; - u64 cur = bio->bi_iter.bi_sector << SECTOR_SHIFT; - bool ret = false; - - bio_for_each_segment(bvec, bio, iter) { - struct page *page = bvec.bv_page; - - if (cur > disk_bytenr) - break; - if (cur + bvec.bv_len <= disk_bytenr) { - cur += bvec.bv_len; - continue; - } - ASSERT(in_range(disk_bytenr, cur, bvec.bv_len)); - if (page->mapping && page->mapping->host && - page->mapping->host == inode) { - ret = true; - *file_offset_ret = page_offset(page) + bvec.bv_offset + - disk_bytenr - cur; - break; - } - } - return ret; -} - /* * Lookup the checksum for the read bio in csum tree. * @@ -386,7 +344,6 @@ blk_status_t btrfs_lookup_bio_sums(struct btrfs_bio *bbio) { struct btrfs_inode *inode = bbio->inode; struct btrfs_fs_info *fs_info = inode->root->fs_info; - struct extent_io_tree *io_tree = &inode->io_tree; struct bio *bio = &bbio->bio; struct btrfs_path *path; const u32 sectorsize = fs_info->sectorsize; @@ -493,13 +450,10 @@ blk_status_t btrfs_lookup_bio_sums(struct btrfs_bio *bbio) if (inode->root->root_key.objectid == BTRFS_DATA_RELOC_TREE_OBJECTID) { - u64 file_offset; + u64 file_offset = bbio->file_offset + + cur_disk_bytenr - orig_disk_bytenr; - if (search_file_offset_in_bio(bio, - &inode->vfs_inode, - cur_disk_bytenr, - &file_offset)) - set_extent_bits(io_tree, file_offset, + set_extent_bits(&inode->io_tree, file_offset, file_offset + sectorsize - 1, EXTENT_NODATASUM); } else { From patchwork Tue Feb 21 20:56:59 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christoph Hellwig X-Patchwork-Id: 13148395 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 4CF66C64EC4 for ; Tue, 21 Feb 2023 20:57:08 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229852AbjBUU5H (ORCPT ); Tue, 21 Feb 2023 15:57:07 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35598 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229501AbjBUU5F (ORCPT ); Tue, 21 Feb 2023 15:57:05 -0500 Received: from bombadil.infradead.org (bombadil.infradead.org [IPv6:2607:7c80:54:3::133]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E0C5A199DF for ; Tue, 21 Feb 2023 12:57:04 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=bombadil.20210309; h=Content-Transfer-Encoding: MIME-Version:References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From:Sender :Reply-To:Content-Type:Content-ID:Content-Description; bh=um+Xcd6h83pD0emvfVcDH2o8EAKFUyxKjqhwY7kaEw0=; b=0yHN26fHCY0KB3L+e8OZ8wc/A6 wIAgZPPDBA6PFnG0uZS9MZHHLHPXf6eQaFWFI6LcCjSoYtu5548Is15cp2ovgri5GcbFlq7u3MzU7 6TzKSJm4c7tCrhu2wpVS2R2iEDh8pfI+w/Zw/zRsQJSF9BhN//QJbVomq7TcD1jkqEwNrGxK5lPis /MYdml7cJTGVjCKfln0s3dQwOYHPenBUV3OOooXnjzIvO5Umg4cnGnQxdxVlIU/Y1tLWJAH17+j9G 0tKmLQ25M3ljdxJB9PB8EQfaatX92caSMZBKQ/THp1J/jg7oM4Hd1P9/Uoniy5RUUWJvgvTK4Fu5q NqreGVvg==; Received: from [4.28.11.157] (helo=localhost) by bombadil.infradead.org with esmtpsa (Exim 4.94.2 #2 (Red Hat Linux)) id 1pUZh8-009lKR-7Y; Tue, 21 Feb 2023 20:57:02 +0000 From: Christoph Hellwig To: Chris Mason , Josef Bacik , David Sterba Cc: linux-btrfs@vger.kernel.org Subject: [PATCH 2/2] btrfs: cleanup btrfs_lookup_bio_sums Date: Tue, 21 Feb 2023 12:56:59 -0800 Message-Id: <20230221205659.530284-3-hch@lst.de> X-Mailer: git-send-email 2.39.1 In-Reply-To: <20230221205659.530284-1-hch@lst.de> References: <20230221205659.530284-1-hch@lst.de> MIME-Version: 1.0 X-SRS-Rewrite: SMTP reverse-path rewritten from by bombadil.infradead.org. See http://www.infradead.org/rpr.html Precedence: bulk List-ID: X-Mailing-List: linux-btrfs@vger.kernel.org Introduce a bio_offset variable for the current offset into the bio instead of recalculating it over and over, remove the now superflous search_len and reduce variable scope as applicable as well as switch count to and unsigned type for the unsigned values it holds. Signed-off-by: Christoph Hellwig --- fs/btrfs/file-item.c | 31 +++++++++---------------------- 1 file changed, 9 insertions(+), 22 deletions(-) diff --git a/fs/btrfs/file-item.c b/fs/btrfs/file-item.c index 9df9b91dbc6463..efc914b2e17e08 100644 --- a/fs/btrfs/file-item.c +++ b/fs/btrfs/file-item.c @@ -350,10 +350,9 @@ blk_status_t btrfs_lookup_bio_sums(struct btrfs_bio *bbio) const u32 csum_size = fs_info->csum_size; u32 orig_len = bio->bi_iter.bi_size; u64 orig_disk_bytenr = bio->bi_iter.bi_sector << SECTOR_SHIFT; - u64 cur_disk_bytenr; const unsigned int nblocks = orig_len >> fs_info->sectorsize_bits; - int count = 0; blk_status_t ret = BLK_STS_OK; + u32 bio_offset = 0; if ((inode->flags & BTRFS_INODE_NODATASUM) || test_bit(BTRFS_FS_STATE_NO_CSUMS, &fs_info->fs_state)) @@ -404,25 +403,12 @@ blk_status_t btrfs_lookup_bio_sums(struct btrfs_bio *bbio) path->skip_locking = 1; } - for (cur_disk_bytenr = orig_disk_bytenr; - cur_disk_bytenr < orig_disk_bytenr + orig_len; - cur_disk_bytenr += (count * sectorsize)) { - u64 search_len = orig_disk_bytenr + orig_len - cur_disk_bytenr; - unsigned int sector_offset; - u8 *csum_dst; - - /* - * Although both cur_disk_bytenr and orig_disk_bytenr is u64, - * we're calculating the offset to the bio start. - * - * Bio size is limited to UINT_MAX, thus unsigned int is large - * enough to contain the raw result, not to mention the right - * shifted result. - */ - ASSERT(cur_disk_bytenr - orig_disk_bytenr < UINT_MAX); - sector_offset = (cur_disk_bytenr - orig_disk_bytenr) >> - fs_info->sectorsize_bits; - csum_dst = bbio->csum + sector_offset * csum_size; + while (bio_offset < orig_len) { + u64 cur_disk_bytenr = orig_disk_bytenr + bio_offset; + u64 search_len = orig_len - bio_offset; + u8 *csum_dst = bbio->csum + + (bio_offset >> fs_info->sectorsize_bits) * csum_size; + u32 count = 0; count = search_csum_tree(fs_info, path, cur_disk_bytenr, search_len, csum_dst); @@ -451,7 +437,7 @@ blk_status_t btrfs_lookup_bio_sums(struct btrfs_bio *bbio) if (inode->root->root_key.objectid == BTRFS_DATA_RELOC_TREE_OBJECTID) { u64 file_offset = bbio->file_offset + - cur_disk_bytenr - orig_disk_bytenr; + bio_offset; set_extent_bits(&inode->io_tree, file_offset, file_offset + sectorsize - 1, @@ -462,6 +448,7 @@ blk_status_t btrfs_lookup_bio_sums(struct btrfs_bio *bbio) cur_disk_bytenr, cur_disk_bytenr + sectorsize); } } + bio_offset += count * sectorsize; } btrfs_free_path(path);