From: Ted Ts'o <tytso@mit.edu>
To: Sami Liedes <sami.liedes@iki.fi>
Cc: linux-ext4@vger.kernel.org
Subject: Re: [PATCH 5/5] libext2fs: Implement fast find_first_zero() for bitarray bitmaps.
Date: Sun, 25 Mar 2012 22:34:00 -0400 [thread overview]
Message-ID: <20120326023400.GA16642@thunk.org> (raw)
In-Reply-To: <20120310213840.GP6961@sli.dy.fi>
On Sat, Mar 10, 2012 at 11:38:40PM +0200, Sami Liedes wrote:
> +/* Find the first zero bit between start and end, inclusive. */
> +static errcode_t ba_find_first_zero(ext2fs_generic_bitmap bitmap,
> + __u64 start, __u64 end, __u64 *out)
> +{
> + ext2fs_ba_private bp = (ext2fs_ba_private)bitmap->private;
> + unsigned long bitpos = start - bitmap->start;
> + unsigned long count = end - start + 1;
> + int byte_found = 0; /* whether a != 0xff byte has been found */
> + const unsigned char *pos;
> + unsigned long max_loop_count, i;
> +
> + if (start < bitmap->start || end > bitmap->end || start > end)
> + return EINVAL;
> +
> + if (bitmap->cluster_bits)
> + return EINVAL;
> +
> + /* scan bits until we hit a byte boundary */
> + while ((bitpos & 0x7) != 0 && count > 0) {
> + if (!ext2fs_test_bit64(bitpos, bp->bitarray)) {
> + *out = bitpos + bitmap->start;
> + return 0;
> + }
> + bitpos++;
> + count--;
> + }
> +
> + if (!count)
> + return ENOENT;
Um, this can't possibly be right. Once we hit a byte boundary, we
will bomb out with ENOENT, and not proceed to the rest of the
function. How much testing did you do before you submitted this patch
series?
I think we just need to delete the two lines, but we also need a good
regression test to make sure the implementation is really correct....
- Ted
> +
> + pos = ((unsigned char *)bp->bitarray) + (bitpos >> 3);
> + /* scan bytes until 8-byte (64-bit) aligned */
> + while (count >= 8 && (((unsigned long)pos) & 0x07)) {
> + if (*pos != 0xff) {
> + byte_found = 1;
> + break;
> + }
> + pos++;
> + count -= 8;
> + bitpos += 8;
> + }
> +
> + if (!byte_found) {
> + max_loop_count = count >> 6; /* 8-byte blocks */
> + i = max_loop_count;
> + while (i) {
> + if (*((const __u64 *)pos) != ((__u64)-1))
> + break;
> + pos += 8;
> + i--;
> + }
> + count -= 64 * (max_loop_count - i);
> + bitpos += 64 * (max_loop_count - i);
> +
> + max_loop_count = count >> 3;
> + i = max_loop_count;
> + while (i) {
> + if (*pos != 0xff) {
> + byte_found = 1;
> + break;
> + }
> + pos++;
> + i--;
> + }
> + count -= 8 * (max_loop_count - i);
> + bitpos += 8 * (max_loop_count - i);
> + }
> +
> + /* Here either count < 8 or byte_found == 1. */
> + while (count-- > 0) {
> + if (!ext2fs_test_bit64(bitpos, bp->bitarray)) {
> + *out = bitpos + bitmap->start;
> + return 0;
> + }
> + bitpos++;
> + }
> +
> + return ENOENT;
> +}
> +
> struct ext2_bitmap_ops ext2fs_blkmap64_bitarray = {
> .type = EXT2FS_BMAP64_BITARRAY,
> .new_bmap = ba_new_bmap,
> @@ -333,4 +413,5 @@ struct ext2_bitmap_ops ext2fs_blkmap64_bitarray = {
> .get_bmap_range = ba_get_bmap_range,
> .clear_bmap = ba_clear_bmap,
> .print_stats = ba_print_stats,
> + .find_first_zero = ba_find_first_zero
> };
next prev parent reply other threads:[~2012-03-26 3:18 UTC|newest]
Thread overview: 17+ messages / expand[flat|nested] mbox.gz Atom feed top
2012-03-10 21:33 [PATCH 0/5] Make filesystem shrinking faster and less CPU-intensive Sami Liedes
2012-03-10 21:34 ` [PATCH 1/5] libext2fs: Move a modulo operation out of a hot loop Sami Liedes
2012-03-11 9:50 ` Andreas Dilger
2012-03-10 21:35 ` [PATCH 2/5] resize2fs: Use EXT2_FLAG_64BITS Sami Liedes
2012-03-10 21:36 ` [PATCH 3/5] libext2fs: Document EXT2_FLAG_64BITS in ext2fs_open2() Sami Liedes
2012-03-10 21:37 ` [PATCH 4/5] libext2fs: Implement ext2fs_find_first_zero_generic_bmap() Sami Liedes
2012-03-11 9:51 ` Andreas Dilger
2012-03-12 19:15 ` Sami Liedes
2012-03-12 23:09 ` Andreas Dilger
2012-03-23 22:33 ` Ted Ts'o
2012-03-26 13:53 ` Sami Liedes
2012-03-26 15:34 ` Ted Ts'o
2012-03-26 2:39 ` Ted Ts'o
2012-03-10 21:38 ` [PATCH 5/5] libext2fs: Implement fast find_first_zero() for bitarray bitmaps Sami Liedes
2012-03-26 2:34 ` Ted Ts'o [this message]
2012-03-26 13:22 ` Sami Liedes
2012-03-26 15:26 ` Ted Ts'o
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=20120326023400.GA16642@thunk.org \
--to=tytso@mit.edu \
--cc=linux-ext4@vger.kernel.org \
--cc=sami.liedes@iki.fi \
/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;
as well as URLs for NNTP newsgroup(s).