]> asedeno.scripts.mit.edu Git - linux.git/commitdiff
ext4: improve smp scalability for inode generation
authorTheodore Ts'o <tytso@mit.edu>
Thu, 9 Nov 2017 03:23:20 +0000 (22:23 -0500)
committerTheodore Ts'o <tytso@mit.edu>
Thu, 9 Nov 2017 03:23:20 +0000 (22:23 -0500)
->s_next_generation is protected by s_next_gen_lock but its usage
pattern is very primitive.  We don't actually need sequentially
increasing new generation numbers, so let's use prandom_u32() instead.

Reported-by: Dmitry Monakhov <dmonakhov@openvz.org>
Signed-off-by: Theodore Ts'o <tytso@mit.edu>
fs/ext4/ext4.h
fs/ext4/ialloc.c
fs/ext4/ioctl.c
fs/ext4/super.c

index 53ce95b52fd8ffce89cafd37274040d4f52089f3..5e6d7b6f50c7bcec63c0e11a419806422f05d37f 100644 (file)
@@ -1355,8 +1355,6 @@ struct ext4_sb_info {
        int s_first_ino;
        unsigned int s_inode_readahead_blks;
        unsigned int s_inode_goal;
-       spinlock_t s_next_gen_lock;
-       u32 s_next_generation;
        u32 s_hash_seed[4];
        int s_def_hash_version;
        int s_hash_unsigned;    /* 3 if hash should be signed, 0 if not */
index ee823022aa344a2723bfac9c11d61ace60b32e69..da79eb5dba400123d65160d40b9903f29444d6db 100644 (file)
@@ -1138,9 +1138,7 @@ struct inode *__ext4_new_inode(handle_t *handle, struct inode *dir,
                           inode->i_ino);
                goto out;
        }
-       spin_lock(&sbi->s_next_gen_lock);
-       inode->i_generation = sbi->s_next_generation++;
-       spin_unlock(&sbi->s_next_gen_lock);
+       inode->i_generation = prandom_u32();
 
        /* Precompute checksum seed for inode metadata */
        if (ext4_has_metadata_csum(sb)) {
index 144bbda2b8083aae42aca0f45cd3c7a9211d4186..23a4766f66783a7a1637b064e6dadf7fd99b7b93 100644 (file)
@@ -14,6 +14,7 @@
 #include <linux/mount.h>
 #include <linux/file.h>
 #include <linux/quotaops.h>
+#include <linux/random.h>
 #include <linux/uuid.h>
 #include <linux/uaccess.h>
 #include <linux/delay.h>
@@ -98,7 +99,6 @@ static long swap_inode_boot_loader(struct super_block *sb,
        int err;
        struct inode *inode_bl;
        struct ext4_inode_info *ei_bl;
-       struct ext4_sb_info *sbi = EXT4_SB(sb);
 
        if (inode->i_nlink != 1 || !S_ISREG(inode->i_mode))
                return -EINVAL;
@@ -157,10 +157,8 @@ static long swap_inode_boot_loader(struct super_block *sb,
 
        inode->i_ctime = inode_bl->i_ctime = current_time(inode);
 
-       spin_lock(&sbi->s_next_gen_lock);
-       inode->i_generation = sbi->s_next_generation++;
-       inode_bl->i_generation = sbi->s_next_generation++;
-       spin_unlock(&sbi->s_next_gen_lock);
+       inode->i_generation = prandom_u32();
+       inode_bl->i_generation = prandom_u32();
 
        ext4_discard_preallocations(inode);
 
index 3a278faf5868ee00f62b6c4ea4bc8ca9465ff8c1..9f2e3eb5131f2447c9f494bb6ba830b8f8346df8 100644 (file)
@@ -3982,8 +3982,6 @@ static int ext4_fill_super(struct super_block *sb, void *data, int silent)
        }
 
        sbi->s_gdb_count = db_count;
-       get_random_bytes(&sbi->s_next_generation, sizeof(u32));
-       spin_lock_init(&sbi->s_next_gen_lock);
 
        timer_setup(&sbi->s_err_report, print_daily_error_info, 0);