Patchwork [5/5] libext2fs: Optimize ext2fs_convert_subcluster_bitmap()

login
register
mail settings
Submitter Andrey Sidorov
Date March 19, 2013, 4:06 p.m.
Message ID <1363709164-3210-6-git-send-email-qrxd43@motorola.com>
Download mbox | patch
Permalink /patch/229106/
State New
Headers show

Comments

Andrey Sidorov - March 19, 2013, 4:06 p.m.
Scan original bitmap with successive ffs/ffz and
insert complete extents into target bitmap.

Signed-off-by Andrey Sidorov <qrxd43@motorola.com>
---
 lib/ext2fs/gen_bitmap64.c |   29 +++++++++++++++--------------
 1 file changed, 15 insertions(+), 14 deletions(-)

Patch

diff --git a/lib/ext2fs/gen_bitmap64.c b/lib/ext2fs/gen_bitmap64.c
index 80502b5..3639f60 100644
--- a/lib/ext2fs/gen_bitmap64.c
+++ b/lib/ext2fs/gen_bitmap64.c
@@ -758,8 +758,7 @@  errcode_t ext2fs_convert_subcluster_bitmap(ext2_filsys fs,
 {
 	ext2fs_block_bitmap	cmap, bmap;
 	errcode_t		retval;
-	blk64_t			i, b_end, c_end;
-	int			n, ratio;
+	blk64_t			b_end, c_end, f_zero, f_set;
 
 	bmap = *bitmap;
 
@@ -771,23 +770,25 @@  errcode_t ext2fs_convert_subcluster_bitmap(ext2_filsys fs,
 	if (retval)
 		return retval;
 
-	i = bmap->start;
+	f_zero = bmap->start;
 	b_end = bmap->end;
 	bmap->end = bmap->real_end;
 	c_end = cmap->end;
 	cmap->end = cmap->real_end;
-	n = 0;
-	ratio = 1 << fs->cluster_ratio_bits;
-	while (i < bmap->real_end) {
-		if (ext2fs_test_block_bitmap2(bmap, i)) {
-			ext2fs_mark_block_bitmap2(cmap, i);
-			i += ratio - n;
-			n = 0;
-			continue;
+
+	while (f_zero < bmap->real_end) {
+		retval = ext2fs_find_first_set_block_bitmap2(bmap, f_zero,
+							     bmap->real_end,
+							     &f_set);
+		if (retval)
+			break;
+		retval = ext2fs_find_first_zero_block_bitmap2(bmap, f_set,
+							      bmap->real_end,
+							      &f_zero);
+		if (retval) {
+			f_zero = bmap->real_end + 1;
 		}
-		i++; n++;
-		if (n >= ratio)
-			n = 0;
+		ext2fs_mark_block_bitmap_range2(cmap, f_set, f_zero - f_set);
 	}
 	bmap->end = b_end;
 	cmap->end = c_end;