From patchwork Tue Dec 3 01:34:17 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Omar Sandoval X-Patchwork-Id: 11270117 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id C330913B6 for ; Tue, 3 Dec 2019 01:34:36 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 98AAC206F0 for ; Tue, 3 Dec 2019 01:34:36 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=osandov-com.20150623.gappssmtp.com header.i=@osandov-com.20150623.gappssmtp.com header.b="LTl3KXbm" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1725957AbfLCBef (ORCPT ); Mon, 2 Dec 2019 20:34:35 -0500 Received: from mail-pg1-f193.google.com ([209.85.215.193]:45879 "EHLO mail-pg1-f193.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725899AbfLCBef (ORCPT ); Mon, 2 Dec 2019 20:34:35 -0500 Received: by mail-pg1-f193.google.com with SMTP id k1so763483pgg.12 for ; Mon, 02 Dec 2019 17:34:34 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=osandov-com.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=UrJk+POn8jMQiHXm0LIPYNlSc03WablfcHBVVM80qCQ=; b=LTl3KXbmLKb2bntr3jEwv/OREpx7IpIX4D2cJ5oHhG8W5nDxQDg5FMsXkJhtcjrLx7 kd9S2jEDtZg2jlGtDCuWF+tR0EyZwwJiymoAtpXTiXLMzzGPImKBqmxAFLdBttFOTuBd l4ZHht8zE/oegZu4BPiu8PcTAIfK0reyR3qdo0R00gIzL68J1lXrHI/ApdpGwf/J1AKy acye/Tmlo5DS3fHraLOQT5YqzlNHBfHnuCI8ET/PSOiF8bzj86JWVQaU20lIWyg4CsZ7 l43uCOo7G9Ft7E+T7pVF0wboj+QOoHC4K6VfOBTDd1kJE59/o8uAkAT05R9LvDaBAOMV odQg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=UrJk+POn8jMQiHXm0LIPYNlSc03WablfcHBVVM80qCQ=; b=iYREyf8SPY59qDdsi4o33MoDkfbuQTbpRfSjc9RMJ9TKne43JH7AQd5yQKQ9gCgcyZ jYd6FeeMx4Svs8wxw0xlGLr1wHVEypRMWHjsPL9Y8ICjYw1RT4s+32UeCcGJmHd3IVUg r1cjUA27iDstwPhvhFDIESEUbKvHHgM+yGH0oXUXRjq+3MJ0mGo1ijDTQS/Joe6VQMOd ngOxtkJNJWU2VX42/+3p+qkJnYIsQbGXbHT1FmCGb8RpD+iQsMNArpxnlehgZCKlC9Ss M2UXN2YcTSQm8NO5RNCvUuPAYtuVUWXSDguCkXaIQXIMQMTnHxCreGiF5XuvXFwEQo7U LlZA== X-Gm-Message-State: APjAAAWTx27dSzJnDNzZzfkoVs5vDiSA27uf3cuG2npTWbPyog/rqy3l nHebrK/QXCrvCaucqLJrBASrY+iEXsaT4Q== X-Google-Smtp-Source: APXvYqzbULyPROD6Lv4WyLcsUMw5qdn+15N0UOdvYfQAcrN8Vc3IKJp311SDm1gnuogQGVsP//8b7g== X-Received: by 2002:a63:c103:: with SMTP id w3mr2503050pgf.275.1575336873853; Mon, 02 Dec 2019 17:34:33 -0800 (PST) Received: from vader.thefacebook.com ([2620:10d:c090:180::6ddc]) by smtp.gmail.com with ESMTPSA id u65sm800242pfb.35.2019.12.02.17.34.32 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 02 Dec 2019 17:34:33 -0800 (PST) From: Omar Sandoval To: linux-btrfs@vger.kernel.org Cc: kernel-team@fb.com, Nikolay Borisov Subject: [PATCH 1/9] btrfs: get rid of trivial __btrfs_lookup_bio_sums() wrappers Date: Mon, 2 Dec 2019 17:34:17 -0800 Message-Id: X-Mailer: git-send-email 2.24.0 In-Reply-To: References: MIME-Version: 1.0 Sender: linux-btrfs-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-btrfs@vger.kernel.org From: Omar Sandoval Currently, we have two wrappers for __btrfs_lookup_bio_sums(): btrfs_lookup_bio_sums_dio(), which is used for direct I/O, and btrfs_lookup_bio_sums(), which is used everywhere else. The only difference is that the _dio variant looks up csums starting at the given offset instead of using the page index, which isn't actually direct I/O-specific. Let's clean up the signature and return value of __btrfs_lookup_bio_sums(), rename it to btrfs_lookup_bio_sums(), and get rid of the trivial helpers. Reviewed-by: Nikolay Borisov Signed-off-by: Omar Sandoval Reviewed-by: Johannes Thumshirn --- fs/btrfs/compression.c | 4 ++-- fs/btrfs/ctree.h | 4 +--- fs/btrfs/file-item.c | 35 +++++++++++++++++------------------ fs/btrfs/inode.c | 6 +++--- 4 files changed, 23 insertions(+), 26 deletions(-) diff --git a/fs/btrfs/compression.c b/fs/btrfs/compression.c index ee834ef7beb4..03eb50727038 100644 --- a/fs/btrfs/compression.c +++ b/fs/btrfs/compression.c @@ -758,7 +758,7 @@ blk_status_t btrfs_submit_compressed_read(struct inode *inode, struct bio *bio, if (!(BTRFS_I(inode)->flags & BTRFS_INODE_NODATASUM)) { ret = btrfs_lookup_bio_sums(inode, comp_bio, - sums); + false, 0, sums); BUG_ON(ret); /* -ENOMEM */ } @@ -786,7 +786,7 @@ blk_status_t btrfs_submit_compressed_read(struct inode *inode, struct bio *bio, BUG_ON(ret); /* -ENOMEM */ if (!(BTRFS_I(inode)->flags & BTRFS_INODE_NODATASUM)) { - ret = btrfs_lookup_bio_sums(inode, comp_bio, sums); + ret = btrfs_lookup_bio_sums(inode, comp_bio, false, 0, sums); BUG_ON(ret); /* -ENOMEM */ } diff --git a/fs/btrfs/ctree.h b/fs/btrfs/ctree.h index b2e8fd8a8e59..5ad45171e482 100644 --- a/fs/btrfs/ctree.h +++ b/fs/btrfs/ctree.h @@ -2789,9 +2789,7 @@ struct btrfs_dio_private; int btrfs_del_csums(struct btrfs_trans_handle *trans, struct btrfs_fs_info *fs_info, u64 bytenr, u64 len); blk_status_t btrfs_lookup_bio_sums(struct inode *inode, struct bio *bio, - u8 *dst); -blk_status_t btrfs_lookup_bio_sums_dio(struct inode *inode, struct bio *bio, - u64 logical_offset); + bool at_offset, u64 offset, u8 *dst); int btrfs_insert_file_extent(struct btrfs_trans_handle *trans, struct btrfs_root *root, u64 objectid, u64 pos, diff --git a/fs/btrfs/file-item.c b/fs/btrfs/file-item.c index 3270a40b0777..b001ad073d16 100644 --- a/fs/btrfs/file-item.c +++ b/fs/btrfs/file-item.c @@ -148,8 +148,21 @@ int btrfs_lookup_file_extent(struct btrfs_trans_handle *trans, return ret; } -static blk_status_t __btrfs_lookup_bio_sums(struct inode *inode, struct bio *bio, - u64 logical_offset, u8 *dst, int dio) +/** + * btrfs_lookup_bio_sums - Look up checksums for a bio. + * @inode: inode that the bio is for. + * @bio: bio embedded in btrfs_io_bio. + * @at_offset: If true, look up checksums for the extent at @offset. + * If false, use the page offsets from the bio. + * @offset: If @at_offset is true, offset in file to look up checksums for. + * Ignored otherwise. + * @dst: Buffer of size btrfs_super_csum_size() used to return checksum. If + * NULL, the checksum is returned in btrfs_io_bio(bio)->csum instead. + * + * Return: BLK_STS_RESOURCE if allocating memory fails, BLK_STS_OK otherwise. + */ +blk_status_t btrfs_lookup_bio_sums(struct inode *inode, struct bio *bio, + bool at_offset, u64 offset, u8 *dst) { struct btrfs_fs_info *fs_info = btrfs_sb(inode->i_sb); struct bio_vec bvec; @@ -159,7 +172,6 @@ static blk_status_t __btrfs_lookup_bio_sums(struct inode *inode, struct bio *bio struct extent_io_tree *io_tree = &BTRFS_I(inode)->io_tree; struct btrfs_path *path; u8 *csum; - u64 offset = 0; u64 item_start_offset = 0; u64 item_last_offset = 0; u64 disk_bytenr; @@ -205,15 +217,13 @@ static blk_status_t __btrfs_lookup_bio_sums(struct inode *inode, struct bio *bio } disk_bytenr = (u64)bio->bi_iter.bi_sector << 9; - if (dio) - offset = logical_offset; bio_for_each_segment(bvec, bio, iter) { page_bytes_left = bvec.bv_len; if (count) goto next; - if (!dio) + if (!at_offset) offset = page_offset(bvec.bv_page) + bvec.bv_offset; count = btrfs_find_ordered_sum(inode, offset, disk_bytenr, csum, nblocks); @@ -285,18 +295,7 @@ static blk_status_t __btrfs_lookup_bio_sums(struct inode *inode, struct bio *bio WARN_ON_ONCE(count); btrfs_free_path(path); - return 0; -} - -blk_status_t btrfs_lookup_bio_sums(struct inode *inode, struct bio *bio, - u8 *dst) -{ - return __btrfs_lookup_bio_sums(inode, bio, 0, dst, 0); -} - -blk_status_t btrfs_lookup_bio_sums_dio(struct inode *inode, struct bio *bio, u64 offset) -{ - return __btrfs_lookup_bio_sums(inode, bio, offset, NULL, 1); + return BLK_STS_OK; } int btrfs_lookup_csums_range(struct btrfs_root *root, u64 start, u64 end, diff --git a/fs/btrfs/inode.c b/fs/btrfs/inode.c index e3c76645cad7..1fe4e5ec7907 100644 --- a/fs/btrfs/inode.c +++ b/fs/btrfs/inode.c @@ -2128,7 +2128,7 @@ static blk_status_t btrfs_submit_bio_hook(struct inode *inode, struct bio *bio, bio_flags); goto out; } else if (!skip_sum) { - ret = btrfs_lookup_bio_sums(inode, bio, NULL); + ret = btrfs_lookup_bio_sums(inode, bio, false, 0, NULL); if (ret) goto out; } @@ -8356,8 +8356,8 @@ static inline blk_status_t btrfs_lookup_and_bind_dio_csum(struct inode *inode, * contention. */ if (dip->logical_offset == file_offset) { - ret = btrfs_lookup_bio_sums_dio(inode, dip->orig_bio, - file_offset); + ret = btrfs_lookup_bio_sums(inode, dip->orig_bio, true, + file_offset, NULL); if (ret) return ret; } From patchwork Tue Dec 3 01:34:18 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Omar Sandoval X-Patchwork-Id: 11270119 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 58314921 for ; Tue, 3 Dec 2019 01:34:38 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 0FEE0206F0 for ; Tue, 3 Dec 2019 01:34:38 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=osandov-com.20150623.gappssmtp.com header.i=@osandov-com.20150623.gappssmtp.com header.b="ZHMzTW5e" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726057AbfLCBeh (ORCPT ); Mon, 2 Dec 2019 20:34:37 -0500 Received: from mail-pj1-f68.google.com ([209.85.216.68]:38908 "EHLO mail-pj1-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725899AbfLCBeg (ORCPT ); Mon, 2 Dec 2019 20:34:36 -0500 Received: by mail-pj1-f68.google.com with SMTP id l4so744884pjt.5 for ; Mon, 02 Dec 2019 17:34:36 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=osandov-com.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=7rKOPRZC/+fnuzCbjvt0nnfP8nVuKQhBnwGQqC5ReRA=; b=ZHMzTW5eNFO1Ls1FD9JCXCx+UtZPcUL5yenah1pPdz+riihrHcBc+IRX+Eb7HaX8mj 9j9VxnsxOM6FxIy7IbYbWlwjZfqonFNlRuBSdmkM/bZ0SWJhiKgqOBYFyI6IEqBLxRLR Pfadzn9UYgM1QOL9KEDNwh3FAqPiy8l1nGoqKy44RISqThzZpNbwJ0stOm+b1QtDGKjo 2VOwfzJzBrzRgZ2bxP+59UovfnW8nu0ujPnhfvegp84j58S3G/kHwhP8JbV9AfVModoL neg+ds22+orhXhDOLGMPBQ+Bwy5p7bzxMlUDMl2V/YSfLk29R9kNShcFcSMvlPGvxB7q KpCw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=7rKOPRZC/+fnuzCbjvt0nnfP8nVuKQhBnwGQqC5ReRA=; b=h0EqLIYVFI19cDwowBr5Vcc4bc2u1NVY5r9P0IISdJXONoPnhgqhk6gQw9efP1OKT4 EUZYQ1RQkco+RTZwB7GsgRhvDrtQUpJl/QJ5McZ25rieNma1gni7w1h9sh0tuoTSEbSz 2WQg0ia+c/dp0Qr2DMUiSQ53e9z4i0dmI61tlieWdZ9N5K+9StodGXOPi/f2VKijds0u iBmLeRpv9vxKI9Vf0M3bCz3Hdju4NOIw0H5Y6UUA4P4YF+zbZQbtAUpzum9OfAnaYcPk K+UaQybOgAbema036bZxiibfPbdKR4CI/Q/bW5sHW69MsvROlc5S/nP9OwLiMfaJBuN2 sfdA== X-Gm-Message-State: APjAAAUIGNfPVWiimyRIebmWuDgXGBUWqt2fv1JxFKCF1xMt5S/DxQrw fkdYa7yvNAMEH/zwV7ilv8m4FgQLD0OEgA== X-Google-Smtp-Source: APXvYqyJy2OJN+W85E6IgqTgjmD2/vz5M0Tyl3mGuWwKO/zZV77k7NbgkQmBR/GCkbVlAU3BC9KQBg== X-Received: by 2002:a17:902:a586:: with SMTP id az6mr2377521plb.137.1575336875265; Mon, 02 Dec 2019 17:34:35 -0800 (PST) Received: from vader.thefacebook.com ([2620:10d:c090:180::6ddc]) by smtp.gmail.com with ESMTPSA id u65sm800242pfb.35.2019.12.02.17.34.34 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 02 Dec 2019 17:34:34 -0800 (PST) From: Omar Sandoval To: linux-btrfs@vger.kernel.org Cc: kernel-team@fb.com, Nikolay Borisov Subject: [PATCH 2/9] btrfs: remove dead snapshot-aware defrag code Date: Mon, 2 Dec 2019 17:34:18 -0800 Message-Id: X-Mailer: git-send-email 2.24.0 In-Reply-To: References: MIME-Version: 1.0 Sender: linux-btrfs-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-btrfs@vger.kernel.org From: Omar Sandoval Snapshot-aware defrag has been disabled since commit 8101c8dbf624 ("Btrfs: disable snapshot aware defrag for now") almost 6 years ago. Let's remove the dead code. If someone is up to the task of bringing it back, they can dig it up from git. This is logically a revert of commit 38c227d87c49 ("Btrfs: snapshot-aware defrag") except that now we have to clear the EXTENT_DEFRAG bit to avoid need_force_cow() returning true forever. Reviewed-by: Nikolay Borisov Signed-off-by: Omar Sandoval Reviewed-by: Johannes Thumshirn --- fs/btrfs/inode.c | 695 +---------------------------------------------- 1 file changed, 11 insertions(+), 684 deletions(-) diff --git a/fs/btrfs/inode.c b/fs/btrfs/inode.c index 1fe4e5ec7907..21506a40ce08 100644 --- a/fs/btrfs/inode.c +++ b/fs/btrfs/inode.c @@ -44,7 +44,6 @@ #include "locking.h" #include "free-space-cache.h" #include "inode-map.h" -#include "backref.h" #include "props.h" #include "qgroup.h" #include "delalloc-space.h" @@ -2394,649 +2393,6 @@ static int insert_reserved_file_extent(struct btrfs_trans_handle *trans, return ret; } -/* snapshot-aware defrag */ -struct sa_defrag_extent_backref { - struct rb_node node; - struct old_sa_defrag_extent *old; - u64 root_id; - u64 inum; - u64 file_pos; - u64 extent_offset; - u64 num_bytes; - u64 generation; -}; - -struct old_sa_defrag_extent { - struct list_head list; - struct new_sa_defrag_extent *new; - - u64 extent_offset; - u64 bytenr; - u64 offset; - u64 len; - int count; -}; - -struct new_sa_defrag_extent { - struct rb_root root; - struct list_head head; - struct btrfs_path *path; - struct inode *inode; - u64 file_pos; - u64 len; - u64 bytenr; - u64 disk_len; - u8 compress_type; -}; - -static int backref_comp(struct sa_defrag_extent_backref *b1, - struct sa_defrag_extent_backref *b2) -{ - if (b1->root_id < b2->root_id) - return -1; - else if (b1->root_id > b2->root_id) - return 1; - - if (b1->inum < b2->inum) - return -1; - else if (b1->inum > b2->inum) - return 1; - - if (b1->file_pos < b2->file_pos) - return -1; - else if (b1->file_pos > b2->file_pos) - return 1; - - /* - * [------------------------------] ===> (a range of space) - * |<--->| |<---->| =============> (fs/file tree A) - * |<---------------------------->| ===> (fs/file tree B) - * - * A range of space can refer to two file extents in one tree while - * refer to only one file extent in another tree. - * - * So we may process a disk offset more than one time(two extents in A) - * and locate at the same extent(one extent in B), then insert two same - * backrefs(both refer to the extent in B). - */ - return 0; -} - -static void backref_insert(struct rb_root *root, - struct sa_defrag_extent_backref *backref) -{ - struct rb_node **p = &root->rb_node; - struct rb_node *parent = NULL; - struct sa_defrag_extent_backref *entry; - int ret; - - while (*p) { - parent = *p; - entry = rb_entry(parent, struct sa_defrag_extent_backref, node); - - ret = backref_comp(backref, entry); - if (ret < 0) - p = &(*p)->rb_left; - else - p = &(*p)->rb_right; - } - - rb_link_node(&backref->node, parent, p); - rb_insert_color(&backref->node, root); -} - -/* - * Note the backref might has changed, and in this case we just return 0. - */ -static noinline int record_one_backref(u64 inum, u64 offset, u64 root_id, - void *ctx) -{ - struct btrfs_file_extent_item *extent; - struct old_sa_defrag_extent *old = ctx; - struct new_sa_defrag_extent *new = old->new; - struct btrfs_path *path = new->path; - struct btrfs_key key; - struct btrfs_root *root; - struct sa_defrag_extent_backref *backref; - struct extent_buffer *leaf; - struct inode *inode = new->inode; - struct btrfs_fs_info *fs_info = btrfs_sb(inode->i_sb); - int slot; - int ret; - u64 extent_offset; - u64 num_bytes; - - if (BTRFS_I(inode)->root->root_key.objectid == root_id && - inum == btrfs_ino(BTRFS_I(inode))) - return 0; - - key.objectid = root_id; - key.type = BTRFS_ROOT_ITEM_KEY; - key.offset = (u64)-1; - - root = btrfs_read_fs_root_no_name(fs_info, &key); - if (IS_ERR(root)) { - if (PTR_ERR(root) == -ENOENT) - return 0; - WARN_ON(1); - btrfs_debug(fs_info, "inum=%llu, offset=%llu, root_id=%llu", - inum, offset, root_id); - return PTR_ERR(root); - } - - key.objectid = inum; - key.type = BTRFS_EXTENT_DATA_KEY; - if (offset > (u64)-1 << 32) - key.offset = 0; - else - key.offset = offset; - - ret = btrfs_search_slot(NULL, root, &key, path, 0, 0); - if (WARN_ON(ret < 0)) - return ret; - ret = 0; - - while (1) { - cond_resched(); - - leaf = path->nodes[0]; - slot = path->slots[0]; - - if (slot >= btrfs_header_nritems(leaf)) { - ret = btrfs_next_leaf(root, path); - if (ret < 0) { - goto out; - } else if (ret > 0) { - ret = 0; - goto out; - } - continue; - } - - path->slots[0]++; - - btrfs_item_key_to_cpu(leaf, &key, slot); - - if (key.objectid > inum) - goto out; - - if (key.objectid < inum || key.type != BTRFS_EXTENT_DATA_KEY) - continue; - - extent = btrfs_item_ptr(leaf, slot, - struct btrfs_file_extent_item); - - if (btrfs_file_extent_disk_bytenr(leaf, extent) != old->bytenr) - continue; - - /* - * 'offset' refers to the exact key.offset, - * NOT the 'offset' field in btrfs_extent_data_ref, ie. - * (key.offset - extent_offset). - */ - if (key.offset != offset) - continue; - - extent_offset = btrfs_file_extent_offset(leaf, extent); - num_bytes = btrfs_file_extent_num_bytes(leaf, extent); - - if (extent_offset >= old->extent_offset + old->offset + - old->len || extent_offset + num_bytes <= - old->extent_offset + old->offset) - continue; - break; - } - - backref = kmalloc(sizeof(*backref), GFP_NOFS); - if (!backref) { - ret = -ENOENT; - goto out; - } - - backref->root_id = root_id; - backref->inum = inum; - backref->file_pos = offset; - backref->num_bytes = num_bytes; - backref->extent_offset = extent_offset; - backref->generation = btrfs_file_extent_generation(leaf, extent); - backref->old = old; - backref_insert(&new->root, backref); - old->count++; -out: - btrfs_release_path(path); - WARN_ON(ret); - return ret; -} - -static noinline bool record_extent_backrefs(struct btrfs_path *path, - struct new_sa_defrag_extent *new) -{ - struct btrfs_fs_info *fs_info = btrfs_sb(new->inode->i_sb); - struct old_sa_defrag_extent *old, *tmp; - int ret; - - new->path = path; - - list_for_each_entry_safe(old, tmp, &new->head, list) { - ret = iterate_inodes_from_logical(old->bytenr + - old->extent_offset, fs_info, - path, record_one_backref, - old, false); - if (ret < 0 && ret != -ENOENT) - return false; - - /* no backref to be processed for this extent */ - if (!old->count) { - list_del(&old->list); - kfree(old); - } - } - - if (list_empty(&new->head)) - return false; - - return true; -} - -static int relink_is_mergable(struct extent_buffer *leaf, - struct btrfs_file_extent_item *fi, - struct new_sa_defrag_extent *new) -{ - if (btrfs_file_extent_disk_bytenr(leaf, fi) != new->bytenr) - return 0; - - if (btrfs_file_extent_type(leaf, fi) != BTRFS_FILE_EXTENT_REG) - return 0; - - if (btrfs_file_extent_compression(leaf, fi) != new->compress_type) - return 0; - - if (btrfs_file_extent_encryption(leaf, fi) || - btrfs_file_extent_other_encoding(leaf, fi)) - return 0; - - return 1; -} - -/* - * Note the backref might has changed, and in this case we just return 0. - */ -static noinline int relink_extent_backref(struct btrfs_path *path, - struct sa_defrag_extent_backref *prev, - struct sa_defrag_extent_backref *backref) -{ - struct btrfs_file_extent_item *extent; - struct btrfs_file_extent_item *item; - struct btrfs_ordered_extent *ordered; - struct btrfs_trans_handle *trans; - struct btrfs_ref ref = { 0 }; - struct btrfs_root *root; - struct btrfs_key key; - struct extent_buffer *leaf; - struct old_sa_defrag_extent *old = backref->old; - struct new_sa_defrag_extent *new = old->new; - struct btrfs_fs_info *fs_info = btrfs_sb(new->inode->i_sb); - struct inode *inode; - struct extent_state *cached = NULL; - int ret = 0; - u64 start; - u64 len; - u64 lock_start; - u64 lock_end; - bool merge = false; - int index; - - if (prev && prev->root_id == backref->root_id && - prev->inum == backref->inum && - prev->file_pos + prev->num_bytes == backref->file_pos) - merge = true; - - /* step 1: get root */ - key.objectid = backref->root_id; - key.type = BTRFS_ROOT_ITEM_KEY; - key.offset = (u64)-1; - - index = srcu_read_lock(&fs_info->subvol_srcu); - - root = btrfs_read_fs_root_no_name(fs_info, &key); - if (IS_ERR(root)) { - srcu_read_unlock(&fs_info->subvol_srcu, index); - if (PTR_ERR(root) == -ENOENT) - return 0; - return PTR_ERR(root); - } - - if (btrfs_root_readonly(root)) { - srcu_read_unlock(&fs_info->subvol_srcu, index); - return 0; - } - - /* step 2: get inode */ - key.objectid = backref->inum; - key.type = BTRFS_INODE_ITEM_KEY; - key.offset = 0; - - inode = btrfs_iget(fs_info->sb, &key, root); - if (IS_ERR(inode)) { - srcu_read_unlock(&fs_info->subvol_srcu, index); - return 0; - } - - srcu_read_unlock(&fs_info->subvol_srcu, index); - - /* step 3: relink backref */ - lock_start = backref->file_pos; - lock_end = backref->file_pos + backref->num_bytes - 1; - lock_extent_bits(&BTRFS_I(inode)->io_tree, lock_start, lock_end, - &cached); - - ordered = btrfs_lookup_first_ordered_extent(inode, lock_end); - if (ordered) { - btrfs_put_ordered_extent(ordered); - goto out_unlock; - } - - trans = btrfs_join_transaction(root); - if (IS_ERR(trans)) { - ret = PTR_ERR(trans); - goto out_unlock; - } - - key.objectid = backref->inum; - key.type = BTRFS_EXTENT_DATA_KEY; - key.offset = backref->file_pos; - - ret = btrfs_search_slot(NULL, root, &key, path, 0, 0); - if (ret < 0) { - goto out_free_path; - } else if (ret > 0) { - ret = 0; - goto out_free_path; - } - - extent = btrfs_item_ptr(path->nodes[0], path->slots[0], - struct btrfs_file_extent_item); - - if (btrfs_file_extent_generation(path->nodes[0], extent) != - backref->generation) - goto out_free_path; - - btrfs_release_path(path); - - start = backref->file_pos; - if (backref->extent_offset < old->extent_offset + old->offset) - start += old->extent_offset + old->offset - - backref->extent_offset; - - len = min(backref->extent_offset + backref->num_bytes, - old->extent_offset + old->offset + old->len); - len -= max(backref->extent_offset, old->extent_offset + old->offset); - - ret = btrfs_drop_extents(trans, root, inode, start, - start + len, 1); - if (ret) - goto out_free_path; -again: - key.objectid = btrfs_ino(BTRFS_I(inode)); - key.type = BTRFS_EXTENT_DATA_KEY; - key.offset = start; - - path->leave_spinning = 1; - if (merge) { - struct btrfs_file_extent_item *fi; - u64 extent_len; - struct btrfs_key found_key; - - ret = btrfs_search_slot(trans, root, &key, path, 0, 1); - if (ret < 0) - goto out_free_path; - - path->slots[0]--; - leaf = path->nodes[0]; - btrfs_item_key_to_cpu(leaf, &found_key, path->slots[0]); - - fi = btrfs_item_ptr(leaf, path->slots[0], - struct btrfs_file_extent_item); - extent_len = btrfs_file_extent_num_bytes(leaf, fi); - - if (extent_len + found_key.offset == start && - relink_is_mergable(leaf, fi, new)) { - btrfs_set_file_extent_num_bytes(leaf, fi, - extent_len + len); - btrfs_mark_buffer_dirty(leaf); - inode_add_bytes(inode, len); - - ret = 1; - goto out_free_path; - } else { - merge = false; - btrfs_release_path(path); - goto again; - } - } - - ret = btrfs_insert_empty_item(trans, root, path, &key, - sizeof(*extent)); - if (ret) { - btrfs_abort_transaction(trans, ret); - goto out_free_path; - } - - leaf = path->nodes[0]; - item = btrfs_item_ptr(leaf, path->slots[0], - struct btrfs_file_extent_item); - btrfs_set_file_extent_disk_bytenr(leaf, item, new->bytenr); - btrfs_set_file_extent_disk_num_bytes(leaf, item, new->disk_len); - btrfs_set_file_extent_offset(leaf, item, start - new->file_pos); - btrfs_set_file_extent_num_bytes(leaf, item, len); - btrfs_set_file_extent_ram_bytes(leaf, item, new->len); - btrfs_set_file_extent_generation(leaf, item, trans->transid); - btrfs_set_file_extent_type(leaf, item, BTRFS_FILE_EXTENT_REG); - btrfs_set_file_extent_compression(leaf, item, new->compress_type); - btrfs_set_file_extent_encryption(leaf, item, 0); - btrfs_set_file_extent_other_encoding(leaf, item, 0); - - btrfs_mark_buffer_dirty(leaf); - inode_add_bytes(inode, len); - btrfs_release_path(path); - - btrfs_init_generic_ref(&ref, BTRFS_ADD_DELAYED_REF, new->bytenr, - new->disk_len, 0); - btrfs_init_data_ref(&ref, backref->root_id, backref->inum, - new->file_pos); /* start - extent_offset */ - ret = btrfs_inc_extent_ref(trans, &ref); - if (ret) { - btrfs_abort_transaction(trans, ret); - goto out_free_path; - } - - ret = 1; -out_free_path: - btrfs_release_path(path); - path->leave_spinning = 0; - btrfs_end_transaction(trans); -out_unlock: - unlock_extent_cached(&BTRFS_I(inode)->io_tree, lock_start, lock_end, - &cached); - iput(inode); - return ret; -} - -static void free_sa_defrag_extent(struct new_sa_defrag_extent *new) -{ - struct old_sa_defrag_extent *old, *tmp; - - if (!new) - return; - - list_for_each_entry_safe(old, tmp, &new->head, list) { - kfree(old); - } - kfree(new); -} - -static void relink_file_extents(struct new_sa_defrag_extent *new) -{ - struct btrfs_fs_info *fs_info = btrfs_sb(new->inode->i_sb); - struct btrfs_path *path; - struct sa_defrag_extent_backref *backref; - struct sa_defrag_extent_backref *prev = NULL; - struct rb_node *node; - int ret; - - path = btrfs_alloc_path(); - if (!path) - return; - - if (!record_extent_backrefs(path, new)) { - btrfs_free_path(path); - goto out; - } - btrfs_release_path(path); - - while (1) { - node = rb_first(&new->root); - if (!node) - break; - rb_erase(node, &new->root); - - backref = rb_entry(node, struct sa_defrag_extent_backref, node); - - ret = relink_extent_backref(path, prev, backref); - WARN_ON(ret < 0); - - kfree(prev); - - if (ret == 1) - prev = backref; - else - prev = NULL; - cond_resched(); - } - kfree(prev); - - btrfs_free_path(path); -out: - free_sa_defrag_extent(new); - - atomic_dec(&fs_info->defrag_running); - wake_up(&fs_info->transaction_wait); -} - -static struct new_sa_defrag_extent * -record_old_file_extents(struct inode *inode, - struct btrfs_ordered_extent *ordered) -{ - struct btrfs_fs_info *fs_info = btrfs_sb(inode->i_sb); - struct btrfs_root *root = BTRFS_I(inode)->root; - struct btrfs_path *path; - struct btrfs_key key; - struct old_sa_defrag_extent *old; - struct new_sa_defrag_extent *new; - int ret; - - new = kmalloc(sizeof(*new), GFP_NOFS); - if (!new) - return NULL; - - new->inode = inode; - new->file_pos = ordered->file_offset; - new->len = ordered->len; - new->bytenr = ordered->start; - new->disk_len = ordered->disk_len; - new->compress_type = ordered->compress_type; - new->root = RB_ROOT; - INIT_LIST_HEAD(&new->head); - - path = btrfs_alloc_path(); - if (!path) - goto out_kfree; - - key.objectid = btrfs_ino(BTRFS_I(inode)); - key.type = BTRFS_EXTENT_DATA_KEY; - key.offset = new->file_pos; - - ret = btrfs_search_slot(NULL, root, &key, path, 0, 0); - if (ret < 0) - goto out_free_path; - if (ret > 0 && path->slots[0] > 0) - path->slots[0]--; - - /* find out all the old extents for the file range */ - while (1) { - struct btrfs_file_extent_item *extent; - struct extent_buffer *l; - int slot; - u64 num_bytes; - u64 offset; - u64 end; - u64 disk_bytenr; - u64 extent_offset; - - l = path->nodes[0]; - slot = path->slots[0]; - - if (slot >= btrfs_header_nritems(l)) { - ret = btrfs_next_leaf(root, path); - if (ret < 0) - goto out_free_path; - else if (ret > 0) - break; - continue; - } - - btrfs_item_key_to_cpu(l, &key, slot); - - if (key.objectid != btrfs_ino(BTRFS_I(inode))) - break; - if (key.type != BTRFS_EXTENT_DATA_KEY) - break; - if (key.offset >= new->file_pos + new->len) - break; - - extent = btrfs_item_ptr(l, slot, struct btrfs_file_extent_item); - - num_bytes = btrfs_file_extent_num_bytes(l, extent); - if (key.offset + num_bytes < new->file_pos) - goto next; - - disk_bytenr = btrfs_file_extent_disk_bytenr(l, extent); - if (!disk_bytenr) - goto next; - - extent_offset = btrfs_file_extent_offset(l, extent); - - old = kmalloc(sizeof(*old), GFP_NOFS); - if (!old) - goto out_free_path; - - offset = max(new->file_pos, key.offset); - end = min(new->file_pos + new->len, key.offset + num_bytes); - - old->bytenr = disk_bytenr; - old->extent_offset = extent_offset; - old->offset = offset - key.offset; - old->len = end - offset; - old->new = new; - old->count = 0; - list_add_tail(&old->list, &new->head); -next: - path->slots[0]++; - cond_resched(); - } - - btrfs_free_path(path); - atomic_inc(&fs_info->defrag_running); - - return new; - -out_free_path: - btrfs_free_path(path); -out_kfree: - free_sa_defrag_extent(new); - return NULL; -} - static void btrfs_release_delalloc_bytes(struct btrfs_fs_info *fs_info, u64 start, u64 len) { @@ -3064,7 +2420,6 @@ static int btrfs_finish_ordered_io(struct btrfs_ordered_extent *ordered_extent) struct btrfs_trans_handle *trans = NULL; struct extent_io_tree *io_tree = &BTRFS_I(inode)->io_tree; struct extent_state *cached_state = NULL; - struct new_sa_defrag_extent *new = NULL; int compress_type = 0; int ret = 0; u64 logical_len = ordered_extent->len; @@ -3073,6 +2428,7 @@ static int btrfs_finish_ordered_io(struct btrfs_ordered_extent *ordered_extent) bool range_locked = false; bool clear_new_delalloc_bytes = false; bool clear_reserved_extent = true; + unsigned int clear_bits; if (!test_bit(BTRFS_ORDERED_NOCOW, &ordered_extent->flags) && !test_bit(BTRFS_ORDERED_PREALLOC, &ordered_extent->flags) && @@ -3131,20 +2487,6 @@ static int btrfs_finish_ordered_io(struct btrfs_ordered_extent *ordered_extent) ordered_extent->file_offset + ordered_extent->len - 1, &cached_state); - ret = test_range_bit(io_tree, ordered_extent->file_offset, - ordered_extent->file_offset + ordered_extent->len - 1, - EXTENT_DEFRAG, 0, cached_state); - if (ret) { - u64 last_snapshot = btrfs_root_last_snapshot(&root->root_item); - if (0 && last_snapshot >= BTRFS_I(inode)->generation) - /* the inode is shared */ - new = record_old_file_extents(inode, ordered_extent); - - clear_extent_bit(io_tree, ordered_extent->file_offset, - ordered_extent->file_offset + ordered_extent->len - 1, - EXTENT_DEFRAG, 0, 0, &cached_state); - } - if (freespace_inode) trans = btrfs_join_transaction_spacecache(root); else @@ -3205,21 +2547,16 @@ static int btrfs_finish_ordered_io(struct btrfs_ordered_extent *ordered_extent) } ret = 0; out: - if (range_locked || clear_new_delalloc_bytes) { - unsigned int clear_bits = 0; - - if (range_locked) - clear_bits |= EXTENT_LOCKED; - if (clear_new_delalloc_bytes) - clear_bits |= EXTENT_DELALLOC_NEW; - clear_extent_bit(&BTRFS_I(inode)->io_tree, - ordered_extent->file_offset, - ordered_extent->file_offset + - ordered_extent->len - 1, - clear_bits, - (clear_bits & EXTENT_LOCKED) ? 1 : 0, - 0, &cached_state); - } + clear_bits = EXTENT_DEFRAG; + if (range_locked) + clear_bits |= EXTENT_LOCKED; + if (clear_new_delalloc_bytes) + clear_bits |= EXTENT_DELALLOC_NEW; + clear_extent_bit(&BTRFS_I(inode)->io_tree, + ordered_extent->file_offset, + ordered_extent->file_offset + ordered_extent->len - 1, + clear_bits, (clear_bits & EXTENT_LOCKED) ? 1 : 0, 0, + &cached_state); if (trans) btrfs_end_transaction(trans); @@ -3263,16 +2600,6 @@ static int btrfs_finish_ordered_io(struct btrfs_ordered_extent *ordered_extent) */ btrfs_remove_ordered_extent(inode, ordered_extent); - /* for snapshot-aware defrag */ - if (new) { - if (ret) { - free_sa_defrag_extent(new); - atomic_dec(&fs_info->defrag_running); - } else { - relink_file_extents(new); - } - } - /* once for us */ btrfs_put_ordered_extent(ordered_extent); /* once for the tree */ From patchwork Tue Dec 3 01:34:19 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Omar Sandoval X-Patchwork-Id: 11270121 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id A9EFD921 for ; Tue, 3 Dec 2019 01:34:39 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 74DA4206F0 for ; Tue, 3 Dec 2019 01:34:39 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=osandov-com.20150623.gappssmtp.com header.i=@osandov-com.20150623.gappssmtp.com header.b="JLO3ZDXd" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726087AbfLCBej (ORCPT ); Mon, 2 Dec 2019 20:34:39 -0500 Received: from mail-pl1-f196.google.com ([209.85.214.196]:39521 "EHLO mail-pl1-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725899AbfLCBei (ORCPT ); Mon, 2 Dec 2019 20:34:38 -0500 Received: by mail-pl1-f196.google.com with SMTP id o9so924605plk.6 for ; Mon, 02 Dec 2019 17:34:37 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=osandov-com.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=HT93LxGnvt3ojCYmM+cjC8AYHume9/kMqgJB9rInEWM=; b=JLO3ZDXdPGnruBsjs3lqQNzcSBcCmh6yxuaiBRxuvkFBRctyeUCRWnt/zn2V3Epyx3 Nw07uYGGdWjI/dVy0PlzzoQBAmxifYmgcF6+X0dS3VwcvCXPBUBE3+764Ch9OWRJ2HX2 tfkApxJlyG+MZi1UrgyGqQKFDrn+uYHuFeK1p0JJas7cMO+aQBsS+t6vgFvmq52azlD8 cL4By+e2cEP4wWcMhwiabRh2BqRl9j6ruADFUnxmGr/jQ6TGCZ/jzYKRCRf3suEEiVJl as4JsG14uBduoAnQp+h8D1JNHDvCUt9734daFrJur3MvgeS2VgtBSy/nILMxA2J5K5qD WlNw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=HT93LxGnvt3ojCYmM+cjC8AYHume9/kMqgJB9rInEWM=; b=GHPozSKbNd+VbWtLigByhpPxtEKteesNfdNIdmhu4X4apUSSnBwvLycxFa713d4waD LrQdzl4n6ekUWjXLuRyCUN0dwo5qSpZiqX1P4WdXm3pzhPVcgHiof/SqoIV9QhGT+ijZ kgLBAZROCAb2BLMoHm1PvUlHrAi0fTrrMiGu/DaB+9RZHDpMeHrAu7Jqi35gJrq0T9is nwXD1Mw8xJQ2e4eFiwISA8qW+cirxSVOCFgeASjp9ZZT2HRKMj6aEUCXjlcICv20yl3j tNJdzwd1mVCL/JtwDcZjyH29Pz7g6R/cuGoPfJ+BOz8/wW8lisFisFrEuBcYxXxaRA6J 3+Bw== X-Gm-Message-State: APjAAAUqzrDJFWC5AQ7MZbe0Km04C5ofDwO87im85i6BxdvEgojHd7ue nqpRCmxN7xSrDtefNyW6npimDaPKN16cuQ== X-Google-Smtp-Source: APXvYqybaaCarWpWRPI6zezcLhxWguQW12ACZZZhl5tMkPK82C1/RBW6TGtNYx5RhjcTgqQ0uplt/Q== X-Received: by 2002:a17:902:7c11:: with SMTP id x17mr2437026pll.190.1575336876751; Mon, 02 Dec 2019 17:34:36 -0800 (PST) Received: from vader.thefacebook.com ([2620:10d:c090:180::6ddc]) by smtp.gmail.com with ESMTPSA id u65sm800242pfb.35.2019.12.02.17.34.35 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 02 Dec 2019 17:34:35 -0800 (PST) From: Omar Sandoval To: linux-btrfs@vger.kernel.org Cc: kernel-team@fb.com Subject: [PATCH 3/9] btrfs: make btrfs_ordered_extent naming consistent with btrfs_file_extent_item Date: Mon, 2 Dec 2019 17:34:19 -0800 Message-Id: <1a8119f808ba10f315b4b6a37ce27896f1b113a4.1575336815.git.osandov@fb.com> X-Mailer: git-send-email 2.24.0 In-Reply-To: References: MIME-Version: 1.0 Sender: linux-btrfs-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-btrfs@vger.kernel.org From: Omar Sandoval ordered->start, ordered->len, and ordered->disk_len correspond to fi->disk_bytenr, fi->num_bytes, and fi->disk_num_bytes, respectively. It's confusing to translate between the two naming schemes. Since a btrfs_ordered_extent is basically a pending btrfs_file_extent_item, let's make the former use the naming from the latter. Note that I didn't touch the names in tracepoints just in case there are scripts depending on the current naming. Signed-off-by: Omar Sandoval Reviewed-by: Johannes Thumshirn --- fs/btrfs/file-item.c | 4 +-- fs/btrfs/file.c | 6 ++-- fs/btrfs/inode.c | 67 ++++++++++++++++------------------ fs/btrfs/ordered-data.c | 69 ++++++++++++++++++------------------ fs/btrfs/ordered-data.h | 26 +++++++------- fs/btrfs/relocation.c | 5 +-- include/trace/events/btrfs.h | 6 ++-- 7 files changed, 90 insertions(+), 93 deletions(-) diff --git a/fs/btrfs/file-item.c b/fs/btrfs/file-item.c index b001ad073d16..6f7777e5a554 100644 --- a/fs/btrfs/file-item.c +++ b/fs/btrfs/file-item.c @@ -482,8 +482,8 @@ blk_status_t btrfs_csum_one_bio(struct inode *inode, struct bio *bio, - 1); for (i = 0; i < nr_sectors; i++) { - if (offset >= ordered->file_offset + ordered->len || - offset < ordered->file_offset) { + if (offset >= ordered->file_offset + ordered->num_bytes || + offset < ordered->file_offset) { unsigned long bytes_left; sums->len = this_sum_bytes; diff --git a/fs/btrfs/file.c b/fs/btrfs/file.c index 1a7e8d6defaf..568b6391c719 100644 --- a/fs/btrfs/file.c +++ b/fs/btrfs/file.c @@ -1501,7 +1501,7 @@ lock_and_cleanup_extent_if_need(struct btrfs_inode *inode, struct page **pages, ordered = btrfs_lookup_ordered_range(inode, start_pos, last_pos - start_pos + 1); if (ordered && - ordered->file_offset + ordered->len > start_pos && + ordered->file_offset + ordered->num_bytes > start_pos && ordered->file_offset <= last_pos) { unlock_extent_cached(&inode->io_tree, start_pos, last_pos, cached_state); @@ -2426,7 +2426,7 @@ static int btrfs_punch_hole_lock_range(struct inode *inode, * we need to try again. */ if ((!ordered || - (ordered->file_offset + ordered->len <= lockstart || + (ordered->file_offset + ordered->num_bytes <= lockstart || ordered->file_offset > lockend)) && !filemap_range_has_page(inode->i_mapping, lockstart, lockend)) { @@ -3248,7 +3248,7 @@ static long btrfs_fallocate(struct file *file, int mode, ordered = btrfs_lookup_first_ordered_extent(inode, locked_end); if (ordered && - ordered->file_offset + ordered->len > alloc_start && + ordered->file_offset + ordered->num_bytes > alloc_start && ordered->file_offset < alloc_end) { btrfs_put_ordered_extent(ordered); unlock_extent_cached(&BTRFS_I(inode)->io_tree, diff --git a/fs/btrfs/inode.c b/fs/btrfs/inode.c index 21506a40ce08..7fe400d18d60 100644 --- a/fs/btrfs/inode.c +++ b/fs/btrfs/inode.c @@ -2420,9 +2420,10 @@ static int btrfs_finish_ordered_io(struct btrfs_ordered_extent *ordered_extent) struct btrfs_trans_handle *trans = NULL; struct extent_io_tree *io_tree = &BTRFS_I(inode)->io_tree; struct extent_state *cached_state = NULL; + u64 start, end; int compress_type = 0; int ret = 0; - u64 logical_len = ordered_extent->len; + u64 logical_len = ordered_extent->num_bytes; bool freespace_inode; bool truncated = false; bool range_locked = false; @@ -2430,6 +2431,9 @@ static int btrfs_finish_ordered_io(struct btrfs_ordered_extent *ordered_extent) bool clear_reserved_extent = true; unsigned int clear_bits; + start = ordered_extent->file_offset; + end = start + ordered_extent->num_bytes - 1; + if (!test_bit(BTRFS_ORDERED_NOCOW, &ordered_extent->flags) && !test_bit(BTRFS_ORDERED_PREALLOC, &ordered_extent->flags) && !test_bit(BTRFS_ORDERED_DIRECT, &ordered_extent->flags)) @@ -2442,10 +2446,7 @@ static int btrfs_finish_ordered_io(struct btrfs_ordered_extent *ordered_extent) goto out; } - btrfs_free_io_failure_record(BTRFS_I(inode), - ordered_extent->file_offset, - ordered_extent->file_offset + - ordered_extent->len - 1); + btrfs_free_io_failure_record(BTRFS_I(inode), start, end); if (test_bit(BTRFS_ORDERED_TRUNCATED, &ordered_extent->flags)) { truncated = true; @@ -2463,8 +2464,8 @@ static int btrfs_finish_ordered_io(struct btrfs_ordered_extent *ordered_extent) * space for NOCOW range. * As NOCOW won't cause a new delayed ref, just free the space */ - btrfs_qgroup_free_data(inode, NULL, ordered_extent->file_offset, - ordered_extent->len); + btrfs_qgroup_free_data(inode, NULL, start, + ordered_extent->num_bytes); btrfs_ordered_update_i_size(inode, 0, ordered_extent); if (freespace_inode) trans = btrfs_join_transaction_spacecache(root); @@ -2483,9 +2484,7 @@ static int btrfs_finish_ordered_io(struct btrfs_ordered_extent *ordered_extent) } range_locked = true; - lock_extent_bits(io_tree, ordered_extent->file_offset, - ordered_extent->file_offset + ordered_extent->len - 1, - &cached_state); + lock_extent_bits(io_tree, start, end, &cached_state); if (freespace_inode) trans = btrfs_join_transaction_spacecache(root); @@ -2503,31 +2502,30 @@ static int btrfs_finish_ordered_io(struct btrfs_ordered_extent *ordered_extent) compress_type = ordered_extent->compress_type; if (test_bit(BTRFS_ORDERED_PREALLOC, &ordered_extent->flags)) { BUG_ON(compress_type); - btrfs_qgroup_free_data(inode, NULL, ordered_extent->file_offset, - ordered_extent->len); + btrfs_qgroup_free_data(inode, NULL, start, + ordered_extent->num_bytes); ret = btrfs_mark_extent_written(trans, BTRFS_I(inode), ordered_extent->file_offset, ordered_extent->file_offset + logical_len); } else { BUG_ON(root == fs_info->tree_root); - ret = insert_reserved_file_extent(trans, inode, - ordered_extent->file_offset, - ordered_extent->start, - ordered_extent->disk_len, + ret = insert_reserved_file_extent(trans, inode, start, + ordered_extent->disk_bytenr, + ordered_extent->disk_num_bytes, logical_len, logical_len, compress_type, 0, 0, BTRFS_FILE_EXTENT_REG); if (!ret) { clear_reserved_extent = false; btrfs_release_delalloc_bytes(fs_info, - ordered_extent->start, - ordered_extent->disk_len); + ordered_extent->disk_bytenr, + ordered_extent->disk_num_bytes); } } unpin_extent_cache(&BTRFS_I(inode)->extent_tree, - ordered_extent->file_offset, ordered_extent->len, - trans->transid); + ordered_extent->file_offset, + ordered_extent->num_bytes, trans->transid); if (ret < 0) { btrfs_abort_transaction(trans, ret); goto out; @@ -2552,27 +2550,23 @@ static int btrfs_finish_ordered_io(struct btrfs_ordered_extent *ordered_extent) clear_bits |= EXTENT_LOCKED; if (clear_new_delalloc_bytes) clear_bits |= EXTENT_DELALLOC_NEW; - clear_extent_bit(&BTRFS_I(inode)->io_tree, - ordered_extent->file_offset, - ordered_extent->file_offset + ordered_extent->len - 1, - clear_bits, (clear_bits & EXTENT_LOCKED) ? 1 : 0, 0, + clear_extent_bit(&BTRFS_I(inode)->io_tree, start, end, clear_bits, + (clear_bits & EXTENT_LOCKED) ? 1 : 0, 0, &cached_state); if (trans) btrfs_end_transaction(trans); if (ret || truncated) { - u64 start, end; + u64 unwritten_start = start; if (truncated) - start = ordered_extent->file_offset + logical_len; - else - start = ordered_extent->file_offset; - end = ordered_extent->file_offset + ordered_extent->len - 1; - clear_extent_uptodate(io_tree, start, end, NULL); + unwritten_start += logical_len; + clear_extent_uptodate(io_tree, unwritten_start, end, NULL); /* Drop the cache for the part of the extent we didn't write. */ - btrfs_drop_extent_cache(BTRFS_I(inode), start, end, 0); + btrfs_drop_extent_cache(BTRFS_I(inode), unwritten_start, end, + 0); /* * If the ordered extent had an IOERR or something else went @@ -2589,11 +2583,11 @@ static int btrfs_finish_ordered_io(struct btrfs_ordered_extent *ordered_extent) !test_bit(BTRFS_ORDERED_NOCOW, &ordered_extent->flags) && !test_bit(BTRFS_ORDERED_PREALLOC, &ordered_extent->flags)) btrfs_free_reserved_extent(fs_info, - ordered_extent->start, - ordered_extent->disk_len, 1); + ordered_extent->disk_bytenr, + ordered_extent->disk_num_bytes, + 1); } - /* * This needs to be done to make sure anybody waiting knows we are done * updating everything for this ordered extent. @@ -8197,7 +8191,8 @@ static void btrfs_invalidatepage(struct page *page, unsigned int offset, ordered = btrfs_lookup_ordered_range(BTRFS_I(inode), start, page_end - start + 1); if (ordered) { - end = min(page_end, ordered->file_offset + ordered->len - 1); + end = min(page_end, + ordered->file_offset + ordered->num_bytes - 1); /* * IO on this page will never be started, so we need * to account for any ordered extents now @@ -8725,7 +8720,7 @@ void btrfs_destroy_inode(struct inode *inode) else { btrfs_err(fs_info, "found ordered extent %llu %llu on inode cleanup", - ordered->file_offset, ordered->len); + ordered->file_offset, ordered->num_bytes); btrfs_remove_ordered_extent(inode, ordered); btrfs_put_ordered_extent(ordered); btrfs_put_ordered_extent(ordered); diff --git a/fs/btrfs/ordered-data.c b/fs/btrfs/ordered-data.c index fb09bc2f8e4d..d3bc9e38d154 100644 --- a/fs/btrfs/ordered-data.c +++ b/fs/btrfs/ordered-data.c @@ -20,9 +20,9 @@ static struct kmem_cache *btrfs_ordered_extent_cache; static u64 entry_end(struct btrfs_ordered_extent *entry) { - if (entry->file_offset + entry->len < entry->file_offset) + if (entry->file_offset + entry->num_bytes < entry->file_offset) return (u64)-1; - return entry->file_offset + entry->len; + return entry->file_offset + entry->num_bytes; } /* returns NULL if the insertion worked, or it returns the node it did find @@ -120,7 +120,7 @@ static struct rb_node *__tree_search(struct rb_root *root, u64 file_offset, static int offset_in_entry(struct btrfs_ordered_extent *entry, u64 file_offset) { if (file_offset < entry->file_offset || - entry->file_offset + entry->len <= file_offset) + entry->file_offset + entry->num_bytes <= file_offset) return 0; return 1; } @@ -129,7 +129,7 @@ static int range_overlaps(struct btrfs_ordered_extent *entry, u64 file_offset, u64 len) { if (file_offset + len <= entry->file_offset || - entry->file_offset + entry->len <= file_offset) + entry->file_offset + entry->num_bytes <= file_offset) return 0; return 1; } @@ -161,19 +161,14 @@ static inline struct rb_node *tree_search(struct btrfs_ordered_inode_tree *tree, } /* allocate and add a new ordered_extent into the per-inode tree. - * file_offset is the logical offset in the file - * - * start is the disk block number of an extent already reserved in the - * extent allocation tree - * - * len is the length of the extent * * The tree is given a single reference on the ordered extent that was * inserted. */ static int __btrfs_add_ordered_extent(struct inode *inode, u64 file_offset, - u64 start, u64 len, u64 disk_len, - int type, int dio, int compress_type) + u64 disk_bytenr, u64 num_bytes, + u64 disk_num_bytes, int type, int dio, + int compress_type) { struct btrfs_fs_info *fs_info = btrfs_sb(inode->i_sb); struct btrfs_root *root = BTRFS_I(inode)->root; @@ -187,10 +182,10 @@ static int __btrfs_add_ordered_extent(struct inode *inode, u64 file_offset, return -ENOMEM; entry->file_offset = file_offset; - entry->start = start; - entry->len = len; - entry->disk_len = disk_len; - entry->bytes_left = len; + entry->disk_bytenr = disk_bytenr; + entry->num_bytes = num_bytes; + entry->disk_num_bytes = disk_num_bytes; + entry->bytes_left = num_bytes; entry->inode = igrab(inode); entry->compress_type = compress_type; entry->truncated_len = (u64)-1; @@ -198,7 +193,7 @@ static int __btrfs_add_ordered_extent(struct inode *inode, u64 file_offset, set_bit(type, &entry->flags); if (dio) { - percpu_counter_add_batch(&fs_info->dio_bytes, len, + percpu_counter_add_batch(&fs_info->dio_bytes, num_bytes, fs_info->delalloc_batch); set_bit(BTRFS_ORDERED_DIRECT, &entry->flags); } @@ -247,27 +242,30 @@ static int __btrfs_add_ordered_extent(struct inode *inode, u64 file_offset, } int btrfs_add_ordered_extent(struct inode *inode, u64 file_offset, - u64 start, u64 len, u64 disk_len, int type) + u64 disk_bytenr, u64 num_bytes, u64 disk_num_bytes, + int type) { - return __btrfs_add_ordered_extent(inode, file_offset, start, len, - disk_len, type, 0, + return __btrfs_add_ordered_extent(inode, file_offset, disk_bytenr, + num_bytes, disk_num_bytes, type, 0, BTRFS_COMPRESS_NONE); } int btrfs_add_ordered_extent_dio(struct inode *inode, u64 file_offset, - u64 start, u64 len, u64 disk_len, int type) + u64 disk_bytenr, u64 num_bytes, + u64 disk_num_bytes, int type) { - return __btrfs_add_ordered_extent(inode, file_offset, start, len, - disk_len, type, 1, + return __btrfs_add_ordered_extent(inode, file_offset, disk_bytenr, + num_bytes, disk_num_bytes, type, 1, BTRFS_COMPRESS_NONE); } int btrfs_add_ordered_extent_compress(struct inode *inode, u64 file_offset, - u64 start, u64 len, u64 disk_len, - int type, int compress_type) + u64 disk_bytenr, u64 num_bytes, + u64 disk_num_bytes, int type, + int compress_type) { - return __btrfs_add_ordered_extent(inode, file_offset, start, len, - disk_len, type, 0, + return __btrfs_add_ordered_extent(inode, file_offset, disk_bytenr, + num_bytes, disk_num_bytes, type, 0, compress_type); } @@ -328,8 +326,8 @@ int btrfs_dec_test_first_ordered_pending(struct inode *inode, } dec_start = max(*file_offset, entry->file_offset); - dec_end = min(*file_offset + io_size, entry->file_offset + - entry->len); + dec_end = min(*file_offset + io_size, + entry->file_offset + entry->num_bytes); *file_offset = dec_end; if (dec_start > dec_end) { btrfs_crit(fs_info, "bad ordering dec_start %llu end %llu", @@ -471,10 +469,11 @@ void btrfs_remove_ordered_extent(struct inode *inode, btrfs_mod_outstanding_extents(btrfs_inode, -1); spin_unlock(&btrfs_inode->lock); if (root != fs_info->tree_root) - btrfs_delalloc_release_metadata(btrfs_inode, entry->len, false); + btrfs_delalloc_release_metadata(btrfs_inode, entry->num_bytes, + false); if (test_bit(BTRFS_ORDERED_DIRECT, &entry->flags)) - percpu_counter_add_batch(&fs_info->dio_bytes, -entry->len, + percpu_counter_add_batch(&fs_info->dio_bytes, -entry->num_bytes, fs_info->delalloc_batch); tree = &btrfs_inode->ordered_tree; @@ -534,8 +533,8 @@ u64 btrfs_wait_ordered_extents(struct btrfs_root *root, u64 nr, ordered = list_first_entry(&splice, struct btrfs_ordered_extent, root_extent_list); - if (range_end <= ordered->start || - ordered->start + ordered->disk_len <= range_start) { + if (range_end <= ordered->disk_bytenr || + ordered->disk_bytenr + ordered->disk_num_bytes <= range_start) { list_move_tail(&ordered->root_extent_list, &skipped); cond_resched_lock(&root->ordered_extent_lock); continue; @@ -619,7 +618,7 @@ void btrfs_start_ordered_extent(struct inode *inode, int wait) { u64 start = entry->file_offset; - u64 end = start + entry->len - 1; + u64 end = start + entry->num_bytes - 1; trace_btrfs_ordered_extent_start(inode, entry); @@ -680,7 +679,7 @@ int btrfs_wait_ordered_range(struct inode *inode, u64 start, u64 len) btrfs_put_ordered_extent(ordered); break; } - if (ordered->file_offset + ordered->len <= start) { + if (ordered->file_offset + ordered->num_bytes <= start) { btrfs_put_ordered_extent(ordered); break; } diff --git a/fs/btrfs/ordered-data.h b/fs/btrfs/ordered-data.h index 4eb0319a86d7..3beb4da4ab41 100644 --- a/fs/btrfs/ordered-data.h +++ b/fs/btrfs/ordered-data.h @@ -67,14 +67,13 @@ struct btrfs_ordered_extent { /* logical offset in the file */ u64 file_offset; - /* disk byte number */ - u64 start; - - /* ram length of the extent in bytes */ - u64 len; - - /* extent length on disk */ - u64 disk_len; + /* + * These fields directly correspond to the same fields in + * btrfs_file_extent_item. + */ + u64 disk_bytenr; + u64 num_bytes; + u64 disk_num_bytes; /* number of bytes that still need writing */ u64 bytes_left; @@ -161,12 +160,15 @@ int btrfs_dec_test_first_ordered_pending(struct inode *inode, u64 *file_offset, u64 io_size, int uptodate); int btrfs_add_ordered_extent(struct inode *inode, u64 file_offset, - u64 start, u64 len, u64 disk_len, int type); + u64 disk_bytenr, u64 num_bytes, u64 disk_num_bytes, + int type); int btrfs_add_ordered_extent_dio(struct inode *inode, u64 file_offset, - u64 start, u64 len, u64 disk_len, int type); + u64 disk_bytenr, u64 num_bytes, + u64 disk_num_bytes, int type); int btrfs_add_ordered_extent_compress(struct inode *inode, u64 file_offset, - u64 start, u64 len, u64 disk_len, - int type, int compress_type); + u64 disk_bytenr, u64 num_bytes, + u64 disk_num_bytes, int type, + int compress_type); void btrfs_add_ordered_sum(struct btrfs_ordered_extent *entry, struct btrfs_ordered_sum *sum); struct btrfs_ordered_extent *btrfs_lookup_ordered_extent(struct inode *inode, diff --git a/fs/btrfs/relocation.c b/fs/btrfs/relocation.c index d897a8e5e430..da0872219010 100644 --- a/fs/btrfs/relocation.c +++ b/fs/btrfs/relocation.c @@ -4614,7 +4614,7 @@ int btrfs_reloc_clone_csums(struct inode *inode, u64 file_pos, u64 len) LIST_HEAD(list); ordered = btrfs_lookup_ordered_extent(inode, file_pos); - BUG_ON(ordered->file_offset != file_pos || ordered->len != len); + BUG_ON(ordered->file_offset != file_pos || ordered->num_bytes != len); disk_bytenr = file_pos + BTRFS_I(inode)->index_cnt; ret = btrfs_lookup_csums_range(fs_info->csum_root, disk_bytenr, @@ -4638,7 +4638,8 @@ int btrfs_reloc_clone_csums(struct inode *inode, u64 file_pos, u64 len) * disk_len vs real len like with real inodes since it's all * disk length. */ - new_bytenr = ordered->start + (sums->bytenr - disk_bytenr); + new_bytenr = (ordered->disk_bytenr + + (sums->bytenr - disk_bytenr)); sums->bytenr = new_bytenr; btrfs_add_ordered_sum(ordered, sums); diff --git a/include/trace/events/btrfs.h b/include/trace/events/btrfs.h index 620bf1b38fba..17088a112ed0 100644 --- a/include/trace/events/btrfs.h +++ b/include/trace/events/btrfs.h @@ -496,9 +496,9 @@ DECLARE_EVENT_CLASS(btrfs__ordered_extent, TP_fast_assign_btrfs(btrfs_sb(inode->i_sb), __entry->ino = btrfs_ino(BTRFS_I(inode)); __entry->file_offset = ordered->file_offset; - __entry->start = ordered->start; - __entry->len = ordered->len; - __entry->disk_len = ordered->disk_len; + __entry->start = ordered->disk_bytenr; + __entry->len = ordered->num_bytes; + __entry->disk_len = ordered->disk_num_bytes; __entry->bytes_left = ordered->bytes_left; __entry->flags = ordered->flags; __entry->compress_type = ordered->compress_type; From patchwork Tue Dec 3 01:34:20 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Omar Sandoval X-Patchwork-Id: 11270123 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id E79E1159A for ; Tue, 3 Dec 2019 01:34:40 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id C6082206F0 for ; Tue, 3 Dec 2019 01:34:40 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=osandov-com.20150623.gappssmtp.com header.i=@osandov-com.20150623.gappssmtp.com header.b="jiNXAixc" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726115AbfLCBej (ORCPT ); Mon, 2 Dec 2019 20:34:39 -0500 Received: from mail-pg1-f195.google.com ([209.85.215.195]:42686 "EHLO mail-pg1-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726066AbfLCBei (ORCPT ); Mon, 2 Dec 2019 20:34:38 -0500 Received: by mail-pg1-f195.google.com with SMTP id i5so768962pgj.9 for ; Mon, 02 Dec 2019 17:34:38 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=osandov-com.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=kl5NusECMuLZ4kJz7JyxyuA7yPSyr6hQjPHERK44q0Q=; b=jiNXAixciDLg8oEHtt43QSDN6frrGin9PnwA6f58KYj1kYb/1qA5c49fol5K0+jgyz Hj66hoOvmyZR6M0zracLI0W4Bt3cawO1Hsva//b/JBnUXe+/WIRfp3uHxmiW8tUQGbXN mPp1l2sBKw8hmTqnaQ9/rXH3Wc+E8jYatozAbFZDPDNKKTia/lLoeXDtlH/Zvn/ImV1n +71WnKaFsnDafB6HD1uaTG7vlt/9EflsRk9feCtGbjDO17+tswYr7I0ke2kOHBjwWYCs HN6oE59acqzXw+Dr530ft90ncA9S3Ox/SOVShrm3J7JSa5AYhjqtnCK+G9lcmPp5xx7t GnHA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=kl5NusECMuLZ4kJz7JyxyuA7yPSyr6hQjPHERK44q0Q=; b=E9yMSI2nlNrHjuv34FFVR84A4aVOEh2Wh0TrN6yENqab0fpQHsesk3aiAekcx81S6L SfLLmEDkFUTX1Tp+Z1KI0bKWqIOqIhQoMQQn4PCnCbDwxETwv+YK4ZuC2OwRTzVor/UE dYl0Tw9OJ26i7bFBZfrFN6f+ccSuEeMH5EOLsfOhMf7h416vepJBd5ZUWKFI9nZamCmS RleoXclGdux3Nif09o7nHWvQMddNA2nEFOB0SjOinN9AEsd1/NGoQP6TqDGpAUDePfBD oJjhJUzuU8L7sJcM/guyoF6RTW2WRDn6C/N25TaZE7o98qaT82Z+mJ5qZ3Ix2kK7gjzd UMVQ== X-Gm-Message-State: APjAAAUZSij6qWCbSo/AqyINvLIxolmQ8Ua69Ar3W2hwd8K9gFugyh8J FDfcOzJwcSDMbcb7tiEFSIORV2SYQl840Q== X-Google-Smtp-Source: APXvYqyAYLjeghV01elUpZWWOcc2E/nDtmmkj106tmMBkVQ/0jfY4/B5PCkMpsa+PUBJ01wUs4kQRg== X-Received: by 2002:aa7:82d8:: with SMTP id f24mr2004848pfn.55.1575336877715; Mon, 02 Dec 2019 17:34:37 -0800 (PST) Received: from vader.thefacebook.com ([2620:10d:c090:180::6ddc]) by smtp.gmail.com with ESMTPSA id u65sm800242pfb.35.2019.12.02.17.34.36 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 02 Dec 2019 17:34:37 -0800 (PST) From: Omar Sandoval To: linux-btrfs@vger.kernel.org Cc: kernel-team@fb.com Subject: [PATCH 4/9] btrfs: remove unnecessary pg_offset assignments in __extent_writepage() Date: Mon, 2 Dec 2019 17:34:20 -0800 Message-Id: <07b6177024a181dfd87c1c2e56a04d07152549fe.1575336816.git.osandov@fb.com> X-Mailer: git-send-email 2.24.0 In-Reply-To: References: MIME-Version: 1.0 Sender: linux-btrfs-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-btrfs@vger.kernel.org From: Omar Sandoval We're initializing pg_offset to 0, setting it immediately, then reassigning it to 0 again after. The former became unnecessary in 211c17f51f46 ("Fix corners in writepage and btrfs_truncate_page"). The latter is a leftover that should've been removed in 40f765805f08 ("Btrfs: split up __extent_writepage to lower stack usage"). Remove both. Signed-off-by: Omar Sandoval Reviewed-by: Johannes Thumshirn --- fs/btrfs/extent_io.c | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/fs/btrfs/extent_io.c b/fs/btrfs/extent_io.c index eb8bd0258360..dad6b06d0a8e 100644 --- a/fs/btrfs/extent_io.c +++ b/fs/btrfs/extent_io.c @@ -3562,7 +3562,7 @@ static int __extent_writepage(struct page *page, struct writeback_control *wbc, u64 page_end = start + PAGE_SIZE - 1; int ret; int nr = 0; - size_t pg_offset = 0; + size_t pg_offset; loff_t i_size = i_size_read(inode); unsigned long end_index = i_size >> PAGE_SHIFT; unsigned long nr_written = 0; @@ -3591,8 +3591,6 @@ static int __extent_writepage(struct page *page, struct writeback_control *wbc, flush_dcache_page(page); } - pg_offset = 0; - set_page_extent_mapped(page); if (!epd->extent_locked) { From patchwork Tue Dec 3 01:34:21 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Omar Sandoval X-Patchwork-Id: 11270127 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 9D002921 for ; Tue, 3 Dec 2019 01:34:42 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 7B99C206F0 for ; Tue, 3 Dec 2019 01:34:42 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=osandov-com.20150623.gappssmtp.com header.i=@osandov-com.20150623.gappssmtp.com header.b="Q8UfocYz" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726142AbfLCBel (ORCPT ); Mon, 2 Dec 2019 20:34:41 -0500 Received: from mail-pf1-f193.google.com ([209.85.210.193]:35552 "EHLO mail-pf1-f193.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726105AbfLCBej (ORCPT ); Mon, 2 Dec 2019 20:34:39 -0500 Received: by mail-pf1-f193.google.com with SMTP id b19so898974pfo.2 for ; Mon, 02 Dec 2019 17:34:39 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=osandov-com.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=3hJ94Hx3xilzbtIBQ65ljDvh6IjEBRdC/DhWOmD8T7M=; b=Q8UfocYzyqKVA1Cx/dc41tlTPP/J3/DZoVld0lwroRly2Hc7W92P/8aZ/4t0zP87Lz sfopkldmGwXe5ZDqqc0/NnIFOeHxY5obcriJHNe73KvMjeF1VWm61JtdQvSGUuxE2HAK Sdt85w2GL+CclXuweN6HE3rhdOKDVGPkKV4rd5oh6TLFH3q+s2rqmJxdotFcnifTA6O+ 6oMQf/riUsz9W5ucD94dBJKuRp8lk2zgwnCkYdiv+o4fEBU4m5IUdR86Or8OnB3gdTEc F70IpNTAptjxL2/uGWwC7h3SmXxY5lvu/Fe6HX/29PQwEG/MvlPv2nxMECjBway39GXz +tvg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=3hJ94Hx3xilzbtIBQ65ljDvh6IjEBRdC/DhWOmD8T7M=; b=MbnxGgSgezjaJ9SSLBsL+H8k1YCkTJ1SvL0Cy5gzmv23Bde5vQMBC8zjiGMUw+6X/u d5bRlMGLwMvleo1yi7a0ct+G6KsbdXQYoVqLtvSx25GMUEgzwnc9cuHq09cAa/N4BQXl v62JgsIJMZf+MJmKxlDwBcwnSV2Eey3OvZ2TNOYK/Qt7OxIFGr9CAAiYQb3okOYUCJYi gb5vHdEmzQ106E17YNRJDBwg6K86lbld8RRBNCwOTcKgrqHx8jyLSgzsmv+FUPPDKCrj X6xz3GAQp/bwSkFhaR5Z6sGgQD4xiKzC+OgJxmrRkp2MAlPAWLZ+fayvryamK6n7L93e qOBw== X-Gm-Message-State: APjAAAU70qXoXS/d9kTqzO2wIUuUOyPoISoJ252FGe6vni+p1hXusOt3 UvHLUGP8wM0wnGQENlkH34y9vCWvG3Bg6A== X-Google-Smtp-Source: APXvYqx1Ix2Q/rv+CvpEI67E7kGyE8vc38slFX+Qy5vSbyIHinrlVkn/yCRUXeGZ9XxY8TA0qi/2/g== X-Received: by 2002:aa7:8256:: with SMTP id e22mr1996904pfn.247.1575336878763; Mon, 02 Dec 2019 17:34:38 -0800 (PST) Received: from vader.thefacebook.com ([2620:10d:c090:180::6ddc]) by smtp.gmail.com with ESMTPSA id u65sm800242pfb.35.2019.12.02.17.34.37 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 02 Dec 2019 17:34:38 -0800 (PST) From: Omar Sandoval To: linux-btrfs@vger.kernel.org Cc: kernel-team@fb.com Subject: [PATCH 5/9] btrfs: remove trivial goto label in __extent_writepage() Date: Mon, 2 Dec 2019 17:34:21 -0800 Message-Id: <81ea4a6b327f26506041e2e43adc9dfccc7a86fe.1575336816.git.osandov@fb.com> X-Mailer: git-send-email 2.24.0 In-Reply-To: References: MIME-Version: 1.0 Sender: linux-btrfs-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-btrfs@vger.kernel.org From: Omar Sandoval Since 40f765805f08 ("Btrfs: split up __extent_writepage to lower stack usage"), done_unlocked is simply a return 0. Get rid of it. Signed-off-by: Omar Sandoval Reviewed-by: Johannes Thumshirn --- fs/btrfs/extent_io.c | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/fs/btrfs/extent_io.c b/fs/btrfs/extent_io.c index dad6b06d0a8e..8622282db31e 100644 --- a/fs/btrfs/extent_io.c +++ b/fs/btrfs/extent_io.c @@ -3596,7 +3596,7 @@ static int __extent_writepage(struct page *page, struct writeback_control *wbc, if (!epd->extent_locked) { ret = writepage_delalloc(inode, page, wbc, start, &nr_written); if (ret == 1) - goto done_unlocked; + return 0; if (ret) goto done; } @@ -3604,7 +3604,7 @@ static int __extent_writepage(struct page *page, struct writeback_control *wbc, ret = __extent_writepage_io(inode, page, wbc, epd, i_size, nr_written, &nr); if (ret == 1) - goto done_unlocked; + return 0; done: if (nr == 0) { @@ -3619,9 +3619,6 @@ static int __extent_writepage(struct page *page, struct writeback_control *wbc, unlock_page(page); ASSERT(ret <= 0); return ret; - -done_unlocked: - return 0; } void wait_on_extent_buffer_writeback(struct extent_buffer *eb) From patchwork Tue Dec 3 01:34:22 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Omar Sandoval X-Patchwork-Id: 11270125 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 2D1D213B6 for ; Tue, 3 Dec 2019 01:34:42 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 0BB9F206ED for ; Tue, 3 Dec 2019 01:34:42 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=osandov-com.20150623.gappssmtp.com header.i=@osandov-com.20150623.gappssmtp.com header.b="ryBR2y29" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726162AbfLCBel (ORCPT ); Mon, 2 Dec 2019 20:34:41 -0500 Received: from mail-pl1-f193.google.com ([209.85.214.193]:37433 "EHLO mail-pl1-f193.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726066AbfLCBel (ORCPT ); Mon, 2 Dec 2019 20:34:41 -0500 Received: by mail-pl1-f193.google.com with SMTP id bb5so930235plb.4 for ; Mon, 02 Dec 2019 17:34:40 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=osandov-com.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=cz4IiSRm1bjZ0sMYi8R6ullo2ASea8qE8Hw8baCLXRQ=; b=ryBR2y29HxZfeUmfm+spjLu0Ikc98Vl5EqGQkUggRHeA+Ev03E0YPKdhufnWRX7T/m 5kINWovwkNWh7Wg85p/oUSN4kNkGBhP8LAWvKFK+8fEARAIX2MwaxtkMbOnzSmwDSuuY BI8z+8I/nvVz0C05WToUBWhl36xTqSEr6pfe1cKZEoy9c3qUYPmbkQX4dLMeU1mnKyXA h3y7BKl+h3XlrnwXIBxxgF1D1NsOJsPlsfFkLLrMHpRFoV7UOoZY73PGCyc1J8DClHlr sKOQUx1uZqwzszVzQbHDu1mcVKRbBu2xNE7vCQTRGzCLYdSIZLdIAez/mMvwvPnF5pP3 6gpg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=cz4IiSRm1bjZ0sMYi8R6ullo2ASea8qE8Hw8baCLXRQ=; b=uKXibQn3sbWc6ARxCcSnIjBfMG/sPdNLYHA8MehAx+XUaj01ZlVWcbUbXmTT2LE2ED HvoX/a7OBUMZGGWx6csxkl351a4ll5X2HZ+E62efzCDbruJhhlvGWOkfIJpdaQ8wmbFS 836yE/mkvDAnvINGHMnw8Rl9voW2gWC6ktT+MXOQUQveN7DaDLWDb2fN2zaBYqwnvOqO sDS/VEcbcwJoSgSTg3rz2/H41q7R00nQaOt74QfeNCRu7fA1wYomtwBAPMnwhHjkkUTt Smx1YV1q5gLYZDaEaceavmGVY/MP1sqUTcBvQBLZHsc8ACVROfb7bvawFEusnszqFzWu TuTg== X-Gm-Message-State: APjAAAVNRs1cHjmWFo/bF1etPnnqU5RyeIhximPF8HGmL+U+qp2w/u6G iq6QgK2TDElf/b+4pu5Uy+6bVhaW2kP8Vw== X-Google-Smtp-Source: APXvYqxwwT4+YzDck/W6uNKdo0AM5Bvv48gdBB0CfhZ38sK3/R1sGqoasN5VlEDKEF31zy3QQxAV8A== X-Received: by 2002:a17:902:7784:: with SMTP id o4mr2407192pll.176.1575336879631; Mon, 02 Dec 2019 17:34:39 -0800 (PST) Received: from vader.thefacebook.com ([2620:10d:c090:180::6ddc]) by smtp.gmail.com with ESMTPSA id u65sm800242pfb.35.2019.12.02.17.34.38 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 02 Dec 2019 17:34:39 -0800 (PST) From: Omar Sandoval To: linux-btrfs@vger.kernel.org Cc: kernel-team@fb.com Subject: [PATCH 6/9] btrfs: remove redundant i_size check in __extent_writepage_io() Date: Mon, 2 Dec 2019 17:34:22 -0800 Message-Id: <365cd6fdadd6a91c22ccf61fcb1deb688763a176.1575336816.git.osandov@fb.com> X-Mailer: git-send-email 2.24.0 In-Reply-To: References: MIME-Version: 1.0 Sender: linux-btrfs-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-btrfs@vger.kernel.org From: Omar Sandoval In __extent_writepage_io(), we check whether i_size <= page_offset(page). Note that if i_size < page_offset(page), then i_size >> PAGE_SHIFT < page->index. If i_size == page_offset(page), then i_size >> PAGE_SHIFT == page->index && offset_in_page(i_size) == 0. __extent_writepage() already has a check for these cases that returns without calling __extent_writepage_io(): end_index = i_size >> PAGE_SHIFT pg_offset = offset_in_page(i_size); if (page->index > end_index || (page->index == end_index && !pg_offset)) { page->mapping->a_ops->invalidatepage(page, 0, PAGE_SIZE); unlock_page(page); return 0; } Get rid of the one in __extent_writepage_io(), which was obsoleted in 211c17f51f46 ("Fix corners in writepage and btrfs_truncate_page"). Signed-off-by: Omar Sandoval Reviewed-by: David Sterba --- fs/btrfs/extent_io.c | 6 ------ 1 file changed, 6 deletions(-) diff --git a/fs/btrfs/extent_io.c b/fs/btrfs/extent_io.c index 8622282db31e..635f5d2954a4 100644 --- a/fs/btrfs/extent_io.c +++ b/fs/btrfs/extent_io.c @@ -3455,11 +3455,6 @@ static noinline_for_stack int __extent_writepage_io(struct inode *inode, update_nr_written(wbc, nr_written + 1); end = page_end; - if (i_size <= start) { - btrfs_writepage_endio_finish_ordered(page, start, page_end, 1); - goto done; - } - blocksize = inode->i_sb->s_blocksize; while (cur <= end) { @@ -3540,7 +3535,6 @@ static noinline_for_stack int __extent_writepage_io(struct inode *inode, pg_offset += iosize; nr++; } -done: *nr_ret = nr; return ret; } From patchwork Tue Dec 3 01:34:23 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Omar Sandoval X-Patchwork-Id: 11270129 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 2C89913B6 for ; Tue, 3 Dec 2019 01:34:44 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 01F5620705 for ; Tue, 3 Dec 2019 01:34:44 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=osandov-com.20150623.gappssmtp.com header.i=@osandov-com.20150623.gappssmtp.com header.b="dP+q/yOV" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726195AbfLCBen (ORCPT ); Mon, 2 Dec 2019 20:34:43 -0500 Received: from mail-pj1-f65.google.com ([209.85.216.65]:43723 "EHLO mail-pj1-f65.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726066AbfLCBem (ORCPT ); Mon, 2 Dec 2019 20:34:42 -0500 Received: by mail-pj1-f65.google.com with SMTP id g4so731759pjs.10 for ; Mon, 02 Dec 2019 17:34:41 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=osandov-com.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=3Z01WoYvrTEc2OUV6ITjBtBaZjRfvvPC11GlOVbz5KM=; b=dP+q/yOVVk/LQzHM5txy6W2okmqDctVG7qp7F+cSVr7f+KqkBllrPr4vs6w1E8SLui jOtIQ+09hUxygcVbocVThyA4eLo3UUO7wy7PSubw+H+jqkXyvxCFnfrwoK6O85MpCFy8 kmQJDivD2FJ54U22rvN/JVZLYvonyfMZotW3GtNRHAQsxkcsct9qjyt3VK4WHPbaS93t JdJNe7FaqePAYpG4abB3xDDNknTOC/Q/z4NAMVB/OlZ/qYEJiys8Srz8zeumJOsBY+Oz yerePqxWXBaxeNbmgkwFVQB5OwCgrgm1Y51ZZ9AjwtXa8ECeifgf3XlT0ePsL0jPd1N5 xMHA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=3Z01WoYvrTEc2OUV6ITjBtBaZjRfvvPC11GlOVbz5KM=; b=jYnrJ3ga1hE5pBFfGGahhfDWQx8jKbszUviaaqUkQy7Q5iPL4JyqfhwQPIy6MwtO3s bXt2mmbjDfo5wvDYWXWwURk8EIfdNYF/2VyktzJTdindKbvPRgcRzKEaa/BI1rLOqEYB qeY1WuYV8nJ2mtzR72Av4txAvWgTfmJX1eb8JPlksDDaUCHfmpN0RXC7fQZ2L9aKTvqB hsvoB6e1ex2WffrCJ24wBAJLM4RQQivNUih7g8qbVCcaQGljSJVXeCKFLDe2JEs3uJLB oxxyalkiT6cTXWdqsFR2GPJPKfdrQ9M/w0yRwN//IxUvL7uKImRCLU0IegotothvmND4 xIww== X-Gm-Message-State: APjAAAVnzTWYnEyeT8Pb6A3ke2cpTw2PhEQDUBrn0xQ+cCsmxp8ma7+8 5lF6CWVwVoC3/m3JbmZUwcDBDKdktSYOEA== X-Google-Smtp-Source: APXvYqyisC41XkUCkUgbHNcjjfQ3Fdgnx9vk1dyZa23Nj804mk9+lpIwsMMx4pslLrWSzfYoTTEVxA== X-Received: by 2002:a17:902:bd96:: with SMTP id q22mr2273927pls.98.1575336880799; Mon, 02 Dec 2019 17:34:40 -0800 (PST) Received: from vader.thefacebook.com ([2620:10d:c090:180::6ddc]) by smtp.gmail.com with ESMTPSA id u65sm800242pfb.35.2019.12.02.17.34.39 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 02 Dec 2019 17:34:40 -0800 (PST) From: Omar Sandoval To: linux-btrfs@vger.kernel.org Cc: kernel-team@fb.com Subject: [PATCH 7/9] btrfs: drop create parameter to btrfs_get_extent() Date: Mon, 2 Dec 2019 17:34:23 -0800 Message-Id: <3012e96179bf1427eca8e26332c7c4475f31c76b.1575336816.git.osandov@fb.com> X-Mailer: git-send-email 2.24.0 In-Reply-To: References: MIME-Version: 1.0 Sender: linux-btrfs-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-btrfs@vger.kernel.org From: Omar Sandoval We only pass this as 1 from __extent_writepage_io(). The parameter basically means "pretend I didn't pass in a page". This is silly since we can simply not pass in the page. Get rid of the parameter from btrfs_get_extent(), and since it's used as a get_extent_t callback, remove it from get_extent_t and btree_get_extent(), neither of which need it. While we're here, let's document btrfs_get_extent(). Signed-off-by: Omar Sandoval --- fs/btrfs/ctree.h | 2 +- fs/btrfs/disk-io.c | 4 ++-- fs/btrfs/disk-io.h | 4 ++-- fs/btrfs/extent_io.c | 6 +++--- fs/btrfs/extent_io.h | 6 ++---- fs/btrfs/file.c | 17 ++++++++--------- fs/btrfs/inode.c | 41 ++++++++++++++++++++++++----------------- fs/btrfs/ioctl.c | 2 +- 8 files changed, 43 insertions(+), 39 deletions(-) diff --git a/fs/btrfs/ctree.h b/fs/btrfs/ctree.h index 5ad45171e482..7a8209b17b3d 100644 --- a/fs/btrfs/ctree.h +++ b/fs/btrfs/ctree.h @@ -2875,7 +2875,7 @@ struct inode *btrfs_iget(struct super_block *s, struct btrfs_key *location, struct btrfs_root *root); struct extent_map *btrfs_get_extent(struct btrfs_inode *inode, struct page *page, size_t pg_offset, - u64 start, u64 end, int create); + u64 start, u64 end); int btrfs_update_inode(struct btrfs_trans_handle *trans, struct btrfs_root *root, struct inode *inode); diff --git a/fs/btrfs/disk-io.c b/fs/btrfs/disk-io.c index ab888d89d844..881aba162e4e 100644 --- a/fs/btrfs/disk-io.c +++ b/fs/btrfs/disk-io.c @@ -202,8 +202,8 @@ void btrfs_set_buffer_lockdep_class(u64 objectid, struct extent_buffer *eb, * that covers the entire device */ struct extent_map *btree_get_extent(struct btrfs_inode *inode, - struct page *page, size_t pg_offset, u64 start, u64 len, - int create) + struct page *page, size_t pg_offset, + u64 start, u64 len) { struct extent_map_tree *em_tree = &inode->extent_tree; struct extent_map *em; diff --git a/fs/btrfs/disk-io.h b/fs/btrfs/disk-io.h index 76f123ebb292..8c2d6cf1ce59 100644 --- a/fs/btrfs/disk-io.h +++ b/fs/btrfs/disk-io.h @@ -134,8 +134,8 @@ struct btrfs_root *btrfs_create_tree(struct btrfs_trans_handle *trans, int btree_lock_page_hook(struct page *page, void *data, void (*flush_fn)(void *)); struct extent_map *btree_get_extent(struct btrfs_inode *inode, - struct page *page, size_t pg_offset, u64 start, u64 len, - int create); + struct page *page, size_t pg_offset, + u64 start, u64 len); int btrfs_get_num_tolerated_disk_barrier_failures(u64 flags); int __init btrfs_end_io_wq_init(void); void __cold btrfs_end_io_wq_exit(void); diff --git a/fs/btrfs/extent_io.c b/fs/btrfs/extent_io.c index 635f5d2954a4..13c03c42ba5c 100644 --- a/fs/btrfs/extent_io.c +++ b/fs/btrfs/extent_io.c @@ -3043,7 +3043,7 @@ __get_extent_map(struct inode *inode, struct page *page, size_t pg_offset, *em_cached = NULL; } - em = get_extent(BTRFS_I(inode), page, pg_offset, start, len, 0); + em = get_extent(BTRFS_I(inode), page, pg_offset, start, len); if (em_cached && !IS_ERR_OR_NULL(em)) { BUG_ON(*em_cached); refcount_inc(&em->refs); @@ -3466,8 +3466,8 @@ static noinline_for_stack int __extent_writepage_io(struct inode *inode, page_end, 1); break; } - em = btrfs_get_extent(BTRFS_I(inode), page, pg_offset, cur, - end - cur + 1, 1); + em = btrfs_get_extent(BTRFS_I(inode), NULL, 0, cur, + end - cur + 1); if (IS_ERR_OR_NULL(em)) { SetPageError(page); ret = PTR_ERR_OR_ZERO(em); diff --git a/fs/btrfs/extent_io.h b/fs/btrfs/extent_io.h index a8551a1f56e2..5d205bbaafdc 100644 --- a/fs/btrfs/extent_io.h +++ b/fs/btrfs/extent_io.h @@ -183,10 +183,8 @@ static inline int extent_compress_type(unsigned long bio_flags) struct extent_map_tree; typedef struct extent_map *(get_extent_t)(struct btrfs_inode *inode, - struct page *page, - size_t pg_offset, - u64 start, u64 len, - int create); + struct page *page, size_t pg_offset, + u64 start, u64 len); int try_release_extent_mapping(struct page *page, gfp_t mask); int try_release_extent_buffer(struct page *page); diff --git a/fs/btrfs/file.c b/fs/btrfs/file.c index 568b6391c719..c7efc0b04c62 100644 --- a/fs/btrfs/file.c +++ b/fs/btrfs/file.c @@ -477,8 +477,7 @@ static int btrfs_find_new_delalloc_bytes(struct btrfs_inode *inode, u64 em_len; int ret = 0; - em = btrfs_get_extent(inode, NULL, 0, search_start, - search_len, 0); + em = btrfs_get_extent(inode, NULL, 0, search_start, search_len); if (IS_ERR(em)) return PTR_ERR(em); @@ -2390,7 +2389,7 @@ static int find_first_non_hole(struct inode *inode, u64 *start, u64 *len) em = btrfs_get_extent(BTRFS_I(inode), NULL, 0, round_down(*start, fs_info->sectorsize), - round_up(*len, fs_info->sectorsize), 0); + round_up(*len, fs_info->sectorsize)); if (IS_ERR(em)) return PTR_ERR(em); @@ -2957,7 +2956,7 @@ static int btrfs_zero_range_check_range_boundary(struct inode *inode, int ret; offset = round_down(offset, sectorsize); - em = btrfs_get_extent(BTRFS_I(inode), NULL, 0, offset, sectorsize, 0); + em = btrfs_get_extent(BTRFS_I(inode), NULL, 0, offset, sectorsize); if (IS_ERR(em)) return PTR_ERR(em); @@ -2990,8 +2989,8 @@ static int btrfs_zero_range(struct inode *inode, inode_dio_wait(inode); - em = btrfs_get_extent(BTRFS_I(inode), NULL, 0, - alloc_start, alloc_end - alloc_start, 0); + em = btrfs_get_extent(BTRFS_I(inode), NULL, 0, alloc_start, + alloc_end - alloc_start); if (IS_ERR(em)) { ret = PTR_ERR(em); goto out; @@ -3034,8 +3033,8 @@ static int btrfs_zero_range(struct inode *inode, if (BTRFS_BYTES_TO_BLKS(fs_info, offset) == BTRFS_BYTES_TO_BLKS(fs_info, offset + len - 1)) { - em = btrfs_get_extent(BTRFS_I(inode), NULL, 0, - alloc_start, sectorsize, 0); + em = btrfs_get_extent(BTRFS_I(inode), NULL, 0, alloc_start, + sectorsize); if (IS_ERR(em)) { ret = PTR_ERR(em); goto out; @@ -3273,7 +3272,7 @@ static long btrfs_fallocate(struct file *file, int mode, INIT_LIST_HEAD(&reserve_list); while (cur_offset < alloc_end) { em = btrfs_get_extent(BTRFS_I(inode), NULL, 0, cur_offset, - alloc_end - cur_offset, 0); + alloc_end - cur_offset); if (IS_ERR(em)) { ret = PTR_ERR(em); break; diff --git a/fs/btrfs/inode.c b/fs/btrfs/inode.c index 7fe400d18d60..2145543b2425 100644 --- a/fs/btrfs/inode.c +++ b/fs/btrfs/inode.c @@ -4478,7 +4478,7 @@ int btrfs_cont_expand(struct inode *inode, loff_t oldsize, loff_t size) cur_offset = hole_start; while (1) { em = btrfs_get_extent(BTRFS_I(inode), NULL, 0, cur_offset, - block_end - cur_offset, 0); + block_end - cur_offset); if (IS_ERR(em)) { err = PTR_ERR(em); em = NULL; @@ -6253,18 +6253,27 @@ static noinline int uncompress_inline(struct btrfs_path *path, return ret; } -/* - * a bit scary, this does extent mapping from logical file offset to the disk. - * the ugly parts come from merging extents from the disk with the in-ram - * representation. This gets more complex because of the data=ordered code, - * where the in-ram extents might be locked pending data=ordered completion. +/** + * btrfs_get_extent - Lookup the first extent overlapping a range in a file. + * @inode: File to search in. + * @page: Page to read extent data into if the extent is inline. + * @pg_offset: Offset into @page to copy to. + * @start: File offset. + * @len: Length of range starting at @start. + * + * This returns the first &struct extent_map which overlaps with the given + * range, reading it from the B-tree and caching it if necessary. Note that + * there may be more extents which overlap the given range after the returned + * extent_map. * - * This also copies inline extents directly into the page. + * If @page is not NULL and the extent is inline, this also reads the extent + * data directly into the page and marks the extent up to date in the io_tree. + * + * Return: ERR_PTR on error, non-NULL extent_map on success. */ struct extent_map *btrfs_get_extent(struct btrfs_inode *inode, - struct page *page, - size_t pg_offset, u64 start, u64 len, - int create) + struct page *page, size_t pg_offset, + u64 start, u64 len) { struct btrfs_fs_info *fs_info = inode->root->fs_info; int ret; @@ -6281,7 +6290,6 @@ struct extent_map *btrfs_get_extent(struct btrfs_inode *inode, struct extent_map *em = NULL; struct extent_map_tree *em_tree = &inode->extent_tree; struct extent_io_tree *io_tree = &inode->io_tree; - const bool new_inline = !page || create; read_lock(&em_tree->lock); em = lookup_extent_mapping(em_tree, start, len); @@ -6404,8 +6412,7 @@ struct extent_map *btrfs_get_extent(struct btrfs_inode *inode, goto insert; } - btrfs_extent_item_to_extent_map(inode, path, item, - new_inline, em); + btrfs_extent_item_to_extent_map(inode, path, item, !page, em); if (extent_type == BTRFS_FILE_EXTENT_REG || extent_type == BTRFS_FILE_EXTENT_PREALLOC) { @@ -6417,7 +6424,7 @@ struct extent_map *btrfs_get_extent(struct btrfs_inode *inode, size_t extent_offset; size_t copy_size; - if (new_inline) + if (!page) goto out; size = btrfs_file_extent_ram_bytes(leaf, item); @@ -6500,7 +6507,7 @@ struct extent_map *btrfs_get_extent_fiemap(struct btrfs_inode *inode, u64 delalloc_end; int err = 0; - em = btrfs_get_extent(inode, NULL, 0, start, len, 0); + em = btrfs_get_extent(inode, NULL, 0, start, len); if (IS_ERR(em)) return em; /* @@ -7125,7 +7132,7 @@ static int btrfs_get_blocks_direct(struct inode *inode, sector_t iblock, goto err; } - em = btrfs_get_extent(BTRFS_I(inode), NULL, 0, start, len, 0); + em = btrfs_get_extent(BTRFS_I(inode), NULL, 0, start, len); if (IS_ERR(em)) { ret = PTR_ERR(em); goto unlock_err; @@ -10153,7 +10160,7 @@ static int btrfs_swap_activate(struct swap_info_struct *sis, struct file *file, struct btrfs_block_group *bg; u64 len = isize - start; - em = btrfs_get_extent(BTRFS_I(inode), NULL, 0, start, len, 0); + em = btrfs_get_extent(BTRFS_I(inode), NULL, 0, start, len); if (IS_ERR(em)) { ret = PTR_ERR(em); goto out; diff --git a/fs/btrfs/ioctl.c b/fs/btrfs/ioctl.c index a1ee0b775e65..00452b98e9f5 100644 --- a/fs/btrfs/ioctl.c +++ b/fs/btrfs/ioctl.c @@ -1122,7 +1122,7 @@ static struct extent_map *defrag_lookup_extent(struct inode *inode, u64 start) /* get the big lock and read metadata off disk */ lock_extent_bits(io_tree, start, end, &cached); - em = btrfs_get_extent(BTRFS_I(inode), NULL, 0, start, len, 0); + em = btrfs_get_extent(BTRFS_I(inode), NULL, 0, start, len); unlock_extent_cached(io_tree, start, end, &cached); if (IS_ERR(em)) From patchwork Tue Dec 3 01:34:24 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Omar Sandoval X-Patchwork-Id: 11270133 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 950DA921 for ; Tue, 3 Dec 2019 01:34:46 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 747B420705 for ; Tue, 3 Dec 2019 01:34:46 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=osandov-com.20150623.gappssmtp.com header.i=@osandov-com.20150623.gappssmtp.com header.b="Fuj0JG3u" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726251AbfLCBeo (ORCPT ); Mon, 2 Dec 2019 20:34:44 -0500 Received: from mail-pf1-f193.google.com ([209.85.210.193]:33292 "EHLO mail-pf1-f193.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726190AbfLCBen (ORCPT ); Mon, 2 Dec 2019 20:34:43 -0500 Received: by mail-pf1-f193.google.com with SMTP id y206so902556pfb.0 for ; Mon, 02 Dec 2019 17:34:43 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=osandov-com.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=dhMNxMRL59v0xeoDIjm8Lrm4C202koHkHPnIlytprVg=; b=Fuj0JG3u+i5I2huz/iy5pJSsWSzzyglTi4BLiPel06JKLDWkLtXVXSoTKTs4/HT7LD yWrt1Zb5UyYlaQSzOzNWofMKTeD8AgpH1ozfOedGMhwsYwUqhzLJwrqbw/hPiF7xc0f5 GHyf6JXG1/TPCfR35iw04XPyRb3pkGg/Xk2hm+Ejnb7z7Mg/fxlzyha9+tvBtra0PaQe /0DsQC2JFYUIb7TSPE51VVWNsNyCQIreWpbltiKRvG+5c7wetNtTTb96uJ6DT7j1c+o7 7jr5SRFvyKeVFlrBoPXxzDHJUgdu5Ol1ZWaVrt/cyzinA+Tpr6CJ6FO5KzQOU/uomuYj cipA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=dhMNxMRL59v0xeoDIjm8Lrm4C202koHkHPnIlytprVg=; b=Yxrk0qLoxQ4uiG9xMd45dVRHCabG8OuP2D8nw4eF0rzyKDdB7mpqy0hrmHcqfIeR+8 L3ht85DgMCF7+pa7De2RJtn9+BXaK13MTnKu0ehM4gGTobnseMGcmiGVeMjHB2ajfFxJ 4A2c0Rp64g5ACmnVElsTsBUEs3M3Dvr4s/soCfag2resJM4sdM9NpKbcUxH+6WAme5fY 1QAsI6GZSvNVsDoDrjwYLO/d8LxBiUJx4IcpMmHVAUWMFyJosSu9RBj+q6ODFI8nc2VV j49DvfgZ1O8bfNWQWVUYGweUx2xWOBxxMGqkZwENGX7N0he+WSdwpl0Fmy0EMYz2abnR kogQ== X-Gm-Message-State: APjAAAWu63Sx983Ww9asaLX0He0Jl4S8737oyxrHuLSJNKng04+OK11w LQyyRTGu2L/qqgyMp6OY0run28fzCWYuSw== X-Google-Smtp-Source: APXvYqwH/7sNmBYBHZB46o3H703wETQmRH62xddMpTEy03SR+nz2CiYX0IdTccm4FxdlJUt58IjZdQ== X-Received: by 2002:aa7:828c:: with SMTP id s12mr2009465pfm.166.1575336882090; Mon, 02 Dec 2019 17:34:42 -0800 (PST) Received: from vader.thefacebook.com ([2620:10d:c090:180::6ddc]) by smtp.gmail.com with ESMTPSA id u65sm800242pfb.35.2019.12.02.17.34.41 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 02 Dec 2019 17:34:41 -0800 (PST) From: Omar Sandoval To: linux-btrfs@vger.kernel.org Cc: kernel-team@fb.com Subject: [PATCH 8/9] btrfs: simplify compressed/inline check in __extent_writepage_io() Date: Mon, 2 Dec 2019 17:34:24 -0800 Message-Id: <8c99ef2ac5f56d6d08716fe8ddfd3a24084f3861.1575336816.git.osandov@fb.com> X-Mailer: git-send-email 2.24.0 In-Reply-To: References: MIME-Version: 1.0 Sender: linux-btrfs-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-btrfs@vger.kernel.org From: Omar Sandoval Commit 7087a9d8db88 ("btrfs: Remove extent_io_ops::writepage_end_io_hook") left this logic in a confusing state. Simplify it. Signed-off-by: Omar Sandoval Reviewed-by: Johannes Thumshirn --- fs/btrfs/extent_io.c | 19 +++++-------------- 1 file changed, 5 insertions(+), 14 deletions(-) diff --git a/fs/btrfs/extent_io.c b/fs/btrfs/extent_io.c index 13c03c42ba5c..385edd31acf0 100644 --- a/fs/btrfs/extent_io.c +++ b/fs/btrfs/extent_io.c @@ -3492,22 +3492,13 @@ static noinline_for_stack int __extent_writepage_io(struct inode *inode, */ if (compressed || block_start == EXTENT_MAP_HOLE || block_start == EXTENT_MAP_INLINE) { - /* - * end_io notification does not happen here for - * compressed extents - */ - if (!compressed) - btrfs_writepage_endio_finish_ordered(page, cur, - cur + iosize - 1, - 1); - else if (compressed) { - /* we don't want to end_page_writeback on - * a compressed extent. this happens - * elsewhere - */ + if (compressed) { nr++; + } else { + btrfs_writepage_endio_finish_ordered(page, cur, + cur + iosize - 1, + 1); } - cur += iosize; pg_offset += iosize; continue; From patchwork Tue Dec 3 01:34:25 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Omar Sandoval X-Patchwork-Id: 11270131 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id B0FCD13B6 for ; Tue, 3 Dec 2019 01:34:45 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 9232520705 for ; Tue, 3 Dec 2019 01:34:45 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=osandov-com.20150623.gappssmtp.com header.i=@osandov-com.20150623.gappssmtp.com header.b="XX/CEznv" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726291AbfLCBeo (ORCPT ); Mon, 2 Dec 2019 20:34:44 -0500 Received: from mail-pg1-f193.google.com ([209.85.215.193]:37767 "EHLO mail-pg1-f193.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726066AbfLCBeo (ORCPT ); Mon, 2 Dec 2019 20:34:44 -0500 Received: by mail-pg1-f193.google.com with SMTP id q127so785382pga.4 for ; Mon, 02 Dec 2019 17:34:43 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=osandov-com.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=XwHbg1a+4pUxALqWYYd9+ycQ/lVXsQpFJwto07+kXV4=; b=XX/CEznvgUjK9MDMZ+kIkJ0dRRS2F3dShYMUbFUiJF2xhGKrt5WXoKo7dzQ0fEYw8L 2xg66uWlzUDjR/kFNQLMmDBzEMPLM905mEYOl8VhR4Z9O1flhf2uhVb2HYSdruna2r00 VUNY2sUh4d4AyPXqfsMOaLwb9pzxgNiEZFK6an0kyCwy0Al1QCz/qfeUtcvVEjQRcuCF v9QQ0c2l0xThvUKOfZr2NhPcXSQgr+956rnDmMWQlt1J8XkVH4gvefpyWL/OIytPAJKR ZQXGcmRGOXmjlid+Z7/Q6nTJsNRF1qdo8wNPHKRdZlqb0c6NqvKRLw7aDHEpXj9qRZ0u 9gtA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=XwHbg1a+4pUxALqWYYd9+ycQ/lVXsQpFJwto07+kXV4=; b=HUxxezWhXF5RnY/8Sfkfyc5QDBb213ORBU21rxDZRQlmFnNCRR/ITQQS8hxr5/HZ7Z 46fkqtmgRKDYkPKmrjvR1B0Qs0qmyU9dDFC3/6+1R48ILGJbnAykNKn+148EFnGJBfpO Z/FsB7Xum6y8UF3avFjBN8uMhTMe7diNWFjCdyG8sbrL9Pon5v14+oQHT9xoM8hV1pVx eECB8iLVtPqLMDjcN6EwPDL/yWXQNzGU3u4ElZNdB7YND+Xk7Nw5ei0kE6nXt0B1toTE P3digZ6yHaAi46g8vn7/pKoHrvUwrdzQOiTggvqj6gjd4V0LWFIxgMgw6iCDRd9AKANa a+VA== X-Gm-Message-State: APjAAAXCrpaD/1zUgSmueAc1YCmormVlFXhk7a3Q+Cn1AhublDjyjkMZ GPGdy5Id2cEja0ORz976VA0wPzUfUFgbRw== X-Google-Smtp-Source: APXvYqy0gOXpW3L6h4MKoicDAY1QGrUqfg5PHGqdNXW8AK4aMv9ioBu8CNVPc2Rh21F7OQngdMci2g== X-Received: by 2002:a62:5485:: with SMTP id i127mr2064374pfb.186.1575336883057; Mon, 02 Dec 2019 17:34:43 -0800 (PST) Received: from vader.thefacebook.com ([2620:10d:c090:180::6ddc]) by smtp.gmail.com with ESMTPSA id u65sm800242pfb.35.2019.12.02.17.34.42 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 02 Dec 2019 17:34:42 -0800 (PST) From: Omar Sandoval To: linux-btrfs@vger.kernel.org Cc: kernel-team@fb.com Subject: [PATCH 9/9] btrfs: remove struct find_free_extent.ram_bytes Date: Mon, 2 Dec 2019 17:34:25 -0800 Message-Id: X-Mailer: git-send-email 2.24.0 In-Reply-To: References: MIME-Version: 1.0 Sender: linux-btrfs-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-btrfs@vger.kernel.org From: Omar Sandoval This hasn't been used since it was first introduced in commit b4bd745d1230 ("btrfs: Introduce find_free_extent_ctl structure for later rework"). Signed-off-by: Omar Sandoval --- fs/btrfs/extent-tree.c | 2 -- 1 file changed, 2 deletions(-) diff --git a/fs/btrfs/extent-tree.c b/fs/btrfs/extent-tree.c index 18df434bfe52..40c000269232 100644 --- a/fs/btrfs/extent-tree.c +++ b/fs/btrfs/extent-tree.c @@ -3437,7 +3437,6 @@ btrfs_release_block_group(struct btrfs_block_group *cache, */ struct find_free_extent_ctl { /* Basic allocation info */ - u64 ram_bytes; u64 num_bytes; u64 empty_size; u64 flags; @@ -3809,7 +3808,6 @@ static noinline int find_free_extent(struct btrfs_fs_info *fs_info, WARN_ON(num_bytes < fs_info->sectorsize); - ffe_ctl.ram_bytes = ram_bytes; ffe_ctl.num_bytes = num_bytes; ffe_ctl.empty_size = empty_size; ffe_ctl.flags = flags;