diff options
author | Theodore Ts'o <tytso@mit.edu> | 2011-06-10 18:51:58 -0400 |
---|---|---|
committer | Theodore Ts'o <tytso@mit.edu> | 2011-06-10 18:51:58 -0400 |
commit | b0ecb787ef9fde414791b644fa074450b28d4060 (patch) | |
tree | 8447c904eb712fd7fe58a3b40e558e61b37dc667 /lib/ext2fs/alloc.c | |
parent | 94968e749b224f01fbb9009ed0285e55f6441784 (diff) | |
download | e2fsprogs-b0ecb787ef9fde414791b644fa074450b28d4060.tar.gz |
libext2fs: teach block allocation functions about bigalloc/clusters
Optimize ext2fs_new_block2() and ext2fs_get_free_blocks2() when
bigalloc is enabled. Also fix the uninitialized block bitmap code so
that it correctly deals clustered allocation.
Signed-off-by: "Theodore Ts'o" <tytso@mit.edu>
Diffstat (limited to 'lib/ext2fs/alloc.c')
-rw-r--r-- | lib/ext2fs/alloc.c | 17 |
1 files changed, 12 insertions, 5 deletions
diff --git a/lib/ext2fs/alloc.c b/lib/ext2fs/alloc.c index 3a8f3328..fbecdbe7 100644 --- a/lib/ext2fs/alloc.c +++ b/lib/ext2fs/alloc.c @@ -52,6 +52,9 @@ static void check_block_uninit(ext2_filsys fs, ext2fs_block_bitmap map, else old_desc_blocks = fs->desc_blocks + fs->super->s_reserved_gdt_blocks; + for (i=0; i < fs->super->s_blocks_per_group; i++, blk++) + ext2fs_fast_unmark_block_bitmap2(map, blk); + for (i=0; i < fs->super->s_blocks_per_group; i++, blk++) { if ((blk == super_blk) || (old_desc_blk && old_desc_blocks && @@ -64,8 +67,6 @@ static void check_block_uninit(ext2_filsys fs, ext2fs_block_bitmap map, (blk < ext2fs_inode_table_loc(fs, group) + fs->inode_blocks_per_group))) ext2fs_fast_mark_block_bitmap2(map, blk); - else - ext2fs_fast_unmark_block_bitmap2(map, blk); } ext2fs_bg_flags_clear(fs, group, EXT2_BG_BLOCK_UNINIT); ext2fs_group_desc_csum_set(fs, group); @@ -149,6 +150,7 @@ errcode_t ext2fs_new_block2(ext2_filsys fs, blk64_t goal, ext2fs_block_bitmap map, blk64_t *ret) { blk64_t i; + int c_ratio; EXT2_CHECK_MAGIC(fs, EXT2_ET_MAGIC_EXT2FS_FILSYS); @@ -159,6 +161,7 @@ errcode_t ext2fs_new_block2(ext2_filsys fs, blk64_t goal, if (!goal || (goal >= ext2fs_blocks_count(fs->super))) goal = fs->super->s_first_data_block; i = goal; + c_ratio = 1 << ext2fs_get_bitmap_granularity(map); check_block_uninit(fs, map, (i - fs->super->s_first_data_block) / EXT2_BLOCKS_PER_GROUP(fs->super)); @@ -173,7 +176,7 @@ errcode_t ext2fs_new_block2(ext2_filsys fs, blk64_t goal, *ret = i; return 0; } - i++; + i = (i + c_ratio) & ~(c_ratio - 1); if (i >= ext2fs_blocks_count(fs->super)) i = fs->super->s_first_data_block; } while (i != goal); @@ -253,7 +256,8 @@ errcode_t ext2fs_alloc_block(ext2_filsys fs, blk_t goal, errcode_t ext2fs_get_free_blocks2(ext2_filsys fs, blk64_t start, blk64_t finish, int num, ext2fs_block_bitmap map, blk64_t *ret) { - blk64_t b = start; + blk64_t b = start, c = 0; + int c_ratio; EXT2_CHECK_MAGIC(fs, EXT2_ET_MAGIC_EXT2FS_FILSYS); @@ -267,6 +271,9 @@ errcode_t ext2fs_get_free_blocks2(ext2_filsys fs, blk64_t start, blk64_t finish, finish = start; if (!num) num = 1; + c_ratio = 1 << ext2fs_get_bitmap_granularity(map); + b &= ~(c_ratio - 1); + finish &= ~(c_ratio -1); do { if (b+num-1 > ext2fs_blocks_count(fs->super)) b = fs->super->s_first_data_block; @@ -274,7 +281,7 @@ errcode_t ext2fs_get_free_blocks2(ext2_filsys fs, blk64_t start, blk64_t finish, *ret = b; return 0; } - b++; + b += c_ratio; } while (b != finish); return EXT2_ET_BLOCK_ALLOC_FAIL; } |