[PATCH 1/5] libext2fs: Optimize ext2fs_allocate_group_table()

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Iterate over groups instead of blocks.

Signed-off-by: Andrey Sidorov <qrxd43@xxxxxxxxxxxx>
---
 lib/ext2fs/alloc_tables.c |   31 +++++++++++++++++++++----------
 1 file changed, 21 insertions(+), 10 deletions(-)

diff --git a/lib/ext2fs/alloc_tables.c b/lib/ext2fs/alloc_tables.c
index 5e6e556..e51dcee 100644
--- a/lib/ext2fs/alloc_tables.c
+++ b/lib/ext2fs/alloc_tables.c
@@ -205,16 +205,27 @@ errcode_t ext2fs_allocate_group_table(ext2_filsys fs, dgrp_t group,
 						bmap, &new_blk);
 		if (retval)
 			return retval;
-		for (j=0, blk = new_blk;
-		     j < fs->inode_blocks_per_group;
-		     j++, blk++) {
-			ext2fs_mark_block_bitmap2(bmap, blk);
-			if (flexbg_size) {
-				dgrp_t gr = ext2fs_group_of_blk2(fs, blk);
-				ext2fs_bg_free_blocks_count_set(fs, gr, ext2fs_bg_free_blocks_count(fs, gr) - 1);
-				ext2fs_free_blocks_count_add(fs->super, -1);
-				ext2fs_bg_flags_clear(fs, gr,
-						     EXT2_BG_BLOCK_UNINIT);
+
+		ext2fs_mark_block_bitmap_range2(bmap, new_blk, fs->inode_blocks_per_group);
+		if (flexbg_size) {
+			blk64_t last_blk = new_blk + fs->inode_blocks_per_group - 1;
+			dgrp_t gr = ext2fs_group_of_blk2(fs, new_blk);
+			dgrp_t last_gr = ext2fs_group_of_blk2(fs, last_blk);
+
+			ext2fs_free_blocks_count_add(fs->super, -(blk64_t)(fs->inode_blocks_per_group));
+			for (; gr <= last_gr; ++gr) {
+				blk64_t gr_first_blk = ext2fs_group_first_block2(fs, gr);
+				blk64_t gr_last_blk = ext2fs_group_last_block2(fs, gr);
+				__u32 free_blocks = ext2fs_bg_free_blocks_count(fs, gr);
+				if (gr_first_blk < new_blk)
+					gr_first_blk = new_blk;
+				if (gr_last_blk > last_blk)
+					gr_last_blk = last_blk;
+
+				free_blocks -= (__u32)(gr_last_blk - gr_first_blk + 1);
+
+				ext2fs_bg_free_blocks_count_set(fs, gr, free_blocks);
+				ext2fs_bg_flags_clear(fs, gr, EXT2_BG_BLOCK_UNINIT);
 				ext2fs_group_desc_csum_set(fs, gr);
 			}
 		}
-- 
1.7.10.4

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


[Index of Archives]     [Reiser Filesystem Development]     [Ceph FS]     [Kernel Newbies]     [Security]     [Netfilter]     [Bugtraq]     [Linux FS]     [Yosemite National Park]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Samba]     [Device Mapper]     [Linux Media]

  Powered by Linux