søn, 08 03 2009 kl. 20:03 -0600, skrev Yien Zheng:
> Thanks Jens!  My research had indicated something about 64-bit
> division and using do_div, but you cleared it up for me.
> 
> The fragmentation_percent function ultimately does another divide to
> get the percentage, so here's what I did to get the function to work:
> 
> static int fragmentation_percent(struct btrfs_block_group_cache *block_group)
> {
>         u64 max_fragments;
>         u64 fragments_ratio;
> 
>         max_fragments = block_group->key.offset -
>                 btrfs_block_group_used(&block_group->item);
>         do_div(max_fragments, block_group->fragment_size);
>         fragments_ratio = block_group->fragments;
>         do_div(fragments_ratio, max_fragments);
>         return (fragments_ratio * 100);
> }
> 
So the idea of the function is to return an integer in the range
[0,100]? The problem is that it will only return either 0 or 100, but
nothing in between, right?

Wouldn't something along the lines of the following be better?

u64 tmp = (block_group->key.offset -
        btrfs_block_group_used(&block_group->item);
u64 tmp2 = 100 * block_group->fragment_size * block_group->fragments;
do_div(tmp2, tmp);
return tmp2;


Simon Holm Thøgersen

--
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

Reply via email to