2022-04-07 13:53:40

by Shaun Tancheff

[permalink] [raw]
Subject: [PATCH] Shrink fast commit buffer when not used

Shrink the fast-commit buffer when the feature is not
enabled. By default the fast-commit buffer will allocate 256
blocks if s_num_fc_blks is 0. Set s_num_fc_blks to a smaller
value (> 0) to avoid allocating a large unused buffer, this
also makes more journal credits available when fast commit
is not used.

Signed-off-by: Shaun Tancheff <[email protected]>
---
fs/ext4/super.c | 15 +++++++++++++++
1 file changed, 15 insertions(+)

diff --git a/fs/ext4/super.c b/fs/ext4/super.c
index 81749eaddf4c..d2df10dc7cc3 100644
--- a/fs/ext4/super.c
+++ b/fs/ext4/super.c
@@ -4222,6 +4222,14 @@ static int count_overhead(struct super_block *sb, ext4_group_t grp,
ext4_count_free(buf, EXT4_CLUSTERS_PER_GROUP(sb) / 8);
}

+static void strink_journal_fc_buffer(struct super_block *ext4_sb)
+{
+ journal_t *journal = EXT4_SB(ext4_sb)->s_journal;
+ journal_superblock_t *sb = journal->j_superblock;
+
+ sb->s_num_fc_blks = cpu_to_be32(8);
+}
+
/*
* Compute the overhead and stash it in sbi->s_overhead
*/
@@ -5189,6 +5197,13 @@ static int __ext4_fill_super(struct fs_context *fc, struct super_block *sb)
goto failed_mount_wq;
}

+ /* Since fast-commit is disabled, shrink it's dedicated memory
+ * and it's share of the journal space so we can use the extra
+ * credits
+ */
+ if (!test_opt2(sb, JOURNAL_FAST_COMMIT))
+ strink_journal_fc_buffer(sb);
+
if (!set_journal_csum_feature_set(sb)) {
ext4_msg(sb, KERN_ERR, "Failed to set journal checksum "
"feature set");
--
2.32.0