Whamcloud - gitweb
LU-14712 ldiskfs: add bg_trimmed_threshold interface 67/55567/2
authorLi Dongyang <dongyangli@ddn.com>
Fri, 28 Jun 2024 02:18:50 +0000 (12:18 +1000)
committerOleg Drokin <green@whamcloud.com>
Mon, 8 Jul 2024 20:10:40 +0000 (20:10 +0000)
Export interface bg_trimmed_threshold via sysfs, and only clear
BG_TRIMMED flag when there are enough blocks freed since
last fstrim(default 128).

Make sure we use cpu_to_le32() with EXT2_FLAGS_TRACK_TRIM.

Change-Id: I98d86f6d7335af53b8e74c747797b0dff3abb5d0
Test-Parameters: trivial
Fixes: ad30edf910 ("LU-14712 ldiskfs: introduce EXT4_BG_TRIMMED to optimize fstrim")
Signed-off-by: Li Dongyang <dongyangli@ddn.com>
Reviewed-on: https://review.whamcloud.com/c/fs/lustre-release/+/55567
Tested-by: jenkins <devops@whamcloud.com>
Tested-by: Maloo <maloo@whamcloud.com>
Reviewed-by: Andreas Dilger <adilger@whamcloud.com>
Reviewed-by: Jian Yu <yujian@whamcloud.com>
Reviewed-by: Shaun Tancheff <shaun.tancheff@hpe.com>
Reviewed-by: Oleg Drokin <green@whamcloud.com>
ldiskfs/kernel_patches/patches/rhel7.9/ext4-introduce-EXT4_BG_TRIMMED-to-optimize-fstrim.patch
ldiskfs/kernel_patches/patches/rhel8.7/ext4-introduce-EXT4_BG_TRIMMED-to-optimize-fstrim.patch [new file with mode: 0644]
ldiskfs/kernel_patches/patches/rhel9/ext4-introduce-EXT4_BG_TRIMMED-to-optimize-fstrim.patch
ldiskfs/kernel_patches/series/ldiskfs-4.18-rhel8.10.series
ldiskfs/kernel_patches/series/ldiskfs-4.18-rhel8.7.series
ldiskfs/kernel_patches/series/ldiskfs-4.18-rhel8.8.series
ldiskfs/kernel_patches/series/ldiskfs-4.18-rhel8.9.series

index 4945e22..227cf06 100644 (file)
@@ -49,12 +49,22 @@ Index: linux-3.10.0-1160.88.1.el7/fs/ext4/ext4.h
  #define EXT4_MAXQUOTAS 3
  
 +/* Default min freed blocks which we could clear BG_TRIMMED flag */
-+#define EXT4_DEF_TRIM_MIN_BLOCKS      128
++#define EXT4_DEF_BG_TRIMMED_THRESHOLD 128
 +
  /*
   * Structure of the super block
   */
-@@ -2805,6 +2810,7 @@ struct ext4_group_info {
+@@ -1456,6 +1461,9 @@ struct ext4_sb_info {
+       /* the size of zero-out chunk */
+       unsigned int s_extent_max_zeroout_kb;
++      /* Min freed blocks per group that we could clear BG_TRIMMED on it */
++      unsigned long s_bg_trimmed_threshold;
++
+       unsigned int s_log_groups_per_flex;
+       struct flex_groups *s_flex_groups;
+       ext4_group_t s_flex_groups_allocated;
+@@ -2796,6 +2804,7 @@ struct ext4_group_info {
        struct rb_root  bb_free_root;
        ext4_grpblk_t   bb_first_free;  /* first free block */
        ext4_grpblk_t   bb_free;        /* total free blocks */
@@ -109,7 +119,16 @@ Index: linux-3.10.0-1160.88.1.el7/fs/ext4/mballoc.c
  
  #ifdef DOUBLE_CHECK
        {
-@@ -3310,15 +3311,6 @@ static void ext4_free_data_callback(stru
+@@ -3115,6 +3116,8 @@ int ext4_mb_init(struct super_block *sb)
+       if (sbi->s_mb_prefetch_limit > ext4_get_groups_count(sb))
+               sbi->s_mb_prefetch_limit = ext4_get_groups_count(sb);
++      sbi->s_bg_trimmed_threshold = EXT4_DEF_BG_TRIMMED_THRESHOLD;
++
+       sbi->s_locality_groups = alloc_percpu(struct ext4_locality_group);
+       if (sbi->s_locality_groups == NULL) {
+               ret = -ENOMEM;
+@@ -3315,15 +3318,6 @@ static void ext4_free_data_callback(stru
        rb_erase(&entry->efd_node, &(db->bb_free_root));
        mb_free_blocks(NULL, &e4b, entry->efd_start_cluster, entry->efd_count);
  
@@ -135,7 +154,7 @@ Index: linux-3.10.0-1160.88.1.el7/fs/ext4/mballoc.c
  
                ext4_lock_group(sb, block_group);
                mb_clear_bits(bitmap_bh->b_data, bit, count_clusters);
-@@ -5432,6 +5423,24 @@ do_more:
+@@ -5437,6 +5430,22 @@ do_more:
        ret = ext4_free_group_clusters(sb, gdp) + count_clusters;
        ext4_free_group_clusters_set(sb, gdp, ret);
        ext4_block_bitmap_csum_set(sb, block_group, gdp, bitmap_bh);
@@ -147,20 +166,18 @@ Index: linux-3.10.0-1160.88.1.el7/fs/ext4/mballoc.c
 +       */
 +      if (!test_opt(sb, DISCARD)) {
 +              struct ext4_super_block *es = sbi->s_es;
-+              unsigned long minblks;
 +
-+              minblks = atomic_read(&EXT4_SB(sb)->s_last_trim_minblks);
 +              e4b.bd_info->bb_freed_since_trim += count;
 +
 +              if (e4b.bd_info->bb_freed_since_trim >=
-+                  (minblks ? minblks : EXT4_DEF_TRIM_MIN_BLOCKS) ||
++                  sbi->s_bg_trimmed_threshold ||
 +                  !(es->s_flags & cpu_to_le32(EXT2_FLAGS_TRACK_TRIM)))
 +                      gdp->bg_flags &= cpu_to_le16(~EXT4_BG_TRIMMED);
 +      }
        ext4_group_desc_csum_set(sb, block_group, gdp);
        ext4_unlock_group(sb, block_group);
  
-@@ -5671,9 +5680,18 @@ ext4_trim_all_free(struct super_block *s
+@@ -5676,9 +5685,16 @@ ext4_trim_all_free(struct super_block *s
        void *bitmap;
        ext4_grpblk_t next, count = 0, free_count = 0;
        struct ext4_buddy e4b;
@@ -172,10 +189,8 @@ Index: linux-3.10.0-1160.88.1.el7/fs/ext4/mballoc.c
  
        trace_ext4_trim_all_free(sb, group, start, max);
 +      gdp = ext4_get_group_desc(sb, group, &gd_bh);
-+      if (!gdp) {
-+              ret = -EIO;
-+              return ret;
-+      }
++      if (!gdp)
++              return -EIO;
  
        ret = ext4_mb_load_buddy(sb, group, &e4b);
        if (ret)
@@ -243,3 +258,23 @@ Index: linux-3.10.0-1160.88.1.el7/fs/ext4/mballoc.c
        ext4_debug("trimmed %d blocks in the group %d\n",
                count, group);
  
+Index: linux-3.10.0-1160.88.1.el7/fs/ext4/super.c
+===================================================================
+--- linux-3.10.0-1160.88.1.el7.orig/fs/ext4/super.c
++++ linux-3.10.0-1160.88.1.el7/fs/ext4/super.c
+@@ -2936,6 +2936,7 @@ EXT4_RW_ATTR_SBI_UI(mb_prefetch, s_mb_pr
+ EXT4_RW_ATTR_SBI_UI(mb_prefetch_limit, s_mb_prefetch_limit);
+ EXT4_DEPRECATED_ATTR(max_writeback_mb_bump, 128);
+ EXT4_RW_ATTR_SBI_UI(extent_max_zeroout_kb, s_extent_max_zeroout_kb);
++EXT4_RW_ATTR_SBI_UI(bg_trimmed_threshold, s_bg_trimmed_threshold);
+ EXT4_ATTR(trigger_fs_error, 0200, NULL, trigger_test_error);
+ EXT4_RW_ATTR_SBI_UI(err_ratelimit_interval_ms, s_err_ratelimit_state.interval);
+ EXT4_RW_ATTR_SBI_UI(err_ratelimit_burst, s_err_ratelimit_state.burst);
+@@ -2969,6 +2970,7 @@ static struct attribute *ext4_attrs[] =
+       ATTR_LIST(mb_group_prealloc),
+       ATTR_LIST(max_writeback_mb_bump),
+       ATTR_LIST(extent_max_zeroout_kb),
++      ATTR_LIST(bg_trimmed_threshold),
+       ATTR_LIST(trigger_fs_error),
+       ATTR_LIST(err_ratelimit_interval_ms),
+       ATTR_LIST(err_ratelimit_burst),
diff --git a/ldiskfs/kernel_patches/patches/rhel8.7/ext4-introduce-EXT4_BG_TRIMMED-to-optimize-fstrim.patch b/ldiskfs/kernel_patches/patches/rhel8.7/ext4-introduce-EXT4_BG_TRIMMED-to-optimize-fstrim.patch
new file mode 100644 (file)
index 0000000..83fcfd6
--- /dev/null
@@ -0,0 +1,280 @@
+From: Wang Shilong <wshilong@ddn.com>
+
+Currently the WAS_TRIMMED flag indicating block group has been
+trimmed is not persistent, and fstrim status will be lost at
+unmount.  As a result, fstrim cannot skip the already trimmed
+groups on remount, which could be slow on very large devices.
+
+To avoid this kind of problem, introduce a new block group flag
+EXT4_BG_TRIMMED to be stored persistently in the block group
+descriptor after trimming each block group.  This adds one extra
+group descriptor write after trimming a block group. When the
+flag is cleared the block group descriptor is journaled  already
+so it does not introduce any overhead.
+
+Add a new super block flag EXT2_FLAGS_TRACK_TRIM, to indicate if
+we should honour persistent EXT4_BG_TRIMMED when doing fstrim.
+The new super block flag can be turned on/off via tune2fs.
+
+Cc: Shuichi Ihara <sihara@ddn.com>
+Cc: Wang Shilong <wangshilong1991@gmail.com>
+Signed-off-by: Wang Shilong <wshilong@ddn.com>
+Signed-off-by: Dongyang Li <dongyangli@ddn.com>
+Reviewed-by: Andreas Dilger <adilger@whamcloud.com>
+Change-Id: I7faaca4754b1726ad05d0aafe3e90e0e9f591617
+Reviewed-on: https://review.whamcloud.com/51923
+
+Index: linux-4.18.0-425.10.1.el8_7/fs/ext4/ext4.h
+===================================================================
+--- linux-4.18.0-425.10.1.el8_7.orig/fs/ext4/ext4.h
++++ linux-4.18.0-425.10.1.el8_7/fs/ext4/ext4.h
+@@ -358,6 +358,7 @@ struct flex_groups {
+ #define EXT4_BG_INODE_UNINIT  0x0001 /* Inode table/bitmap not in use */
+ #define EXT4_BG_BLOCK_UNINIT  0x0002 /* Block bitmap not in use */
+ #define EXT4_BG_INODE_ZEROED  0x0004 /* On-disk itable initialized to zero */
++#define EXT4_BG_TRIMMED               0x0008 /* block group was trimmed */
+ /*
+  * Macro-instructions used to manage group descriptors
+@@ -1124,6 +1125,7 @@ struct ext4_inode_info {
+ #define EXT2_FLAGS_SIGNED_HASH                0x0001  /* Signed dirhash in use */
+ #define EXT2_FLAGS_UNSIGNED_HASH      0x0002  /* Unsigned dirhash in use */
+ #define EXT2_FLAGS_TEST_FILESYS               0x0004  /* to test development code */
++#define EXT2_FLAGS_TRACK_TRIM         0x0008  /* Track trim status in each bg */
+ /*
+  * Mount flags set via mount options or defaults
+@@ -1223,6 +1225,9 @@ extern void ext4_set_bits(void *bm, int
+ #define EXT4_DFL_MAX_MNT_COUNT                20      /* Allow 20 mounts */
+ #define EXT4_DFL_CHECKINTERVAL                0       /* Don't use interval check */
++/* Default min freed blocks which we could clear BG_TRIMMED flag */
++#define EXT4_DEF_BG_TRIMMED_THRESHOLD 128
++
+ /*
+  * Behaviour when detecting errors
+  */
+@@ -1527,6 +1532,9 @@ struct ext4_sb_info {
+       /* the size of zero-out chunk */
+       unsigned int s_extent_max_zeroout_kb;
++      /* Min freed blocks per group that we could clear BG_TRIMMED on it */
++      unsigned long s_bg_trimmed_threshold;
++
+       unsigned int s_log_groups_per_flex;
+       struct flex_groups * __rcu *s_flex_groups;
+       ext4_group_t s_flex_groups_allocated;
+@@ -3168,6 +3176,7 @@ struct ext4_group_info {
+       struct rb_root  bb_free_root;
+       ext4_grpblk_t   bb_first_free;  /* first free block */
+       ext4_grpblk_t   bb_free;        /* total free blocks */
++      ext4_grpblk_t   bb_freed_since_trim; /* blocks freed since last trim */
+       ext4_grpblk_t   bb_fragments;   /* nr of freespace fragments */
+       ext4_grpblk_t   bb_largest_free_order;/* order of largest frag in BG */
+       struct          list_head bb_prealloc_list;
+@@ -3183,7 +3192,6 @@ struct ext4_group_info {
+ };
+ #define EXT4_GROUP_INFO_NEED_INIT_BIT         0
+-#define EXT4_GROUP_INFO_WAS_TRIMMED_BIT               1
+ #define EXT4_GROUP_INFO_BBITMAP_CORRUPT_BIT   2
+ #define EXT4_GROUP_INFO_IBITMAP_CORRUPT_BIT   3
+ #define EXT4_GROUP_INFO_BBITMAP_CORRUPT               \
+@@ -3199,12 +3207,6 @@ struct ext4_group_info {
+ #define EXT4_MB_GRP_IBITMAP_CORRUPT(grp)      \
+       (test_bit(EXT4_GROUP_INFO_IBITMAP_CORRUPT_BIT, &((grp)->bb_state)))
+-#define EXT4_MB_GRP_WAS_TRIMMED(grp)  \
+-      (test_bit(EXT4_GROUP_INFO_WAS_TRIMMED_BIT, &((grp)->bb_state)))
+-#define EXT4_MB_GRP_SET_TRIMMED(grp)  \
+-      (set_bit(EXT4_GROUP_INFO_WAS_TRIMMED_BIT, &((grp)->bb_state)))
+-#define EXT4_MB_GRP_CLEAR_TRIMMED(grp)        \
+-      (clear_bit(EXT4_GROUP_INFO_WAS_TRIMMED_BIT, &((grp)->bb_state)))
+ #define EXT4_MB_GRP_TEST(grp) \
+       (test_bit(EXT4_GROUP_INFO_BBITMAP_READ_BIT, &((grp)->bb_state)))
+ #define EXT4_MB_GRP_TEST_AND_SET_READ(grp)    \
+Index: linux-4.18.0-425.10.1.el8_7/fs/ext4/ext4_jbd2.h
+===================================================================
+--- linux-4.18.0-425.10.1.el8_7.orig/fs/ext4/ext4_jbd2.h
++++ linux-4.18.0-425.10.1.el8_7/fs/ext4/ext4_jbd2.h
+@@ -123,7 +123,8 @@
+ #define EXT4_HT_MOVE_EXTENTS     9
+ #define EXT4_HT_XATTR           10
+ #define EXT4_HT_EXT_CONVERT     11
+-#define EXT4_HT_MAX             12
++#define EXT4_HT_FS_TRIM               12
++#define EXT4_HT_MAX             13
+ /**
+  *   struct ext4_journal_cb_entry - Base structure for callback information.
+Index: linux-4.18.0-425.10.1.el8_7/fs/ext4/mballoc.c
+===================================================================
+--- linux-4.18.0-425.10.1.el8_7.orig/fs/ext4/mballoc.c
++++ linux-4.18.0-425.10.1.el8_7/fs/ext4/mballoc.c
+@@ -2956,6 +2956,7 @@ int ext4_mb_add_groupinfo(struct super_b
+       init_rwsem(&meta_group_info[i]->alloc_sem);
+       meta_group_info[i]->bb_free_root = RB_ROOT;
+       meta_group_info[i]->bb_largest_free_order = -1;  /* uninit */
++      meta_group_info[i]->bb_freed_since_trim = 0;
+       mb_group_bb_bitmap_alloc(sb, meta_group_info[i], group);
+       return 0;
+@@ -3209,6 +3210,8 @@ int ext4_mb_init(struct super_block *sb)
+       if (sbi->s_mb_prefetch_limit > ext4_get_groups_count(sb))
+               sbi->s_mb_prefetch_limit = ext4_get_groups_count(sb);
++      sbi->s_bg_trimmed_threshold = EXT4_DEF_BG_TRIMMED_THRESHOLD;
++
+       sbi->s_locality_groups = alloc_percpu(struct ext4_locality_group);
+       if (sbi->s_locality_groups == NULL) {
+               ret = -ENOMEM;
+@@ -3382,15 +3385,6 @@ static void ext4_free_data_in_buddy(stru
+       rb_erase(&entry->efd_node, &(db->bb_free_root));
+       mb_free_blocks(NULL, &e4b, entry->efd_start_cluster, entry->efd_count);
+-      /*
+-       * Clear the trimmed flag for the group so that the next
+-       * ext4_trim_fs can trim it.
+-       * If the volume is mounted with -o discard, online discard
+-       * is supported and the free blocks will be trimmed online.
+-       */
+-      if (!test_opt(sb, DISCARD))
+-              EXT4_MB_GRP_CLEAR_TRIMMED(db);
+-
+       if (!db->bb_free_root.rb_node) {
+               /* No more items in the per group rb tree
+                * balance refcounts from ext4_mb_free_metadata()
+@@ -5624,8 +5618,7 @@ do_more:
+                                        " group:%d block:%d count:%lu failed"
+                                        " with %d", block_group, bit, count,
+                                        err);
+-              } else
+-                      EXT4_MB_GRP_CLEAR_TRIMMED(e4b.bd_info);
++              }
+               ext4_lock_group(sb, block_group);
+               mb_clear_bits(bitmap_bh->b_data, bit, count_clusters);
+@@ -5635,6 +5628,22 @@ do_more:
+       ret = ext4_free_group_clusters(sb, gdp) + count_clusters;
+       ext4_free_group_clusters_set(sb, gdp, ret);
+       ext4_block_bitmap_csum_set(sb, block_group, gdp, bitmap_bh);
++      /*
++       * Clear the trimmed flag for the group so that the next
++       * ext4_trim_fs can trim it.
++       * If the volume is mounted with -o discard, online discard
++       * is supported and the free blocks will be trimmed online.
++       */
++      if (!test_opt(sb, DISCARD)) {
++              struct ext4_super_block *es = sbi->s_es;
++
++              e4b.bd_info->bb_freed_since_trim += count;
++
++              if (e4b.bd_info->bb_freed_since_trim >=
++                  sbi->s_bg_trimmed_threshold ||
++                  !(es->s_flags & cpu_to_le32(EXT2_FLAGS_TRACK_TRIM)))
++                      gdp->bg_flags &= cpu_to_le16(~EXT4_BG_TRIMMED);
++      }
+       ext4_group_desc_csum_set(sb, block_group, gdp);
+       ext4_unlock_group(sb, block_group);
+@@ -5889,9 +5898,16 @@ ext4_trim_all_free(struct super_block *s
+       void *bitmap;
+       ext4_grpblk_t next, count = 0, free_count = 0;
+       struct ext4_buddy e4b;
++      struct ext4_super_block *es = EXT4_SB(sb)->s_es;
++      struct ext4_group_desc *gdp;
++      struct buffer_head *gd_bh;
++      ext4_grpblk_t freed_last_trimmed_orig;
+       int ret = 0;
+       trace_ext4_trim_all_free(sb, group, start, max);
++      gdp = ext4_get_group_desc(sb, group, &gd_bh);
++      if (!gdp)
++              return -EIO;
+       ret = ext4_mb_load_buddy(sb, group, &e4b);
+       if (ret)
+@@ -5899,10 +5915,12 @@ ext4_trim_all_free(struct super_block *s
+       bitmap = e4b.bd_bitmap;
+       ext4_lock_group(sb, group);
+-      if (EXT4_MB_GRP_WAS_TRIMMED(e4b.bd_info) &&
++      if (es->s_flags & cpu_to_le32(EXT2_FLAGS_TRACK_TRIM) &&
++          gdp->bg_flags & cpu_to_le16(EXT4_BG_TRIMMED) &&
+           minblocks >= atomic_read(&EXT4_SB(sb)->s_last_trim_minblks))
+               goto out;
++      freed_last_trimmed_orig = e4b.bd_info->bb_freed_since_trim;
+       start = (e4b.bd_info->bb_first_free > start) ?
+               e4b.bd_info->bb_first_free : start;
+@@ -5938,14 +5956,46 @@ ext4_trim_all_free(struct super_block *s
+                       break;
+       }
+-      if (!ret) {
++      if (!ret)
+               ret = count;
+-              EXT4_MB_GRP_SET_TRIMMED(e4b.bd_info);
+-      }
+ out:
+       ext4_unlock_group(sb, group);
+       ext4_mb_unload_buddy(&e4b);
++      if (ret > 0 && es->s_flags & cpu_to_le32(EXT2_FLAGS_TRACK_TRIM)) {
++              int err;
++              handle_t *handle;
++
++              handle = ext4_journal_start_sb(sb, EXT4_HT_FS_TRIM, 1);
++              if (IS_ERR(handle)) {
++                      ret = PTR_ERR(handle);
++                      goto out_return;
++              }
++              err = ext4_journal_get_write_access(handle, gd_bh);
++              if (err) {
++                      ret = err;
++                      goto out_journal;
++              }
++              ext4_lock_group(sb, group);
++              /* someone freed blocks while we were working on the group */
++              if (freed_last_trimmed_orig !=
++                      e4b.bd_info->bb_freed_since_trim) {
++                      ext4_unlock_group(sb, group);
++                      goto out_journal;
++              }
++              gdp->bg_flags |= cpu_to_le16(EXT4_BG_TRIMMED);
++              e4b.bd_info->bb_freed_since_trim = 0;
++              ext4_group_desc_csum_set(sb, group, gdp);
++              ext4_unlock_group(sb, group);
++              err = ext4_handle_dirty_metadata(handle, NULL, gd_bh);
++              if (err)
++                      ret = err;
++out_journal:
++              err = ext4_journal_stop(handle);
++              if (err)
++                      ret = err;
++      }
++out_return:
+       ext4_debug("trimmed %d blocks in the group %d\n",
+               count, group);
+Index: linux-4.18.0-425.10.1.el8_7/fs/ext4/sysfs.c
+===================================================================
+--- linux-4.18.0-425.10.1.el8_7.orig/fs/ext4/sysfs.c
++++ linux-4.18.0-425.10.1.el8_7/fs/ext4/sysfs.c
+@@ -223,6 +223,7 @@ EXT4_RW_ATTR_SBI_UI(mb_small_req, s_mb_s
+ EXT4_RW_ATTR_SBI_UI(mb_large_req, s_mb_large_req);
+ EXT4_RW_ATTR_SBI_UI(mb_group_prealloc, s_mb_group_prealloc);
+ EXT4_RW_ATTR_SBI_UI(extent_max_zeroout_kb, s_extent_max_zeroout_kb);
++EXT4_RW_ATTR_SBI_UI(bg_trimmed_threshold, s_bg_trimmed_threshold);
+ EXT4_ATTR(trigger_fs_error, 0200, trigger_test_error);
+ EXT4_RW_ATTR_SBI_UI(err_ratelimit_interval_ms, s_err_ratelimit_state.interval);
+ EXT4_RW_ATTR_SBI_UI(err_ratelimit_burst, s_err_ratelimit_state.burst);
+@@ -262,6 +263,7 @@ static struct attribute *ext4_attrs[] =
+       ATTR_LIST(mb_group_prealloc),
+       ATTR_LIST(max_writeback_mb_bump),
+       ATTR_LIST(extent_max_zeroout_kb),
++      ATTR_LIST(bg_trimmed_threshold),
+       ATTR_LIST(trigger_fs_error),
+       ATTR_LIST(err_ratelimit_interval_ms),
+       ATTR_LIST(err_ratelimit_burst),
index 48abe47..d3a4a37 100644 (file)
@@ -49,12 +49,22 @@ Index: linux-5.14.0-162.23.1.el9_1/fs/ext4/ext4.h
  #define EXT4_LABEL_MAX                        16
  
 +/* Default min freed blocks which we could clear BG_TRIMMED flag */
-+#define EXT4_DEF_TRIM_MIN_BLOCKS      128
++#define EXT4_DEF_BG_TRIMMED_THRESHOLD 128
 +
  /*
   * Structure of the super block
   */
-@@ -3641,6 +3646,7 @@ struct ext4_group_info {
+@@ -1660,6 +1665,9 @@ struct ext4_sb_info {
+       /* the size of zero-out chunk */
+       unsigned int s_extent_max_zeroout_kb;
++      /* Min freed blocks per group that we could clear BG_TRIMMED on it */
++      unsigned long s_bg_trimmed_threshold;
++
+       unsigned int s_log_groups_per_flex;
+       struct flex_groups * __rcu *s_flex_groups;
+       ext4_group_t s_flex_groups_allocated;
+@@ -3629,6 +3637,7 @@ struct ext4_group_info {
        struct rb_root  bb_free_root;
        ext4_grpblk_t   bb_first_free;  /* first free block */
        ext4_grpblk_t   bb_free;        /* total free blocks */
@@ -110,7 +120,16 @@ Index: linux-5.14.0-162.23.1.el9_1/fs/ext4/mballoc.c
  
        mb_group_bb_bitmap_alloc(sb, meta_group_info[i], group);
        return 0;
-@@ -3849,15 +3850,6 @@ static void ext4_free_data_in_buddy(stru
+@@ -3671,6 +3672,8 @@ int ext4_mb_init(struct super_block *sb)
+               sbi->s_mb_group_prealloc = sbi->s_stripe * 4;
+       }
++      sbi->s_bg_trimmed_threshold = EXT4_DEF_BG_TRIMMED_THRESHOLD;
++
+       sbi->s_locality_groups = alloc_percpu(struct ext4_locality_group);
+       if (sbi->s_locality_groups == NULL) {
+               ret = -ENOMEM;
+@@ -3849,15 +3852,6 @@ static void ext4_free_data_in_buddy(stru
        rb_erase(&entry->efd_node, &(db->bb_free_root));
        mb_free_blocks(NULL, &e4b, entry->efd_start_cluster, entry->efd_count);
  
@@ -148,18 +167,18 @@ Index: linux-5.14.0-162.23.1.el9_1/fs/ext4/mballoc.c
 +       */
 +      if (!test_opt(sb, DISCARD)) {
 +              struct ext4_super_block *es = sbi->s_es;
-+              unsigned long minblks = EXT4_SB(sb)->s_last_trim_minblks;
++
 +              e4b.bd_info->bb_freed_since_trim += count;
 +
 +              if (e4b.bd_info->bb_freed_since_trim >=
-+                  (minblks ? minblks : EXT4_DEF_TRIM_MIN_BLOCKS) ||
++                  sbi->s_bg_trimmed_threshold ||
 +                  !(es->s_flags & cpu_to_le32(EXT2_FLAGS_TRACK_TRIM)))
 +                      gdp->bg_flags &= cpu_to_le16(~EXT4_BG_TRIMMED);
 +      }
        ext4_group_desc_csum_set(sb, block_group, gdp);
        ext4_unlock_group(sb, block_group);
  
-@@ -6692,10 +6699,20 @@ ext4_trim_all_free(struct super_block *s
+@@ -6692,10 +6701,18 @@ ext4_trim_all_free(struct super_block *s
                   ext4_grpblk_t minblocks, bool set_trimmed)
  {
        struct ext4_buddy e4b;
@@ -172,10 +191,8 @@ Index: linux-5.14.0-162.23.1.el9_1/fs/ext4/mballoc.c
        trace_ext4_trim_all_free(sb, group, start, max);
  
 +      gdp = ext4_get_group_desc(sb, group, &gd_bh);
-+      if (!gdp) {
-+              ret = -EIO;
-+              return ret;
-+      }
++      if (!gdp)
++              return -EIO;
 +
        ret = ext4_mb_load_buddy(sb, group, &e4b);
        if (ret) {
@@ -187,7 +204,7 @@ Index: linux-5.14.0-162.23.1.el9_1/fs/ext4/mballoc.c
 -      if (!EXT4_MB_GRP_WAS_TRIMMED(e4b.bd_info) ||
 +      freed_last_trimmed_orig = e4b.bd_info->bb_freed_since_trim;
 +
-+      if (!(es->s_flags & cpu_to_le16(EXT2_FLAGS_TRACK_TRIM) &&
++      if (!(es->s_flags & cpu_to_le32(EXT2_FLAGS_TRACK_TRIM) &&
 +            gdp->bg_flags & cpu_to_le16(EXT4_BG_TRIMMED)) ||
            minblocks < EXT4_SB(sb)->s_last_trim_minblks) {
                ret = ext4_try_to_trim_range(sb, &e4b, start, max, minblocks);
@@ -239,3 +256,23 @@ Index: linux-5.14.0-162.23.1.el9_1/fs/ext4/mballoc.c
        ext4_debug("trimmed %d blocks in the group %d\n",
                ret, group);
  
+Index: linux-5.14.0-162.23.1.el9_1/fs/ext4/sysfs.c
+===================================================================
+--- linux-5.14.0-162.23.1.el9_1.orig/fs/ext4/sysfs.c
++++ linux-5.14.0-162.23.1.el9_1/fs/ext4/sysfs.c
+@@ -221,6 +221,7 @@ EXT4_RW_ATTR_SBI_UI(mb_group_prealloc, s
+ EXT4_RW_ATTR_SBI_UI(mb_max_inode_prealloc, s_mb_max_inode_prealloc);
+ EXT4_RW_ATTR_SBI_UI(mb_max_linear_groups, s_mb_max_linear_groups);
+ EXT4_RW_ATTR_SBI_UI(extent_max_zeroout_kb, s_extent_max_zeroout_kb);
++EXT4_RW_ATTR_SBI_UI(bg_trimmed_threshold, s_bg_trimmed_threshold);
+ EXT4_ATTR(trigger_fs_error, 0200, trigger_test_error);
+ EXT4_RW_ATTR_SBI_UI(err_ratelimit_interval_ms, s_err_ratelimit_state.interval);
+ EXT4_RW_ATTR_SBI_UI(err_ratelimit_burst, s_err_ratelimit_state.burst);
+@@ -276,6 +277,7 @@ static struct attribute *ext4_attrs[] =
+       ATTR_LIST(mb_max_linear_groups),
+       ATTR_LIST(max_writeback_mb_bump),
+       ATTR_LIST(extent_max_zeroout_kb),
++      ATTR_LIST(bg_trimmed_threshold),
+       ATTR_LIST(trigger_fs_error),
+       ATTR_LIST(err_ratelimit_interval_ms),
+       ATTR_LIST(err_ratelimit_burst),
index d6a3bc6..ea6a0d1 100644 (file)
@@ -28,7 +28,7 @@ rhel8.7/ext4-mballoc-prefetch.patch
 rhel8.3/ext4-xattr-disable-credits-check.patch
 base/ext4-no-max-dir-size-limit-for-iam-objects.patch
 rhel7.6/ext4-dquot-commit-speedup.patch
-rhel7.9/ext4-introduce-EXT4_BG_TRIMMED-to-optimize-fstrim.patch
+rhel8.7/ext4-introduce-EXT4_BG_TRIMMED-to-optimize-fstrim.patch
 rhel8/ext4-ialloc-uid-gid-and-pass-owner-down.patch
 base/ext4-projid-xattrs.patch
 rhel8.5/ext4-enc-flag.patch
index d6a3bc6..ea6a0d1 100644 (file)
@@ -28,7 +28,7 @@ rhel8.7/ext4-mballoc-prefetch.patch
 rhel8.3/ext4-xattr-disable-credits-check.patch
 base/ext4-no-max-dir-size-limit-for-iam-objects.patch
 rhel7.6/ext4-dquot-commit-speedup.patch
-rhel7.9/ext4-introduce-EXT4_BG_TRIMMED-to-optimize-fstrim.patch
+rhel8.7/ext4-introduce-EXT4_BG_TRIMMED-to-optimize-fstrim.patch
 rhel8/ext4-ialloc-uid-gid-and-pass-owner-down.patch
 base/ext4-projid-xattrs.patch
 rhel8.5/ext4-enc-flag.patch
index d6a3bc6..ea6a0d1 100644 (file)
@@ -28,7 +28,7 @@ rhel8.7/ext4-mballoc-prefetch.patch
 rhel8.3/ext4-xattr-disable-credits-check.patch
 base/ext4-no-max-dir-size-limit-for-iam-objects.patch
 rhel7.6/ext4-dquot-commit-speedup.patch
-rhel7.9/ext4-introduce-EXT4_BG_TRIMMED-to-optimize-fstrim.patch
+rhel8.7/ext4-introduce-EXT4_BG_TRIMMED-to-optimize-fstrim.patch
 rhel8/ext4-ialloc-uid-gid-and-pass-owner-down.patch
 base/ext4-projid-xattrs.patch
 rhel8.5/ext4-enc-flag.patch
index d6a3bc6..ea6a0d1 100644 (file)
@@ -28,7 +28,7 @@ rhel8.7/ext4-mballoc-prefetch.patch
 rhel8.3/ext4-xattr-disable-credits-check.patch
 base/ext4-no-max-dir-size-limit-for-iam-objects.patch
 rhel7.6/ext4-dquot-commit-speedup.patch
-rhel7.9/ext4-introduce-EXT4_BG_TRIMMED-to-optimize-fstrim.patch
+rhel8.7/ext4-introduce-EXT4_BG_TRIMMED-to-optimize-fstrim.patch
 rhel8/ext4-ialloc-uid-gid-and-pass-owner-down.patch
 base/ext4-projid-xattrs.patch
 rhel8.5/ext4-enc-flag.patch