Skip to content

Commit 896b02d

Browse files
OjaswinMtytso
authored andcommitted
ext4: Make sb update interval tunable
Currently, outside error paths, we auto commit the super block after 1 hour has passed and 16MB worth of updates have been written since last commit. This is a policy decision so make this tunable while keeping the defaults same. This is useful if user wants to tweak the superblock behavior or for debugging the codepath by allowing to trigger it more frequently. We can now tweak the super block update using sb_update_sec and sb_update_kb files in /sys/fs/ext4/<dev>/ Reviewed-by: Jan Kara <jack@suse.cz> Reviewed-by: Ritesh Harjani (IBM) <ritesh.list@gmail.com> Reviewed-by: Baokun Li <libaokun1@huawei.com> Signed-off-by: Ojaswin Mujoo <ojaswin@linux.ibm.com> Link: https://patch.msgid.link/950fb8c9b2905620e16f02a3b9eeea5a5b6cb87e.1742279837.git.ojaswin@linux.ibm.com Signed-off-by: Theodore Ts'o <tytso@mit.edu>
1 parent ce2f26e commit 896b02d

File tree

3 files changed

+21
-7
lines changed

3 files changed

+21
-7
lines changed

fs/ext4/ext4.h

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1609,6 +1609,8 @@ struct ext4_sb_info {
16091609
unsigned int s_mb_prefetch;
16101610
unsigned int s_mb_prefetch_limit;
16111611
unsigned int s_mb_best_avail_max_trim_order;
1612+
unsigned int s_sb_update_sec;
1613+
unsigned int s_sb_update_kb;
16121614

16131615
/* stats for buddy allocator */
16141616
atomic_t s_bal_reqs; /* number of reqs with len > 1 */
@@ -2298,6 +2300,13 @@ static inline int ext4_emergency_state(struct super_block *sb)
22982300
#define EXT4_DEF_MIN_BATCH_TIME 0
22992301
#define EXT4_DEF_MAX_BATCH_TIME 15000 /* 15ms */
23002302

2303+
/*
2304+
* Default values for superblock update
2305+
*/
2306+
#define EXT4_DEF_SB_UPDATE_INTERVAL_SEC (3600) /* seconds (1 hour) */
2307+
#define EXT4_DEF_SB_UPDATE_INTERVAL_KB (16384) /* kilobytes (16MB) */
2308+
2309+
23012310
/*
23022311
* Minimum number of groups in a flexgroup before we separate out
23032312
* directories into the first block group of a flexgroup

fs/ext4/super.c

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -447,18 +447,17 @@ static time64_t __ext4_get_tstamp(__le32 *lo, __u8 *hi)
447447
#define ext4_get_tstamp(es, tstamp) \
448448
__ext4_get_tstamp(&(es)->tstamp, &(es)->tstamp ## _hi)
449449

450-
#define EXT4_SB_REFRESH_INTERVAL_SEC (3600) /* seconds (1 hour) */
451-
#define EXT4_SB_REFRESH_INTERVAL_KB (16384) /* kilobytes (16MB) */
452-
453450
/*
454451
* The ext4_maybe_update_superblock() function checks and updates the
455452
* superblock if needed.
456453
*
457454
* This function is designed to update the on-disk superblock only under
458455
* certain conditions to prevent excessive disk writes and unnecessary
459456
* waking of the disk from sleep. The superblock will be updated if:
460-
* 1. More than an hour has passed since the last superblock update, and
461-
* 2. More than 16MB have been written since the last superblock update.
457+
* 1. More than sbi->s_sb_update_sec (def: 1 hour) has passed since the last
458+
* superblock update
459+
* 2. More than sbi->s_sb_update_kb (def: 16MB) kbs have been written since the
460+
* last superblock update.
462461
*
463462
* @sb: The superblock
464463
*/
@@ -480,7 +479,7 @@ static void ext4_maybe_update_superblock(struct super_block *sb)
480479
now = ktime_get_real_seconds();
481480
last_update = ext4_get_tstamp(es, s_wtime);
482481

483-
if (likely(now - last_update < EXT4_SB_REFRESH_INTERVAL_SEC))
482+
if (likely(now - last_update < sbi->s_sb_update_sec))
484483
return;
485484

486485
lifetime_write_kbytes = sbi->s_kbytes_written +
@@ -495,7 +494,7 @@ static void ext4_maybe_update_superblock(struct super_block *sb)
495494
*/
496495
diff_size = lifetime_write_kbytes - le64_to_cpu(es->s_kbytes_written);
497496

498-
if (diff_size > EXT4_SB_REFRESH_INTERVAL_KB)
497+
if (diff_size > sbi->s_sb_update_kb)
499498
schedule_work(&EXT4_SB(sb)->s_sb_upd_work);
500499
}
501500

@@ -5280,6 +5279,8 @@ static int __ext4_fill_super(struct fs_context *fc, struct super_block *sb)
52805279
sbi->s_commit_interval = JBD2_DEFAULT_MAX_COMMIT_AGE * HZ;
52815280
sbi->s_min_batch_time = EXT4_DEF_MIN_BATCH_TIME;
52825281
sbi->s_max_batch_time = EXT4_DEF_MAX_BATCH_TIME;
5282+
sbi->s_sb_update_kb = EXT4_DEF_SB_UPDATE_INTERVAL_KB;
5283+
sbi->s_sb_update_sec = EXT4_DEF_SB_UPDATE_INTERVAL_SEC;
52835284

52845285
/*
52855286
* set default s_li_wait_mult for lazyinit, for the case there is

fs/ext4/sysfs.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -254,6 +254,8 @@ EXT4_ATTR(journal_task, 0444, journal_task);
254254
EXT4_RW_ATTR_SBI_UI(mb_prefetch, s_mb_prefetch);
255255
EXT4_RW_ATTR_SBI_UI(mb_prefetch_limit, s_mb_prefetch_limit);
256256
EXT4_RW_ATTR_SBI_UL(last_trim_minblks, s_last_trim_minblks);
257+
EXT4_RW_ATTR_SBI_UI(sb_update_sec, s_sb_update_sec);
258+
EXT4_RW_ATTR_SBI_UI(sb_update_kb, s_sb_update_kb);
257259

258260
static unsigned int old_bump_val = 128;
259261
EXT4_ATTR_PTR(max_writeback_mb_bump, 0444, pointer_ui, &old_bump_val);
@@ -305,6 +307,8 @@ static struct attribute *ext4_attrs[] = {
305307
ATTR_LIST(mb_prefetch),
306308
ATTR_LIST(mb_prefetch_limit),
307309
ATTR_LIST(last_trim_minblks),
310+
ATTR_LIST(sb_update_sec),
311+
ATTR_LIST(sb_update_kb),
308312
NULL,
309313
};
310314
ATTRIBUTE_GROUPS(ext4);

0 commit comments

Comments
 (0)