* [PATCH v2] Btrfs: use do_div to avoid compile errors on 32bit box
@ 2011-08-20 2:17 Liu Bo
2011-08-20 12:21 ` Josef Bacik
0 siblings, 1 reply; 3+ messages in thread
From: Liu Bo @ 2011-08-20 2:17 UTC (permalink / raw)
To: linux-kernel
Cc: torvalds, mingo, jwboyer, josef, linux-btrfs, chris.mason, dave
When doing div operation of u64 type, we need to be careful and use do_div
to avoid compile ERROR on 32bit box:
"ERROR: "__udivdi3" [fs/btrfs/btrfs.ko] undefined!
make[1]: *** [__modpost] Error 1
v1->v2:
- fix stupid do_div() with type "signed integer".
Signed-off-by: Liu Bo <liubo2009@cn.fujitsu.com>
---
fs/btrfs/extent-tree.c | 11 ++++++-----
1 files changed, 6 insertions(+), 5 deletions(-)
diff --git a/fs/btrfs/extent-tree.c b/fs/btrfs/extent-tree.c
index 80d6148..e43e4f1 100644
--- a/fs/btrfs/extent-tree.c
+++ b/fs/btrfs/extent-tree.c
@@ -6735,9 +6735,10 @@ int btrfs_can_relocate(struct btrfs_root *root, u64 bytenr)
struct btrfs_fs_devices *fs_devices = root->fs_info->fs_devices;
struct btrfs_device *device;
u64 min_free;
+ u32 dev_min = 1;
+ u32 dev_nr = 0;
+ u32 dup = 2;
int index;
- int dev_nr = 0;
- int dev_min = 1;
int full = 0;
int ret = 0;
@@ -6796,14 +6797,14 @@ int btrfs_can_relocate(struct btrfs_root *root, u64 bytenr)
index = get_block_group_index(block_group);
if (index == 0) {
dev_min = 4;
- min_free /= 2;
+ do_div(min_free, dup);
} else if (index == 1) {
dev_min = 2;
} else if (index == 2) {
- min_free *= 2;
+ min_free *= dup;
} else if (index == 3) {
dev_min = fs_devices->rw_devices;
- min_free /= dev_min;
+ do_div(min_free, dev_min);
}
mutex_lock(&root->fs_info->chunk_mutex);
--
1.6.5.2
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [PATCH v2] Btrfs: use do_div to avoid compile errors on 32bit box
2011-08-20 2:17 [PATCH v2] Btrfs: use do_div to avoid compile errors on 32bit box Liu Bo
@ 2011-08-20 12:21 ` Josef Bacik
2011-08-21 1:04 ` Linus Torvalds
0 siblings, 1 reply; 3+ messages in thread
From: Josef Bacik @ 2011-08-20 12:21 UTC (permalink / raw)
To: Liu Bo
Cc: linux-kernel, torvalds, mingo, jwboyer, linux-btrfs, chris.mason,
dave
On 08/19/2011 10:17 PM, Liu Bo wrote:
> When doing div operation of u64 type, we need to be careful and use do_div
> to avoid compile ERROR on 32bit box:
>
> "ERROR: "__udivdi3" [fs/btrfs/btrfs.ko] undefined!
> make[1]: *** [__modpost] Error 1
>
> v1->v2:
> - fix stupid do_div() with type "signed integer".
>
> Signed-off-by: Liu Bo <liubo2009@cn.fujitsu.com>
> ---
> fs/btrfs/extent-tree.c | 11 ++++++-----
> 1 files changed, 6 insertions(+), 5 deletions(-)
>
> diff --git a/fs/btrfs/extent-tree.c b/fs/btrfs/extent-tree.c
> index 80d6148..e43e4f1 100644
> --- a/fs/btrfs/extent-tree.c
> +++ b/fs/btrfs/extent-tree.c
> @@ -6735,9 +6735,10 @@ int btrfs_can_relocate(struct btrfs_root *root, u64 bytenr)
> struct btrfs_fs_devices *fs_devices = root->fs_info->fs_devices;
> struct btrfs_device *device;
> u64 min_free;
> + u32 dev_min = 1;
> + u32 dev_nr = 0;
> + u32 dup = 2;
> int index;
> - int dev_nr = 0;
> - int dev_min = 1;
> int full = 0;
> int ret = 0;
>
> @@ -6796,14 +6797,14 @@ int btrfs_can_relocate(struct btrfs_root *root, u64 bytenr)
> index = get_block_group_index(block_group);
> if (index == 0) {
> dev_min = 4;
> - min_free /= 2;
> + do_div(min_free, dup);
I think Linus was less complaining about how you're dividing here and
more about the fact that you are. A divide by 2 is the same as a >> 1.
I'll send a patch to fix this. Thanks,
Josef
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH v2] Btrfs: use do_div to avoid compile errors on 32bit box
2011-08-20 12:21 ` Josef Bacik
@ 2011-08-21 1:04 ` Linus Torvalds
0 siblings, 0 replies; 3+ messages in thread
From: Linus Torvalds @ 2011-08-21 1:04 UTC (permalink / raw)
To: Josef Bacik
Cc: Liu Bo, linux-kernel, mingo, jwboyer, linux-btrfs, chris.mason,
dave
On Sat, Aug 20, 2011 at 5:21 AM, Josef Bacik <josef@redhat.com> wrote:
>
> I think Linus was less complaining about how you're dividing here and
> more about the fact that you are. =A0A divide by 2 is the same as a >=
> 1.
> =A0I'll send a patch to fix this. =A0Thanks,
Indeed. A single-bit 64-bit "double shift" may be a few cycles, but
it's still pretty damn cheap. Especially when compared to a 64x32 bit
divide. We absolutely don't want to do "do_div()" in order to divide
by the constant 2.
Linus
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2011-08-21 1:04 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2011-08-20 2:17 [PATCH v2] Btrfs: use do_div to avoid compile errors on 32bit box Liu Bo
2011-08-20 12:21 ` Josef Bacik
2011-08-21 1:04 ` Linus Torvalds
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).