public inbox for linux-btrfs@vger.kernel.org
 help / color / mirror / Atom feed
From: "Simon Holm Thøgersen" <odie@cs.aau.dk>
To: Yien Zheng <esprout@gmail.com>
Cc: Jens Axboe <jens.axboe@oracle.com>,
	linux-btrfs@vger.kernel.org, Josef Bacik <jbacik@redhat.com>
Subject: Re: [PATCH] Btrfs: take block group fragmentation into account for allocation
Date: Mon, 09 Mar 2009 14:56:33 +0100	[thread overview]
Message-ID: <1236606993.7842.8.camel@odie.local> (raw)
In-Reply-To: <2c259a8f0903081903w7cebb98excfbf9a4ec5c147d8@mail.gmail.com>

s=C3=B8n, 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.
>=20
> The fragmentation_percent function ultimately does another divide to
> get the percentage, so here's what I did to get the function to work:
>=20
> static int fragmentation_percent(struct btrfs_block_group_cache *bloc=
k_group)
> {
>         u64 max_fragments;
>         u64 fragments_ratio;
>=20
>         max_fragments =3D block_group->key.offset -
>                 btrfs_block_group_used(&block_group->item);
>         do_div(max_fragments, block_group->fragment_size);
>         fragments_ratio =3D block_group->fragments;
>         do_div(fragments_ratio, max_fragments);
>         return (fragments_ratio * 100);
> }
>=20
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 =3D (block_group->key.offset -
	btrfs_block_group_used(&block_group->item);
u64 tmp2 =3D 100 * block_group->fragment_size * block_group->fragments;
do_div(tmp2, tmp);
return tmp2;


Simon Holm Th=C3=B8gersen

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

  reply	other threads:[~2009-03-09 13:56 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2009-03-08 14:42 [PATCH] Btrfs: take block group fragmentation into account for allocation Yien Zheng
2009-03-08 16:37 ` Jens Axboe
2009-03-09  2:03   ` Yien Zheng
2009-03-09 13:56     ` Simon Holm Thøgersen [this message]
2009-03-09 15:21       ` Oliver Mattos
2009-03-09 15:24         ` Josef Bacik
2009-03-09 17:29           ` jim owens
  -- strict thread matches above, loose matches on Subject: below --
2009-03-06 19:30 Josef Bacik

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1236606993.7842.8.camel@odie.local \
    --to=odie@cs.aau.dk \
    --cc=esprout@gmail.com \
    --cc=jbacik@redhat.com \
    --cc=jens.axboe@oracle.com \
    --cc=linux-btrfs@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox