]> git.proxmox.com Git - mirror_ubuntu-artful-kernel.git/commitdiff
ext4: optimize ext4_should_retry_alloc() to improve ENOSPC performance
authorTheodore Ts'o <tytso@mit.edu>
Sun, 26 Jun 2016 22:24:01 +0000 (18:24 -0400)
committerTheodore Ts'o <tytso@mit.edu>
Sun, 26 Jun 2016 22:24:01 +0000 (18:24 -0400)
If there are no pending blocks to be released after a commit, forcing
a journal commit has no hope of helping.  It's possible that a commit
had just completed, so if there are now free blocks available for
allocation, it's worth retrying the commit.

Reported-by: Chao Yu <yuchao0@huawei.com>
Signed-off-by: Theodore Ts'o <tytso@mit.edu>
fs/ext4/balloc.c
fs/ext4/ext4.h
fs/ext4/ext4_jbd2.h
fs/ext4/mballoc.c

index 3020fd70c392d1f2b55913e374ed11831b2aa967..0b8105b3293d72be53de50483f9bc6683bf6049f 100644 (file)
@@ -610,7 +610,9 @@ int ext4_should_retry_alloc(struct super_block *sb, int *retries)
 
        jbd_debug(1, "%s: retrying operation after ENOSPC\n", sb->s_id);
 
-       jbd2_journal_force_commit_nested(EXT4_SB(sb)->s_journal);
+       smp_mb();
+       if (EXT4_SB(sb)->s_mb_free_pending)
+               jbd2_journal_force_commit_nested(EXT4_SB(sb)->s_journal);
        return 1;
 }
 
index b84aa1ca480a9564e51d61bc2a0d782c8de104ef..96c73e6fec6e0620e1d7c07a77a40693fee73618 100644 (file)
@@ -1430,6 +1430,7 @@ struct ext4_sb_info {
        unsigned short *s_mb_offsets;
        unsigned int *s_mb_maxs;
        unsigned int s_group_info_size;
+       unsigned int s_mb_free_pending;
 
        /* tunables */
        unsigned long s_stripe;
index 09c1ef38cbe6aaff2c03185b31da20255df8990b..b1d52c14098e135f24e15ebeb8ca61b2e12da1c7 100644 (file)
@@ -175,6 +175,13 @@ struct ext4_journal_cb_entry {
  * There is no guaranteed calling order of multiple registered callbacks on
  * the same transaction.
  */
+static inline void _ext4_journal_callback_add(handle_t *handle,
+                       struct ext4_journal_cb_entry *jce)
+{
+       /* Add the jce to transaction's private list */
+       list_add_tail(&jce->jce_list, &handle->h_transaction->t_private_list);
+}
+
 static inline void ext4_journal_callback_add(handle_t *handle,
                        void (*func)(struct super_block *sb,
                                     struct ext4_journal_cb_entry *jce,
@@ -187,10 +194,11 @@ static inline void ext4_journal_callback_add(handle_t *handle,
        /* Add the jce to transaction's private list */
        jce->jce_func = func;
        spin_lock(&sbi->s_md_lock);
-       list_add_tail(&jce->jce_list, &handle->h_transaction->t_private_list);
+       _ext4_journal_callback_add(handle, jce);
        spin_unlock(&sbi->s_md_lock);
 }
 
+
 /**
  * ext4_journal_callback_del: delete a registered callback
  * @handle: active journal transaction handle on which callback was registered
index c1ab3ec30423f65878789c6602cb63dc82b6746f..77249e1f5c3a0ae1cb3437613ecab08a9090ad01 100644 (file)
@@ -2627,6 +2627,7 @@ int ext4_mb_init(struct super_block *sb)
 
        spin_lock_init(&sbi->s_md_lock);
        spin_lock_init(&sbi->s_bal_lock);
+       sbi->s_mb_free_pending = 0;
 
        sbi->s_mb_max_to_scan = MB_DEFAULT_MAX_TO_SCAN;
        sbi->s_mb_min_to_scan = MB_DEFAULT_MIN_TO_SCAN;
@@ -2814,6 +2815,9 @@ static void ext4_free_data_callback(struct super_block *sb,
        /* we expect to find existing buddy because it's pinned */
        BUG_ON(err != 0);
 
+       spin_lock(&EXT4_SB(sb)->s_md_lock);
+       EXT4_SB(sb)->s_mb_free_pending -= entry->efd_count;
+       spin_unlock(&EXT4_SB(sb)->s_md_lock);
 
        db = e4b.bd_info;
        /* there are blocks to put in buddy to make them really free */
@@ -4583,6 +4587,7 @@ ext4_mb_free_metadata(handle_t *handle, struct ext4_buddy *e4b,
 {
        ext4_group_t group = e4b->bd_group;
        ext4_grpblk_t cluster;
+       ext4_grpblk_t clusters = new_entry->efd_count;
        struct ext4_free_data *entry;
        struct ext4_group_info *db = e4b->bd_info;
        struct super_block *sb = e4b->bd_sb;
@@ -4649,8 +4654,11 @@ ext4_mb_free_metadata(handle_t *handle, struct ext4_buddy *e4b,
                }
        }
        /* Add the extent to transaction's private list */
-       ext4_journal_callback_add(handle, ext4_free_data_callback,
-                                 &new_entry->efd_jce);
+       new_entry->efd_jce.jce_func = ext4_free_data_callback;
+       spin_lock(&sbi->s_md_lock);
+       _ext4_journal_callback_add(handle, &new_entry->efd_jce);
+       sbi->s_mb_free_pending += clusters;
+       spin_unlock(&sbi->s_md_lock);
        return 0;
 }