]> git.proxmox.com Git - mirror_ubuntu-jammy-kernel.git/commitdiff
ext4: add MB_NUM_ORDERS macro
authorHarshad Shirwadkar <harshadshirwadkar@gmail.com>
Thu, 1 Apr 2021 17:21:26 +0000 (10:21 -0700)
committerTheodore Ts'o <tytso@mit.edu>
Fri, 9 Apr 2021 15:34:59 +0000 (11:34 -0400)
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 <harshadshirwadkar@gmail.com>
Reviewed-by: Andreas Dilger <adilger@dilger.ca>
Reviewed-by: Ritesh Harjani <ritesh.list@gmail.com>
Link: https://lore.kernel.org/r/20210401172129.189766-5-harshadshirwadkar@gmail.com
Signed-off-by: Theodore Ts'o <tytso@mit.edu>
fs/ext4/mballoc.c
fs/ext4/mballoc.h

index 70b8ab19c25222bf5ce58667ddcad70afe587844..e899a7d219828994588e3fb204a07a9edd100abb 100644 (file)
@@ -756,7 +756,7 @@ mb_set_largest_free_order(struct super_block *sb, struct ext4_group_info *grp)
 
        grp->bb_largest_free_order = -1; /* uninit */
 
-       bits = sb->s_blocksize_bits + 1;
+       bits = MB_NUM_ORDERS(sb) - 1;
        for (i = bits; i >= 0; i--) {
                if (grp->bb_counters[i] > 0) {
                        grp->bb_largest_free_order = i;
@@ -957,7 +957,7 @@ static int ext4_mb_init_cache(struct page *page, char *incore, gfp_t gfp)
                        grinfo->bb_fragments = 0;
                        memset(grinfo->bb_counters, 0,
                               sizeof(*grinfo->bb_counters) *
-                               (sb->s_blocksize_bits+2));
+                              (MB_NUM_ORDERS(sb)));
                        /*
                         * incore got set to the group block bitmap below
                         */
@@ -1928,7 +1928,7 @@ void ext4_mb_simple_scan_group(struct ext4_allocation_context *ac,
        int max;
 
        BUG_ON(ac->ac_2order <= 0);
-       for (i = ac->ac_2order; i <= sb->s_blocksize_bits + 1; i++) {
+       for (i = ac->ac_2order; i < MB_NUM_ORDERS(sb); i++) {
                if (grp->bb_counters[i] == 0)
                        continue;
 
@@ -2107,7 +2107,7 @@ static bool ext4_mb_good_group(struct ext4_allocation_context *ac,
                if (free < ac->ac_g_ex.fe_len)
                        return false;
 
-               if (ac->ac_2order > ac->ac_sb->s_blocksize_bits+1)
+               if (ac->ac_2order >= MB_NUM_ORDERS(ac->ac_sb))
                        return true;
 
                if (grp->bb_largest_free_order < ac->ac_2order)
@@ -2315,13 +2315,13 @@ ext4_mb_regular_allocator(struct ext4_allocation_context *ac)
         * We also support searching for power-of-two requests only for
         * requests upto maximum buddy size we have constructed.
         */
-       if (i >= sbi->s_mb_order2_reqs && i <= sb->s_blocksize_bits + 2) {
+       if (i >= sbi->s_mb_order2_reqs && i <= MB_NUM_ORDERS(sb)) {
                /*
                 * This should tell if fe_len is exactly power of 2
                 */
                if ((ac->ac_g_ex.fe_len & (~(1 << (i - 1)))) == 0)
                        ac->ac_2order = array_index_nospec(i - 1,
-                                                          sb->s_blocksize_bits + 2);
+                                                          MB_NUM_ORDERS(sb));
        }
 
        /* if stream allocation is enabled, use global goal */
@@ -2880,7 +2880,7 @@ int ext4_mb_init(struct super_block *sb)
        unsigned max;
        int ret;
 
-       i = (sb->s_blocksize_bits + 2) * sizeof(*sbi->s_mb_offsets);
+       i = MB_NUM_ORDERS(sb) * sizeof(*sbi->s_mb_offsets);
 
        sbi->s_mb_offsets = kmalloc(i, GFP_KERNEL);
        if (sbi->s_mb_offsets == NULL) {
@@ -2888,7 +2888,7 @@ int ext4_mb_init(struct super_block *sb)
                goto out;
        }
 
-       i = (sb->s_blocksize_bits + 2) * sizeof(*sbi->s_mb_maxs);
+       i = MB_NUM_ORDERS(sb) * sizeof(*sbi->s_mb_maxs);
        sbi->s_mb_maxs = kmalloc(i, GFP_KERNEL);
        if (sbi->s_mb_maxs == NULL) {
                ret = -ENOMEM;
@@ -2914,7 +2914,8 @@ int ext4_mb_init(struct super_block *sb)
                offset_incr = offset_incr >> 1;
                max = max >> 1;
                i++;
-       } while (i <= sb->s_blocksize_bits + 1);
+       } while (i < MB_NUM_ORDERS(sb));
+
 
        spin_lock_init(&sbi->s_md_lock);
        sbi->s_mb_free_pending = 0;
index e75b4749aa1c27cfb1f712bfdbf561801b312d20..68111a10cfee11ceee52480b64a1ea3ac84d6943 100644 (file)
  */
 #define MB_DEFAULT_MAX_INODE_PREALLOC  512
 
+/*
+ * Number of valid buddy orders
+ */
+#define MB_NUM_ORDERS(sb)              ((sb)->s_blocksize_bits + 2)
+
 struct ext4_free_data {
        /* this links the free block information from sb_info */
        struct list_head                efd_list;