linux-btrfs.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] Btrfs: do not create empty block group if we have allocated data
@ 2015-12-15  2:29 Liu Bo
  2016-04-11 15:02 ` David Sterba
  0 siblings, 1 reply; 3+ messages in thread
From: Liu Bo @ 2015-12-15  2:29 UTC (permalink / raw)
  To: linux-btrfs; +Cc: zhaolei

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 <bo.li.liu@oracle.com>
---
 fs/btrfs/volumes.c |    9 ++++++++-
 1 files changed, 8 insertions(+), 1 deletions(-)

diff --git a/fs/btrfs/volumes.c b/fs/btrfs/volumes.c
index 4564522..14139c9 100644
--- a/fs/btrfs/volumes.c
+++ b/fs/btrfs/volumes.c
@@ -3400,6 +3400,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;
@@ -3538,7 +3539,13 @@ again:
 			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);
-- 
1.7.1


^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH] Btrfs: do not create empty block group if we have allocated data
  2015-12-15  2:29 [PATCH] Btrfs: do not create empty block group if we have allocated data Liu Bo
@ 2016-04-11 15:02 ` David Sterba
  2016-04-12 17:03   ` Liu Bo
  0 siblings, 1 reply; 3+ messages in thread
From: David Sterba @ 2016-04-11 15:02 UTC (permalink / raw)
  To: Liu Bo; +Cc: linux-btrfs, zhaolei

On Mon, Dec 14, 2015 at 06:29:32PM -0800, Liu Bo wrote:
> 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 <bo.li.liu@oracle.com>

I'm adding the patch to my for-next.

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] Btrfs: do not create empty block group if we have allocated data
  2016-04-11 15:02 ` David Sterba
@ 2016-04-12 17:03   ` Liu Bo
  0 siblings, 0 replies; 3+ messages in thread
From: Liu Bo @ 2016-04-12 17:03 UTC (permalink / raw)
  To: dsterba, linux-btrfs, zhaolei

On Mon, Apr 11, 2016 at 05:02:18PM +0200, David Sterba wrote:
> On Mon, Dec 14, 2015 at 06:29:32PM -0800, Liu Bo wrote:
> > 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 <bo.li.liu@oracle.com>
> 
> I'm adding the patch to my for-next.

Thank you, David.

Thanks,

-liubo

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2016-04-12 17:02 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2015-12-15  2:29 [PATCH] Btrfs: do not create empty block group if we have allocated data Liu Bo
2016-04-11 15:02 ` David Sterba
2016-04-12 17:03   ` Liu Bo

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).