Skip to contentSkip to conversation

Btrfs: fix chunk allocate size calculation

PATCH In review Josef Bacik 3 participants 4 messages Mar 17, 2010 – Apr 6, 2010 Btrfs file system

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 Btrfs: fix chunk allocate size calculation

If the amount of free space left in a device is less than what we think should be the minimum size, just ignore the minimum size and use the amount we have. I ran into this running tests on a 600mb volume, the chunk allocator wouldn't let me allocate the last 52mb of the disk for data because we want to have at least 64mb chunks for data. This patch fixes that problem. Thanks,

fs/btrfs/volumes.c +3 -1
index 9df8e3f..1c5b5ba 100644
@@ -2244,8 +2244,10 @@ 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);
+	if (!looped)
+		calc_size = max_t(u64, min_stripe_size, calc_size);
 
 	do_div(calc_size, stripe_len);
 	calc_size *= stripe_len;
Signature · 1 line
1.6.6
#1 lore raw
Quoted 1 line · Josef Bacik

If the amount of free space left in a device is less than what we thi=

nk should

Quoted 1 line

be the minimum size, just ignore the minimum size and use the amount =

we have. =A0I

Quoted 1 line

ran into this running tests on a 600mb volume, the chunk allocator wo=

uldn't let

Quoted 1 line

me allocate the last 52mb of the disk for data because we want to hav=

e at least

Quoted 13 lines

64mb chunks for data. =A0This patch fixes that problem. =A0Thanks,

fs/btrfs/volumes.c +1 -0
index 9df8e3f..1c5b5ba 100644
@@ -2244,8 +2244,10 @@ again:
 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0do_div(calc_size, stripe_len);
 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0calc_size *=3D stripe_len;
 =A0 =A0 =A0 =A0}
+
Quoted 4 lines

=A0 =A0 =A0 =A0/* we don't want tiny stripes */
- =A0 =A0 =A0 calc_size =3D max_t(u64, min_stripe_size, calc_size);
+ =A0 =A0 =A0 if (!looped)
+ =A0 =A0 =A0 =A0 =A0 =A0 =A0 calc_size =3D max_t(u64, min_stripe_siz=

e, calc_size);

Quoted 3 lines

=A0 =A0 =A0 =A0do_div(calc_size, stripe_len);
=A0 =A0 =A0 =A0calc_size *=3D stripe_len;

I encountered an Oops caused by 'calc_size =3D=3D 0'. It's likely intro= duced
by this change. (calc_size can be zero after calling do_div) --
To unsubscribe from this list: send the line "unsubscribe linux-btrfs" = in
the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html

#2 lore raw
Quoted 1 line · Zheng

On Thu, Mar 18, 2010 at 4:45 AM, Josef Bacik <[email protected]> wrote=

:

Quoted 1 line
Quoted 1 line

If the amount of free space left in a device is less than what we t=

hink should

Quoted 1 line
Quoted 1 line

be the minimum size, just ignore the minimum size and use the amoun=

t we have. =A0I

Quoted 1 line
Quoted 1 line

ran into this running tests on a 600mb volume, the chunk allocator =

wouldn't let

Quoted 1 line
Quoted 1 line

me allocate the last 52mb of the disk for data because we want to h=

ave at least

Quoted 4 lines
Quoted 4 lines

64mb chunks for data. =A0This patch fixes that problem. =A0Thanks,

Quoted 13 lines
Quoted 9 lines
fs/btrfs/volumes.c +1 -0
index 9df8e3f..1c5b5ba 100644
@@ -2244,8 +2244,10 @@ again:
 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0do_div(calc_size, stripe_len);
 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0calc_size *=3D stripe_len;
 =A0 =A0 =A0 =A0}
+
Quoted 4 lines

=A0 =A0 =A0 =A0/* we don't want tiny stripes */
- =A0 =A0 =A0 calc_size =3D max_t(u64, min_stripe_size, calc_size);
+ =A0 =A0 =A0 if (!looped)
+ =A0 =A0 =A0 =A0 =A0 =A0 =A0 calc_size =3D max_t(u64, min_stripe_s=

ize, calc_size);

Quoted 5 lines
Quoted 3 lines

=A0 =A0 =A0 =A0do_div(calc_size, stripe_len);
=A0 =A0 =A0 =A0calc_size *=3D stripe_len;

=20
I encountered an Oops caused by 'calc_size =3D=3D 0'. It's likely int=

roduced

Quoted 1 line

by this change. (calc_size can be zero after calling do_div)

Ok, thanks will fix it up.

-chris

--
To unsubscribe from this list: send the line "unsubscribe linux-btrfs" = in
the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html

#3 lore raw
Quoted 2 lines · Chris Mason
Quoted 1 line · Zheng

On Thu, Mar 18, 2010 at 4:45 AM, Josef Bacik <[email protected]> wro=

te:

Quoted 1 line
Quoted 1 line
Quoted 1 line

If the amount of free space left in a device is less than what we=

think should

Quoted 1 line
Quoted 1 line
Quoted 1 line

be the minimum size, just ignore the minimum size and use the amo=

unt we have. =A0I

Quoted 1 line
Quoted 1 line
Quoted 1 line

ran into this running tests on a 600mb volume, the chunk allocato=

r wouldn't let

Quoted 1 line
Quoted 1 line
Quoted 1 line

me allocate the last 52mb of the disk for data because we want to=

have at least

Quoted 1 line
Quoted 1 line
Quoted 1 line

64mb chunks for data. =A0This patch fixes that problem. =A0Thanks=

,

Quoted 14 lines
Quoted 14 lines
Quoted 12 lines
fs/btrfs/volumes.c +1 -0
index 9df8e3f..1c5b5ba 100644
@@ -2244,8 +2244,10 @@ again:
 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0do_div(calc_size, stripe_len);
 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0calc_size *=3D stripe_len;
 =A0 =A0 =A0 =A0}
+
Quoted 2 lines

=A0 =A0 =A0 =A0/* we don't want tiny stripes */
- =A0 =A0 =A0 calc_size =3D max_t(u64, min_stripe_size, calc_size=

);

Quoted 2 lines
Quoted 2 lines
Quoted 2 lines

+ =A0 =A0 =A0 if (!looped)
+ =A0 =A0 =A0 =A0 =A0 =A0 =A0 calc_size =3D max_t(u64, min_stripe=

_size, calc_size);

Quoted 5 lines
Quoted 5 lines
Quoted 3 lines

=A0 =A0 =A0 =A0do_div(calc_size, stripe_len);
=A0 =A0 =A0 =A0calc_size *=3D stripe_len;

=20
I encountered an Oops caused by 'calc_size =3D=3D 0'. It's likely i=

ntroduced

Quoted 1 line
Quoted 1 line

by this change. (calc_size can be zero after calling do_div)

Ok, anyone object to this:

=46rom 9f680ce04ea19dabbbafe01b57b61930a9b70741 Mon Sep 17 00:00:00 200= 1
=46rom: Chris Mason <[email protected]>
Date: Tue, 6 Apr 2010 09:37:47 -0400
Subject: [PATCH] Btrfs: make sure the chunk allocator doesn't create ze= ro length chunks

A recent commit allowed for smaller chunks to be created, but didn't make sure they were always bigger than a stripe. After some divides, this led to zero length stripes.

---
 fs/btrfs/volumes.c |    6 ++++++
 1 files changed, 6 insertions(+), 0 deletions(-)
fs/btrfs/volumes.c +0 -0
index 9bf1f58..b584e9a 100644
@@ -2249,6 +2249,12 @@ again:
 	if (!looped)
 		calc_size =3D max_t(u64, min_stripe_size, calc_size);

=20
+ /*
+ * we're about to do_div by the stripe_len so lets make sure
+ * we end up with something bigger than a stripe
+ */
+ calc_size =3D max_t(u64, calc_size, stripe_len * 4);
+
do_div(calc_size, stripe_len);
calc_size *=3D stripe_len;
=20
--=20
1.7.0.2

--
To unsubscribe from this list: send the line "unsubscribe linux-btrfs" = in
the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html