]> git.proxmox.com Git - mirror_ubuntu-jammy-kernel.git/commitdiff
ext4: drop s_mb_bal_lock and convert protected fields to atomic
authorHarshad Shirwadkar <harshadshirwadkar@gmail.com>
Thu, 1 Apr 2021 17:21:23 +0000 (10:21 -0700)
committerTheodore Ts'o <tytso@mit.edu>
Fri, 9 Apr 2021 15:34:58 +0000 (11:34 -0400)
s_mb_buddies_generated gets used later in this patch series to
determine if the cr 0 and cr 1 optimziations should be performed or
not. Currently, s_mb_buddies_generated is protected under a
spin_lock. In the allocation path, it is better if we don't depend on
the lock and instead read the value atomically. In order to do that,
we drop s_bal_lock altogether and we convert the only two protected
fields by it s_mb_buddies_generated and s_mb_generation_time to atomic
type.

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-2-harshadshirwadkar@gmail.com
Signed-off-by: Theodore Ts'o <tytso@mit.edu>
fs/ext4/ext4.h
fs/ext4/mballoc.c

index da7cb2c755b67fd081f2aea56f3e7d46fe15496a..7ba90a9fd53a5279151abb36bda65ce6ae31d7e6 100644 (file)
@@ -1553,9 +1553,8 @@ struct ext4_sb_info {
        atomic_t s_bal_goals;   /* goal hits */
        atomic_t s_bal_breaks;  /* too long searches */
        atomic_t s_bal_2orders; /* 2^order hits */
-       spinlock_t s_bal_lock;
-       unsigned long s_mb_buddies_generated;
-       unsigned long long s_mb_generation_time;
+       atomic_t s_mb_buddies_generated;        /* number of buddies generated */
+       atomic64_t s_mb_generation_time;
        atomic_t s_mb_lost_chunks;
        atomic_t s_mb_preallocated;
        atomic_t s_mb_discarded;
index a02fadf4fc84e21e0b4b94182d66e07b2a52ae1c..34ddce5d6e5d469c389ed027f126013b92ade938 100644 (file)
@@ -816,10 +816,8 @@ void ext4_mb_generate_buddy(struct super_block *sb,
        clear_bit(EXT4_GROUP_INFO_NEED_INIT_BIT, &(grp->bb_state));
 
        period = get_cycles() - period;
-       spin_lock(&sbi->s_bal_lock);
-       sbi->s_mb_buddies_generated++;
-       sbi->s_mb_generation_time += period;
-       spin_unlock(&sbi->s_bal_lock);
+       atomic_inc(&sbi->s_mb_buddies_generated);
+       atomic64_add(period, &sbi->s_mb_generation_time);
 }
 
 /* The buddy information is attached the buddy cache inode
@@ -2850,7 +2848,6 @@ int ext4_mb_init(struct super_block *sb)
        } while (i <= sb->s_blocksize_bits + 1);
 
        spin_lock_init(&sbi->s_md_lock);
-       spin_lock_init(&sbi->s_bal_lock);
        sbi->s_mb_free_pending = 0;
        INIT_LIST_HEAD(&sbi->s_freed_data_list);
 
@@ -2986,9 +2983,9 @@ int ext4_mb_release(struct super_block *sb)
                                atomic_read(&sbi->s_bal_breaks),
                                atomic_read(&sbi->s_mb_lost_chunks));
                ext4_msg(sb, KERN_INFO,
-                      "mballoc: %lu generated and it took %Lu",
-                               sbi->s_mb_buddies_generated,
-                               sbi->s_mb_generation_time);
+                      "mballoc: %u generated and it took %llu",
+                               atomic_read(&sbi->s_mb_buddies_generated),
+                               atomic64_read(&sbi->s_mb_generation_time));
                ext4_msg(sb, KERN_INFO,
                       "mballoc: %u preallocated, %u discarded",
                                atomic_read(&sbi->s_mb_preallocated),