From patchwork Fri Sep 14 07:49:44 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Qu Wenruo X-Patchwork-Id: 10600339 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 8FE3E933 for ; Fri, 14 Sep 2018 07:49:55 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 378CB2B5E3 for ; Fri, 14 Sep 2018 07:49:55 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 2A80D2B5EE; Fri, 14 Sep 2018 07:49:55 +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,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 C3B0B2B5E3 for ; Fri, 14 Sep 2018 07:49:54 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728004AbeINNDH (ORCPT ); Fri, 14 Sep 2018 09:03:07 -0400 Received: from mx2.suse.de ([195.135.220.15]:51620 "EHLO mx1.suse.de" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1727987AbeINNDH (ORCPT ); Fri, 14 Sep 2018 09:03:07 -0400 X-Virus-Scanned: by amavisd-new at test-mx.suse.de Received: from relay1.suse.de (unknown [195.135.220.254]) by mx1.suse.de (Postfix) with ESMTP id DD6B6AF68 for ; Fri, 14 Sep 2018 07:49:51 +0000 (UTC) From: Qu Wenruo To: linux-btrfs@vger.kernel.org Subject: [PATCH v1.1] btrfs-progs: Do metadata prealloc as long as we're not modifying extent tree Date: Fri, 14 Sep 2018 15:49:44 +0800 Message-Id: <20180914074944.19526-1-wqu@suse.com> X-Mailer: git-send-email 2.19.0 MIME-Version: 1.0 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 In github issues, one user reports unexpected ENOSPC error if enabling datasum. After some investigation, it looks like that during ext2_saved/image creation, we could create large file extent whose size can be 128M (max data extent size). In that case, its csum will be at least 128K. Under certain case we need to allocate extra metadata chunks to fulfill such space requirement. However we only do metadata prealloc if we're reserving extents for fs trees. (we use btrfs_root::ref_cows to determine whether we should do metadata prealloc, and that member is only set for fs trees). There is no explaination on why we only do metadata prealloc for file trees, but at least from my investigation, it could be related to avoid nested extent tree modication. At least extent reservation for csum tree shouldn't be a problem with metadata block group preallocation. So change the metadata block group preallocation check from "root->ref_cow" to "root->root_key.objectid != BTRFS_EXTENT_TREE_OBJECTID", and add some comment for it. Issue: 123 Signed-off-by: Qu Wenruo --- changelog: v1.1 Fix stupid subject, from "csum tree" to "extent tree" --- extent-tree.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/extent-tree.c b/extent-tree.c index 5d49af5a901e..bdf1b0e94c5f 100644 --- a/extent-tree.c +++ b/extent-tree.c @@ -2652,7 +2652,12 @@ int btrfs_reserve_extent(struct btrfs_trans_handle *trans, profile = BTRFS_BLOCK_GROUP_METADATA | alloc_profile; } - if (root->ref_cows) { + /* + * Do metadata preallocate if we're not modifying extent tree. + * Allocating chunk while modify extent tree could lead to tranid + * mismatch, as do_chunk_alloc() could commit transaction. + */ + if (root->root_key.objectid != BTRFS_EXTENT_TREE_OBJECTID) { if (!(profile & BTRFS_BLOCK_GROUP_METADATA)) { ret = do_chunk_alloc(trans, info, num_bytes,