From patchwork Thu Jan 11 07:35:02 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Su Yue X-Patchwork-Id: 10157423 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id EB835601A1 for ; Thu, 11 Jan 2018 07:31:19 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id DB5A8286F2 for ; Thu, 11 Jan 2018 07:31:19 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id D06DD286F8; Thu, 11 Jan 2018 07:31:19 +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=-6.9 required=2.0 tests=BAYES_00,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 78FA5286F2 for ; Thu, 11 Jan 2018 07:31:19 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S932069AbeAKHbP (ORCPT ); Thu, 11 Jan 2018 02:31:15 -0500 Received: from mail.cn.fujitsu.com ([183.91.158.132]:21049 "EHLO heian.cn.fujitsu.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1753918AbeAKHbN (ORCPT ); Thu, 11 Jan 2018 02:31:13 -0500 X-IronPort-AV: E=Sophos;i="5.43,368,1503331200"; d="scan'208";a="35167959" Received: from bogon (HELO cn.fujitsu.com) ([10.167.33.5]) by heian.cn.fujitsu.com with ESMTP; 11 Jan 2018 15:31:10 +0800 Received: from G08CNEXCHPEKD03.g08.fujitsu.local (unknown [10.167.33.85]) by cn.fujitsu.com (Postfix) with ESMTP id C0DAE48AEA0D for ; Thu, 11 Jan 2018 15:31:08 +0800 (CST) Received: from archlinux.g08.fujitsu.local (10.167.226.31) by G08CNEXCHPEKD03.g08.fujitsu.local (10.167.33.89) with Microsoft SMTP Server (TLS) id 14.3.361.1; Thu, 11 Jan 2018 15:31:06 +0800 From: Su Yue To: CC: Subject: [PATCH v3 08/17] btrfs-progs: lowmem check: exclude extents if init-extent-tree in lowmem Date: Thu, 11 Jan 2018 15:35:02 +0800 Message-ID: <20180111073511.25288-9-suy.fnst@cn.fujitsu.com> X-Mailer: git-send-email 2.15.1 In-Reply-To: <20180111073511.25288-1-suy.fnst@cn.fujitsu.com> References: <20180111073511.25288-1-suy.fnst@cn.fujitsu.com> MIME-Version: 1.0 X-Originating-IP: [10.167.226.31] X-yoursite-MailScanner-ID: C0DAE48AEA0D.AEEB5 X-yoursite-MailScanner: Found to be clean X-yoursite-MailScanner-From: suy.fnst@cn.fujitsu.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 If options '--init-extent-tree' and '--mode=lowmem' are both input, all metadata blocks will be traversed twice. First one is done by pin_metadata_blocks() in reinit_extent_tree(). Second one is in check_chunks_and_extents_v2(). Excluding instead of pining metadata blocks before reinit extent tree in lowmem can save some time. Signed-off-by: Su Yue --- cmds-check.c | 26 +++++++++++++++++++++----- 1 file changed, 21 insertions(+), 5 deletions(-) diff --git a/cmds-check.c b/cmds-check.c index 8ebd1a38a1b9..341f73829ec7 100644 --- a/cmds-check.c +++ b/cmds-check.c @@ -13793,6 +13793,11 @@ out: /* if repair, update block accounting */ if (repair) { + /* Just do clean up, ignore return values here*/ + end_avoid_extents_overwrite(fs_info); + modify_block_groups_cache(fs_info, BTRFS_BLOCK_GROUP_METADATA, + 0); + ret = btrfs_fix_block_accounting(trans, root); if (ret) err |= ret; @@ -13804,7 +13809,6 @@ out: btrfs_commit_transaction(trans, root->fs_info->extent_root); btrfs_release_path(&path); - return err; } @@ -14215,6 +14219,7 @@ static int reinit_extent_tree(struct btrfs_trans_handle *trans, { u64 start = 0; int ret; + int pin_extents = check_mode == CHECK_MODE_ORIGINAL; /* * The only reason we don't do this is because right now we're just @@ -14236,10 +14241,21 @@ static int reinit_extent_tree(struct btrfs_trans_handle *trans, * down the bytes that are in use so we don't overwrite any existing * metadata. */ - ret = pin_metadata_blocks(fs_info); - if (ret) { - fprintf(stderr, "error pinning down used bytes\n"); - return ret; +again: + if (pin_extents) { + ret = pin_metadata_blocks(fs_info); + if (ret) { + fprintf(stderr, "error pinning down used bytes\n"); + return ret; + } + } else { + ret = avoid_extents_overwrite(fs_info, EXTENTS_EXCLUDE); + if (ret) { + fprintf(stderr, "error excluding used bytes\n"); + printf("try to pin down used bytes\n"); + pin_extents = 1; + goto again; + } } /*