From patchwork Tue Sep 11 17:57:42 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Josef Bacik X-Patchwork-Id: 10596073 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 36DB214BD for ; Tue, 11 Sep 2018 17:58:34 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 22B1529B9D for ; Tue, 11 Sep 2018 17:58:34 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 170B829BA0; Tue, 11 Sep 2018 17:58:34 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.9 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 9C5A629B9D for ; Tue, 11 Sep 2018 17:58:33 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728277AbeIKW65 (ORCPT ); Tue, 11 Sep 2018 18:58:57 -0400 Received: from mail-qk1-f177.google.com ([209.85.222.177]:43697 "EHLO mail-qk1-f177.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728184AbeIKW65 (ORCPT ); Tue, 11 Sep 2018 18:58:57 -0400 Received: by mail-qk1-f177.google.com with SMTP id 130-v6so17342608qkd.10 for ; Tue, 11 Sep 2018 10:58:31 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=toxicpanda-com.20150623.gappssmtp.com; s=20150623; h=from:to:subject:date:message-id:in-reply-to:references; bh=GfUW6hVuaKijBZKZg8WWggojmVzGxL5tDLxyZCdCQok=; b=C8sWdMCdyr1iveRUQkBF1oX6jqMOevmLxislX20JFaCa3oQt7YXjC694bqkUHW3l0q /o8E2lEUq5SxP6OmBB5rzQTjpoEu+IsoFX9SbYPZXUhouH6Jco/XsGFDIbf/UJOvK/3r T17aJDSh3+DJb0eNn5hH4/aJdZQoHh1SBJThnQw3lB3ct5wG1sDQFklDcSjbEgZKT18n yzBunbDSW0DOiTBtcu28TpNkZRjMVaUGWE6ey4ugWUU+ZYumkfmOB17eo+OBm0t75W9y QzD9jPN+R+PMIL0//RiK0OwVmGQu+4R/gvOtuk1XmAhuP9hriDFIN1JowuboVxsX5ULu Bmxg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references; bh=GfUW6hVuaKijBZKZg8WWggojmVzGxL5tDLxyZCdCQok=; b=W7YoHn8siYfdrQChHIs6WbiTQE2z9Wr7k0jjqnQ51mmRkvMf9zcsGR7QsFlkjcsWfM X1g2jVQM0ns64QKUDAIaSPclUwWY4uqeZtUTg8PI7F8+CNNzwwABoXAq6wDBeWXNVvzO q6GZNEu/PVqd4ZEKnOG1Swq30lrksFuTynmXgY1vziLPRFbpmcHA4XXbdKt9Ax14O1MY 8rD/PLudMX+aioc8bcMRg9ieEKrgJUbgbYv/lgpe+M6yZlFuvP+ZP6h+sHn6b95uR18n okkqA5KQJ2wM5ZHwlH7QhmoS3tB2jaZk3VjA3x+sb8k5mBQWEpzBStA/ehI6uvBxQ9kn rCLQ== X-Gm-Message-State: APzg51CyF4KMi0cZrtnerZaVfZoDwSUdgoOP/xRP+1fsv4ts/Br/mRRb VJIeXxtBHMxq9gpHFczRlo5lBg== X-Google-Smtp-Source: ANB0Vda0inwRU4quggrwqvAOmG7MboAOM3EpsqIeZlqYDK0HrsjF6pnN0aKrn4Ldh790w99zmbm4+Q== X-Received: by 2002:a37:9dd8:: with SMTP id g207-v6mr19228953qke.19.1536688711233; Tue, 11 Sep 2018 10:58:31 -0700 (PDT) Received: from localhost ([107.15.81.208]) by smtp.gmail.com with ESMTPSA id x76-v6sm12162333qkx.25.2018.09.11.10.58.30 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Tue, 11 Sep 2018 10:58:30 -0700 (PDT) From: Josef Bacik To: kernel-team@fb.com, linux-btrfs@vger.kernel.org Subject: [PATCH 11/36] btrfs: fix truncate throttling Date: Tue, 11 Sep 2018 13:57:42 -0400 Message-Id: <20180911175807.26181-12-josef@toxicpanda.com> X-Mailer: git-send-email 2.14.3 In-Reply-To: <20180911175807.26181-1-josef@toxicpanda.com> References: <20180911175807.26181-1-josef@toxicpanda.com> Sender: linux-btrfs-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-btrfs@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP We have a bunch of magic to make sure we're throttling delayed refs when truncating a file. Now that we have a delayed refs rsv and a mechanism for refilling that reserve simply use that instead of all of this magic. Signed-off-by: Josef Bacik --- fs/btrfs/inode.c | 78 ++++++++++++-------------------------------------------- 1 file changed, 16 insertions(+), 62 deletions(-) diff --git a/fs/btrfs/inode.c b/fs/btrfs/inode.c index cd00ec869c96..60bcad901857 100644 --- a/fs/btrfs/inode.c +++ b/fs/btrfs/inode.c @@ -4493,31 +4493,6 @@ static int btrfs_rmdir(struct inode *dir, struct dentry *dentry) return err; } -static int truncate_space_check(struct btrfs_trans_handle *trans, - struct btrfs_root *root, - u64 bytes_deleted) -{ - struct btrfs_fs_info *fs_info = root->fs_info; - int ret; - - /* - * This is only used to apply pressure to the enospc system, we don't - * intend to use this reservation at all. - */ - bytes_deleted = btrfs_csum_bytes_to_leaves(fs_info, bytes_deleted); - bytes_deleted *= fs_info->nodesize; - ret = btrfs_block_rsv_add(root, &fs_info->trans_block_rsv, - bytes_deleted, BTRFS_RESERVE_NO_FLUSH); - if (!ret) { - trace_btrfs_space_reservation(fs_info, "transaction", - trans->transid, - bytes_deleted, 1); - trans->bytes_reserved += bytes_deleted; - } - return ret; - -} - /* * Return this if we need to call truncate_block for the last bit of the * truncate. @@ -4562,7 +4537,6 @@ int btrfs_truncate_inode_items(struct btrfs_trans_handle *trans, u64 bytes_deleted = 0; bool be_nice = false; bool should_throttle = false; - bool should_end = false; BUG_ON(new_size > 0 && min_type != BTRFS_EXTENT_DATA_KEY); @@ -4775,15 +4749,7 @@ int btrfs_truncate_inode_items(struct btrfs_trans_handle *trans, btrfs_abort_transaction(trans, ret); break; } - if (btrfs_should_throttle_delayed_refs(trans, fs_info)) - btrfs_async_run_delayed_refs(fs_info, - trans->delayed_ref_updates * 2, - trans->transid, 0); if (be_nice) { - if (truncate_space_check(trans, root, - extent_num_bytes)) { - should_end = true; - } if (btrfs_should_throttle_delayed_refs(trans, fs_info)) should_throttle = true; @@ -4795,7 +4761,7 @@ int btrfs_truncate_inode_items(struct btrfs_trans_handle *trans, if (path->slots[0] == 0 || path->slots[0] != pending_del_slot || - should_throttle || should_end) { + should_throttle) { if (pending_del_nr) { ret = btrfs_del_items(trans, root, path, pending_del_slot, @@ -4807,23 +4773,23 @@ int btrfs_truncate_inode_items(struct btrfs_trans_handle *trans, pending_del_nr = 0; } btrfs_release_path(path); - if (should_throttle) { - unsigned long updates = trans->delayed_ref_updates; - if (updates) { - trans->delayed_ref_updates = 0; - ret = btrfs_run_delayed_refs(trans, - updates * 2); - if (ret) - break; - } - } + /* - * if we failed to refill our space rsv, bail out - * and let the transaction restart + * 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 + * only FLUSH_LIMIT, if this fails we just return EAGAIN + * and let the normal space allocation stuff do it's + * work. */ - if (should_end) { - ret = -EAGAIN; - break; + if (should_throttle) { + ret = btrfs_throttle_delayed_refs(fs_info, + BTRFS_RESERVE_FLUSH_LIMIT); + if (ret) { + ret = -EAGAIN; + break; + } } goto search_again; } else { @@ -4849,18 +4815,6 @@ int btrfs_truncate_inode_items(struct btrfs_trans_handle *trans, } btrfs_free_path(path); - - if (be_nice && bytes_deleted > SZ_32M && (ret >= 0 || ret == -EAGAIN)) { - unsigned long updates = trans->delayed_ref_updates; - int err; - - if (updates) { - trans->delayed_ref_updates = 0; - err = btrfs_run_delayed_refs(trans, updates * 2); - if (err) - ret = err; - } - } return ret; }