Btrfs: don't allocate more than max_available bytes when looped
PATCH 1/1 Btrfs: don't allocate more than max_available bytes when looped
Hello,
I had a problem running this simple test case that I was writing to test the GNU coreutils cp tool:
truncate --size=256M btrfs.img
mkfs.btrfs btrfs.img
mkdir btrfs
mount -t btrfs -o loop btrfs.img btrfs
dd bs=1M count=200 if=/dev/zero of=btrfs/alloc.test
with the current git version I get an ENOSPC error on dd, even if the available space is 256M.
The simple patch that I have attached seems to fix it.
Am I missing someting? If there is something wrong please let me know and I'll try to fix it.
Regards,
Giuseppe
Quoted 1 line
From
d6345f720f9fa5e60edd904d90d56bf9e96fb118Mon Sep 17 00:00:00 2001
From: Giuseppe Scrivano <[email protected]>
Date: Sun, 2 Aug 2009 23:29:21 +0200
Subject: [PATCH] Btrfs: don't allocate more than max_available bytes when looped
avoid that __btrfs_alloc_chunk can try to allocate more than max_available bytes if it wasn't possible on the first attempt.
--- fs/btrfs/volumes.c | 13 ++++++++----- 1 files changed, 8 insertions(+), 5 deletions(-)
fs/btrfs/volumes.c +8 -5
@@ -2180,8 +2180,8 @@ static int __btrfs_alloc_chunk(struct btrfs_trans_handle *trans, max_chunk_size =min (div_factor (fs_devices->total_rw_bytes,1 ), max_chunk_size); -again: max_avail =0 ; +again:if (!map || map->num_stripes != num_stripes) {kfree (map); map =kmalloc (map_lookup_size (num_stripes),GFP_NOFS );
@@ -2196,11 +2196,12 @@ again:do_div (calc_size, stripe_len); calc_size *= stripe_len; } -/* we don't want tiny stripes */ - calc_size =max_t (u64, min_stripe_size, calc_size); -do_div (calc_size, stripe_len); - calc_size *= stripe_len; +/* we don't want tiny stripes */ + calc_size =max_t (u64, min_stripe_size, calc_size); + +do_div (calc_size, stripe_len); + calc_size *= stripe_len; cur = fs_devices->alloc_list.next; index =0 ;
@@ -2217,6 +2218,8 @@ again:*/ if (!looped) min_free +=1024 *1024 ; +else + min_free =min_t (u64, max_avail, min_free);INIT_LIST_HEAD (&private_devs);while (index < num_stripes) {
Signature · 1 line
1.6.3.3
Hi Chris,
Thanks for your comments, I changed the patch according to them.
Quoted 1 line
From my tests, I can see that it helps to get 10% more usable space on a
256MB partition and 5% on a 750MB one.
Cheers,
Giuseppe
Quoted 1 line
From
4eff62a7132018f8685cdeff3aa439089c708258Mon Sep 17 00:00:00 2001
From: Giuseppe Scrivano <[email protected]>
Date: Mon, 3 Aug 2009 22:26:43 +0200
Subject: [PATCH] Btrfs: reduce the default min_stripe_size
The default min_stripe_size used by __btrfs_alloc_chunk was reduced to 32MB for data and 16MB for metadata chunks.
Also, after a failed attempt to alloc data, try again reducing the minimum size by a factor of 4. It may help allocating space that wouldn't otherwise.
--- fs/btrfs/volumes.c | 7 +++++-- 1 files changed, 5 insertions(+), 2 deletions(-)
fs/btrfs/volumes.c +5 -2
@@ -2166,10 +2166,10 @@ static int __btrfs_alloc_chunk(struct btrfs_trans_handle *trans,if (type &BTRFS_BLOCK_GROUP_DATA ) { max_chunk_size =10 * calc_size; - min_stripe_size =64 *1024 *1024 ; + min_stripe_size =32 *1024 *1024 ; }else if (type &BTRFS_BLOCK_GROUP_METADATA ) { max_chunk_size =4 * calc_size; - min_stripe_size =32 *1024 *1024 ; + min_stripe_size =16 *1024 *1024 ; }else if (type &BTRFS_BLOCK_GROUP_SYSTEM ) { calc_size =8 *1024 *1024 ; max_chunk_size = calc_size *2 ;
@@ -2190,6 +2190,9 @@ again: map->num_stripes = num_stripes; } +if (looped) + min_stripe_size = min_stripe_size /4 ; +if (calc_size * num_stripes > max_chunk_size) { calc_size = max_chunk_size;do_div (calc_size, num_stripes);
Signature · 1 line
1.6.3.3