From patchwork Wed Dec 20 04:57:19 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Su Yue X-Patchwork-Id: 10124975 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 9934860638 for ; Wed, 20 Dec 2017 04:53:52 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 91AAF28E2D for ; Wed, 20 Dec 2017 04:53:52 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 80C8E294D7; Wed, 20 Dec 2017 04:53:52 +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 1579B2920C for ; Wed, 20 Dec 2017 04:53:52 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754482AbdLTExr (ORCPT ); Tue, 19 Dec 2017 23:53:47 -0500 Received: from mail.cn.fujitsu.com ([183.91.158.132]:38594 "EHLO heian.cn.fujitsu.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1754430AbdLTExq (ORCPT ); Tue, 19 Dec 2017 23:53:46 -0500 X-IronPort-AV: E=Sophos;i="5.43,368,1503331200"; d="scan'208";a="31879397" Received: from localhost (HELO cn.fujitsu.com) ([10.167.33.5]) by heian.cn.fujitsu.com with ESMTP; 20 Dec 2017 12:53:41 +0800 Received: from G08CNEXCHPEKD02.g08.fujitsu.local (unknown [10.167.33.83]) by cn.fujitsu.com (Postfix) with ESMTP id 2936D48AE9E5; Wed, 20 Dec 2017 12:53:39 +0800 (CST) Received: from archlinux.g08.fujitsu.local (10.167.226.31) by G08CNEXCHPEKD02.g08.fujitsu.local (10.167.33.89) with Microsoft SMTP Server (TLS) id 14.3.361.1; Wed, 20 Dec 2017 12:53:37 +0800 From: Su Yue To: CC: , Subject: [PATCH v2 05/17] btrfs-progs: lowmem check: introduce modify_block_groups_cache() Date: Wed, 20 Dec 2017 12:57:19 +0800 Message-ID: <20171220045731.19343-6-suy.fnst@cn.fujitsu.com> X-Mailer: git-send-email 2.15.1 In-Reply-To: <20171220045731.19343-1-suy.fnst@cn.fujitsu.com> References: <20171220045731.19343-1-suy.fnst@cn.fujitsu.com> MIME-Version: 1.0 X-Originating-IP: [10.167.226.31] X-yoursite-MailScanner-ID: 2936D48AE9E5.AAF42 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 Excluding or pining all metadata blocks is not time-efficient for large storage filesystems. Here is another way to mark all metadata block groups full and allocate a new chunk for CoW. So new reservered extents never overwrite extents. Introduce modify_block_groups_cache() to modify all blocks groups cache state and set all extents in block groups unfree in free space cache. Suggested-by: Qu Wenruo Signed-off-by: Su Yue --- cmds-check.c | 83 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 83 insertions(+) diff --git a/cmds-check.c b/cmds-check.c index dd46569f3811..d98d4bda7357 100644 --- a/cmds-check.c +++ b/cmds-check.c @@ -10828,6 +10828,89 @@ static void reset_cached_block_groups(struct btrfs_fs_info *fs_info) } } +/* + * Mark all extents unfree in the block group. And set @block_group->cached + * according to @cache. + */ +static int modify_block_group_cache(struct btrfs_fs_info *fs_info, + struct btrfs_block_group_cache *block_group, int cache) +{ + struct extent_io_tree *free_space_cache = &fs_info->free_space_cache; + u64 start = block_group->key.objectid; + u64 end = start + block_group->key.offset; + + if (cache && !block_group->cached) { + block_group->cached = 1; + clear_extent_dirty(free_space_cache, start, end - 1); + } + + if (!cache && block_group->cached) { + block_group->cached = 0; + clear_extent_dirty(free_space_cache, start, end - 1); + } + return 0; +} + +/* + * Modify block groups which have @flags unfree in free space cache. + * + * @cache: if 0, clear block groups cache state; + * not 0, mark blocks groups cached. + */ +static int modify_block_groups_cache(struct btrfs_fs_info *fs_info, u64 flags, + int cache) +{ + struct btrfs_root *root = fs_info->extent_root; + struct btrfs_key key; + struct btrfs_path path; + struct btrfs_block_group_cache *bg_cache; + struct btrfs_block_group_item *bi; + struct btrfs_block_group_item bg_item; + struct extent_buffer *eb; + int slot; + int ret; + + key.objectid = 0; + key.type = BTRFS_BLOCK_GROUP_ITEM_KEY; + key.offset = 0; + + btrfs_init_path(&path); + ret = btrfs_search_slot(NULL, root, &key, &path, 0, 0); + if (ret < 0) { + error("fail to search block groups due to %s", strerror(-ret)); + goto out; + } + + while (1) { + eb = path.nodes[0]; + slot = path.slots[0]; + btrfs_item_key_to_cpu(eb, &key, slot); + bg_cache = btrfs_lookup_block_group(fs_info, key.objectid); + if (!bg_cache) { + ret = -ENOENT; + goto out; + } + + bi = btrfs_item_ptr(eb, slot, struct btrfs_block_group_item); + read_extent_buffer(eb, &bg_item, (unsigned long)bi, + sizeof(bg_item)); + if (btrfs_block_group_flags(&bg_item) & flags) + modify_block_group_cache(fs_info, bg_cache, cache); + + ret = btrfs_next_item(root, &path); + if (ret > 0) { + ret = 0; + goto out; + } + if (ret < 0) + goto out; + } + +out: + btrfs_release_path(&path); + return ret; +} + static int check_extent_refs(struct btrfs_root *root, struct cache_tree *extent_cache) {