From patchwork Fri Dec 3 22:18:03 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Josef Bacik X-Patchwork-Id: 12655887 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 39B9EC433F5 for ; Fri, 3 Dec 2021 22:18:28 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1383377AbhLCWVu (ORCPT ); Fri, 3 Dec 2021 17:21:50 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47788 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S240628AbhLCWVs (ORCPT ); Fri, 3 Dec 2021 17:21:48 -0500 Received: from mail-qv1-xf32.google.com (mail-qv1-xf32.google.com [IPv6:2607:f8b0:4864:20::f32]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id ACEB5C061751 for ; Fri, 3 Dec 2021 14:18:23 -0800 (PST) Received: by mail-qv1-xf32.google.com with SMTP id u16so4153675qvk.4 for ; Fri, 03 Dec 2021 14:18:23 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=toxicpanda-com.20210112.gappssmtp.com; s=20210112; h=from:to:subject:date:message-id:in-reply-to:references:mime-version :content-transfer-encoding; bh=lbxHzMijQw7mL7Q1EwgegdzG4cyTaynJVs5wNTOjL+A=; b=7rMbJh5D587QLe8Fmp0nQRz6gLBY83G4NC9bN9B1n+b5ekeg85NYR0SmvTi2CXojvO XN7ZW4H8oPS+jMGKF3DvobhQYQrt6x9cqGwRiK7NrqN4jAq5jkyXFx9Um/hQ0P+tTCuE aOax8AFthT9WPniOCJDKQKvjHs2xUrgdVNei0Y6g8r1oTLjGruEyRYYKgmA8Mwtlvk7f DM6QVmoK3jLQnrEHxHSrOFQz3M+Qn5hy52giJtoC53Lg+O+iNp8/+j5YDcOAEdf5xxh5 /4hw5Uv80Wqmm91pCXlmZVENvDpCSaDDK+66ZntXFn35hgh1zXl/2m6Ttf0TiasfjLNg X+GQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=lbxHzMijQw7mL7Q1EwgegdzG4cyTaynJVs5wNTOjL+A=; b=yqiTF+syaZMuQr241jigiYtvoPn85aNESyPTKMdyIlsTPvpYYboCveagqK7lqen2UJ H6YtNXMmA++ZWHaXDeqngoqV9gBmj9+lu+Iv6KeD4YmyX6J7tV0R3NirIHQcXDwFb6wQ 4oY4iZrBb7YGJqW6ORogP9qZnCx7zjsTNwYCIsKY/7lDqSKiaZTg75s6aFPId4hhCrHd ap96OwpAH4OTr3uTGTAPgK+NXvijHDZYR87GhudRjlG03NCHKmA2FfKl77vVR62jWp/9 avKL16hlvDlPmToSHi9DgcOjZeicdKSTFpY4qMZcB4i4Pk2lJmE0qFK5bQD22RJrIwtg m36w== X-Gm-Message-State: AOAM5301LfoPOYqIPgRG5YZwkX4NCyA0d8t/xFRbjkANzIPGd+Iu1R5Z uqaZscW5U0P54Q4qAsvHp3YnciRPUfatlA== X-Google-Smtp-Source: ABdhPJy27teKZsTL/jzK7k4bPJD8jQkwNOLZ/i7+rOv6cRCT+OA9m55+UqOQ+S+SZJRcVgnvGih3Yw== X-Received: by 2002:a0c:d841:: with SMTP id i1mr21666195qvj.126.1638569902531; Fri, 03 Dec 2021 14:18:22 -0800 (PST) Received: from localhost (cpe-174-109-172-136.nc.res.rr.com. [174.109.172.136]) by smtp.gmail.com with ESMTPSA id f18sm3046281qko.34.2021.12.03.14.18.22 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 03 Dec 2021 14:18:22 -0800 (PST) From: Josef Bacik To: linux-btrfs@vger.kernel.org, kernel-team@fb.com Subject: [PATCH 01/18] btrfs: add an inode-item.h Date: Fri, 3 Dec 2021 17:18:03 -0500 Message-Id: X-Mailer: git-send-email 2.26.3 In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-btrfs@vger.kernel.org We have a few helpers in inode-item.c, and I'm going to make a few changes to how we do truncate in the future, so break out these definitions into their own header file to trim down ctree.h some and make it easier to do the work on truncate in the future. Signed-off-by: Josef Bacik --- fs/btrfs/ctree.h | 30 ------------------------------ fs/btrfs/delayed-inode.c | 1 + fs/btrfs/free-space-cache.c | 1 + fs/btrfs/inode-item.c | 1 + fs/btrfs/inode-item.h | 37 +++++++++++++++++++++++++++++++++++++ fs/btrfs/inode.c | 1 + fs/btrfs/relocation.c | 1 + fs/btrfs/tree-log.c | 1 + 8 files changed, 43 insertions(+), 30 deletions(-) create mode 100644 fs/btrfs/inode-item.h diff --git a/fs/btrfs/ctree.h b/fs/btrfs/ctree.h index dfee4b403da1..f33cae82e7dd 100644 --- a/fs/btrfs/ctree.h +++ b/fs/btrfs/ctree.h @@ -3126,36 +3126,6 @@ int btrfs_del_orphan_item(struct btrfs_trans_handle *trans, struct btrfs_root *root, u64 offset); int btrfs_find_orphan_item(struct btrfs_root *root, u64 offset); -/* inode-item.c */ -int btrfs_insert_inode_ref(struct btrfs_trans_handle *trans, - struct btrfs_root *root, - const char *name, int name_len, - u64 inode_objectid, u64 ref_objectid, u64 index); -int btrfs_del_inode_ref(struct btrfs_trans_handle *trans, - struct btrfs_root *root, - const char *name, int name_len, - u64 inode_objectid, u64 ref_objectid, u64 *index); -int btrfs_insert_empty_inode(struct btrfs_trans_handle *trans, - struct btrfs_root *root, - struct btrfs_path *path, u64 objectid); -int btrfs_lookup_inode(struct btrfs_trans_handle *trans, struct btrfs_root - *root, struct btrfs_path *path, - struct btrfs_key *location, int mod); - -struct btrfs_inode_extref * -btrfs_lookup_inode_extref(struct btrfs_trans_handle *trans, - struct btrfs_root *root, - struct btrfs_path *path, - const char *name, int name_len, - u64 inode_objectid, u64 ref_objectid, int ins_len, - int cow); - -struct btrfs_inode_ref *btrfs_find_name_in_backref(struct extent_buffer *leaf, - int slot, const char *name, - int name_len); -struct btrfs_inode_extref *btrfs_find_name_in_ext_backref( - struct extent_buffer *leaf, int slot, u64 ref_objectid, - const char *name, int name_len); /* file-item.c */ struct btrfs_dio_private; int btrfs_del_csums(struct btrfs_trans_handle *trans, diff --git a/fs/btrfs/delayed-inode.c b/fs/btrfs/delayed-inode.c index 6f134f2c5e68..748bf6b0d860 100644 --- a/fs/btrfs/delayed-inode.c +++ b/fs/btrfs/delayed-inode.c @@ -13,6 +13,7 @@ #include "ctree.h" #include "qgroup.h" #include "locking.h" +#include "inode-item.h" #define BTRFS_DELAYED_WRITEBACK 512 #define BTRFS_DELAYED_BACKGROUND 128 diff --git a/fs/btrfs/free-space-cache.c b/fs/btrfs/free-space-cache.c index 132209ff2262..55e1be703a39 100644 --- a/fs/btrfs/free-space-cache.c +++ b/fs/btrfs/free-space-cache.c @@ -23,6 +23,7 @@ #include "block-group.h" #include "discard.h" #include "subpage.h" +#include "inode-item.h" #define BITS_PER_BITMAP (PAGE_SIZE * 8UL) #define MAX_CACHE_BYTES_PER_GIG SZ_64K diff --git a/fs/btrfs/inode-item.c b/fs/btrfs/inode-item.c index 56755ce9a907..72593a93c43c 100644 --- a/fs/btrfs/inode-item.c +++ b/fs/btrfs/inode-item.c @@ -4,6 +4,7 @@ */ #include "ctree.h" +#include "inode-item.h" #include "disk-io.h" #include "transaction.h" #include "print-tree.h" diff --git a/fs/btrfs/inode-item.h b/fs/btrfs/inode-item.h new file mode 100644 index 000000000000..cb4b140e3b7d --- /dev/null +++ b/fs/btrfs/inode-item.h @@ -0,0 +1,37 @@ +/* SPDX-License-Identifier: GPL-2.0 */ + +#ifndef BTRFS_INODE_ITEM_H +#define BTRFS_INODE_ITEM_H + + +int btrfs_insert_inode_ref(struct btrfs_trans_handle *trans, + struct btrfs_root *root, + const char *name, int name_len, + u64 inode_objectid, u64 ref_objectid, u64 index); +int btrfs_del_inode_ref(struct btrfs_trans_handle *trans, + struct btrfs_root *root, + const char *name, int name_len, + u64 inode_objectid, u64 ref_objectid, u64 *index); +int btrfs_insert_empty_inode(struct btrfs_trans_handle *trans, + struct btrfs_root *root, + struct btrfs_path *path, u64 objectid); +int btrfs_lookup_inode(struct btrfs_trans_handle *trans, struct btrfs_root + *root, struct btrfs_path *path, + struct btrfs_key *location, int mod); + +struct btrfs_inode_extref * +btrfs_lookup_inode_extref(struct btrfs_trans_handle *trans, + struct btrfs_root *root, + struct btrfs_path *path, + const char *name, int name_len, + u64 inode_objectid, u64 ref_objectid, int ins_len, + int cow); + +struct btrfs_inode_ref *btrfs_find_name_in_backref(struct extent_buffer *leaf, + int slot, const char *name, + int name_len); +struct btrfs_inode_extref *btrfs_find_name_in_ext_backref( + struct extent_buffer *leaf, int slot, u64 ref_objectid, + const char *name, int name_len); + +#endif /* BTRFS_INODE_ITEM_H */ diff --git a/fs/btrfs/inode.c b/fs/btrfs/inode.c index 504cf090fc88..6ccdcf76b02f 100644 --- a/fs/btrfs/inode.c +++ b/fs/btrfs/inode.c @@ -54,6 +54,7 @@ #include "space-info.h" #include "zoned.h" #include "subpage.h" +#include "inode-item.h" struct btrfs_iget_args { u64 ino; diff --git a/fs/btrfs/relocation.c b/fs/btrfs/relocation.c index 775aff5a2c26..f5465197996d 100644 --- a/fs/btrfs/relocation.c +++ b/fs/btrfs/relocation.c @@ -26,6 +26,7 @@ #include "misc.h" #include "subpage.h" #include "zoned.h" +#include "inode-item.h" /* * Relocation overview diff --git a/fs/btrfs/tree-log.c b/fs/btrfs/tree-log.c index de79e15a7c6a..c7a7f78708d5 100644 --- a/fs/btrfs/tree-log.c +++ b/fs/btrfs/tree-log.c @@ -20,6 +20,7 @@ #include "block-group.h" #include "space-info.h" #include "zoned.h" +#include "inode-item.h" /* magic values for the inode_only field in btrfs_log_inode: * From patchwork Fri Dec 3 22:18:04 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Josef Bacik X-Patchwork-Id: 12655889 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 EEE49C433EF for ; Fri, 3 Dec 2021 22:18:28 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1383380AbhLCWVw (ORCPT ); Fri, 3 Dec 2021 17:21:52 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47798 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1383375AbhLCWVt (ORCPT ); Fri, 3 Dec 2021 17:21:49 -0500 Received: from mail-qt1-x831.google.com (mail-qt1-x831.google.com [IPv6:2607:f8b0:4864:20::831]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 0B6CDC061751 for ; Fri, 3 Dec 2021 14:18:25 -0800 (PST) Received: by mail-qt1-x831.google.com with SMTP id q14so4836523qtx.10 for ; Fri, 03 Dec 2021 14:18:25 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=toxicpanda-com.20210112.gappssmtp.com; s=20210112; h=from:to:subject:date:message-id:in-reply-to:references:mime-version :content-transfer-encoding; bh=RB4t9xLbGDhDjqgUyreo3pRFqHyScWHuy+U4/ANRGJ4=; b=WHRMqChA1Q0gLyKweYOM0ukzVqMTQ2p2UUipvqfRFyEEaQjJdHRDartdmTfx9uTTAC X67tTdneA/DtyFkwSPkOuRI3Cpqc7tVa00Xo7HZ0A7dpcnHuhN8JZUufqh8lpNXStcb1 ++u6p+bIGMV986QeHSj1smg74d3EJWlUNX7QRDhbAE6ddXL3YXM4A+2pa55Hf8/Tv0no X0ODjebR/55PJ2Dnv5O6hqUHamOnSniRF6XDyuJxNRfRNMnrCxKTs64hw3ELxYOlT9sE DbuCODWKyqy/nKl4Ns0jMs5vsGMUZEx88t1Ai0lUXEtC7qZzLLNCEv+iZNwOfxPc8KOL O8Bg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=RB4t9xLbGDhDjqgUyreo3pRFqHyScWHuy+U4/ANRGJ4=; b=TkSWu16GGKcgfKj0798OgTiM9f54p3m8Y6Szzy36UiuNrEblYCroMGiDfpQrtuoD8O Hb3gz6o60vpTd+SoFa/o5ipKonc1IIN0xeMqybqVNo2tSkOUQBi4oNfS0FHawbwdTzDd MrDaSb/9+YzrhZoMl4p0/MM8gjqcIzcrtHpFXMfMMytzVnJyZWPSKXJU/GFJ8RWofSI+ D1mwhv9ATchXTpcqFPccDoYDXzXjXLWbyJ36XxNFjWgMUov2w8LlzTVgnS5MRh6pSCtZ 9DjK2vGGz1r+ztgupsud1QilwIunPFwQCRS57dq2Z8gDwm4KDxvnrrERR4Ib0E+Ov8Fg kWtg== X-Gm-Message-State: AOAM533Smh2zsH+kAmZPIaL6PCmrRJHm6q6/j1L1Iu36fxm84f3s+c5u veKgYkhIjD3S9mp8abvU3d+6g3RA6K5z4Q== X-Google-Smtp-Source: ABdhPJxv0T3gizEicm+0ODZlV+gUoF/UdYZ0Q24pCOneNh3K0DAFBfzgxLW7OkGAnLu+sm7jY6701w== X-Received: by 2002:ac8:7dcd:: with SMTP id c13mr23920558qte.133.1638569903728; Fri, 03 Dec 2021 14:18:23 -0800 (PST) Received: from localhost (cpe-174-109-172-136.nc.res.rr.com. [174.109.172.136]) by smtp.gmail.com with ESMTPSA id bp38sm2896021qkb.66.2021.12.03.14.18.23 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 03 Dec 2021 14:18:23 -0800 (PST) From: Josef Bacik To: linux-btrfs@vger.kernel.org, kernel-team@fb.com Subject: [PATCH 02/18] btrfs: move btrfs_truncate_inode_items to inode-item.c Date: Fri, 3 Dec 2021 17:18:04 -0500 Message-Id: <036068f03e1d8a9a572e84198464f6de18eb8fe9.1638569556.git.josef@toxicpanda.com> X-Mailer: git-send-email 2.26.3 In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-btrfs@vger.kernel.org This is an inode item related manipulation with a few vfs related adjustments. I'm going to remove the vfs related code from this helper and simplify it a lot, but I want those changes to be easily seen via git blame, so move this function now and then the simplification work can be done. Signed-off-by: Josef Bacik --- fs/btrfs/ctree.h | 4 - fs/btrfs/inode-item.c | 377 ++++++++++++++++++++++++++++++++++++++++ fs/btrfs/inode-item.h | 9 + fs/btrfs/inode.c | 391 +----------------------------------------- 4 files changed, 390 insertions(+), 391 deletions(-) diff --git a/fs/btrfs/ctree.h b/fs/btrfs/ctree.h index f33cae82e7dd..02f06ee02e4e 100644 --- a/fs/btrfs/ctree.h +++ b/fs/btrfs/ctree.h @@ -3185,10 +3185,6 @@ int btrfs_add_link(struct btrfs_trans_handle *trans, int btrfs_delete_subvolume(struct inode *dir, struct dentry *dentry); int btrfs_truncate_block(struct btrfs_inode *inode, loff_t from, loff_t len, int front); -int btrfs_truncate_inode_items(struct btrfs_trans_handle *trans, - struct btrfs_root *root, - struct btrfs_inode *inode, u64 new_size, - u32 min_type, u64 *extents_found); int btrfs_start_delalloc_snapshot(struct btrfs_root *root, bool in_reclaim_context); int btrfs_start_delalloc_roots(struct btrfs_fs_info *fs_info, long nr, diff --git a/fs/btrfs/inode-item.c b/fs/btrfs/inode-item.c index 72593a93c43c..6e4b244ce96c 100644 --- a/fs/btrfs/inode-item.c +++ b/fs/btrfs/inode-item.c @@ -418,3 +418,380 @@ int btrfs_lookup_inode(struct btrfs_trans_handle *trans, struct btrfs_root } return ret; } + +/* + * Remove inode items from a given root. + * + * @trans: A transaction handle. + * @root: The root from which to remove items. + * @inode: The inode whose items we want to remove. + * @new_size: The new i_size for the inode. This is only applicable when + * @min_type is BTRFS_EXTENT_DATA_KEY, must be 0 otherwise. + * @min_type: The minimum key type to remove. All keys with a type + * greater than this value are removed and all keys with + * this type are removed only if their offset is >= @new_size. + * @extents_found: Output parameter that will contain the number of file + * extent items that were removed or adjusted to the new + * inode i_size. The caller is responsible for initializing + * the counter. Also, it can be NULL if the caller does not + * need this counter. + * + * Remove all keys associated with the inode from the given root that have a key + * with a type greater than or equals to @min_type. When @min_type has a value of + * BTRFS_EXTENT_DATA_KEY, only remove file extent items that have an offset value + * greater than or equals to @new_size. If a file extent item that starts before + * @new_size and ends after it is found, its length is adjusted. + * + * Returns: 0 on success, < 0 on error and NEED_TRUNCATE_BLOCK when @min_type is + * BTRFS_EXTENT_DATA_KEY and the caller must truncate the last block. + */ +int btrfs_truncate_inode_items(struct btrfs_trans_handle *trans, + struct btrfs_root *root, + struct btrfs_inode *inode, + u64 new_size, u32 min_type, + u64 *extents_found) +{ + struct btrfs_fs_info *fs_info = root->fs_info; + struct btrfs_path *path; + struct extent_buffer *leaf; + struct btrfs_file_extent_item *fi; + struct btrfs_key key; + struct btrfs_key found_key; + u64 extent_start = 0; + u64 extent_num_bytes = 0; + u64 extent_offset = 0; + u64 item_end = 0; + u64 last_size = new_size; + u32 found_type = (u8)-1; + int found_extent; + int del_item; + int pending_del_nr = 0; + int pending_del_slot = 0; + int extent_type = -1; + int ret; + u64 ino = btrfs_ino(inode); + u64 bytes_deleted = 0; + bool be_nice = false; + bool should_throttle = false; + const u64 lock_start = ALIGN_DOWN(new_size, fs_info->sectorsize); + struct extent_state *cached_state = NULL; + + BUG_ON(new_size > 0 && min_type != BTRFS_EXTENT_DATA_KEY); + + /* + * For non-free space inodes and non-shareable roots, we want to back + * off from time to time. This means all inodes in subvolume roots, + * reloc roots, and data reloc roots. + */ + if (!btrfs_is_free_space_inode(inode) && + test_bit(BTRFS_ROOT_SHAREABLE, &root->state)) + be_nice = true; + + path = btrfs_alloc_path(); + if (!path) + return -ENOMEM; + path->reada = READA_BACK; + + if (root->root_key.objectid != BTRFS_TREE_LOG_OBJECTID) { + lock_extent_bits(&inode->io_tree, lock_start, (u64)-1, + &cached_state); + + /* + * We want to drop from the next block forward in case this + * new size is not block aligned since we will be keeping the + * last block of the extent just the way it is. + */ + btrfs_drop_extent_cache(inode, ALIGN(new_size, + fs_info->sectorsize), + (u64)-1, 0); + } + + /* + * This function is also used to drop the items in the log tree before + * we relog the inode, so if root != BTRFS_I(inode)->root, it means + * it is used to drop the logged items. So we shouldn't kill the delayed + * items. + */ + if (min_type == 0 && root == inode->root) + btrfs_kill_delayed_inode_items(inode); + + key.objectid = ino; + key.offset = (u64)-1; + key.type = (u8)-1; + +search_again: + /* + * with a 16K leaf size and 128MB extents, you can actually queue + * up a huge file in a single leaf. Most of the time that + * bytes_deleted is > 0, it will be huge by the time we get here + */ + if (be_nice && bytes_deleted > SZ_32M && + btrfs_should_end_transaction(trans)) { + ret = -EAGAIN; + goto out; + } + + ret = btrfs_search_slot(trans, root, &key, path, -1, 1); + if (ret < 0) + goto out; + + if (ret > 0) { + ret = 0; + /* there are no items in the tree for us to truncate, we're + * done + */ + if (path->slots[0] == 0) + goto out; + path->slots[0]--; + } + + while (1) { + u64 clear_start = 0, clear_len = 0; + + fi = NULL; + leaf = path->nodes[0]; + btrfs_item_key_to_cpu(leaf, &found_key, path->slots[0]); + found_type = found_key.type; + + if (found_key.objectid != ino) + break; + + if (found_type < min_type) + break; + + item_end = found_key.offset; + if (found_type == BTRFS_EXTENT_DATA_KEY) { + fi = btrfs_item_ptr(leaf, path->slots[0], + struct btrfs_file_extent_item); + extent_type = btrfs_file_extent_type(leaf, fi); + if (extent_type != BTRFS_FILE_EXTENT_INLINE) { + item_end += + btrfs_file_extent_num_bytes(leaf, fi); + + trace_btrfs_truncate_show_fi_regular( + inode, leaf, fi, found_key.offset); + } else if (extent_type == BTRFS_FILE_EXTENT_INLINE) { + item_end += btrfs_file_extent_ram_bytes(leaf, + fi); + + trace_btrfs_truncate_show_fi_inline( + inode, leaf, fi, path->slots[0], + found_key.offset); + } + item_end--; + } + if (found_type > min_type) { + del_item = 1; + } else { + if (item_end < new_size) + break; + if (found_key.offset >= new_size) + del_item = 1; + else + del_item = 0; + } + found_extent = 0; + /* FIXME, shrink the extent if the ref count is only 1 */ + if (found_type != BTRFS_EXTENT_DATA_KEY) + goto delete; + + if (extents_found != NULL) + (*extents_found)++; + + if (extent_type != BTRFS_FILE_EXTENT_INLINE) { + u64 num_dec; + + clear_start = found_key.offset; + extent_start = btrfs_file_extent_disk_bytenr(leaf, fi); + if (!del_item) { + u64 orig_num_bytes = + btrfs_file_extent_num_bytes(leaf, fi); + extent_num_bytes = ALIGN(new_size - + found_key.offset, + fs_info->sectorsize); + clear_start = ALIGN(new_size, fs_info->sectorsize); + btrfs_set_file_extent_num_bytes(leaf, fi, + extent_num_bytes); + num_dec = (orig_num_bytes - + extent_num_bytes); + if (test_bit(BTRFS_ROOT_SHAREABLE, + &root->state) && + extent_start != 0) + inode_sub_bytes(&inode->vfs_inode, + num_dec); + btrfs_mark_buffer_dirty(leaf); + } else { + extent_num_bytes = + btrfs_file_extent_disk_num_bytes(leaf, + fi); + extent_offset = found_key.offset - + btrfs_file_extent_offset(leaf, fi); + + /* FIXME blocksize != 4096 */ + num_dec = btrfs_file_extent_num_bytes(leaf, fi); + if (extent_start != 0) { + found_extent = 1; + if (test_bit(BTRFS_ROOT_SHAREABLE, + &root->state)) + inode_sub_bytes(&inode->vfs_inode, + num_dec); + } + } + clear_len = num_dec; + } else if (extent_type == BTRFS_FILE_EXTENT_INLINE) { + /* + * we can't truncate inline items that have had + * special encodings + */ + if (!del_item && + btrfs_file_extent_encryption(leaf, fi) == 0 && + btrfs_file_extent_other_encoding(leaf, fi) == 0 && + btrfs_file_extent_compression(leaf, fi) == 0) { + u32 size = (u32)(new_size - found_key.offset); + + btrfs_set_file_extent_ram_bytes(leaf, fi, size); + size = btrfs_file_extent_calc_inline_size(size); + btrfs_truncate_item(path, size, 1); + } else if (!del_item) { + /* + * We have to bail so the last_size is set to + * just before this extent. + */ + ret = BTRFS_NEED_TRUNCATE_BLOCK; + break; + } else { + /* + * Inline extents are special, we just treat + * them as a full sector worth in the file + * extent tree just for simplicity sake. + */ + clear_len = fs_info->sectorsize; + } + + if (test_bit(BTRFS_ROOT_SHAREABLE, &root->state)) + inode_sub_bytes(&inode->vfs_inode, + item_end + 1 - new_size); + } +delete: + /* + * We use btrfs_truncate_inode_items() to clean up log trees for + * multiple fsyncs, and in this case we don't want to clear the + * file extent range because it's just the log. + */ + if (root == inode->root) { + ret = btrfs_inode_clear_file_extent_range(inode, + clear_start, clear_len); + if (ret) { + btrfs_abort_transaction(trans, ret); + break; + } + } + + if (del_item) + last_size = found_key.offset; + else + last_size = new_size; + if (del_item) { + if (!pending_del_nr) { + /* no pending yet, add ourselves */ + pending_del_slot = path->slots[0]; + pending_del_nr = 1; + } else if (pending_del_nr && + path->slots[0] + 1 == pending_del_slot) { + /* hop on the pending chunk */ + pending_del_nr++; + pending_del_slot = path->slots[0]; + } else { + BUG(); + } + } else { + break; + } + should_throttle = false; + + if (found_extent && + root->root_key.objectid != BTRFS_TREE_LOG_OBJECTID) { + struct btrfs_ref ref = { 0 }; + + bytes_deleted += extent_num_bytes; + + btrfs_init_generic_ref(&ref, BTRFS_DROP_DELAYED_REF, + extent_start, extent_num_bytes, 0); + btrfs_init_data_ref(&ref, btrfs_header_owner(leaf), + ino, extent_offset, + root->root_key.objectid, false); + ret = btrfs_free_extent(trans, &ref); + if (ret) { + btrfs_abort_transaction(trans, ret); + break; + } + if (be_nice) { + if (btrfs_should_throttle_delayed_refs(trans)) + should_throttle = true; + } + } + + if (found_type == BTRFS_INODE_ITEM_KEY) + break; + + if (path->slots[0] == 0 || + path->slots[0] != pending_del_slot || + should_throttle) { + if (pending_del_nr) { + ret = btrfs_del_items(trans, root, path, + pending_del_slot, + pending_del_nr); + if (ret) { + btrfs_abort_transaction(trans, ret); + break; + } + pending_del_nr = 0; + } + btrfs_release_path(path); + + /* + * We can generate a lot of delayed refs, so we need to + * throttle every once and a while and make sure we're + * adding enough space to keep up with the work we are + * generating. Since we hold a transaction here we + * can't flush, and we don't want to FLUSH_LIMIT because + * we could have generated too many delayed refs to + * actually allocate, so just bail if we're short and + * let the normal reservation dance happen higher up. + */ + if (should_throttle) { + ret = btrfs_delayed_refs_rsv_refill(fs_info, + BTRFS_RESERVE_NO_FLUSH); + if (ret) { + ret = -EAGAIN; + break; + } + } + goto search_again; + } else { + path->slots[0]--; + } + } +out: + if (ret >= 0 && pending_del_nr) { + int err; + + err = btrfs_del_items(trans, root, path, pending_del_slot, + pending_del_nr); + if (err) { + btrfs_abort_transaction(trans, err); + ret = err; + } + } + if (root->root_key.objectid != BTRFS_TREE_LOG_OBJECTID) { + ASSERT(last_size >= new_size); + if (!ret && last_size > new_size) + last_size = new_size; + btrfs_inode_safe_disk_i_size_write(inode, last_size); + unlock_extent_cached(&inode->io_tree, lock_start, (u64)-1, + &cached_state); + } + + btrfs_free_path(path); + return ret; +} diff --git a/fs/btrfs/inode-item.h b/fs/btrfs/inode-item.h index cb4b140e3b7d..63e8f45f110f 100644 --- a/fs/btrfs/inode-item.h +++ b/fs/btrfs/inode-item.h @@ -3,7 +3,16 @@ #ifndef BTRFS_INODE_ITEM_H #define BTRFS_INODE_ITEM_H +/* + * Return this if we need to call truncate_block for the last bit of the + * truncate. + */ +#define BTRFS_NEED_TRUNCATE_BLOCK 1 +int btrfs_truncate_inode_items(struct btrfs_trans_handle *trans, + struct btrfs_root *root, + struct btrfs_inode *inode, u64 new_size, + u32 min_type, u64 *extents_found); int btrfs_insert_inode_ref(struct btrfs_trans_handle *trans, struct btrfs_root *root, const char *name, int name_len, diff --git a/fs/btrfs/inode.c b/fs/btrfs/inode.c index 6ccdcf76b02f..c29e7c87ff27 100644 --- a/fs/btrfs/inode.c +++ b/fs/btrfs/inode.c @@ -4616,389 +4616,6 @@ static int btrfs_rmdir(struct inode *dir, struct dentry *dentry) return err; } -/* - * Return this if we need to call truncate_block for the last bit of the - * truncate. - */ -#define NEED_TRUNCATE_BLOCK 1 - -/* - * Remove inode items from a given root. - * - * @trans: A transaction handle. - * @root: The root from which to remove items. - * @inode: The inode whose items we want to remove. - * @new_size: The new i_size for the inode. This is only applicable when - * @min_type is BTRFS_EXTENT_DATA_KEY, must be 0 otherwise. - * @min_type: The minimum key type to remove. All keys with a type - * greater than this value are removed and all keys with - * this type are removed only if their offset is >= @new_size. - * @extents_found: Output parameter that will contain the number of file - * extent items that were removed or adjusted to the new - * inode i_size. The caller is responsible for initializing - * the counter. Also, it can be NULL if the caller does not - * need this counter. - * - * Remove all keys associated with the inode from the given root that have a key - * with a type greater than or equals to @min_type. When @min_type has a value of - * BTRFS_EXTENT_DATA_KEY, only remove file extent items that have an offset value - * greater than or equals to @new_size. If a file extent item that starts before - * @new_size and ends after it is found, its length is adjusted. - * - * Returns: 0 on success, < 0 on error and NEED_TRUNCATE_BLOCK when @min_type is - * BTRFS_EXTENT_DATA_KEY and the caller must truncate the last block. - */ -int btrfs_truncate_inode_items(struct btrfs_trans_handle *trans, - struct btrfs_root *root, - struct btrfs_inode *inode, - u64 new_size, u32 min_type, - u64 *extents_found) -{ - struct btrfs_fs_info *fs_info = root->fs_info; - struct btrfs_path *path; - struct extent_buffer *leaf; - struct btrfs_file_extent_item *fi; - struct btrfs_key key; - struct btrfs_key found_key; - u64 extent_start = 0; - u64 extent_num_bytes = 0; - u64 extent_offset = 0; - u64 item_end = 0; - u64 last_size = new_size; - u32 found_type = (u8)-1; - int found_extent; - int del_item; - int pending_del_nr = 0; - int pending_del_slot = 0; - int extent_type = -1; - int ret; - u64 ino = btrfs_ino(inode); - u64 bytes_deleted = 0; - bool be_nice = false; - bool should_throttle = false; - const u64 lock_start = ALIGN_DOWN(new_size, fs_info->sectorsize); - struct extent_state *cached_state = NULL; - - BUG_ON(new_size > 0 && min_type != BTRFS_EXTENT_DATA_KEY); - - /* - * For non-free space inodes and non-shareable roots, we want to back - * off from time to time. This means all inodes in subvolume roots, - * reloc roots, and data reloc roots. - */ - if (!btrfs_is_free_space_inode(inode) && - test_bit(BTRFS_ROOT_SHAREABLE, &root->state)) - be_nice = true; - - path = btrfs_alloc_path(); - if (!path) - return -ENOMEM; - path->reada = READA_BACK; - - if (root->root_key.objectid != BTRFS_TREE_LOG_OBJECTID) { - lock_extent_bits(&inode->io_tree, lock_start, (u64)-1, - &cached_state); - - /* - * We want to drop from the next block forward in case this - * new size is not block aligned since we will be keeping the - * last block of the extent just the way it is. - */ - btrfs_drop_extent_cache(inode, ALIGN(new_size, - fs_info->sectorsize), - (u64)-1, 0); - } - - /* - * This function is also used to drop the items in the log tree before - * we relog the inode, so if root != BTRFS_I(inode)->root, it means - * it is used to drop the logged items. So we shouldn't kill the delayed - * items. - */ - if (min_type == 0 && root == inode->root) - btrfs_kill_delayed_inode_items(inode); - - key.objectid = ino; - key.offset = (u64)-1; - key.type = (u8)-1; - -search_again: - /* - * with a 16K leaf size and 128MB extents, you can actually queue - * up a huge file in a single leaf. Most of the time that - * bytes_deleted is > 0, it will be huge by the time we get here - */ - if (be_nice && bytes_deleted > SZ_32M && - btrfs_should_end_transaction(trans)) { - ret = -EAGAIN; - goto out; - } - - ret = btrfs_search_slot(trans, root, &key, path, -1, 1); - if (ret < 0) - goto out; - - if (ret > 0) { - ret = 0; - /* there are no items in the tree for us to truncate, we're - * done - */ - if (path->slots[0] == 0) - goto out; - path->slots[0]--; - } - - while (1) { - u64 clear_start = 0, clear_len = 0; - - fi = NULL; - leaf = path->nodes[0]; - btrfs_item_key_to_cpu(leaf, &found_key, path->slots[0]); - found_type = found_key.type; - - if (found_key.objectid != ino) - break; - - if (found_type < min_type) - break; - - item_end = found_key.offset; - if (found_type == BTRFS_EXTENT_DATA_KEY) { - fi = btrfs_item_ptr(leaf, path->slots[0], - struct btrfs_file_extent_item); - extent_type = btrfs_file_extent_type(leaf, fi); - if (extent_type != BTRFS_FILE_EXTENT_INLINE) { - item_end += - btrfs_file_extent_num_bytes(leaf, fi); - - trace_btrfs_truncate_show_fi_regular( - inode, leaf, fi, found_key.offset); - } else if (extent_type == BTRFS_FILE_EXTENT_INLINE) { - item_end += btrfs_file_extent_ram_bytes(leaf, - fi); - - trace_btrfs_truncate_show_fi_inline( - inode, leaf, fi, path->slots[0], - found_key.offset); - } - item_end--; - } - if (found_type > min_type) { - del_item = 1; - } else { - if (item_end < new_size) - break; - if (found_key.offset >= new_size) - del_item = 1; - else - del_item = 0; - } - found_extent = 0; - /* FIXME, shrink the extent if the ref count is only 1 */ - if (found_type != BTRFS_EXTENT_DATA_KEY) - goto delete; - - if (extents_found != NULL) - (*extents_found)++; - - if (extent_type != BTRFS_FILE_EXTENT_INLINE) { - u64 num_dec; - - clear_start = found_key.offset; - extent_start = btrfs_file_extent_disk_bytenr(leaf, fi); - if (!del_item) { - u64 orig_num_bytes = - btrfs_file_extent_num_bytes(leaf, fi); - extent_num_bytes = ALIGN(new_size - - found_key.offset, - fs_info->sectorsize); - clear_start = ALIGN(new_size, fs_info->sectorsize); - btrfs_set_file_extent_num_bytes(leaf, fi, - extent_num_bytes); - num_dec = (orig_num_bytes - - extent_num_bytes); - if (test_bit(BTRFS_ROOT_SHAREABLE, - &root->state) && - extent_start != 0) - inode_sub_bytes(&inode->vfs_inode, - num_dec); - btrfs_mark_buffer_dirty(leaf); - } else { - extent_num_bytes = - btrfs_file_extent_disk_num_bytes(leaf, - fi); - extent_offset = found_key.offset - - btrfs_file_extent_offset(leaf, fi); - - /* FIXME blocksize != 4096 */ - num_dec = btrfs_file_extent_num_bytes(leaf, fi); - if (extent_start != 0) { - found_extent = 1; - if (test_bit(BTRFS_ROOT_SHAREABLE, - &root->state)) - inode_sub_bytes(&inode->vfs_inode, - num_dec); - } - } - clear_len = num_dec; - } else if (extent_type == BTRFS_FILE_EXTENT_INLINE) { - /* - * we can't truncate inline items that have had - * special encodings - */ - if (!del_item && - btrfs_file_extent_encryption(leaf, fi) == 0 && - btrfs_file_extent_other_encoding(leaf, fi) == 0 && - btrfs_file_extent_compression(leaf, fi) == 0) { - u32 size = (u32)(new_size - found_key.offset); - - btrfs_set_file_extent_ram_bytes(leaf, fi, size); - size = btrfs_file_extent_calc_inline_size(size); - btrfs_truncate_item(path, size, 1); - } else if (!del_item) { - /* - * We have to bail so the last_size is set to - * just before this extent. - */ - ret = NEED_TRUNCATE_BLOCK; - break; - } else { - /* - * Inline extents are special, we just treat - * them as a full sector worth in the file - * extent tree just for simplicity sake. - */ - clear_len = fs_info->sectorsize; - } - - if (test_bit(BTRFS_ROOT_SHAREABLE, &root->state)) - inode_sub_bytes(&inode->vfs_inode, - item_end + 1 - new_size); - } -delete: - /* - * We use btrfs_truncate_inode_items() to clean up log trees for - * multiple fsyncs, and in this case we don't want to clear the - * file extent range because it's just the log. - */ - if (root == inode->root) { - ret = btrfs_inode_clear_file_extent_range(inode, - clear_start, clear_len); - if (ret) { - btrfs_abort_transaction(trans, ret); - break; - } - } - - if (del_item) - last_size = found_key.offset; - else - last_size = new_size; - if (del_item) { - if (!pending_del_nr) { - /* no pending yet, add ourselves */ - pending_del_slot = path->slots[0]; - pending_del_nr = 1; - } else if (pending_del_nr && - path->slots[0] + 1 == pending_del_slot) { - /* hop on the pending chunk */ - pending_del_nr++; - pending_del_slot = path->slots[0]; - } else { - BUG(); - } - } else { - break; - } - should_throttle = false; - - if (found_extent && - root->root_key.objectid != BTRFS_TREE_LOG_OBJECTID) { - struct btrfs_ref ref = { 0 }; - - bytes_deleted += extent_num_bytes; - - btrfs_init_generic_ref(&ref, BTRFS_DROP_DELAYED_REF, - extent_start, extent_num_bytes, 0); - btrfs_init_data_ref(&ref, btrfs_header_owner(leaf), - ino, extent_offset, - root->root_key.objectid, false); - ret = btrfs_free_extent(trans, &ref); - if (ret) { - btrfs_abort_transaction(trans, ret); - break; - } - if (be_nice) { - if (btrfs_should_throttle_delayed_refs(trans)) - should_throttle = true; - } - } - - if (found_type == BTRFS_INODE_ITEM_KEY) - break; - - if (path->slots[0] == 0 || - path->slots[0] != pending_del_slot || - should_throttle) { - if (pending_del_nr) { - ret = btrfs_del_items(trans, root, path, - pending_del_slot, - pending_del_nr); - if (ret) { - btrfs_abort_transaction(trans, ret); - break; - } - pending_del_nr = 0; - } - btrfs_release_path(path); - - /* - * We can generate a lot of delayed refs, so we need to - * throttle every once and a while and make sure we're - * adding enough space to keep up with the work we are - * generating. Since we hold a transaction here we - * can't flush, and we don't want to FLUSH_LIMIT because - * we could have generated too many delayed refs to - * actually allocate, so just bail if we're short and - * let the normal reservation dance happen higher up. - */ - if (should_throttle) { - ret = btrfs_delayed_refs_rsv_refill(fs_info, - BTRFS_RESERVE_NO_FLUSH); - if (ret) { - ret = -EAGAIN; - break; - } - } - goto search_again; - } else { - path->slots[0]--; - } - } -out: - if (ret >= 0 && pending_del_nr) { - int err; - - err = btrfs_del_items(trans, root, path, pending_del_slot, - pending_del_nr); - if (err) { - btrfs_abort_transaction(trans, err); - ret = err; - } - } - if (root->root_key.objectid != BTRFS_TREE_LOG_OBJECTID) { - ASSERT(last_size >= new_size); - if (!ret && last_size > new_size) - last_size = new_size; - btrfs_inode_safe_disk_i_size_write(inode, last_size); - unlock_extent_cached(&inode->io_tree, lock_start, (u64)-1, - &cached_state); - } - - btrfs_free_path(path); - return ret; -} - /* * btrfs_truncate_block - read, zero a chunk and write a block * @inode - inode that we're zeroing @@ -8997,11 +8614,11 @@ static int btrfs_truncate(struct inode *inode, bool skip_writeback) /* * We can't call btrfs_truncate_block inside a trans handle as we could - * deadlock with freeze, if we got NEED_TRUNCATE_BLOCK then we know - * we've truncated everything except the last little bit, and can do - * btrfs_truncate_block and then update the disk_i_size. + * deadlock with freeze, if we got BTRFS_NEED_TRUNCATE_BLOCK then we + * know we've truncated everything except the last little bit, and can + * do btrfs_truncate_block and then update the disk_i_size. */ - if (ret == NEED_TRUNCATE_BLOCK) { + if (ret == BTRFS_NEED_TRUNCATE_BLOCK) { btrfs_end_transaction(trans); btrfs_btree_balance_dirty(fs_info); From patchwork Fri Dec 3 22:18:05 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Josef Bacik X-Patchwork-Id: 12655893 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 8B7C4C433FE for ; Fri, 3 Dec 2021 22:18:29 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1383381AbhLCWVw (ORCPT ); Fri, 3 Dec 2021 17:21:52 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47800 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1383378AbhLCWVu (ORCPT ); Fri, 3 Dec 2021 17:21:50 -0500 Received: from mail-qk1-x72b.google.com (mail-qk1-x72b.google.com [IPv6:2607:f8b0:4864:20::72b]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id F242AC061353 for ; Fri, 3 Dec 2021 14:18:25 -0800 (PST) Received: by mail-qk1-x72b.google.com with SMTP id 193so4969180qkh.10 for ; Fri, 03 Dec 2021 14:18:25 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=toxicpanda-com.20210112.gappssmtp.com; s=20210112; h=from:to:subject:date:message-id:in-reply-to:references:mime-version :content-transfer-encoding; bh=1LwK30TqGgFDmXlbggxhf5z1dOgxczE8yANuERgWp+M=; b=gqIbYdy3584b9ck1ZW6ggdWZoy+RnlJcQWQ3CLyj4ZlcrOuN+GHxopUpdMk4dnutaI 4RE5SsniAT8zHwQAglkOm+2rNx7n1wpeGshRIyCRqh6MXumvA5cF8+SN4//HyCg0GHxv s++LM3TKajO3sMofR/kB0Tqmpvl3zTQRPwaQFB8SuRY+ILsT6jtcsGttVDg9W8h4jFFr Fh5LzbgKylt2k53m+LQfyquei8kJrbuA8CG75+lVpciCI6GrLeodg8tXEr4rANrMkXvP DU79LT0uv1MHBJme7IyjlDr3l1n7E/ySCUW5La1U8goyTzVENjfrmxLGD0dTyk0KWm0v dnQQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=1LwK30TqGgFDmXlbggxhf5z1dOgxczE8yANuERgWp+M=; b=JXQ/qoAyTb9jt67wM49PVAb7aEBH1wKWViQTX0aSMeOQ8OIOL+/Ja+4vhw37tMPHBb 4e94ogG/JrEW+BpdTdZSyLFAgeefvNUGed0PN4HjZWh47bjWAsoPjvIq6QgVkDBGs1lD NpnnbeC0gWklQ4hNcxB76B0Ihnr5wfwnI/BVgO157Py0B4tiLAiYXKML7UNMZmYaTjQY wj1ksSpa9I1LVMjS9KULB8y/JB3Fmg5jyuItDxsecS8ys3baSePBaHuSKgXsE8QJgiGv IAcY1Sx5gDFuwm5rK5lASlGwPo4ST9eTMgbZI8iTeH32W0POLPOvkOvswYxiZiJL3EFA tAdQ== X-Gm-Message-State: AOAM531A/WQqvKiDNm7paDe7+salZ1iNmnA27tJvWQdJFIdVxO5tLZNV vLSa+3SszMElCxuBAGBtZYBdXo2enWz9ow== X-Google-Smtp-Source: ABdhPJwkHnZfXx0TwNnNRbHWlSb8ZLOx81JCKBZUI5OxMYD/Z+UyWB1l8fYnF1oruDNetQmh/Hz1Xg== X-Received: by 2002:a05:620a:22d7:: with SMTP id o23mr19779262qki.222.1638569904901; Fri, 03 Dec 2021 14:18:24 -0800 (PST) Received: from localhost (cpe-174-109-172-136.nc.res.rr.com. [174.109.172.136]) by smtp.gmail.com with ESMTPSA id u11sm2772791qko.33.2021.12.03.14.18.24 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 03 Dec 2021 14:18:24 -0800 (PST) From: Josef Bacik To: linux-btrfs@vger.kernel.org, kernel-team@fb.com Subject: [PATCH 03/18] btrfs: move extent locking outside of btrfs_truncate_inode_items Date: Fri, 3 Dec 2021 17:18:05 -0500 Message-Id: <7e0b2245f997b01d45747bc1a68176016402ce9f.1638569556.git.josef@toxicpanda.com> X-Mailer: git-send-email 2.26.3 In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-btrfs@vger.kernel.org Currently we are locking the extent and dropping the extent cache for any inodes we truncate, unless they're in the tree log. We call this helper from - truncate - evict - tree log - free space cache truncation For evict we've already dropped all of the extent cache for this inode once we've gotten here, and we're the only one accessing this inode, so this step is unnecessary. For the tree log code we already skip this part. Pull this work into the truncate path and the free space cache truncation path. Signed-off-by: Josef Bacik --- fs/btrfs/free-space-cache.c | 20 +++++++++++++------- fs/btrfs/inode-item.c | 18 ------------------ fs/btrfs/inode.c | 18 ++++++++++++++++++ 3 files changed, 31 insertions(+), 25 deletions(-) diff --git a/fs/btrfs/free-space-cache.c b/fs/btrfs/free-space-cache.c index 55e1be703a39..28b9c63ba536 100644 --- a/fs/btrfs/free-space-cache.c +++ b/fs/btrfs/free-space-cache.c @@ -289,9 +289,11 @@ int btrfs_check_trunc_cache_free_space(struct btrfs_fs_info *fs_info, int btrfs_truncate_free_space_cache(struct btrfs_trans_handle *trans, struct btrfs_block_group *block_group, - struct inode *inode) + struct inode *vfs_inode) { - struct btrfs_root *root = BTRFS_I(inode)->root; + struct btrfs_inode *inode = BTRFS_I(vfs_inode); + struct btrfs_root *root = inode->root; + struct extent_state *cached_state = NULL; int ret = 0; bool locked = false; @@ -321,19 +323,23 @@ int btrfs_truncate_free_space_cache(struct btrfs_trans_handle *trans, btrfs_free_path(path); } - btrfs_i_size_write(BTRFS_I(inode), 0); - truncate_pagecache(inode, 0); + btrfs_i_size_write(inode, 0); + truncate_pagecache(vfs_inode, 0); + + lock_extent_bits(&inode->io_tree, 0, (u64)-1, &cached_state); + btrfs_drop_extent_cache(inode, 0, (u64)-1, 0); /* * We skip the throttling logic for free space cache inodes, so we don't * need to check for -EAGAIN. */ - ret = btrfs_truncate_inode_items(trans, root, BTRFS_I(inode), - 0, BTRFS_EXTENT_DATA_KEY, NULL); + ret = btrfs_truncate_inode_items(trans, root, inode, 0, + BTRFS_EXTENT_DATA_KEY, NULL); + unlock_extent_cached(&inode->io_tree, 0, (u64)-1, &cached_state); if (ret) goto fail; - ret = btrfs_update_inode(trans, root, BTRFS_I(inode)); + ret = btrfs_update_inode(trans, root, inode); fail: if (locked) diff --git a/fs/btrfs/inode-item.c b/fs/btrfs/inode-item.c index 6e4b244ce96c..124f952ab9f2 100644 --- a/fs/btrfs/inode-item.c +++ b/fs/btrfs/inode-item.c @@ -473,8 +473,6 @@ int btrfs_truncate_inode_items(struct btrfs_trans_handle *trans, u64 bytes_deleted = 0; bool be_nice = false; bool should_throttle = false; - const u64 lock_start = ALIGN_DOWN(new_size, fs_info->sectorsize); - struct extent_state *cached_state = NULL; BUG_ON(new_size > 0 && min_type != BTRFS_EXTENT_DATA_KEY); @@ -492,20 +490,6 @@ int btrfs_truncate_inode_items(struct btrfs_trans_handle *trans, return -ENOMEM; path->reada = READA_BACK; - if (root->root_key.objectid != BTRFS_TREE_LOG_OBJECTID) { - lock_extent_bits(&inode->io_tree, lock_start, (u64)-1, - &cached_state); - - /* - * We want to drop from the next block forward in case this - * new size is not block aligned since we will be keeping the - * last block of the extent just the way it is. - */ - btrfs_drop_extent_cache(inode, ALIGN(new_size, - fs_info->sectorsize), - (u64)-1, 0); - } - /* * This function is also used to drop the items in the log tree before * we relog the inode, so if root != BTRFS_I(inode)->root, it means @@ -788,8 +772,6 @@ int btrfs_truncate_inode_items(struct btrfs_trans_handle *trans, if (!ret && last_size > new_size) last_size = new_size; btrfs_inode_safe_disk_i_size_write(inode, last_size); - unlock_extent_cached(&inode->io_tree, lock_start, (u64)-1, - &cached_state); } btrfs_free_path(path); diff --git a/fs/btrfs/inode.c b/fs/btrfs/inode.c index c29e7c87ff27..da474791da23 100644 --- a/fs/btrfs/inode.c +++ b/fs/btrfs/inode.c @@ -8583,10 +8583,28 @@ static int btrfs_truncate(struct inode *inode, bool skip_writeback) trans->block_rsv = rsv; while (1) { + struct extent_state *cached_state = NULL; + const u64 new_size = inode->i_size; + const u64 lock_start = ALIGN_DOWN(new_size, fs_info->sectorsize); + + lock_extent_bits(&BTRFS_I(inode)->io_tree, lock_start, (u64)-1, + &cached_state); + /* + * We want to drop from the next block forward in case this + * new size is not block aligned since we will be keeping the + * last block of the extent just the way it is. + */ + btrfs_drop_extent_cache(BTRFS_I(inode), + ALIGN(new_size, fs_info->sectorsize), + (u64)-1, 0); + ret = btrfs_truncate_inode_items(trans, root, BTRFS_I(inode), inode->i_size, BTRFS_EXTENT_DATA_KEY, &extents_found); + unlock_extent_cached(&BTRFS_I(inode)->io_tree, lock_start, + (u64)-1, &cached_state); + trans->block_rsv = &fs_info->trans_block_rsv; if (ret != -ENOSPC && ret != -EAGAIN) break; From patchwork Fri Dec 3 22:18:06 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Josef Bacik X-Patchwork-Id: 12655891 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 3D989C4332F for ; Fri, 3 Dec 2021 22:18:30 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1383383AbhLCWVx (ORCPT ); Fri, 3 Dec 2021 17:21:53 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47808 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1383379AbhLCWVv (ORCPT ); Fri, 3 Dec 2021 17:21:51 -0500 Received: from mail-qk1-x72e.google.com (mail-qk1-x72e.google.com [IPv6:2607:f8b0:4864:20::72e]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 4A047C061751 for ; Fri, 3 Dec 2021 14:18:27 -0800 (PST) Received: by mail-qk1-x72e.google.com with SMTP id t83so4987918qke.8 for ; Fri, 03 Dec 2021 14:18:27 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=toxicpanda-com.20210112.gappssmtp.com; s=20210112; h=from:to:subject:date:message-id:in-reply-to:references:mime-version :content-transfer-encoding; bh=Bo2RX6LdV5hpF2DCxD00VCy1MjzWbZWSCledozZeJ1k=; b=Ol6dtPL79NrtwntR99dTW3B1IfMxgckJuqty7jkOUpVkQMEJsVmlbOJ370RWGlPXiX Rc+IACZ2ffFK6FcVmgdwLn2mvi8BHMlgXt1UHlGfxUhBGF+JKVLGxGX2D2ld7whYC8KP H3nz7QL4M7DCL/5SVigROnKghbB7e3eQSXd2vDvU6WxCUCMif0H/iymo1qXlW0z7pzvu nAIGeCi5NsRcJfW2WJrSTh2jTfNyGrcOks1cxnTZNPq+ZXIq6NeE9pPtx0jlZhMAodEv ItGksytngUwl5zaRLfh3A9162O8Ca2kSPhz15yrb8dszWRsKYGh/o1DcYP8PJKS849z6 Qj2A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=Bo2RX6LdV5hpF2DCxD00VCy1MjzWbZWSCledozZeJ1k=; b=QEo4Mg3y9jP92tmTirWbPYytyPVgoRIwEhMf61aFH/v0eXgNDKqfqZq9JW326sjcpB QwxI23Ohv87gx/N/fwkzOTEZvGmJwemXoArkkz3p0Rvyc8ltt/xPBQln+F0/v1IawClQ k4vkEmWVg7RJl+q/i9GHQ5eZaLWsuifn1qeZwyf6vgIgt3GNPIXI7CJN/pRIOhtlFatN eVPyxdo3kNBmPHul3bFLH/sGpIiR37R+rmFilFCzFf7E2/FBRKjIYbDdf5Qqz0oxrbJT jWYl23HwmPcnkokJ4axQYr4Ipk2jXKsma6W+98306mbWc/kOu5p8HuopmovvXFj7I0iM rteA== X-Gm-Message-State: AOAM531RdD4sC3FaffM+/1is8zuyv2VTlWCilsl/7RSW5ghIi2lc4MAV vMbg8zsYGUMi2AA5VG3JvMshu9wq4IEA5g== X-Google-Smtp-Source: ABdhPJzz7U0EzIlyeohp6Mc2bDuwLoxLsOolOKoXXbB792fmUlgva9mJA+JDvDcwL9KuwPOyoTU3Tw== X-Received: by 2002:a05:620a:20d6:: with SMTP id f22mr20444621qka.342.1638569906216; Fri, 03 Dec 2021 14:18:26 -0800 (PST) Received: from localhost (cpe-174-109-172-136.nc.res.rr.com. [174.109.172.136]) by smtp.gmail.com with ESMTPSA id az16sm3047770qkb.124.2021.12.03.14.18.25 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 03 Dec 2021 14:18:25 -0800 (PST) From: Josef Bacik To: linux-btrfs@vger.kernel.org, kernel-team@fb.com Subject: [PATCH 04/18] btrfs: remove free space cache inode check in btrfs_truncate_inode_items Date: Fri, 3 Dec 2021 17:18:06 -0500 Message-Id: <97ccab84acd52af25e981952ead9a45c09f5348a.1638569556.git.josef@toxicpanda.com> X-Mailer: git-send-email 2.26.3 In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-btrfs@vger.kernel.org We no longer have inode cache, so this check is extraneous as the only inode cache is in the tree_root, which is not marked as SHAREABLE. Signed-off-by: Josef Bacik --- fs/btrfs/inode-item.c | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/fs/btrfs/inode-item.c b/fs/btrfs/inode-item.c index 124f952ab9f2..ee7ac75ed6c8 100644 --- a/fs/btrfs/inode-item.c +++ b/fs/btrfs/inode-item.c @@ -477,12 +477,10 @@ int btrfs_truncate_inode_items(struct btrfs_trans_handle *trans, BUG_ON(new_size > 0 && min_type != BTRFS_EXTENT_DATA_KEY); /* - * For non-free space inodes and non-shareable roots, we want to back - * off from time to time. This means all inodes in subvolume roots, - * reloc roots, and data reloc roots. + * For shareable roots we want to back off from time to time, this turns + * out to be subvolume roots, reloc roots, and data reloc roots. */ - if (!btrfs_is_free_space_inode(inode) && - test_bit(BTRFS_ROOT_SHAREABLE, &root->state)) + if (test_bit(BTRFS_ROOT_SHAREABLE, &root->state)) be_nice = true; path = btrfs_alloc_path(); From patchwork Fri Dec 3 22:18:07 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Josef Bacik X-Patchwork-Id: 12655895 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 EF780C433F5 for ; Fri, 3 Dec 2021 22:18:30 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1383384AbhLCWVy (ORCPT ); Fri, 3 Dec 2021 17:21:54 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47812 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1383382AbhLCWVx (ORCPT ); Fri, 3 Dec 2021 17:21:53 -0500 Received: from mail-qk1-x729.google.com (mail-qk1-x729.google.com [IPv6:2607:f8b0:4864:20::729]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 966F5C061751 for ; Fri, 3 Dec 2021 14:18:28 -0800 (PST) Received: by mail-qk1-x729.google.com with SMTP id i9so5002110qki.3 for ; Fri, 03 Dec 2021 14:18:28 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=toxicpanda-com.20210112.gappssmtp.com; s=20210112; h=from:to:subject:date:message-id:in-reply-to:references:mime-version :content-transfer-encoding; bh=Hdk6IGC1r5OdjW/6E849de+YzzXb1kC1ZOVBZF+BkbU=; b=7CiBZrHbZK0ZZN73TO2RjM10lkHc9q8WOqqGNJQAT/MtXg/ElJvFHz2EVa1Z3nJ8PN nSGQq65dEGuNRM+Pexue1CE5VHWDHgstlvgvYrzGN/PwJtzWsHuMm7vVXIOt/ulkxvnB asOcyr1JdlGFwUXqd8pgjfsHzXRBtoMZU75UpGYQe9j0FHuAz2PmJS+/tOubwNFrzeg2 REdIZIF+4NuFxZvBf2TBnj5A73Rqeuw+maMF8woDB+xf+IdXnQMoAU53kcB5ph9FVva/ kpZNYA5rW7DqUf6RFJ69kiM9XiBrGjXEisyJl0g9gw6Qgbse6QXa/wkBts+qmTtkuzYR otiQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=Hdk6IGC1r5OdjW/6E849de+YzzXb1kC1ZOVBZF+BkbU=; b=y81Tnjs7T6jxljZ58PQsTFVIbf+m3VGmluJpDh4Yzm9y6uT34H9FuTQOyspXFwWMoO eFWXJpq1MDI1g9mlIzGzwlI0EZZIBTvGrnXKgH3O58ZqXNVafi587PQnqCMmBZMj3FxS A41E+RwXszFEB3UPAgRcoPZPSwE5FYTMzRwO5J88KCyPe2NSCKFb+9VbLVqF/zV0LF0c HkKh1RKCdIziIWlSpKNhn3YhzgJvdM0/IG6NNpRorwObA7Ph4Kao6c/7Fu9iByGOrkH3 ZEincf2oluIYDyhiowrtf/h8zeIEa+E1eTfgKuYxh/xv2ZKhudKAdpCqNDDwJY/KI5f+ OAkg== X-Gm-Message-State: AOAM5339JfG/Mx19HryKQLoa4aAkliCr0xBvMr2jc+TMCeYvG77t/Gdc FT3XxJKnTf2Um8A7dYeRcn97s1QznrRHHA== X-Google-Smtp-Source: ABdhPJxLYX5rxLup8lnzwb5zih4Ro6RLFx72nuEkAITb1VqagDthx558V9FZKmqI2fbm1LfH+iTlLQ== X-Received: by 2002:a05:620a:8d4:: with SMTP id z20mr19715219qkz.526.1638569907474; Fri, 03 Dec 2021 14:18:27 -0800 (PST) Received: from localhost (cpe-174-109-172-136.nc.res.rr.com. [174.109.172.136]) by smtp.gmail.com with ESMTPSA id y6sm3053524qtn.23.2021.12.03.14.18.26 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 03 Dec 2021 14:18:27 -0800 (PST) From: Josef Bacik To: linux-btrfs@vger.kernel.org, kernel-team@fb.com Subject: [PATCH 05/18] btrfs: move btrfs_kill_delayed_inode_items into evict Date: Fri, 3 Dec 2021 17:18:07 -0500 Message-Id: <108dc02e55b99c09e8544052c9981585693710aa.1638569556.git.josef@toxicpanda.com> X-Mailer: git-send-email 2.26.3 In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-btrfs@vger.kernel.org We have a special case in btrfs_truncate_inode_items() to call btrfs_kill_delayed_inode_items() if min_type == 0, which is only called during evict. Instead move this out into evict proper, and add some comments because I erroneously attempted to remove this code altogether without understanding what we were doing. Evict is updating the inode only because we only care about making sure the i_nlink count has hit disk. If we had pending deletions we don't want to process those via the delayed inode updates, we simply want to drop all of them and reclaim the reserved metadata space. Then from there the btrfs_truncate_inode_items() will do the work to remove all of the items as appropriate. Signed-off-by: Josef Bacik --- fs/btrfs/inode-item.c | 9 --------- fs/btrfs/inode.c | 12 ++++++++++++ 2 files changed, 12 insertions(+), 9 deletions(-) diff --git a/fs/btrfs/inode-item.c b/fs/btrfs/inode-item.c index ee7ac75ed6c8..bc59f80510ad 100644 --- a/fs/btrfs/inode-item.c +++ b/fs/btrfs/inode-item.c @@ -488,15 +488,6 @@ int btrfs_truncate_inode_items(struct btrfs_trans_handle *trans, return -ENOMEM; path->reada = READA_BACK; - /* - * This function is also used to drop the items in the log tree before - * we relog the inode, so if root != BTRFS_I(inode)->root, it means - * it is used to drop the logged items. So we shouldn't kill the delayed - * items. - */ - if (min_type == 0 && root == inode->root) - btrfs_kill_delayed_inode_items(inode); - key.objectid = ino; key.offset = (u64)-1; key.type = (u8)-1; diff --git a/fs/btrfs/inode.c b/fs/btrfs/inode.c index da474791da23..73bb7acf6813 100644 --- a/fs/btrfs/inode.c +++ b/fs/btrfs/inode.c @@ -5226,10 +5226,22 @@ void btrfs_evict_inode(struct inode *inode) goto no_delete; } + /* + * This makes sure the inode item in tree is uptodate and the space for + * the inode update is released. + */ ret = btrfs_commit_inode_delayed_inode(BTRFS_I(inode)); if (ret) goto no_delete; + /* + * This drops any pending insert or delete operations we have for this + * inode. We could have a delayed dir index deletion queued up, but + * we're removing the inode completely so that'll be taken care of in + * the truncate. + */ + btrfs_kill_delayed_inode_items(BTRFS_I(inode)); + rsv = btrfs_alloc_block_rsv(fs_info, BTRFS_BLOCK_RSV_TEMP); if (!rsv) goto no_delete; From patchwork Fri Dec 3 22:18:08 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Josef Bacik X-Patchwork-Id: 12655897 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 CD7F2C43219 for ; Fri, 3 Dec 2021 22:18:31 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1383386AbhLCWVz (ORCPT ); Fri, 3 Dec 2021 17:21:55 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47822 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1383382AbhLCWVy (ORCPT ); Fri, 3 Dec 2021 17:21:54 -0500 Received: from mail-qt1-x831.google.com (mail-qt1-x831.google.com [IPv6:2607:f8b0:4864:20::831]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 1340BC061751 for ; Fri, 3 Dec 2021 14:18:30 -0800 (PST) Received: by mail-qt1-x831.google.com with SMTP id 8so4853166qtx.5 for ; Fri, 03 Dec 2021 14:18:30 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=toxicpanda-com.20210112.gappssmtp.com; s=20210112; h=from:to:subject:date:message-id:in-reply-to:references:mime-version :content-transfer-encoding; bh=XqAIWxCeVhJhfycau7RWLN/sT+F//qXYcejmX7pU5BU=; b=C4E6uG253angtZQtHZzduHp+ByJZETwUyGdqHS4ANBDo7/c0QLYFZXOBfW6/0BLel0 ddv6p4DeOP6tCvK6VT4MIpmIKc+jkenC+vqc/U5PyUrsWZDuKv61o1uXg9HMHGU1OG4F xkVtGRS8+vmwXjOHD35Z1cJhz1MnsjUCq8PLVbyQ1WCder06MDejyuncnPjxJKCOTMDP CvvmuhaUdRumRQSxbZrmf5uoB1bF5vX74NQKKjFg5Jj0AcZUEWkL73n/AgxIPLns3lBH bpjQ8y28RHg5jJXoEw6AaoVvDJmy4mR+idjO4rlcPi0U4jzTQTvCF+dCe6vwSnzuuC4K dnjw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=XqAIWxCeVhJhfycau7RWLN/sT+F//qXYcejmX7pU5BU=; b=N6cWe3ISNEw3d4yXABp+n11d61wmuNdoWmM1oUCwRKOMV5IEf+phVbUEWLCcpPZOFQ 5L60d8YZ0eIYMsIoKyzus1sD+png14kfYpmTyIdn/b+/mUqopS6GQB5l0VDGrrajbU5w I0h93RsQYIhsKWUMJXqWxjax2IEsm+iIf41o7STcY4DLNhpuPQpqPm83mxby/fYvUJYe CTFQiyR0lj+o/wQyq4fiMHVcqqyr0fcllPlOQL7sDKa6JtOKMYpkkDSVEj25GCdTK+F8 pJL2N645JvGKJaPX11da50tNKKrsbZD+15+wTgJ1D3WPoBdAHh4vBF6A3MZ9hXz84Kw3 0hmQ== X-Gm-Message-State: AOAM532h38PIFLHBWYE3BZLNwTprCvmvLQujNTKwMlmL8rV0R4xKglK2 i39wGRbaXPhE0JqIbJD2VYx0MHZONM3sQg== X-Google-Smtp-Source: ABdhPJxLqpkZBINa/KEyLlQbPOZh2ZBHfAvc7kSRmeUDSgSZl8hL68I/rkzVLmCuhCh7CPFRjqOk6w== X-Received: by 2002:ac8:5990:: with SMTP id e16mr23797650qte.615.1638569908815; Fri, 03 Dec 2021 14:18:28 -0800 (PST) Received: from localhost (cpe-174-109-172-136.nc.res.rr.com. [174.109.172.136]) by smtp.gmail.com with ESMTPSA id m4sm3149260qtu.87.2021.12.03.14.18.28 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 03 Dec 2021 14:18:28 -0800 (PST) From: Josef Bacik To: linux-btrfs@vger.kernel.org, kernel-team@fb.com Subject: [PATCH 06/18] btrfs: remove found_extent from btrfs_truncate_inode_items Date: Fri, 3 Dec 2021 17:18:08 -0500 Message-Id: X-Mailer: git-send-email 2.26.3 In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-btrfs@vger.kernel.org We only set this if we find a normal file extent, del_item == 1, and the file extent points to a real extent and isn't a hole extent. We can use del_item == 1 && extent_start != 0 to get the same information that found_extent provides, so remove this variable and use the other variables instead. Signed-off-by: Josef Bacik --- fs/btrfs/inode-item.c | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/fs/btrfs/inode-item.c b/fs/btrfs/inode-item.c index bc59f80510ad..8afc8d1c607b 100644 --- a/fs/btrfs/inode-item.c +++ b/fs/btrfs/inode-item.c @@ -457,13 +457,11 @@ int btrfs_truncate_inode_items(struct btrfs_trans_handle *trans, struct btrfs_file_extent_item *fi; struct btrfs_key key; struct btrfs_key found_key; - u64 extent_start = 0; u64 extent_num_bytes = 0; u64 extent_offset = 0; u64 item_end = 0; u64 last_size = new_size; u32 found_type = (u8)-1; - int found_extent; int del_item; int pending_del_nr = 0; int pending_del_slot = 0; @@ -519,7 +517,7 @@ int btrfs_truncate_inode_items(struct btrfs_trans_handle *trans, } while (1) { - u64 clear_start = 0, clear_len = 0; + u64 clear_start = 0, clear_len = 0, extent_start = 0; fi = NULL; leaf = path->nodes[0]; @@ -563,7 +561,7 @@ int btrfs_truncate_inode_items(struct btrfs_trans_handle *trans, else del_item = 0; } - found_extent = 0; + /* FIXME, shrink the extent if the ref count is only 1 */ if (found_type != BTRFS_EXTENT_DATA_KEY) goto delete; @@ -603,7 +601,6 @@ int btrfs_truncate_inode_items(struct btrfs_trans_handle *trans, /* FIXME blocksize != 4096 */ num_dec = btrfs_file_extent_num_bytes(leaf, fi); if (extent_start != 0) { - found_extent = 1; if (test_bit(BTRFS_ROOT_SHAREABLE, &root->state)) inode_sub_bytes(&inode->vfs_inode, @@ -682,7 +679,7 @@ int btrfs_truncate_inode_items(struct btrfs_trans_handle *trans, } should_throttle = false; - if (found_extent && + if (del_item && extent_start != 0 && root->root_key.objectid != BTRFS_TREE_LOG_OBJECTID) { struct btrfs_ref ref = { 0 }; From patchwork Fri Dec 3 22:18:09 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Josef Bacik X-Patchwork-Id: 12655899 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 091F0C433EF for ; Fri, 3 Dec 2021 22:18:33 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1383388AbhLCWV4 (ORCPT ); Fri, 3 Dec 2021 17:21:56 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47828 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1383382AbhLCWVz (ORCPT ); Fri, 3 Dec 2021 17:21:55 -0500 Received: from mail-qt1-x82b.google.com (mail-qt1-x82b.google.com [IPv6:2607:f8b0:4864:20::82b]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 4CF5BC061751 for ; Fri, 3 Dec 2021 14:18:31 -0800 (PST) Received: by mail-qt1-x82b.google.com with SMTP id t34so4837300qtc.7 for ; Fri, 03 Dec 2021 14:18:31 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=toxicpanda-com.20210112.gappssmtp.com; s=20210112; h=from:to:subject:date:message-id:in-reply-to:references:mime-version :content-transfer-encoding; bh=ZS+ol8O8pmIgXaXsYBrUfZI8GDYZiX0j1omdO4gu9sA=; b=1XhZgpRFCBSIvwBL3Nwv0ymhmYQ3j7jpWqEXp7PjvVV1M3TQwW20yDKqUPCz2jTNVN rGY77yleCbuFFkJ0dZLsCZpbe6I0b2+wQeJVIrtwYw+3bTuFLiZD6voXwSnaXWuYu54b 9v9eOt6BVVK0mhtjwecdl5bMcUFZMdrVGerFfRDlsHMqoYW7apzvcNmX1BKq7AtCFRTR nymWt76G6r3QgXjDHweEdy/zx2foOqm3LhPBRBlilK8l5Lcbms/ry5PNiE3aSSrG4lbO xUK1aWDRC114YBgHwYqcJLMZfjFETm9k4GAv2WmZTjh/j20i5qcSjWWNK7L44ObgAB0v XHvQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=ZS+ol8O8pmIgXaXsYBrUfZI8GDYZiX0j1omdO4gu9sA=; b=fzuxdwxXy8qtCGP52tQSl3HWSQqW3nwCOnHM3Kpsq+Jj33pEyFOHnpIb/DeSoKXtKD +1HPA9nNkfOy6Xz6xR9OCosoS+5LoRFQ9DKJrpK4VXTtyz3t1nSzTDxj98Loq94mwrMM KG42kKyfsAYXXS2qfed0oejWVEbMTVJRsEbwK2obaLABRuBbbNlhevgmCl5Oc0UScweu RpFDznya6bzNdutVegZ7T7nZFTsAsDu0WzG/j1YmW202BNYq0GLSkjY5licrLD2eMnG2 hrEIoHJ6BRgBW460+GE3HMv7yWVu4bgDbwC839ebBRqDEsFq6MJTpow+3LmUTutv1CGo bOMQ== X-Gm-Message-State: AOAM532QMGmdhUcnMqrsd5s/Td6FTNHU7wgM0HRCW6mHSQNAxC0JsJIm rvnHBYHgETTf6/P8G5A2Yh2ETMWJ4UvRJw== X-Google-Smtp-Source: ABdhPJwLg+yvXU8YE94BW5Mbi3gm26U8eu4hGPRNjOAIRDM2IhHkWF333Zy3B4egSP9vzaH4QfoREQ== X-Received: by 2002:a05:622a:50d:: with SMTP id l13mr23920835qtx.75.1638569910130; Fri, 03 Dec 2021 14:18:30 -0800 (PST) Received: from localhost (cpe-174-109-172-136.nc.res.rr.com. [174.109.172.136]) by smtp.gmail.com with ESMTPSA id f1sm3376947qtf.74.2021.12.03.14.18.29 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 03 Dec 2021 14:18:29 -0800 (PST) From: Josef Bacik To: linux-btrfs@vger.kernel.org, kernel-team@fb.com Subject: [PATCH 07/18] btrfs: add btrfs_truncate_control struct Date: Fri, 3 Dec 2021 17:18:09 -0500 Message-Id: X-Mailer: git-send-email 2.26.3 In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-btrfs@vger.kernel.org I'm going to be adding more arguments and counters to btrfs_truncate_inode_items, so add a control struct to handle all of the extra arguments to make it easier to follow. Signed-off-by: Josef Bacik --- fs/btrfs/free-space-cache.c | 7 +++++-- fs/btrfs/inode-item.c | 25 ++++++++----------------- fs/btrfs/inode-item.h | 18 ++++++++++++++++-- fs/btrfs/inode.c | 18 ++++++++++++------ fs/btrfs/tree-log.c | 6 +++++- 5 files changed, 46 insertions(+), 28 deletions(-) diff --git a/fs/btrfs/free-space-cache.c b/fs/btrfs/free-space-cache.c index 28b9c63ba536..a05dd3d29695 100644 --- a/fs/btrfs/free-space-cache.c +++ b/fs/btrfs/free-space-cache.c @@ -291,6 +291,10 @@ int btrfs_truncate_free_space_cache(struct btrfs_trans_handle *trans, struct btrfs_block_group *block_group, struct inode *vfs_inode) { + struct btrfs_truncate_control control = { + .new_size = 0, + .min_type = BTRFS_EXTENT_DATA_KEY, + }; struct btrfs_inode *inode = BTRFS_I(vfs_inode); struct btrfs_root *root = inode->root; struct extent_state *cached_state = NULL; @@ -333,8 +337,7 @@ int btrfs_truncate_free_space_cache(struct btrfs_trans_handle *trans, * We skip the throttling logic for free space cache inodes, so we don't * need to check for -EAGAIN. */ - ret = btrfs_truncate_inode_items(trans, root, inode, 0, - BTRFS_EXTENT_DATA_KEY, NULL); + ret = btrfs_truncate_inode_items(trans, root, inode, &control); unlock_extent_cached(&inode->io_tree, 0, (u64)-1, &cached_state); if (ret) goto fail; diff --git a/fs/btrfs/inode-item.c b/fs/btrfs/inode-item.c index 8afc8d1c607b..fa172c760fe2 100644 --- a/fs/btrfs/inode-item.c +++ b/fs/btrfs/inode-item.c @@ -425,16 +425,8 @@ int btrfs_lookup_inode(struct btrfs_trans_handle *trans, struct btrfs_root * @trans: A transaction handle. * @root: The root from which to remove items. * @inode: The inode whose items we want to remove. - * @new_size: The new i_size for the inode. This is only applicable when - * @min_type is BTRFS_EXTENT_DATA_KEY, must be 0 otherwise. - * @min_type: The minimum key type to remove. All keys with a type - * greater than this value are removed and all keys with - * this type are removed only if their offset is >= @new_size. - * @extents_found: Output parameter that will contain the number of file - * extent items that were removed or adjusted to the new - * inode i_size. The caller is responsible for initializing - * the counter. Also, it can be NULL if the caller does not - * need this counter. + * @control: The btrfs_truncate_control to control how and what we + * are truncating. * * Remove all keys associated with the inode from the given root that have a key * with a type greater than or equals to @min_type. When @min_type has a value of @@ -448,8 +440,7 @@ int btrfs_lookup_inode(struct btrfs_trans_handle *trans, struct btrfs_root int btrfs_truncate_inode_items(struct btrfs_trans_handle *trans, struct btrfs_root *root, struct btrfs_inode *inode, - u64 new_size, u32 min_type, - u64 *extents_found) + struct btrfs_truncate_control *control) { struct btrfs_fs_info *fs_info = root->fs_info; struct btrfs_path *path; @@ -457,6 +448,7 @@ int btrfs_truncate_inode_items(struct btrfs_trans_handle *trans, struct btrfs_file_extent_item *fi; struct btrfs_key key; struct btrfs_key found_key; + u64 new_size = control->new_size; u64 extent_num_bytes = 0; u64 extent_offset = 0; u64 item_end = 0; @@ -472,7 +464,7 @@ int btrfs_truncate_inode_items(struct btrfs_trans_handle *trans, bool be_nice = false; bool should_throttle = false; - BUG_ON(new_size > 0 && min_type != BTRFS_EXTENT_DATA_KEY); + BUG_ON(new_size > 0 && control->min_type != BTRFS_EXTENT_DATA_KEY); /* * For shareable roots we want to back off from time to time, this turns @@ -527,7 +519,7 @@ int btrfs_truncate_inode_items(struct btrfs_trans_handle *trans, if (found_key.objectid != ino) break; - if (found_type < min_type) + if (found_type < control->min_type) break; item_end = found_key.offset; @@ -551,7 +543,7 @@ int btrfs_truncate_inode_items(struct btrfs_trans_handle *trans, } item_end--; } - if (found_type > min_type) { + if (found_type > control->min_type) { del_item = 1; } else { if (item_end < new_size) @@ -566,8 +558,7 @@ int btrfs_truncate_inode_items(struct btrfs_trans_handle *trans, if (found_type != BTRFS_EXTENT_DATA_KEY) goto delete; - if (extents_found != NULL) - (*extents_found)++; + control->extents_found++; if (extent_type != BTRFS_FILE_EXTENT_INLINE) { u64 num_dec; diff --git a/fs/btrfs/inode-item.h b/fs/btrfs/inode-item.h index 63e8f45f110f..47c3fec579f8 100644 --- a/fs/btrfs/inode-item.h +++ b/fs/btrfs/inode-item.h @@ -9,10 +9,24 @@ */ #define BTRFS_NEED_TRUNCATE_BLOCK 1 +struct btrfs_truncate_control { + /* IN: the size we're truncating to. */ + u64 new_size; + + /* OUT: the number of extents truncated. */ + u64 extents_found; + + /* + * IN: minimum key type to remove. All key types with this type are + * removed only if their offset >= new_size. + */ + u32 min_type; +}; + int btrfs_truncate_inode_items(struct btrfs_trans_handle *trans, struct btrfs_root *root, - struct btrfs_inode *inode, u64 new_size, - u32 min_type, u64 *extents_found); + struct btrfs_inode *inode, + struct btrfs_truncate_control *control); int btrfs_insert_inode_ref(struct btrfs_trans_handle *trans, struct btrfs_root *root, const char *name, int name_len, diff --git a/fs/btrfs/inode.c b/fs/btrfs/inode.c index 73bb7acf6813..6600c474b2e8 100644 --- a/fs/btrfs/inode.c +++ b/fs/btrfs/inode.c @@ -5251,6 +5251,11 @@ void btrfs_evict_inode(struct inode *inode) btrfs_i_size_write(BTRFS_I(inode), 0); while (1) { + struct btrfs_truncate_control control = { + .new_size = 0, + .min_type = 0, + }; + trans = evict_refill_and_join(root, rsv); if (IS_ERR(trans)) goto free_rsv; @@ -5258,7 +5263,7 @@ void btrfs_evict_inode(struct inode *inode) trans->block_rsv = rsv; ret = btrfs_truncate_inode_items(trans, root, BTRFS_I(inode), - 0, 0, NULL); + &control); trans->block_rsv = &fs_info->trans_block_rsv; btrfs_end_transaction(trans); btrfs_btree_balance_dirty(fs_info); @@ -8527,6 +8532,9 @@ vm_fault_t btrfs_page_mkwrite(struct vm_fault *vmf) static int btrfs_truncate(struct inode *inode, bool skip_writeback) { + struct btrfs_truncate_control control = { + .min_type = BTRFS_EXTENT_DATA_KEY, + }; struct btrfs_fs_info *fs_info = btrfs_sb(inode->i_sb); struct btrfs_root *root = BTRFS_I(inode)->root; struct btrfs_block_rsv *rsv; @@ -8534,7 +8542,6 @@ static int btrfs_truncate(struct inode *inode, bool skip_writeback) struct btrfs_trans_handle *trans; u64 mask = fs_info->sectorsize - 1; u64 min_size = btrfs_calc_metadata_size(fs_info, 1); - u64 extents_found = 0; if (!skip_writeback) { ret = btrfs_wait_ordered_range(inode, inode->i_size & (~mask), @@ -8599,6 +8606,7 @@ static int btrfs_truncate(struct inode *inode, bool skip_writeback) const u64 new_size = inode->i_size; const u64 lock_start = ALIGN_DOWN(new_size, fs_info->sectorsize); + control.new_size = new_size; lock_extent_bits(&BTRFS_I(inode)->io_tree, lock_start, (u64)-1, &cached_state); /* @@ -8611,9 +8619,7 @@ static int btrfs_truncate(struct inode *inode, bool skip_writeback) (u64)-1, 0); ret = btrfs_truncate_inode_items(trans, root, BTRFS_I(inode), - inode->i_size, - BTRFS_EXTENT_DATA_KEY, - &extents_found); + &control); unlock_extent_cached(&BTRFS_I(inode)->io_tree, lock_start, (u64)-1, &cached_state); @@ -8692,7 +8698,7 @@ static int btrfs_truncate(struct inode *inode, bool skip_writeback) * between the old i_size and the new i_size, and there were no prealloc * extents beyond i_size to drop. */ - if (extents_found > 0) + if (control.extents_found > 0) set_bit(BTRFS_INODE_NEEDS_FULL_SYNC, &BTRFS_I(inode)->runtime_flags); return ret; diff --git a/fs/btrfs/tree-log.c b/fs/btrfs/tree-log.c index c7a7f78708d5..04374a7346db 100644 --- a/fs/btrfs/tree-log.c +++ b/fs/btrfs/tree-log.c @@ -4095,11 +4095,15 @@ static int truncate_inode_items(struct btrfs_trans_handle *trans, struct btrfs_inode *inode, u64 new_size, u32 min_type) { + struct btrfs_truncate_control control = { + .new_size = new_size, + .min_type = min_type, + }; int ret; do { ret = btrfs_truncate_inode_items(trans, log_root, inode, - new_size, min_type, NULL); + &control); } while (ret == -EAGAIN); return ret; From patchwork Fri Dec 3 22:18:10 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Josef Bacik X-Patchwork-Id: 12655901 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 45AE7C433FE for ; Fri, 3 Dec 2021 22:18:35 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1383390AbhLCWV5 (ORCPT ); Fri, 3 Dec 2021 17:21:57 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47832 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1383382AbhLCWV5 (ORCPT ); Fri, 3 Dec 2021 17:21:57 -0500 Received: from mail-qt1-x82a.google.com (mail-qt1-x82a.google.com [IPv6:2607:f8b0:4864:20::82a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 912B4C061751 for ; Fri, 3 Dec 2021 14:18:32 -0800 (PST) Received: by mail-qt1-x82a.google.com with SMTP id a2so4816930qtx.11 for ; Fri, 03 Dec 2021 14:18:32 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=toxicpanda-com.20210112.gappssmtp.com; s=20210112; h=from:to:subject:date:message-id:in-reply-to:references:mime-version :content-transfer-encoding; bh=75beZCfjU1J2T2g2eJHqUp1T8G+zWOWlLw5fTK6HPCA=; b=if9Z6r7nPG6J+eFUa53I9QU48QcK4xuestDirPS4Yy+O+VT7CRa4rjd9VWOktmzfVX rZPh/RznqVol1Wmro4dE+SzArOyjRiLR+62kkgA3Lrah8H+dzzqCrKvibEk5fi5DNlrR 72hbQmF8/1AiCsrBNbrtPIDc71Ufajk1G2s73lR5tFcOqqzYRhbYLzEDd5BRpeuVmnAx qvVnNMwv4HAFxMXiU/Jc2HmRZ8qIshQwQgdYqxyz5WoPm7qDkM80+8uHDnn8/nxeXgai /GoCaEzRuScOzG4mjXO8kRo/zrQBueBTGMk71EzJiNnKsbVQskAGx9or97MmDhosygcB e19Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=75beZCfjU1J2T2g2eJHqUp1T8G+zWOWlLw5fTK6HPCA=; b=bbBC4qftAb9r998NEMODMP31xbUG2hIA2F7EiqI25OenPdowaE5tKb2e7OQ+oFkkIw tnTZOzirN0mCyFafSA58iN1U9yMLwupq3fOQ5I1LJStXnc9LjyJwQJPE/ROMObQO2V/h Cmuaun3Ok5khtEJlpQkXhwNArQUU82Rh3ZdrdfAQa4TdImv3nOMJUrCdVLugqD13MkSq DlW/kE0CiajcABjEdIEfJ/gGRVUHqXWWd+8zYwXrFXc3VRmT3kYBLJSFGjMtp+EdSDtN EiCazyP92/Iy0x8UbyUDA1brJUOq7FNzSGg4TPZJtZHj0jy1Os7dsDorVs3vbHsZ1I7C n77w== X-Gm-Message-State: AOAM531JYqeBq82gjG1fH+VLBp9VPvG/9QaaqMdvRvMvgLU7zatYn+I1 4uWohxu6JtW3vZXpoTMw4IC8Oknb++qdHw== X-Google-Smtp-Source: ABdhPJyJfpo7YU94ehqTGdtL7c/kWdKLvkJ0NwDO1uFpBNSHRggNk2Gy9q34kwf+g4gr5A2UbqH17A== X-Received: by 2002:a05:622a:54c:: with SMTP id m12mr11721106qtx.280.1638569911422; Fri, 03 Dec 2021 14:18:31 -0800 (PST) Received: from localhost (cpe-174-109-172-136.nc.res.rr.com. [174.109.172.136]) by smtp.gmail.com with ESMTPSA id s126sm2724710qkf.7.2021.12.03.14.18.30 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 03 Dec 2021 14:18:31 -0800 (PST) From: Josef Bacik To: linux-btrfs@vger.kernel.org, kernel-team@fb.com Subject: [PATCH 08/18] btrfs: only update i_size in truncate paths that care Date: Fri, 3 Dec 2021 17:18:10 -0500 Message-Id: X-Mailer: git-send-email 2.26.3 In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-btrfs@vger.kernel.org We currently will update the i_size of the inode as we truncate it down, however we skip this if we're calling btrfs_truncate_inode_items from the tree log code. However we also don't care about this in the case of evict. Instead keep track of this value in the btrfs_truncate_control and then have btrfs_truncate() and the free space cache truncate path both do the i_size update themselves. Signed-off-by: Josef Bacik --- fs/btrfs/free-space-cache.c | 3 +++ fs/btrfs/inode-item.c | 17 ++++++++--------- fs/btrfs/inode-item.h | 3 +++ fs/btrfs/inode.c | 4 ++++ 4 files changed, 18 insertions(+), 9 deletions(-) diff --git a/fs/btrfs/free-space-cache.c b/fs/btrfs/free-space-cache.c index a05dd3d29695..fd469beb0985 100644 --- a/fs/btrfs/free-space-cache.c +++ b/fs/btrfs/free-space-cache.c @@ -338,6 +338,9 @@ int btrfs_truncate_free_space_cache(struct btrfs_trans_handle *trans, * need to check for -EAGAIN. */ ret = btrfs_truncate_inode_items(trans, root, inode, &control); + + btrfs_inode_safe_disk_i_size_write(inode, control.last_size); + unlock_extent_cached(&inode->io_tree, 0, (u64)-1, &cached_state); if (ret) goto fail; diff --git a/fs/btrfs/inode-item.c b/fs/btrfs/inode-item.c index fa172c760fe2..15dc5352d08a 100644 --- a/fs/btrfs/inode-item.c +++ b/fs/btrfs/inode-item.c @@ -452,7 +452,6 @@ int btrfs_truncate_inode_items(struct btrfs_trans_handle *trans, u64 extent_num_bytes = 0; u64 extent_offset = 0; u64 item_end = 0; - u64 last_size = new_size; u32 found_type = (u8)-1; int del_item; int pending_del_nr = 0; @@ -466,6 +465,8 @@ int btrfs_truncate_inode_items(struct btrfs_trans_handle *trans, BUG_ON(new_size > 0 && control->min_type != BTRFS_EXTENT_DATA_KEY); + control->last_size = new_size; + /* * For shareable roots we want to back off from time to time, this turns * out to be subvolume roots, reloc roots, and data reloc roots. @@ -649,9 +650,9 @@ int btrfs_truncate_inode_items(struct btrfs_trans_handle *trans, } if (del_item) - last_size = found_key.offset; + control->last_size = found_key.offset; else - last_size = new_size; + control->last_size = new_size; if (del_item) { if (!pending_del_nr) { /* no pending yet, add ourselves */ @@ -744,12 +745,10 @@ int btrfs_truncate_inode_items(struct btrfs_trans_handle *trans, ret = err; } } - if (root->root_key.objectid != BTRFS_TREE_LOG_OBJECTID) { - ASSERT(last_size >= new_size); - if (!ret && last_size > new_size) - last_size = new_size; - btrfs_inode_safe_disk_i_size_write(inode, last_size); - } + + ASSERT(control->last_size >= new_size); + if (!ret && control->last_size > new_size) + control->last_size = new_size; btrfs_free_path(path); return ret; diff --git a/fs/btrfs/inode-item.h b/fs/btrfs/inode-item.h index 47c3fec579f8..21adab1df4e5 100644 --- a/fs/btrfs/inode-item.h +++ b/fs/btrfs/inode-item.h @@ -16,6 +16,9 @@ struct btrfs_truncate_control { /* OUT: the number of extents truncated. */ u64 extents_found; + /* OUT: the last size we truncated this inode to. */ + u64 last_size; + /* * IN: minimum key type to remove. All key types with this type are * removed only if their offset >= new_size. diff --git a/fs/btrfs/inode.c b/fs/btrfs/inode.c index 6600c474b2e8..23b47c7bce0f 100644 --- a/fs/btrfs/inode.c +++ b/fs/btrfs/inode.c @@ -8620,6 +8620,10 @@ static int btrfs_truncate(struct inode *inode, bool skip_writeback) ret = btrfs_truncate_inode_items(trans, root, BTRFS_I(inode), &control); + + btrfs_inode_safe_disk_i_size_write(BTRFS_I(inode), + control.last_size); + unlock_extent_cached(&BTRFS_I(inode)->io_tree, lock_start, (u64)-1, &cached_state); From patchwork Fri Dec 3 22:18:11 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Josef Bacik X-Patchwork-Id: 12655903 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 4EE7EC433EF for ; Fri, 3 Dec 2021 22:18:38 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1383394AbhLCWWB (ORCPT ); Fri, 3 Dec 2021 17:22:01 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47840 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1383382AbhLCWV6 (ORCPT ); Fri, 3 Dec 2021 17:21:58 -0500 Received: from mail-qk1-x72e.google.com (mail-qk1-x72e.google.com [IPv6:2607:f8b0:4864:20::72e]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C7304C061751 for ; Fri, 3 Dec 2021 14:18:33 -0800 (PST) Received: by mail-qk1-x72e.google.com with SMTP id 132so4966656qkj.11 for ; Fri, 03 Dec 2021 14:18:33 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=toxicpanda-com.20210112.gappssmtp.com; s=20210112; h=from:to:subject:date:message-id:in-reply-to:references:mime-version :content-transfer-encoding; bh=imd6Mj5IpmPkMiVMmMNXrKBaVIdTu+C67zcm03S8NXA=; b=r64bE6UjeMJuxFWOwyfDtRJbGLddU5iTlG6wL6jSb37unjYN53z9fP4VwS0LNjqPYu GPb98fEmNco001Cjy+hFJn6kgN3yBIGowmKSkQgMg9zhoaiRZY+xJXBSpqSUdQJpXVyc 5LczuLg/+WtUwqkovIn0CF55ao0Wr6hhOa/imxkVkgtUZPL4Cye1h4m5j1MrtG0Mayaz GOuIn4ap9Y5V9FeynGbUf3YEI9TGEDnvkMszRmulEVXL4g1xGFse2CGiCIKYZVzO1W/f 6FV1AZniYQmruDCJg2DIF+gaxZquo/k/FZWMeCzyvqVaORyC0zlRTTzz14KkRS2TcZZB ZnuQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=imd6Mj5IpmPkMiVMmMNXrKBaVIdTu+C67zcm03S8NXA=; b=avOQD4+j1wmuGEqwDoq48TmpzTbpP4Hoqm/01Cd5PJaOWldfTxIL8Wu+hAMsACfDol 3OLSlPThBM/TwAPBVmPa4HIEZ2j+9hY2LjS/JBi++V6yyTCGcViubnwfEraoOA+9sQE1 kQxq/8564+Jf/1MvIwJvV7/z2h5F7SgigX2p5br9cYjxYQgnGrZ+RELjAHJIOqeor4lH CD6QPT4QvSa6bmEhAo3YbaCq8SfrCx6xaNE+8uBxUyoygM4hnmgWPL3SK/x8sWj/nZFR 4p0LWttvd3NbGDzmjaI8JN4xtDD/rq0WEnPqVKde8jj9xpDzkxsN4FYjDmvlurnSORNk EO0g== X-Gm-Message-State: AOAM530ErD4tBobwUdhJpZD+qsbFiSkekeeNMmcVoRWthS6BVg29Aajc pjwf0Bh6tLlTGQ+B7L+vnJb8rgQJ6StP1Q== X-Google-Smtp-Source: ABdhPJzflypNss+/7nuaAYu4O62o53NrP+hcNN40wiO8+kNQTj3KUFv6RNhME4KIYBdQArvOSG4w+g== X-Received: by 2002:a05:620a:13f9:: with SMTP id h25mr20277720qkl.99.1638569912726; Fri, 03 Dec 2021 14:18:32 -0800 (PST) Received: from localhost (cpe-174-109-172-136.nc.res.rr.com. [174.109.172.136]) by smtp.gmail.com with ESMTPSA id d16sm2999337qtn.59.2021.12.03.14.18.32 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 03 Dec 2021 14:18:32 -0800 (PST) From: Josef Bacik To: linux-btrfs@vger.kernel.org, kernel-team@fb.com Subject: [PATCH 09/18] btrfs: only call inode_sub_bytes in truncate paths that care Date: Fri, 3 Dec 2021 17:18:11 -0500 Message-Id: <7ad98c17758eb33c309a3c453927a94ed9ea4264.1638569556.git.josef@toxicpanda.com> X-Mailer: git-send-email 2.26.3 In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-btrfs@vger.kernel.org We currently have a bunch of awkward checks to make sure we only update the inode i_bytes if we're truncating the real inode. Instead keep track of the number of bytes we need to sub in the btrfs_truncate_control, and then do the appropriate adjustment in the truncate paths that care. Signed-off-by: Josef Bacik --- fs/btrfs/free-space-cache.c | 1 + fs/btrfs/inode-item.c | 20 ++++++-------------- fs/btrfs/inode-item.h | 3 +++ fs/btrfs/inode.c | 1 + 4 files changed, 11 insertions(+), 14 deletions(-) diff --git a/fs/btrfs/free-space-cache.c b/fs/btrfs/free-space-cache.c index fd469beb0985..d2f4716f8485 100644 --- a/fs/btrfs/free-space-cache.c +++ b/fs/btrfs/free-space-cache.c @@ -339,6 +339,7 @@ int btrfs_truncate_free_space_cache(struct btrfs_trans_handle *trans, */ ret = btrfs_truncate_inode_items(trans, root, inode, &control); + inode_sub_bytes(&inode->vfs_inode, control.sub_bytes); btrfs_inode_safe_disk_i_size_write(inode, control.last_size); unlock_extent_cached(&inode->io_tree, 0, (u64)-1, &cached_state); diff --git a/fs/btrfs/inode-item.c b/fs/btrfs/inode-item.c index 15dc5352d08a..ebbe4054ae93 100644 --- a/fs/btrfs/inode-item.c +++ b/fs/btrfs/inode-item.c @@ -466,6 +466,7 @@ int btrfs_truncate_inode_items(struct btrfs_trans_handle *trans, BUG_ON(new_size > 0 && control->min_type != BTRFS_EXTENT_DATA_KEY); control->last_size = new_size; + control->sub_bytes = 0; /* * For shareable roots we want to back off from time to time, this turns @@ -577,11 +578,8 @@ int btrfs_truncate_inode_items(struct btrfs_trans_handle *trans, extent_num_bytes); num_dec = (orig_num_bytes - extent_num_bytes); - if (test_bit(BTRFS_ROOT_SHAREABLE, - &root->state) && - extent_start != 0) - inode_sub_bytes(&inode->vfs_inode, - num_dec); + if (extent_start != 0) + control->sub_bytes += num_dec; btrfs_mark_buffer_dirty(leaf); } else { extent_num_bytes = @@ -592,12 +590,8 @@ int btrfs_truncate_inode_items(struct btrfs_trans_handle *trans, /* FIXME blocksize != 4096 */ num_dec = btrfs_file_extent_num_bytes(leaf, fi); - if (extent_start != 0) { - if (test_bit(BTRFS_ROOT_SHAREABLE, - &root->state)) - inode_sub_bytes(&inode->vfs_inode, - num_dec); - } + if (extent_start != 0) + control->sub_bytes += num_dec; } clear_len = num_dec; } else if (extent_type == BTRFS_FILE_EXTENT_INLINE) { @@ -630,9 +624,7 @@ int btrfs_truncate_inode_items(struct btrfs_trans_handle *trans, clear_len = fs_info->sectorsize; } - if (test_bit(BTRFS_ROOT_SHAREABLE, &root->state)) - inode_sub_bytes(&inode->vfs_inode, - item_end + 1 - new_size); + control->sub_bytes += item_end + 1 - new_size; } delete: /* diff --git a/fs/btrfs/inode-item.h b/fs/btrfs/inode-item.h index 21adab1df4e5..771e264a2ede 100644 --- a/fs/btrfs/inode-item.h +++ b/fs/btrfs/inode-item.h @@ -19,6 +19,9 @@ struct btrfs_truncate_control { /* OUT: the last size we truncated this inode to. */ u64 last_size; + /* OUT: the number of bytes to sub from this inode. */ + u64 sub_bytes; + /* * IN: minimum key type to remove. All key types with this type are * removed only if their offset >= new_size. diff --git a/fs/btrfs/inode.c b/fs/btrfs/inode.c index 23b47c7bce0f..306d410b4db4 100644 --- a/fs/btrfs/inode.c +++ b/fs/btrfs/inode.c @@ -8621,6 +8621,7 @@ static int btrfs_truncate(struct inode *inode, bool skip_writeback) ret = btrfs_truncate_inode_items(trans, root, BTRFS_I(inode), &control); + inode_sub_bytes(inode, control.sub_bytes); btrfs_inode_safe_disk_i_size_write(BTRFS_I(inode), control.last_size); From patchwork Fri Dec 3 22:18:12 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Josef Bacik X-Patchwork-Id: 12655905 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 8E91EC433FE for ; Fri, 3 Dec 2021 22:18:38 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1383395AbhLCWWB (ORCPT ); Fri, 3 Dec 2021 17:22:01 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47848 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1383391AbhLCWV7 (ORCPT ); Fri, 3 Dec 2021 17:21:59 -0500 Received: from mail-qk1-x72f.google.com (mail-qk1-x72f.google.com [IPv6:2607:f8b0:4864:20::72f]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 1ED8AC061353 for ; Fri, 3 Dec 2021 14:18:35 -0800 (PST) Received: by mail-qk1-x72f.google.com with SMTP id b67so4998377qkg.6 for ; Fri, 03 Dec 2021 14:18:35 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=toxicpanda-com.20210112.gappssmtp.com; s=20210112; h=from:to:subject:date:message-id:in-reply-to:references:mime-version :content-transfer-encoding; bh=0bWGGXJlS9Jn3POFye1qVoQWPeB6GgvgS19h7McZZ1s=; b=WBZo80dSc+6Vi+EwNZXY34nZxYnfSNxhP5w4GvMYOdRD9nblMi5YiBawjJA1STTnRi rZkRIqyOBp3U7u1ZQ6/uRRfjm+OTC3WwDMdQ3bibxtxUqV/EMpBiGNr4R1l0MQaCM7K3 TDFETRLn1LYAgqw1Xr2c6hTYtkVmbfpoThZJoxEuMtwtz3bXuhFAb+pnB2EJ+VEJoxPL 3oOLD9hwyEwTwowinpxD0iPOWDtRmFAreC64CQSv2JiI9a3rts49vry++uWkpK31Tux1 q5Gjz5M3Ct+yTQFT8C/hsIi0dc9SlwQEJxsBYXxpoHJtg+dzYAzyqZScR6R2jx7SwTTa lCMQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=0bWGGXJlS9Jn3POFye1qVoQWPeB6GgvgS19h7McZZ1s=; b=3hqg66WI074JA/1SxkMKOwUvkMsYhmb91GQnRTZAqC6GBnnt1PPiDhKhXkFCOdYEn5 mUrbSbvXAUiYt3EoHjMsbt2IunWlCWNWe1neZZeFVjnitwqhb7CoyyrWiVzzQLzfYjjk P+u0gOTfi2GfslTztTcBAsWofFbbMAQJqwSWI6utlrfQeddq98vL+bh270dTPrPZqGga E5fRHgTFT+mYOKaQHs3vFx5/EUqYVpIyYU3qOPYaxqkOa8QBeWdgvh/dfSOjbesaSqG5 Jj1IUsoqwUF0RHRMDMe//3TTCq2X10NoSII2Cizhjwy2KbFcudGrX5KdJ/n6H9DeoWmY dqpg== X-Gm-Message-State: AOAM533JYGmJAPaeVTdjDN9c2DL+K8QC7eZ+IOmKd+G8kOVJaGNXN+PC 47RmDDPvF07PanQ7qzQL0ODqhWEcazqLSQ== X-Google-Smtp-Source: ABdhPJwQ1x+I04fWsYICfwOL/RiBuGVaR7rVZe7dZixClm1UG3OXWMPH88S8lveeY9H4vZRyiLx8kg== X-Received: by 2002:a05:620a:28c3:: with SMTP id l3mr20027937qkp.584.1638569914034; Fri, 03 Dec 2021 14:18:34 -0800 (PST) Received: from localhost (cpe-174-109-172-136.nc.res.rr.com. [174.109.172.136]) by smtp.gmail.com with ESMTPSA id bk25sm2987991qkb.13.2021.12.03.14.18.33 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 03 Dec 2021 14:18:33 -0800 (PST) From: Josef Bacik To: linux-btrfs@vger.kernel.org, kernel-team@fb.com Subject: [PATCH 10/18] btrfs: control extent reference updates with a control flag for truncate Date: Fri, 3 Dec 2021 17:18:12 -0500 Message-Id: <450bed2abc79c39b448de30cf381a7e418cec058.1638569556.git.josef@toxicpanda.com> X-Mailer: git-send-email 2.26.3 In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-btrfs@vger.kernel.org We've had weird bugs in the past where we forgot to adjust the truncate path to deal with the fact that we can be called by the tree log path. Instead of checking if our root is a LOG_ROOT use a flag on the btrfs_truncate_control to indicate that we don't want to do extent reference updates during this truncate. Signed-off-by: Josef Bacik --- fs/btrfs/inode-item.c | 3 +-- fs/btrfs/inode-item.h | 6 ++++++ fs/btrfs/tree-log.c | 1 + 3 files changed, 8 insertions(+), 2 deletions(-) diff --git a/fs/btrfs/inode-item.c b/fs/btrfs/inode-item.c index ebbe4054ae93..79305d646b98 100644 --- a/fs/btrfs/inode-item.c +++ b/fs/btrfs/inode-item.c @@ -663,8 +663,7 @@ int btrfs_truncate_inode_items(struct btrfs_trans_handle *trans, } should_throttle = false; - if (del_item && extent_start != 0 && - root->root_key.objectid != BTRFS_TREE_LOG_OBJECTID) { + if (del_item && extent_start != 0 && !control->skip_ref_updates) { struct btrfs_ref ref = { 0 }; bytes_deleted += extent_num_bytes; diff --git a/fs/btrfs/inode-item.h b/fs/btrfs/inode-item.h index 771e264a2ede..0cb16cac07d1 100644 --- a/fs/btrfs/inode-item.h +++ b/fs/btrfs/inode-item.h @@ -27,6 +27,12 @@ struct btrfs_truncate_control { * removed only if their offset >= new_size. */ u32 min_type; + + /* + * IN: true if we don't want to do extent reference updates for any file + * extents we drop. + */ + bool skip_ref_updates; }; int btrfs_truncate_inode_items(struct btrfs_trans_handle *trans, diff --git a/fs/btrfs/tree-log.c b/fs/btrfs/tree-log.c index 04374a7346db..11b9b516af80 100644 --- a/fs/btrfs/tree-log.c +++ b/fs/btrfs/tree-log.c @@ -4098,6 +4098,7 @@ static int truncate_inode_items(struct btrfs_trans_handle *trans, struct btrfs_truncate_control control = { .new_size = new_size, .min_type = min_type, + .skip_ref_updates = true, }; int ret; From patchwork Fri Dec 3 22:18:13 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Josef Bacik X-Patchwork-Id: 12655909 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 36C4EC433F5 for ; Fri, 3 Dec 2021 22:18:39 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1383397AbhLCWWC (ORCPT ); Fri, 3 Dec 2021 17:22:02 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47852 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1383393AbhLCWWA (ORCPT ); Fri, 3 Dec 2021 17:22:00 -0500 Received: from mail-qv1-xf2d.google.com (mail-qv1-xf2d.google.com [IPv6:2607:f8b0:4864:20::f2d]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 68548C061751 for ; Fri, 3 Dec 2021 14:18:36 -0800 (PST) Received: by mail-qv1-xf2d.google.com with SMTP id j9so4115911qvm.10 for ; Fri, 03 Dec 2021 14:18:36 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=toxicpanda-com.20210112.gappssmtp.com; s=20210112; h=from:to:subject:date:message-id:in-reply-to:references:mime-version :content-transfer-encoding; bh=5KmbS+8OgjJksWB2vTqx97Mpyu6/QKGGCISuLJbxFGA=; b=A2aLCwaS6Zc13Nua07b8GiTF5fPQVx2qC5tlmeXOWasZ5F+8yQJoJ8wEllRyxOQIaI Fh3A1IY0jM6GO3VYqbN94ToPM2ve4cYPAGxW7ke8gjnmNpoefzsQp7nqAQyqMit1mmrb 6PMeU8klPJB3SdvNxxvGYjWrVCZbz9Biz9V2oVYDfQyEct83YPOWCXYeTxFjoEdUJdMj Nl4JMHBN/pFn7DGtFcmq+OPxdHBr8nousTshbOkse6GOB8xSHUk37MidOPLsOE/ugGiV yhh0VkNYP9uydlJvv7bb0QH/XXZ2fa5KqPej8ENKJXKtRUQWzqG895O7NQugFIZDkKAe RXuQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=5KmbS+8OgjJksWB2vTqx97Mpyu6/QKGGCISuLJbxFGA=; b=6mPiSJfuxTUihyJFls+QYS471Y51O4n0lu10SqN+PFVqhmwyYan455ubTHkWrwyYP9 KyuE6iMX0GtShZqrVId/Nj1G/rh6CVOO0DcPRUkTKxnuTNLZEdRwFyAnOyUPOnCZE7ti zVgH7f7hogTsTNnc9U0RPJpKuWBaULqpo2BDa1H9yUk3bPHRUg6fmZCWUVUlNgV/MzWj NwZze1GJoA+OrFpbs2al3Sv5Q8hXfXVC/zrBNtKZJ5CfWUhDOjacy4YRpUTWSxldUdtl G6KfJ9hHK4hmFh8MVpGU21uBdXIZp40E6zhX/syu4ibYncdPv3PvS4TY6AiryHMEqJcX jFjw== X-Gm-Message-State: AOAM531h07sdxMXf+UxwErJVBj+GTeS5fBx4jywwLvkP82UA9fZYRhHV CYg3LHev77f/bw4I6MtJZwKINZ4tlqD+pA== X-Google-Smtp-Source: ABdhPJymjTcuXXgVze+7jiTs3CvfCI93C8zq7XiFpQerCjoVszoykzSHl3KfIEyF9ut/HPxAaKZcSA== X-Received: by 2002:a05:6214:767:: with SMTP id f7mr22693277qvz.36.1638569915279; Fri, 03 Dec 2021 14:18:35 -0800 (PST) Received: from localhost (cpe-174-109-172-136.nc.res.rr.com. [174.109.172.136]) by smtp.gmail.com with ESMTPSA id r16sm3301232qta.46.2021.12.03.14.18.34 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 03 Dec 2021 14:18:34 -0800 (PST) From: Josef Bacik To: linux-btrfs@vger.kernel.org, kernel-team@fb.com Subject: [PATCH 11/18] btrfs: use a flag to control when to clear the file extent range Date: Fri, 3 Dec 2021 17:18:13 -0500 Message-Id: <9bf47eb21a7497c3ea75d0a1ff5b6309d4465183.1638569556.git.josef@toxicpanda.com> X-Mailer: git-send-email 2.26.3 In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-btrfs@vger.kernel.org We only care about updating the file extent range when we are doing a normal truncation. We skip this for tree logging currently, but we can also skip this for eviction as well. Using a flag makes it more explicit when we want to do this work. Signed-off-by: Josef Bacik --- fs/btrfs/free-space-cache.c | 1 + fs/btrfs/inode-item.c | 8 ++++---- fs/btrfs/inode-item.h | 6 ++++++ fs/btrfs/inode.c | 1 + 4 files changed, 12 insertions(+), 4 deletions(-) diff --git a/fs/btrfs/free-space-cache.c b/fs/btrfs/free-space-cache.c index d2f4716f8485..3a6bf361409b 100644 --- a/fs/btrfs/free-space-cache.c +++ b/fs/btrfs/free-space-cache.c @@ -294,6 +294,7 @@ int btrfs_truncate_free_space_cache(struct btrfs_trans_handle *trans, struct btrfs_truncate_control control = { .new_size = 0, .min_type = BTRFS_EXTENT_DATA_KEY, + .clear_extent_range = true, }; struct btrfs_inode *inode = BTRFS_I(vfs_inode); struct btrfs_root *root = inode->root; diff --git a/fs/btrfs/inode-item.c b/fs/btrfs/inode-item.c index 79305d646b98..225a5cd3f0ea 100644 --- a/fs/btrfs/inode-item.c +++ b/fs/btrfs/inode-item.c @@ -628,11 +628,11 @@ int btrfs_truncate_inode_items(struct btrfs_trans_handle *trans, } delete: /* - * We use btrfs_truncate_inode_items() to clean up log trees for - * multiple fsyncs, and in this case we don't want to clear the - * file extent range because it's just the log. + * We only want to clear the file extent range if we're + * modifying the actual inode's mapping, which is just the + * normal truncate path. */ - if (root == inode->root) { + if (control->clear_extent_range) { ret = btrfs_inode_clear_file_extent_range(inode, clear_start, clear_len); if (ret) { diff --git a/fs/btrfs/inode-item.h b/fs/btrfs/inode-item.h index 0cb16cac07d1..50acee3f4e28 100644 --- a/fs/btrfs/inode-item.h +++ b/fs/btrfs/inode-item.h @@ -33,6 +33,12 @@ struct btrfs_truncate_control { * extents we drop. */ bool skip_ref_updates; + + /* + * IN: true if we need to clear the file extent range for the inode as + * we drop the file extent items. + */ + bool clear_extent_range; }; int btrfs_truncate_inode_items(struct btrfs_trans_handle *trans, diff --git a/fs/btrfs/inode.c b/fs/btrfs/inode.c index 306d410b4db4..45dc4355102a 100644 --- a/fs/btrfs/inode.c +++ b/fs/btrfs/inode.c @@ -8534,6 +8534,7 @@ static int btrfs_truncate(struct inode *inode, bool skip_writeback) { struct btrfs_truncate_control control = { .min_type = BTRFS_EXTENT_DATA_KEY, + .clear_extent_range = true, }; struct btrfs_fs_info *fs_info = btrfs_sb(inode->i_sb); struct btrfs_root *root = BTRFS_I(inode)->root; From patchwork Fri Dec 3 22:18:14 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Josef Bacik X-Patchwork-Id: 12655907 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 D3910C4332F for ; Fri, 3 Dec 2021 22:18:39 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1383398AbhLCWWD (ORCPT ); Fri, 3 Dec 2021 17:22:03 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47860 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1383391AbhLCWWC (ORCPT ); Fri, 3 Dec 2021 17:22:02 -0500 Received: from mail-qv1-xf31.google.com (mail-qv1-xf31.google.com [IPv6:2607:f8b0:4864:20::f31]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id BD605C061751 for ; Fri, 3 Dec 2021 14:18:37 -0800 (PST) Received: by mail-qv1-xf31.google.com with SMTP id p3so4136974qvj.9 for ; Fri, 03 Dec 2021 14:18:37 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=toxicpanda-com.20210112.gappssmtp.com; s=20210112; h=from:to:subject:date:message-id:in-reply-to:references:mime-version :content-transfer-encoding; bh=WV0LrUOPdRqkwItvm3/BfUCVJeqgGy/IfZHO/mfhQ6U=; b=CjrsE5wvvcv+HYSCu8ijyv1aHlcWxGz61I/3JdszIPmbbyMIPHdpul7J6vk5IMhBY1 ghcgZxtzzo4iOEz9husnP2GTE64Eb4qSNoPzjcTwdi0uE4ykDiJnjoLFFVkugOWHV78Y oPL8x7itwJlCc3J5W1GV3MvGVyo6rqGDHwwDQKHBg6sC33bYWJd+fc/c3QFaJGWuq/bm da/sveenKOQqkx+CLOsP15xeXRD1Ox4IKEiBlpYhdtUrlOdIBzIekdTZwDPtwRUas/QY VjCPrIk7OlSUIqkG2TOBqJwiE99+wXzkQERZhVZRxGyUA9gF++LGIrMcGMnhM5L62iJF S5mQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=WV0LrUOPdRqkwItvm3/BfUCVJeqgGy/IfZHO/mfhQ6U=; b=6YRwXikxbM6mn2Vcufhf95UPN8utPweNri578BeO5G9fCteHesir/FsaRZm8gpDIul XOnuRyS01E5B0b29FAOuwIBvQGvoUD6ybBxHzoHskl68Y1lKf2Jmb4TqojtvvMv1Cy8y lTH9QdcvX56KTrvHZnejkdaf8IoTX0JnDj42j9Zgz6svEABOWdH3q46ijmIxWH1A2mI2 N1MqRniCRVXuPefz1bLuOXYslSOl88NqB57VnTvuouYh8Lha2fLh64Y3xK1RP3H9JiLV aqSYt6NCXL/11UeyRs8iKG5dhblHDUKrA79uPIvsuN7NtsTT+FiB9gnmXS39locYlWVA BL6g== X-Gm-Message-State: AOAM531fn8qEIUrqAm/hWd5ux/kBrPdS4JioV4UIkKRTzV/viSL5HG9a mAYPlOOmKt9wnLFAk0062sQH64fMRWYdrg== X-Google-Smtp-Source: ABdhPJzpaYvV6nX9p8vMES7IduUTTdnAuDaDUfh3QESxfqnR0/rxuydxv/ww3u32VrrCpqrGmfjopQ== X-Received: by 2002:a05:6214:2c5:: with SMTP id g5mr21202275qvu.94.1638569916610; Fri, 03 Dec 2021 14:18:36 -0800 (PST) Received: from localhost (cpe-174-109-172-136.nc.res.rr.com. [174.109.172.136]) by smtp.gmail.com with ESMTPSA id t18sm3302363qtw.64.2021.12.03.14.18.36 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 03 Dec 2021 14:18:36 -0800 (PST) From: Josef Bacik To: linux-btrfs@vger.kernel.org, kernel-team@fb.com Subject: [PATCH 12/18] btrfs: pass the ino via btrfs_truncate_control Date: Fri, 3 Dec 2021 17:18:14 -0500 Message-Id: <0f979b59665b5607b418fdf5380dd779d72d06b1.1638569556.git.josef@toxicpanda.com> X-Mailer: git-send-email 2.26.3 In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-btrfs@vger.kernel.org In the future we are going to want to truncate inode items without needing to have an btrfs_inode to pass in, so add ino to the btrfs_truncate_control and use that to look up the inode items to truncate. Signed-off-by: Josef Bacik --- fs/btrfs/free-space-cache.c | 1 + fs/btrfs/inode-item.c | 7 +++---- fs/btrfs/inode-item.h | 3 +++ fs/btrfs/inode.c | 2 ++ fs/btrfs/tree-log.c | 1 + 5 files changed, 10 insertions(+), 4 deletions(-) diff --git a/fs/btrfs/free-space-cache.c b/fs/btrfs/free-space-cache.c index 3a6bf361409b..c2a34179bddc 100644 --- a/fs/btrfs/free-space-cache.c +++ b/fs/btrfs/free-space-cache.c @@ -293,6 +293,7 @@ int btrfs_truncate_free_space_cache(struct btrfs_trans_handle *trans, { struct btrfs_truncate_control control = { .new_size = 0, + .ino = btrfs_ino(BTRFS_I(vfs_inode)), .min_type = BTRFS_EXTENT_DATA_KEY, .clear_extent_range = true, }; diff --git a/fs/btrfs/inode-item.c b/fs/btrfs/inode-item.c index 225a5cd3f0ea..b11c3da680fd 100644 --- a/fs/btrfs/inode-item.c +++ b/fs/btrfs/inode-item.c @@ -458,7 +458,6 @@ int btrfs_truncate_inode_items(struct btrfs_trans_handle *trans, int pending_del_slot = 0; int extent_type = -1; int ret; - u64 ino = btrfs_ino(inode); u64 bytes_deleted = 0; bool be_nice = false; bool should_throttle = false; @@ -480,7 +479,7 @@ int btrfs_truncate_inode_items(struct btrfs_trans_handle *trans, return -ENOMEM; path->reada = READA_BACK; - key.objectid = ino; + key.objectid = control->ino; key.offset = (u64)-1; key.type = (u8)-1; @@ -518,7 +517,7 @@ int btrfs_truncate_inode_items(struct btrfs_trans_handle *trans, btrfs_item_key_to_cpu(leaf, &found_key, path->slots[0]); found_type = found_key.type; - if (found_key.objectid != ino) + if (found_key.objectid != control->ino) break; if (found_type < control->min_type) @@ -671,7 +670,7 @@ int btrfs_truncate_inode_items(struct btrfs_trans_handle *trans, btrfs_init_generic_ref(&ref, BTRFS_DROP_DELAYED_REF, extent_start, extent_num_bytes, 0); btrfs_init_data_ref(&ref, btrfs_header_owner(leaf), - ino, extent_offset, + control->ino, extent_offset, root->root_key.objectid, false); ret = btrfs_free_extent(trans, &ref); if (ret) { diff --git a/fs/btrfs/inode-item.h b/fs/btrfs/inode-item.h index 50acee3f4e28..1948461e5a46 100644 --- a/fs/btrfs/inode-item.h +++ b/fs/btrfs/inode-item.h @@ -22,6 +22,9 @@ struct btrfs_truncate_control { /* OUT: the number of bytes to sub from this inode. */ u64 sub_bytes; + /* IN: the ino we are truncating. */ + u64 ino; + /* * IN: minimum key type to remove. All key types with this type are * removed only if their offset >= new_size. diff --git a/fs/btrfs/inode.c b/fs/btrfs/inode.c index 45dc4355102a..06e7c5e26a65 100644 --- a/fs/btrfs/inode.c +++ b/fs/btrfs/inode.c @@ -5252,6 +5252,7 @@ void btrfs_evict_inode(struct inode *inode) while (1) { struct btrfs_truncate_control control = { + .ino = btrfs_ino(BTRFS_I(inode)), .new_size = 0, .min_type = 0, }; @@ -8533,6 +8534,7 @@ vm_fault_t btrfs_page_mkwrite(struct vm_fault *vmf) static int btrfs_truncate(struct inode *inode, bool skip_writeback) { struct btrfs_truncate_control control = { + .ino = btrfs_ino(BTRFS_I(inode)), .min_type = BTRFS_EXTENT_DATA_KEY, .clear_extent_range = true, }; diff --git a/fs/btrfs/tree-log.c b/fs/btrfs/tree-log.c index 11b9b516af80..fb3bf7cc21c5 100644 --- a/fs/btrfs/tree-log.c +++ b/fs/btrfs/tree-log.c @@ -4097,6 +4097,7 @@ static int truncate_inode_items(struct btrfs_trans_handle *trans, { struct btrfs_truncate_control control = { .new_size = new_size, + .ino = btrfs_ino(inode), .min_type = min_type, .skip_ref_updates = true, }; From patchwork Fri Dec 3 22:18:15 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Josef Bacik X-Patchwork-Id: 12655911 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 A0181C43217 for ; Fri, 3 Dec 2021 22:18:40 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1383400AbhLCWWE (ORCPT ); Fri, 3 Dec 2021 17:22:04 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47868 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1383391AbhLCWWD (ORCPT ); Fri, 3 Dec 2021 17:22:03 -0500 Received: from mail-qt1-x834.google.com (mail-qt1-x834.google.com [IPv6:2607:f8b0:4864:20::834]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 252D5C061751 for ; Fri, 3 Dec 2021 14:18:39 -0800 (PST) Received: by mail-qt1-x834.google.com with SMTP id n15so4919241qta.0 for ; Fri, 03 Dec 2021 14:18:39 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=toxicpanda-com.20210112.gappssmtp.com; s=20210112; h=from:to:subject:date:message-id:in-reply-to:references:mime-version :content-transfer-encoding; bh=ukI+l95mZb18s6Or2llHiNBO59CmInfCJad/XlhqzUk=; b=joigiQQfV7O7HXpklaEW4J8IEccXSqQyT83ohRYvUk24uCrLLNRtM3Og/mh3urcXW3 p7ASmqxyUjgYo56OYUsht4/f1iFf03SN3wMnd4pLcoavgAT4QpALjQZO5Col8l1E94nb zC2RnuRM1oKJZOZbRYSvnxNZGWZBdeK0M1/KmYYnG9bfpjD8sEjf+ytZRDTz+6c1+WRN BmJdT1bFRY1oT0Km60BWKxQn0oOJ8D6aUHFHxynr/j1s9GOfpdC1U8BjuZ6yhoARR4bS UVKSkkx3a/UMtR6FpyxJ2pwCmiF7X95ckdhopsjKVmGqpETeXzBkSMSaPEuMrJdC7QiO RN3w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=ukI+l95mZb18s6Or2llHiNBO59CmInfCJad/XlhqzUk=; b=GNly53pj8Iqp+7YlF6OyYTwssvn1AET76XZ1w+3kOb1OXW2V5sstqD8zrHAOatjeeg BMbAXPl6Zztrqzf1dflen8pWkIvzYkPWLubV/ccOMKBgX6WuQJ/DPwv1KZW+xj41hDNU 9qkv0/BWdjSnwZZI/kAya4BxMFOj/ZDLkDJ2krSD4x2egsTwBf4nU9d8pGxK2CLNWX+M WlvD4VdKz6fccF0u0+96ZGSJyKT/LzlKadnr8yo9Si4vjPdRyCJqlMPTpdxU1XRjK7AV I9f486PxtmJ1BXDpsWnmmcjLDuijDjUEWaNWWdBA2DBN90kjmkiQ6NSWw5o9Htx8Ysng 0g0w== X-Gm-Message-State: AOAM533aUnCj4bc8rHrQ7952yfd2L7EDCbjmjyPtksiqYCBNVX0qzDSL AwW2sQJizU2SxXBUip91q8IYUP8WzA6DLg== X-Google-Smtp-Source: ABdhPJxkWXaze4HtMbcjsfujHzadC3i2Sp4It7rH4Git4tJfKxPkZPkMV80ZzQogthgMlXh+Ep1O4g== X-Received: by 2002:ac8:7489:: with SMTP id v9mr23387228qtq.676.1638569917993; Fri, 03 Dec 2021 14:18:37 -0800 (PST) Received: from localhost (cpe-174-109-172-136.nc.res.rr.com. [174.109.172.136]) by smtp.gmail.com with ESMTPSA id 196sm2710160qkd.61.2021.12.03.14.18.37 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 03 Dec 2021 14:18:37 -0800 (PST) From: Josef Bacik To: linux-btrfs@vger.kernel.org, kernel-team@fb.com Subject: [PATCH 13/18] btrfs: add inode to btrfs_truncate_control Date: Fri, 3 Dec 2021 17:18:15 -0500 Message-Id: <67c6672e3493fbe4ef7f83fb75f6ea021d8fd024.1638569556.git.josef@toxicpanda.com> X-Mailer: git-send-email 2.26.3 In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-btrfs@vger.kernel.org In the future we're going to want to use btrfs_truncate_inode_items without looking up the associated inode. In order to accommodate this add the inode to btrfs_truncate_control and handle the case where control->inode is NULL appropriately. This is fairly straightforward, we simply need to add a helper for the trace points, as the file extent map update is controlled by a flag on btrfs_truncate_control. Signed-off-by: Josef Bacik --- fs/btrfs/free-space-cache.c | 3 ++- fs/btrfs/inode-item.c | 32 +++++++++++++++++++++----------- fs/btrfs/inode-item.h | 7 ++++++- fs/btrfs/inode.c | 8 ++++---- fs/btrfs/tree-log.c | 3 +-- 5 files changed, 34 insertions(+), 19 deletions(-) diff --git a/fs/btrfs/free-space-cache.c b/fs/btrfs/free-space-cache.c index c2a34179bddc..01a408db5683 100644 --- a/fs/btrfs/free-space-cache.c +++ b/fs/btrfs/free-space-cache.c @@ -292,6 +292,7 @@ int btrfs_truncate_free_space_cache(struct btrfs_trans_handle *trans, struct inode *vfs_inode) { struct btrfs_truncate_control control = { + .inode = BTRFS_I(vfs_inode), .new_size = 0, .ino = btrfs_ino(BTRFS_I(vfs_inode)), .min_type = BTRFS_EXTENT_DATA_KEY, @@ -339,7 +340,7 @@ int btrfs_truncate_free_space_cache(struct btrfs_trans_handle *trans, * We skip the throttling logic for free space cache inodes, so we don't * need to check for -EAGAIN. */ - ret = btrfs_truncate_inode_items(trans, root, inode, &control); + ret = btrfs_truncate_inode_items(trans, root, &control); inode_sub_bytes(&inode->vfs_inode, control.sub_bytes); btrfs_inode_safe_disk_i_size_write(inode, control.last_size); diff --git a/fs/btrfs/inode-item.c b/fs/btrfs/inode-item.c index b11c3da680fd..aee374e18131 100644 --- a/fs/btrfs/inode-item.c +++ b/fs/btrfs/inode-item.c @@ -419,6 +419,20 @@ int btrfs_lookup_inode(struct btrfs_trans_handle *trans, struct btrfs_root return ret; } +static inline void btrfs_trace_truncate(struct btrfs_inode *inode, + struct extent_buffer *leaf, + struct btrfs_file_extent_item *fi, + u64 offset, int extent_type, int slot) +{ + if (!inode) + return; + if (extent_type == BTRFS_FILE_EXTENT_INLINE) + trace_btrfs_truncate_show_fi_inline(inode, leaf, fi, slot, + offset); + else + trace_btrfs_truncate_show_fi_regular(inode, leaf, fi, offset); +} + /* * Remove inode items from a given root. * @@ -439,7 +453,6 @@ int btrfs_lookup_inode(struct btrfs_trans_handle *trans, struct btrfs_root */ int btrfs_truncate_inode_items(struct btrfs_trans_handle *trans, struct btrfs_root *root, - struct btrfs_inode *inode, struct btrfs_truncate_control *control) { struct btrfs_fs_info *fs_info = root->fs_info; @@ -462,6 +475,7 @@ int btrfs_truncate_inode_items(struct btrfs_trans_handle *trans, bool be_nice = false; bool should_throttle = false; + ASSERT(control->inode || !control->clear_extent_range); BUG_ON(new_size > 0 && control->min_type != BTRFS_EXTENT_DATA_KEY); control->last_size = new_size; @@ -528,20 +542,16 @@ int btrfs_truncate_inode_items(struct btrfs_trans_handle *trans, fi = btrfs_item_ptr(leaf, path->slots[0], struct btrfs_file_extent_item); extent_type = btrfs_file_extent_type(leaf, fi); - if (extent_type != BTRFS_FILE_EXTENT_INLINE) { + if (extent_type != BTRFS_FILE_EXTENT_INLINE) item_end += btrfs_file_extent_num_bytes(leaf, fi); - - trace_btrfs_truncate_show_fi_regular( - inode, leaf, fi, found_key.offset); - } else if (extent_type == BTRFS_FILE_EXTENT_INLINE) { + else if (extent_type == BTRFS_FILE_EXTENT_INLINE) item_end += btrfs_file_extent_ram_bytes(leaf, fi); - trace_btrfs_truncate_show_fi_inline( - inode, leaf, fi, path->slots[0], - found_key.offset); - } + btrfs_trace_truncate(control->inode, leaf, fi, + found_key.offset, extent_type, + path->slots[0]); item_end--; } if (found_type > control->min_type) { @@ -632,7 +642,7 @@ int btrfs_truncate_inode_items(struct btrfs_trans_handle *trans, * normal truncate path. */ if (control->clear_extent_range) { - ret = btrfs_inode_clear_file_extent_range(inode, + ret = btrfs_inode_clear_file_extent_range(control->inode, clear_start, clear_len); if (ret) { btrfs_abort_transaction(trans, ret); diff --git a/fs/btrfs/inode-item.h b/fs/btrfs/inode-item.h index 1948461e5a46..b8c788f71c95 100644 --- a/fs/btrfs/inode-item.h +++ b/fs/btrfs/inode-item.h @@ -10,6 +10,12 @@ #define BTRFS_NEED_TRUNCATE_BLOCK 1 struct btrfs_truncate_control { + /* + * IN: the inode we're operating on, this can be NULL if + * ->clear_extent_range is false. + */ + struct btrfs_inode *inode; + /* IN: the size we're truncating to. */ u64 new_size; @@ -46,7 +52,6 @@ struct btrfs_truncate_control { int btrfs_truncate_inode_items(struct btrfs_trans_handle *trans, struct btrfs_root *root, - struct btrfs_inode *inode, struct btrfs_truncate_control *control); int btrfs_insert_inode_ref(struct btrfs_trans_handle *trans, struct btrfs_root *root, diff --git a/fs/btrfs/inode.c b/fs/btrfs/inode.c index 06e7c5e26a65..07e8539819b9 100644 --- a/fs/btrfs/inode.c +++ b/fs/btrfs/inode.c @@ -5252,6 +5252,7 @@ void btrfs_evict_inode(struct inode *inode) while (1) { struct btrfs_truncate_control control = { + .inode = BTRFS_I(inode), .ino = btrfs_ino(BTRFS_I(inode)), .new_size = 0, .min_type = 0, @@ -5263,8 +5264,7 @@ void btrfs_evict_inode(struct inode *inode) trans->block_rsv = rsv; - ret = btrfs_truncate_inode_items(trans, root, BTRFS_I(inode), - &control); + ret = btrfs_truncate_inode_items(trans, root, &control); trans->block_rsv = &fs_info->trans_block_rsv; btrfs_end_transaction(trans); btrfs_btree_balance_dirty(fs_info); @@ -8534,6 +8534,7 @@ vm_fault_t btrfs_page_mkwrite(struct vm_fault *vmf) static int btrfs_truncate(struct inode *inode, bool skip_writeback) { struct btrfs_truncate_control control = { + .inode = BTRFS_I(inode), .ino = btrfs_ino(BTRFS_I(inode)), .min_type = BTRFS_EXTENT_DATA_KEY, .clear_extent_range = true, @@ -8621,8 +8622,7 @@ static int btrfs_truncate(struct inode *inode, bool skip_writeback) ALIGN(new_size, fs_info->sectorsize), (u64)-1, 0); - ret = btrfs_truncate_inode_items(trans, root, BTRFS_I(inode), - &control); + ret = btrfs_truncate_inode_items(trans, root, &control); inode_sub_bytes(inode, control.sub_bytes); btrfs_inode_safe_disk_i_size_write(BTRFS_I(inode), diff --git a/fs/btrfs/tree-log.c b/fs/btrfs/tree-log.c index fb3bf7cc21c5..80520ad1de4f 100644 --- a/fs/btrfs/tree-log.c +++ b/fs/btrfs/tree-log.c @@ -4104,8 +4104,7 @@ static int truncate_inode_items(struct btrfs_trans_handle *trans, int ret; do { - ret = btrfs_truncate_inode_items(trans, log_root, inode, - &control); + ret = btrfs_truncate_inode_items(trans, log_root, &control); } while (ret == -EAGAIN); return ret; From patchwork Fri Dec 3 22:18:16 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Josef Bacik X-Patchwork-Id: 12655913 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 BD631C433FE for ; Fri, 3 Dec 2021 22:18:41 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1383402AbhLCWWF (ORCPT ); Fri, 3 Dec 2021 17:22:05 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47874 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1383391AbhLCWWE (ORCPT ); Fri, 3 Dec 2021 17:22:04 -0500 Received: from mail-qt1-x82b.google.com (mail-qt1-x82b.google.com [IPv6:2607:f8b0:4864:20::82b]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 4B9BCC061751 for ; Fri, 3 Dec 2021 14:18:40 -0800 (PST) Received: by mail-qt1-x82b.google.com with SMTP id t34so4837647qtc.7 for ; Fri, 03 Dec 2021 14:18:40 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=toxicpanda-com.20210112.gappssmtp.com; s=20210112; h=from:to:subject:date:message-id:in-reply-to:references:mime-version :content-transfer-encoding; bh=auRiCBm73SRbgqtmm4dQ8LLwAEPsmUT7T76V24Lpn60=; b=PanWj55HtKZL/QGLTuiaKOpiaV1YQh9mbguiY5tdKnmST2FnvUED/X2pih5hmwmEJj IVy/XIoG2IfghGX2xtfTPhMqZwpEWJdMMlNKB3DYfQi/nS6Q7AWxZo2wRfm/hxFhSRKV SGnUeOZ5P2JryaM9e4eBhm8qHZ2GIerxouQN+vV9FR4WJUJ63hA/tnhmv7U+oEJAzg2T 8O4OHHPsoAuQf+Dclpi+eFEL278yTFo4S3+98OFSXnP8gvwpoPFS7MArKtYk1Rc1lrwh 8leBygf2FNHn0JYvBr/Ax7H5WlQCmZ8ResY9c3z7dNd0V/ojMjWksPGd7TbhN0B9ZacM JD2Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=auRiCBm73SRbgqtmm4dQ8LLwAEPsmUT7T76V24Lpn60=; b=7kr/T8RZL7DTVPwmNm1ZN/1YzcBuZvgSnl+Pi7A6fIXwXv6M0cKTShBQiziq3ElYtA zEwSga535L5oYZIWvPDi7YqVO19fKJnpfNbzRTs/7LzJIqwrGIC8nUbhKh5mKj8XGHXJ iYk3OMmlAfg79+1vsGZOMPURKaFFdN7QeibTd9BgyWJhf8mjcHcwmzdKF/7iyXB0glAd lJFK/RwlABolZrEhE1x3gjTrGWkfoaxEdZgroPg7wskHzdZSxmVqnU1KbSPDj4bRj9eD eM9w3yuVyuLIOWMwQrKGjBXzfQm/gUw9JDDqKosctCAO8ObEjA359cj6q8n1Lk239dYd 9iZA== X-Gm-Message-State: AOAM53133OCaNQD8ccFUQgTc45waPT8qNQHnuTQj0mzysE9vMHLEibI2 KMBUFn0Roj4U6MSqc0rTAbG17y4lC3sH2Q== X-Google-Smtp-Source: ABdhPJzcdVkTrboA5DNjjv1D8bSJUvNS+29OrTKTXy57TZ9Ft+QvAv7DTKFrYsSjdtbDnNINOBwovQ== X-Received: by 2002:ac8:5883:: with SMTP id t3mr23555409qta.551.1638569919266; Fri, 03 Dec 2021 14:18:39 -0800 (PST) Received: from localhost (cpe-174-109-172-136.nc.res.rr.com. [174.109.172.136]) by smtp.gmail.com with ESMTPSA id y20sm2905755qkj.24.2021.12.03.14.18.38 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 03 Dec 2021 14:18:38 -0800 (PST) From: Josef Bacik To: linux-btrfs@vger.kernel.org, kernel-team@fb.com Subject: [PATCH 14/18] btrfs: convert BUG_ON() in btrfs_truncate_inode_items to ASSERT Date: Fri, 3 Dec 2021 17:18:16 -0500 Message-Id: <28050d7b14a11ccf488b566192a31bbe8099da4e.1638569556.git.josef@toxicpanda.com> X-Mailer: git-send-email 2.26.3 In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-btrfs@vger.kernel.org We have a correctness BUG_ON() in btrfs_truncate_inode_items to make sure that we're always using min_type == BTRFS_EXTENT_DATA_KEY if new_size is > 0. Convert this to an ASSERT. Signed-off-by: Josef Bacik --- fs/btrfs/inode-item.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/fs/btrfs/inode-item.c b/fs/btrfs/inode-item.c index aee374e18131..652b7069f63d 100644 --- a/fs/btrfs/inode-item.c +++ b/fs/btrfs/inode-item.c @@ -476,7 +476,7 @@ int btrfs_truncate_inode_items(struct btrfs_trans_handle *trans, bool should_throttle = false; ASSERT(control->inode || !control->clear_extent_range); - BUG_ON(new_size > 0 && control->min_type != BTRFS_EXTENT_DATA_KEY); + ASSERT(new_size == 0 || control->min_type == BTRFS_EXTENT_DATA_KEY); control->last_size = new_size; control->sub_bytes = 0; From patchwork Fri Dec 3 22:18:17 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Josef Bacik X-Patchwork-Id: 12655915 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 F20F4C433F5 for ; Fri, 3 Dec 2021 22:18:42 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1383404AbhLCWWG (ORCPT ); Fri, 3 Dec 2021 17:22:06 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47882 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1383391AbhLCWWF (ORCPT ); Fri, 3 Dec 2021 17:22:05 -0500 Received: from mail-qv1-xf36.google.com (mail-qv1-xf36.google.com [IPv6:2607:f8b0:4864:20::f36]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 7CCA4C061751 for ; Fri, 3 Dec 2021 14:18:41 -0800 (PST) Received: by mail-qv1-xf36.google.com with SMTP id i12so4121841qvh.11 for ; Fri, 03 Dec 2021 14:18:41 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=toxicpanda-com.20210112.gappssmtp.com; s=20210112; h=from:to:subject:date:message-id:in-reply-to:references:mime-version :content-transfer-encoding; bh=movu3ZDMaTPISGz+rJN4jMsmWtBrdiB3UzbXLgAyFOk=; b=r2//tP+IxEjvjxbHFXHdY3mns1j+J1iwupVAEOz4mQofhoHUPGnHWgKNrrWNYWvYK4 5x/nFnJ+xzxmoZsL+7NXAG8yP9U5TCZ5XJ0L6WXXqOsLcpFx2mpxRMV4Gt4whGAflKrK 5gnbmnHosJZ34R0M9/49xg7hmqeh9h5RaVyU2ucVTqPD3yr1oOk9EGjkZcjnob6ZkAMr BTEvqX0MhO0aJQjBsx4DzOoguUhh1djnNzNVSznhZZ/lJk6oMN/ttHOJAeQMZvi32guO tjmTuKhA7rg9HpmckvVqd6Rb1Plp8WuMW1CYxpV/pAQAm6wnonoINn/VsMvCieLRhl7n M0/g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=movu3ZDMaTPISGz+rJN4jMsmWtBrdiB3UzbXLgAyFOk=; b=D/LX8yl2OdrgSxlhIJq39v95gqFLTX9/oSz3Fqz7AhWmEgetL9zjgr6tVUercxvzqI aIuVXqJBS54V2U9hsdNih+VcsKbMrNNQRIpXyIEeADlUZsjibFGWaH3A5BUQ6ai1Ge0L mlvbjbbWJBd6kV9fANP2isG4FzYg7Wrncn3mujvW4JmNlCHQ8/WTjjUepcn8qzZcu+W4 I5q5+wznn22CWr3PJ2ziXzorkUKAlNl7sYCM7chVtXNwHo9NnB1fj1S4A3g9V6+M4vG2 5lROWZLJXx1crVGAZFvNlKgNPDQGZfDR6ZSMwaadc9TgsDmFrxN+zlucJi5aOWJu8x2y AjvA== X-Gm-Message-State: AOAM530LTcwN7GJ9zjZvayaE/l21rzihjV3dseZDp4N59kcVFmQLKIcf UB4JCEpno143lONOs99SdXjO6Tz7Ywqauw== X-Google-Smtp-Source: ABdhPJzblfZ8BsNqlw0BaGcFk5kUSan9uix/fklhnAAiDUHs6A+lIQQGfqTD5WtxDx0n8QfPvlac+g== X-Received: by 2002:ad4:528d:: with SMTP id v13mr21708576qvr.100.1638569920453; Fri, 03 Dec 2021 14:18:40 -0800 (PST) Received: from localhost (cpe-174-109-172-136.nc.res.rr.com. [174.109.172.136]) by smtp.gmail.com with ESMTPSA id bp18sm2940129qkb.39.2021.12.03.14.18.40 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 03 Dec 2021 14:18:40 -0800 (PST) From: Josef Bacik To: linux-btrfs@vger.kernel.org, kernel-team@fb.com Subject: [PATCH 15/18] btrfs: convert BUG() for pending_del_nr into an ASSERT Date: Fri, 3 Dec 2021 17:18:17 -0500 Message-Id: X-Mailer: git-send-email 2.26.3 In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-btrfs@vger.kernel.org This is a logic correctness check, convert it into an ASSERT() instead of a BUG(). Signed-off-by: Josef Bacik --- fs/btrfs/inode-item.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/fs/btrfs/inode-item.c b/fs/btrfs/inode-item.c index 652b7069f63d..9c44cf30d930 100644 --- a/fs/btrfs/inode-item.c +++ b/fs/btrfs/inode-item.c @@ -655,6 +655,9 @@ int btrfs_truncate_inode_items(struct btrfs_trans_handle *trans, else control->last_size = new_size; if (del_item) { + ASSERT(!pending_del_nr || + ((path->slots[0] + 1) == pending_del_slot)); + if (!pending_del_nr) { /* no pending yet, add ourselves */ pending_del_slot = path->slots[0]; @@ -664,8 +667,6 @@ int btrfs_truncate_inode_items(struct btrfs_trans_handle *trans, /* hop on the pending chunk */ pending_del_nr++; pending_del_slot = path->slots[0]; - } else { - BUG(); } } else { break; From patchwork Fri Dec 3 22:18:18 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Josef Bacik X-Patchwork-Id: 12655917 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 0576BC433F5 for ; Fri, 3 Dec 2021 22:18:46 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1383407AbhLCWWJ (ORCPT ); Fri, 3 Dec 2021 17:22:09 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47886 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1383391AbhLCWWH (ORCPT ); Fri, 3 Dec 2021 17:22:07 -0500 Received: from mail-qv1-xf33.google.com (mail-qv1-xf33.google.com [IPv6:2607:f8b0:4864:20::f33]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id CD946C061751 for ; Fri, 3 Dec 2021 14:18:42 -0800 (PST) Received: by mail-qv1-xf33.google.com with SMTP id u16so4154219qvk.4 for ; Fri, 03 Dec 2021 14:18:42 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=toxicpanda-com.20210112.gappssmtp.com; s=20210112; h=from:to:subject:date:message-id:in-reply-to:references:mime-version :content-transfer-encoding; bh=/bBsBjxz1iH6IV9wDQCX9R/1MrdKCI+JQIITaleL4hY=; b=vUF3YEXH/SFJxPosSONTvsZ+9eLZtS23+iJ7Z8IzGagN8RM703A39ZM8jhg34E4tqU ORN9rt+kY70tzIHChtFJTMlobPAlZXKaxiswNB98XTENkNjIf6sCw1XGyGQMLk6LJTnF dPsOmiBP1E1O62jF5l6WMqCixyFpl1TqKJrrLX20X/b84eMN0dUAw6E7rj3PfkWpfQNq wXikiclPVW7qGtSfZs/pCvOWUEgDA4nD/ikO0SfDvQW+CKaxU4LSk8drc/Vq8Q+PAKMo xnnCyVJSaXqhExhoodi9U955RvR8maL1eQs0rI4rOPP39oQDuSHhZ+sZHG0RTWiSQ5hM 18Yg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=/bBsBjxz1iH6IV9wDQCX9R/1MrdKCI+JQIITaleL4hY=; b=KqMoIClgetGOGA9rO6foQRhmraw+YyYmus2iGjDmcvZDdJU/Yt68BeIhCK472RbITq 4vSpuMvC2iH1jJ/X3S+G+/sGBeMGnTEfHnFj6pA4C4gIq2ivCG2jIPvEccSn7GAq/6TP G7pczClR9UVkAxf8ic1jBpH9fKWSyDYlG2JV3sfarmK0CTtLjCZg0UPbHvuLNomO2mjs IFkK7scUs9Pq8j0bMGxGe6N2tDRFXgYpfCEaWnP1DvlDeJWbItcICBMcFZkh8gASzZMT CnV5reKL5le9yPcaK/htab9pcciZjYpVeWjS0J17sE7uVSKt7dcdTGfUZucUD/rDsAtN rBWg== X-Gm-Message-State: AOAM531S7tkMa8MZCEu5jwz3vlIy8DWPohh7SkG+EJbXS4RgczvEJNsa pckTG5CAqp3B1gefaGK4vvJM3Spc4ZeRtQ== X-Google-Smtp-Source: ABdhPJywCiGWKdZ3i8Y3q5+yjBkv9JHiJBOhuhAAF89HS9AyhLcgGF0T4cqhFJKEEOCUGPZbGdvXAg== X-Received: by 2002:a05:6214:20e3:: with SMTP id 3mr22093631qvk.47.1638569921732; Fri, 03 Dec 2021 14:18:41 -0800 (PST) Received: from localhost (cpe-174-109-172-136.nc.res.rr.com. [174.109.172.136]) by smtp.gmail.com with ESMTPSA id a38sm2705959qkp.80.2021.12.03.14.18.41 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 03 Dec 2021 14:18:41 -0800 (PST) From: Josef Bacik To: linux-btrfs@vger.kernel.org, kernel-team@fb.com Subject: [PATCH 16/18] btrfs: combine extra if statements in btrfs_truncate_inode_items Date: Fri, 3 Dec 2021 17:18:18 -0500 Message-Id: X-Mailer: git-send-email 2.26.3 In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-btrfs@vger.kernel.org We have if (del_item) // do something else // something else if (del_item) // do yet another thing else // something else entirely back to back in btrfs_truncate_inode_items, collapse these two sets of if statements into one. Signed-off-by: Josef Bacik --- fs/btrfs/inode-item.c | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/fs/btrfs/inode-item.c b/fs/btrfs/inode-item.c index 9c44cf30d930..257a72ec8993 100644 --- a/fs/btrfs/inode-item.c +++ b/fs/btrfs/inode-item.c @@ -650,14 +650,11 @@ int btrfs_truncate_inode_items(struct btrfs_trans_handle *trans, } } - if (del_item) - control->last_size = found_key.offset; - else - control->last_size = new_size; if (del_item) { ASSERT(!pending_del_nr || ((path->slots[0] + 1) == pending_del_slot)); + control->last_size = found_key.offset; if (!pending_del_nr) { /* no pending yet, add ourselves */ pending_del_slot = path->slots[0]; @@ -669,6 +666,7 @@ int btrfs_truncate_inode_items(struct btrfs_trans_handle *trans, pending_del_slot = path->slots[0]; } } else { + control->last_size = new_size; break; } should_throttle = false; From patchwork Fri Dec 3 22:18:19 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Josef Bacik X-Patchwork-Id: 12655919 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 8CF03C433EF for ; Fri, 3 Dec 2021 22:18:46 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1383409AbhLCWWK (ORCPT ); Fri, 3 Dec 2021 17:22:10 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47892 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1383406AbhLCWWI (ORCPT ); Fri, 3 Dec 2021 17:22:08 -0500 Received: from mail-qt1-x82c.google.com (mail-qt1-x82c.google.com [IPv6:2607:f8b0:4864:20::82c]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 08960C061751 for ; Fri, 3 Dec 2021 14:18:44 -0800 (PST) Received: by mail-qt1-x82c.google.com with SMTP id q14so4837284qtx.10 for ; Fri, 03 Dec 2021 14:18:43 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=toxicpanda-com.20210112.gappssmtp.com; s=20210112; h=from:to:subject:date:message-id:in-reply-to:references:mime-version :content-transfer-encoding; bh=b8zGFD9fhXMashBpKjDCP8Sd3BJtE+0UViVXFTlarZM=; b=h5JkDO+JbidbgHMhmx2QQthuNIku6elAR9KBY7oRuzJK7cCscSaGPfUPRXx8tsJD7F ouFR02MfRF57AA/SZzwCY7hrKGdKP3EZkOrn//OggD6zxBPtfbAg1xeEKBEHPzFV92a/ KG9chtnT4KgoIYye699aEzwMZuObUeHkDFQEZpXZCN3NLKLpnlDiS8ggCdb8oOQCTTzW I9pXenXM+EjnhsCbE2XXmEDqk4g1Mb13v5hs670eXjkU9BtqAxJp+eX/tEJAisFO08wq pETBUo6BjmpPJ85upe8P3pN3cwAyKSjL85XKPs7HPASUcCmscyD79/BENsQn+nfgr+ax NseA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=b8zGFD9fhXMashBpKjDCP8Sd3BJtE+0UViVXFTlarZM=; b=kPE3GyrDEdcYSSB3tXxKFOTDKyKR2Lw6RII3O/Is2Lgu0BLkA5BqRgwRzUBr3uImE5 aJdvNWqHw9J6t9KYrWi5Fxc4xnG+Nw2zgm9I2dVhUCFL8uQLC5nT3sWWcmg9fRKpFkeI nLtB6N2FucTpezKcY83iM3Hf7AL3lvIt00AciKMHLqd+hQsRbTVFf+64SbOcraMV/zIJ +oF3H/vbdHwd2skiOuR87X5TEx3KRA6WXC75Q7DV82Veov4SAj13XGeCD4M4eTk+olqH 6ddrbWfsbdVjPnOWzxk4cBFJGlyeK0Ha53l1ckp0EdjHLtgqVR8RPUk2qx56chdeN8EI M8vA== X-Gm-Message-State: AOAM533rAd4JsOvGG017kksobXKUak2rX++7Tc4IBv3EfF930itNGGQS 0ZxQQhcDX0u+ZVu4OoNEtaFHVe2XfcWcWA== X-Google-Smtp-Source: ABdhPJz7VwTJNL0NDQzo8RFRk57NnY8XXaLCw6+oRPw53AcS2fT8ogKA5gU5mF5bHh+IasYadX7NEQ== X-Received: by 2002:ac8:7d0e:: with SMTP id g14mr23421467qtb.638.1638569922975; Fri, 03 Dec 2021 14:18:42 -0800 (PST) Received: from localhost (cpe-174-109-172-136.nc.res.rr.com. [174.109.172.136]) by smtp.gmail.com with ESMTPSA id j126sm2787673qke.103.2021.12.03.14.18.42 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 03 Dec 2021 14:18:42 -0800 (PST) From: Josef Bacik To: linux-btrfs@vger.kernel.org, kernel-team@fb.com Subject: [PATCH 17/18] btrfs: make should_throttle loop local in btrfs_truncate_inode_items Date: Fri, 3 Dec 2021 17:18:19 -0500 Message-Id: <696600c24743e5265c188e7d5522f04870ad080d.1638569556.git.josef@toxicpanda.com> X-Mailer: git-send-email 2.26.3 In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-btrfs@vger.kernel.org We reset this bool on every loop through the truncate loop, make this variable local to the loop. Signed-off-by: Josef Bacik --- fs/btrfs/inode-item.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/fs/btrfs/inode-item.c b/fs/btrfs/inode-item.c index 257a72ec8993..4d3a6448aca2 100644 --- a/fs/btrfs/inode-item.c +++ b/fs/btrfs/inode-item.c @@ -473,7 +473,6 @@ int btrfs_truncate_inode_items(struct btrfs_trans_handle *trans, int ret; u64 bytes_deleted = 0; bool be_nice = false; - bool should_throttle = false; ASSERT(control->inode || !control->clear_extent_range); ASSERT(new_size == 0 || control->min_type == BTRFS_EXTENT_DATA_KEY); @@ -525,6 +524,7 @@ int btrfs_truncate_inode_items(struct btrfs_trans_handle *trans, while (1) { u64 clear_start = 0, clear_len = 0, extent_start = 0; + bool should_throttle = false; fi = NULL; leaf = path->nodes[0]; @@ -669,7 +669,6 @@ int btrfs_truncate_inode_items(struct btrfs_trans_handle *trans, control->last_size = new_size; break; } - should_throttle = false; if (del_item && extent_start != 0 && !control->skip_ref_updates) { struct btrfs_ref ref = { 0 }; From patchwork Fri Dec 3 22:18:20 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Josef Bacik X-Patchwork-Id: 12655921 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 1EF87C433FE for ; Fri, 3 Dec 2021 22:18:47 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1383410AbhLCWWK (ORCPT ); Fri, 3 Dec 2021 17:22:10 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47902 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1383408AbhLCWWJ (ORCPT ); Fri, 3 Dec 2021 17:22:09 -0500 Received: from mail-qv1-xf34.google.com (mail-qv1-xf34.google.com [IPv6:2607:f8b0:4864:20::f34]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 46D89C061751 for ; Fri, 3 Dec 2021 14:18:45 -0800 (PST) Received: by mail-qv1-xf34.google.com with SMTP id i12so4122012qvh.11 for ; Fri, 03 Dec 2021 14:18:45 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=toxicpanda-com.20210112.gappssmtp.com; s=20210112; h=from:to:subject:date:message-id:in-reply-to:references:mime-version :content-transfer-encoding; bh=qISeoj5fnwcteS9756ffi82UIwH3LmhPGhdkH/LqKD0=; b=SO7RTIFpLHUAgs5UXV7kiHn0nPlXuycZ1EaE4Bc6Vc/JRbSkC613mCO5ikmJ2YVk1a OKgada+Awkw7M5fFq1D+ZRUY5iim2DKZfytJdvGj2GnSEuJoJBegkLs2hcZPAm0B2ogD Smmhv0XXem0GrwLMCyYTR3zyTMnO2bH/vnbi3TpzuPdHzNg809AP7VBekxDxKgjZWSvD n2unS/hL4hpkQSABxdAbkhcT9eg4zJIfmMyfUP1qKQ/YbpLBoPkAhbo6pOr/ftUX4Y/G NDtLhJl1GRtLyAGXMacKVpQd6r2ogZYyQq/c+FeNppQEm/fxHgX4+VNJvo9Tt+RI+1vD b9Sg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=qISeoj5fnwcteS9756ffi82UIwH3LmhPGhdkH/LqKD0=; b=iaK20nX7Hx5ssrF2L5eGucVDJQfP4THjJd/RMmqLc02RVyMMK1kfi1gWNfdx4L49qk U0kSmZLaIwhIJ6l9bETuaRsntNHlb5E9Exw8ZFDs3ksd5FZiC5SGntO3k8YeuFoNdcm2 BoJ/V4ZKAiMQQl8doh1yvDD3zWmqDektOK+ZfORen3Gwy6ChN+1mbb1h+qW/XCzHtkVa 2hUDb+/8iuiWtH/qFxRJxbZhE0n3/0Y/WYqarWQYNmg5yxZbicDVLSbEq7fobKEuAewN 1OqUryqWvMeQ0vBYTArTvipRt/6D+FTdFnUmbFIPepPhAA0hE7NOoFgusdKj4O9qSWU6 OlTA== X-Gm-Message-State: AOAM532IHN3m7ad97KhC4EuV4xTrPw39cZ7XLwiqE1imG573GsAnUqiS zA3u2KCOAlNLmG41l2SUMhiO8xSlaPk5gA== X-Google-Smtp-Source: ABdhPJyXM6DE8QWKoTzMp6hf5wLCpmtWxRJq4Ded+StJKn0Xb6NY2AKVUqZjrmw1P6pEbVkPTCWu+Q== X-Received: by 2002:ad4:42cb:: with SMTP id f11mr21946934qvr.23.1638569924238; Fri, 03 Dec 2021 14:18:44 -0800 (PST) Received: from localhost (cpe-174-109-172-136.nc.res.rr.com. [174.109.172.136]) by smtp.gmail.com with ESMTPSA id t11sm2790122qkm.96.2021.12.03.14.18.43 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 03 Dec 2021 14:18:43 -0800 (PST) From: Josef Bacik To: linux-btrfs@vger.kernel.org, kernel-team@fb.com Subject: [PATCH 18/18] btrfs: do not check -EAGAIN when truncating inodes in the log root Date: Fri, 3 Dec 2021 17:18:20 -0500 Message-Id: <0fe7c6435fb966e93f748d7d2132931e94870f5d.1638569556.git.josef@toxicpanda.com> X-Mailer: git-send-email 2.26.3 In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-btrfs@vger.kernel.org We only throttle the btrfs_truncate_inode_items if the root is SHAREABLE, which isn't set on the log root, which means this loop is unnecessary. Signed-off-by: Josef Bacik --- fs/btrfs/tree-log.c | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/fs/btrfs/tree-log.c b/fs/btrfs/tree-log.c index 80520ad1de4f..d7322ceb8aa2 100644 --- a/fs/btrfs/tree-log.c +++ b/fs/btrfs/tree-log.c @@ -4101,13 +4101,8 @@ static int truncate_inode_items(struct btrfs_trans_handle *trans, .min_type = min_type, .skip_ref_updates = true, }; - int ret; - - do { - ret = btrfs_truncate_inode_items(trans, log_root, &control); - } while (ret == -EAGAIN); - return ret; + return btrfs_truncate_inode_items(trans, log_root, &control); } static void fill_inode_item(struct btrfs_trans_handle *trans,