Skip to content

Commit 4b68f6d

Browse files
harshadjstytso
authored andcommitted
ext4: add MB_NUM_ORDERS macro
A few arrays in mballoc.c use the total number of valid orders as their size. Currently, this value is set as "sb->s_blocksize_bits + 2". This makes code harder to read. So, instead add a new macro MB_NUM_ORDERS(sb) to make the code more readable. Signed-off-by: Harshad Shirwadkar <[email protected]> Reviewed-by: Andreas Dilger <[email protected]> Reviewed-by: Ritesh Harjani <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Theodore Ts'o <[email protected]>
1 parent a6c75ea commit 4b68f6d

File tree

2 files changed

+15
-9
lines changed

2 files changed

+15
-9
lines changed

fs/ext4/mballoc.c

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -756,7 +756,7 @@ mb_set_largest_free_order(struct super_block *sb, struct ext4_group_info *grp)
756756

757757
grp->bb_largest_free_order = -1; /* uninit */
758758

759-
bits = sb->s_blocksize_bits + 1;
759+
bits = MB_NUM_ORDERS(sb) - 1;
760760
for (i = bits; i >= 0; i--) {
761761
if (grp->bb_counters[i] > 0) {
762762
grp->bb_largest_free_order = i;
@@ -957,7 +957,7 @@ static int ext4_mb_init_cache(struct page *page, char *incore, gfp_t gfp)
957957
grinfo->bb_fragments = 0;
958958
memset(grinfo->bb_counters, 0,
959959
sizeof(*grinfo->bb_counters) *
960-
(sb->s_blocksize_bits+2));
960+
(MB_NUM_ORDERS(sb)));
961961
/*
962962
* incore got set to the group block bitmap below
963963
*/
@@ -1928,7 +1928,7 @@ void ext4_mb_simple_scan_group(struct ext4_allocation_context *ac,
19281928
int max;
19291929

19301930
BUG_ON(ac->ac_2order <= 0);
1931-
for (i = ac->ac_2order; i <= sb->s_blocksize_bits + 1; i++) {
1931+
for (i = ac->ac_2order; i < MB_NUM_ORDERS(sb); i++) {
19321932
if (grp->bb_counters[i] == 0)
19331933
continue;
19341934

@@ -2107,7 +2107,7 @@ static bool ext4_mb_good_group(struct ext4_allocation_context *ac,
21072107
if (free < ac->ac_g_ex.fe_len)
21082108
return false;
21092109

2110-
if (ac->ac_2order > ac->ac_sb->s_blocksize_bits+1)
2110+
if (ac->ac_2order >= MB_NUM_ORDERS(ac->ac_sb))
21112111
return true;
21122112

21132113
if (grp->bb_largest_free_order < ac->ac_2order)
@@ -2315,13 +2315,13 @@ ext4_mb_regular_allocator(struct ext4_allocation_context *ac)
23152315
* We also support searching for power-of-two requests only for
23162316
* requests upto maximum buddy size we have constructed.
23172317
*/
2318-
if (i >= sbi->s_mb_order2_reqs && i <= sb->s_blocksize_bits + 2) {
2318+
if (i >= sbi->s_mb_order2_reqs && i <= MB_NUM_ORDERS(sb)) {
23192319
/*
23202320
* This should tell if fe_len is exactly power of 2
23212321
*/
23222322
if ((ac->ac_g_ex.fe_len & (~(1 << (i - 1)))) == 0)
23232323
ac->ac_2order = array_index_nospec(i - 1,
2324-
sb->s_blocksize_bits + 2);
2324+
MB_NUM_ORDERS(sb));
23252325
}
23262326

23272327
/* if stream allocation is enabled, use global goal */
@@ -2880,15 +2880,15 @@ int ext4_mb_init(struct super_block *sb)
28802880
unsigned max;
28812881
int ret;
28822882

2883-
i = (sb->s_blocksize_bits + 2) * sizeof(*sbi->s_mb_offsets);
2883+
i = MB_NUM_ORDERS(sb) * sizeof(*sbi->s_mb_offsets);
28842884

28852885
sbi->s_mb_offsets = kmalloc(i, GFP_KERNEL);
28862886
if (sbi->s_mb_offsets == NULL) {
28872887
ret = -ENOMEM;
28882888
goto out;
28892889
}
28902890

2891-
i = (sb->s_blocksize_bits + 2) * sizeof(*sbi->s_mb_maxs);
2891+
i = MB_NUM_ORDERS(sb) * sizeof(*sbi->s_mb_maxs);
28922892
sbi->s_mb_maxs = kmalloc(i, GFP_KERNEL);
28932893
if (sbi->s_mb_maxs == NULL) {
28942894
ret = -ENOMEM;
@@ -2914,7 +2914,8 @@ int ext4_mb_init(struct super_block *sb)
29142914
offset_incr = offset_incr >> 1;
29152915
max = max >> 1;
29162916
i++;
2917-
} while (i <= sb->s_blocksize_bits + 1);
2917+
} while (i < MB_NUM_ORDERS(sb));
2918+
29182919

29192920
spin_lock_init(&sbi->s_md_lock);
29202921
sbi->s_mb_free_pending = 0;

fs/ext4/mballoc.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,11 @@
7878
*/
7979
#define MB_DEFAULT_MAX_INODE_PREALLOC 512
8080

81+
/*
82+
* Number of valid buddy orders
83+
*/
84+
#define MB_NUM_ORDERS(sb) ((sb)->s_blocksize_bits + 2)
85+
8186
struct ext4_free_data {
8287
/* this links the free block information from sb_info */
8388
struct list_head efd_list;

0 commit comments

Comments
 (0)