Skip to content

Commit

Permalink
ext4: introduce ext4_get_group_number()
Browse files Browse the repository at this point in the history
Currently on many places in ext4 we're using
ext4_get_group_no_and_offset() even though we're only interested in
knowing the block group of the particular block, not the offset within
the block group so we can use more efficient way to compute block
group.

This patch introduces ext4_get_group_number() which computes block
group for a given block much more efficiently. Use this function
instead of ext4_get_group_no_and_offset() everywhere where we're only
interested in knowing the block group.

Signed-off-by: Lukas Czerner <lczerner@redhat.com>
Signed-off-by: "Theodore Ts'o" <tytso@mit.edu>
  • Loading branch information
Lukas Czerner authored and tytso committed Apr 4, 2013
1 parent 6891100 commit bd86298
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 18 deletions.
25 changes: 18 additions & 7 deletions fs/ext4/balloc.c
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,23 @@ static unsigned ext4_num_base_meta_clusters(struct super_block *sb,
* balloc.c contains the blocks allocation and deallocation routines
*/

/*
* Calculate block group number for a given block number
*/
ext4_group_t ext4_get_group_number(struct super_block *sb,
ext4_fsblk_t block)
{
ext4_group_t group;

if (test_opt2(sb, STD_GROUP_SIZE))
group = (le32_to_cpu(EXT4_SB(sb)->s_es->s_first_data_block) +
block) >>
(EXT4_BLOCK_SIZE_BITS(sb) + EXT4_CLUSTER_BITS(sb) + 3);
else
ext4_get_group_no_and_offset(sb, block, &group, NULL);
return group;
}

/*
* Calculate the block group number and offset into the block/cluster
* allocation bitmap, given a block number
Expand Down Expand Up @@ -59,13 +76,7 @@ static inline int ext4_block_in_group(struct super_block *sb,
{
ext4_group_t actual_group;

if (test_opt2(sb, STD_GROUP_SIZE))
actual_group =
(le32_to_cpu(EXT4_SB(sb)->s_es->s_first_data_block) +
block) >>
(EXT4_BLOCK_SIZE_BITS(sb) + EXT4_CLUSTER_BITS(sb) + 3);
else
ext4_get_group_no_and_offset(sb, block, &actual_group, NULL);
actual_group = ext4_get_group_number(sb, block);
return (actual_group == block_group) ? 1 : 0;
}

Expand Down
10 changes: 7 additions & 3 deletions fs/ext4/ext4.h
Original file line number Diff line number Diff line change
Expand Up @@ -1793,9 +1793,6 @@ ext4_group_first_block_no(struct super_block *sb, ext4_group_t group_no)
*/
#define ERR_BAD_DX_DIR -75000

void ext4_get_group_no_and_offset(struct super_block *sb, ext4_fsblk_t blocknr,
ext4_group_t *blockgrpp, ext4_grpblk_t *offsetp);

/*
* Timeout and state flag for lazy initialization inode thread.
*/
Expand Down Expand Up @@ -1917,6 +1914,13 @@ int ext4_block_bitmap_csum_verify(struct super_block *sb, ext4_group_t group,
struct buffer_head *bh);

/* balloc.c */
extern void ext4_get_group_no_and_offset(struct super_block *sb,
ext4_fsblk_t blocknr,
ext4_group_t *blockgrpp,
ext4_grpblk_t *offsetp);
extern ext4_group_t ext4_get_group_number(struct super_block *sb,
ext4_fsblk_t block);

extern void ext4_validate_block_bitmap(struct super_block *sb,
struct ext4_group_desc *desc,
unsigned int block_group,
Expand Down
6 changes: 3 additions & 3 deletions fs/ext4/mballoc.c
Original file line number Diff line number Diff line change
Expand Up @@ -3344,7 +3344,7 @@ static void ext4_mb_put_pa(struct ext4_allocation_context *ac,
if (pa->pa_type == MB_GROUP_PA)
grp_blk--;

ext4_get_group_no_and_offset(sb, grp_blk, &grp, NULL);
grp = ext4_get_group_number(sb, grp_blk);

/*
* possible race:
Expand Down Expand Up @@ -3809,7 +3809,7 @@ void ext4_discard_preallocations(struct inode *inode)

list_for_each_entry_safe(pa, tmp, &list, u.pa_tmp_list) {
BUG_ON(pa->pa_type != MB_INODE_PA);
ext4_get_group_no_and_offset(sb, pa->pa_pstart, &group, NULL);
group = ext4_get_group_number(sb, pa->pa_pstart);

err = ext4_mb_load_buddy(sb, group, &e4b);
if (err) {
Expand Down Expand Up @@ -4071,7 +4071,7 @@ ext4_mb_discard_lg_preallocations(struct super_block *sb,

list_for_each_entry_safe(pa, tmp, &discard_list, u.pa_tmp_list) {

ext4_get_group_no_and_offset(sb, pa->pa_pstart, &group, NULL);
group = ext4_get_group_number(sb, pa->pa_pstart);
if (ext4_mb_load_buddy(sb, group, &e4b)) {
ext4_error(sb, "Error loading buddy information for %u",
group);
Expand Down
10 changes: 5 additions & 5 deletions fs/ext4/resize.c
Original file line number Diff line number Diff line change
Expand Up @@ -272,7 +272,7 @@ static int ext4_alloc_group_tables(struct super_block *sb,
if (start_blk >= last_blk)
goto next_group;
group_data[bb_index].block_bitmap = start_blk++;
ext4_get_group_no_and_offset(sb, start_blk - 1, &group, NULL);
group = ext4_get_group_number(sb, start_blk - 1);
group -= group_data[0].group;
group_data[group].free_blocks_count--;
if (flexbg_size > 1)
Expand All @@ -284,7 +284,7 @@ static int ext4_alloc_group_tables(struct super_block *sb,
if (start_blk >= last_blk)
goto next_group;
group_data[ib_index].inode_bitmap = start_blk++;
ext4_get_group_no_and_offset(sb, start_blk - 1, &group, NULL);
group = ext4_get_group_number(sb, start_blk - 1);
group -= group_data[0].group;
group_data[group].free_blocks_count--;
if (flexbg_size > 1)
Expand All @@ -296,7 +296,7 @@ static int ext4_alloc_group_tables(struct super_block *sb,
if (start_blk + EXT4_SB(sb)->s_itb_per_group > last_blk)
goto next_group;
group_data[it_index].inode_table = start_blk;
ext4_get_group_no_and_offset(sb, start_blk, &group, NULL);
group = ext4_get_group_number(sb, start_blk - 1);
group -= group_data[0].group;
group_data[group].free_blocks_count -=
EXT4_SB(sb)->s_itb_per_group;
Expand Down Expand Up @@ -392,7 +392,7 @@ static int set_flexbg_block_bitmap(struct super_block *sb, handle_t *handle,
ext4_group_t group;
int err;

ext4_get_group_no_and_offset(sb, block, &group, NULL);
group = ext4_get_group_number(sb, block);
start = ext4_group_first_block_no(sb, group);
group -= flex_gd->groups[0].group;

Expand Down Expand Up @@ -1879,7 +1879,7 @@ int ext4_resize_fs(struct super_block *sb, ext4_fsblk_t n_blocks_count)
/* Nothing need to do */
return 0;

ext4_get_group_no_and_offset(sb, n_blocks_count - 1, &n_group, &offset);
n_group = ext4_get_group_number(sb, n_blocks_count - 1);
ext4_get_group_no_and_offset(sb, o_blocks_count - 1, &o_group, &offset);

n_desc_blocks = num_desc_blocks(sb, n_group + 1);
Expand Down

0 comments on commit bd86298

Please sign in to comment.