From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mx2.suse.de ([195.135.220.15]:51382 "EHLO mx2.suse.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S932083AbcFCPmu (ORCPT ); Fri, 3 Jun 2016 11:42:50 -0400 Received: from relay2.suse.de (charybdis-ext.suse.de [195.135.220.254]) by mx2.suse.de (Postfix) with ESMTP id 398D0AC71 for ; Fri, 3 Jun 2016 15:42:49 +0000 (UTC) From: David Sterba To: stable@vger.kernel.org Subject: [PATCH 02/21] Btrfs: do not create empty block group if we have allocated data Date: Fri, 3 Jun 2016 17:42:10 +0200 Message-Id: <1464968530-6233-1-git-send-email-dsterba@suse.com> In-Reply-To: <20160603154006.GP29147@suse.cz> References: <20160603154006.GP29147@suse.cz> Sender: stable-owner@vger.kernel.org List-ID: From: Liu Bo commit cf25ce518e8ef9d59b292e51193bed2b023a32da upstream. Now we force to create empty block group to keep data profile alive, however, in the below example, we eventually get an empty block group while we're trying to get more space for other types (metadata/system), - Before, block group "A": size=2G, used=1.2G block group "B": size=2G, used=512M - After "btrfs balance start -dusage=50 mount_point", block group "A": size=2G, used=(1.2+0.5)G block group "C": size=2G, used=0 Since there is no data in block group C, it won't be deleted automatically and we have to get the unused 2G until the next mount. Balance itself just moves data and doesn't remove data, so it's safe to not create such a empty block group if we already have data allocated in other block groups. Signed-off-by: Liu Bo Signed-off-by: David Sterba --- fs/btrfs/volumes.c | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/fs/btrfs/volumes.c b/fs/btrfs/volumes.c index 366b335946fa..adb5f697a963 100644 --- a/fs/btrfs/volumes.c +++ b/fs/btrfs/volumes.c @@ -3401,6 +3401,7 @@ static int __btrfs_balance(struct btrfs_fs_info *fs_info) u32 count_meta = 0; u32 count_sys = 0; int chunk_reserved = 0; + u64 bytes_used = 0; /* step one make some room on all the devices */ devices = &fs_info->fs_devices->devices; @@ -3539,7 +3540,13 @@ static int __btrfs_balance(struct btrfs_fs_info *fs_info) goto loop; } - if ((chunk_type & BTRFS_BLOCK_GROUP_DATA) && !chunk_reserved) { + ASSERT(fs_info->data_sinfo); + spin_lock(&fs_info->data_sinfo->lock); + bytes_used = fs_info->data_sinfo->bytes_used; + spin_unlock(&fs_info->data_sinfo->lock); + + if ((chunk_type & BTRFS_BLOCK_GROUP_DATA) && + !chunk_reserved && !bytes_used) { trans = btrfs_start_transaction(chunk_root, 0); if (IS_ERR(trans)) { mutex_unlock(&fs_info->delete_unused_bgs_mutex); -- 2.7.1