Commit 8b87dc17 authored by David Sterba's avatar David Sterba Committed by Chris Mason

btrfs: add mount option to set commit interval

I'ts hardcoded to 30 seconds which is fine for most users. Higher values
defer data being synced to permanent storage with obvious consequences
when the system crashes. The upper bound is not forced, but a warning is
printed if it's more than 300 seconds (5 minutes).
Signed-off-by: default avatarDavid Sterba <dsterba@suse.cz>
Signed-off-by: default avatarJosef Bacik <jbacik@fusionio.com>
Signed-off-by: default avatarChris Mason <chris.mason@fusionio.com>
parent 9ec72677
...@@ -1351,6 +1351,7 @@ struct btrfs_fs_info { ...@@ -1351,6 +1351,7 @@ struct btrfs_fs_info {
u64 last_trans_log_full_commit; u64 last_trans_log_full_commit;
unsigned long mount_opt; unsigned long mount_opt;
unsigned long compress_type:4; unsigned long compress_type:4;
int commit_interval;
/* /*
* It is a suggestive number, the read side is safe even it gets a * It is a suggestive number, the read side is safe even it gets a
* wrong number because we will write out the data into a regular * wrong number because we will write out the data into a regular
...@@ -1969,6 +1970,8 @@ struct btrfs_ioctl_defrag_range_args { ...@@ -1969,6 +1970,8 @@ struct btrfs_ioctl_defrag_range_args {
#define BTRFS_MOUNT_CHECK_INTEGRITY_INCLUDING_EXTENT_DATA (1 << 21) #define BTRFS_MOUNT_CHECK_INTEGRITY_INCLUDING_EXTENT_DATA (1 << 21)
#define BTRFS_MOUNT_PANIC_ON_FATAL_ERROR (1 << 22) #define BTRFS_MOUNT_PANIC_ON_FATAL_ERROR (1 << 22)
#define BTRFS_DEFAULT_COMMIT_INTERVAL (30)
#define btrfs_clear_opt(o, opt) ((o) &= ~BTRFS_MOUNT_##opt) #define btrfs_clear_opt(o, opt) ((o) &= ~BTRFS_MOUNT_##opt)
#define btrfs_set_opt(o, opt) ((o) |= BTRFS_MOUNT_##opt) #define btrfs_set_opt(o, opt) ((o) |= BTRFS_MOUNT_##opt)
#define btrfs_raw_test_opt(o, opt) ((o) & BTRFS_MOUNT_##opt) #define btrfs_raw_test_opt(o, opt) ((o) & BTRFS_MOUNT_##opt)
......
...@@ -1742,7 +1742,7 @@ static int transaction_kthread(void *arg) ...@@ -1742,7 +1742,7 @@ static int transaction_kthread(void *arg)
do { do {
cannot_commit = false; cannot_commit = false;
delay = HZ * 30; delay = HZ * root->fs_info->commit_interval;
mutex_lock(&root->fs_info->transaction_kthread_mutex); mutex_lock(&root->fs_info->transaction_kthread_mutex);
spin_lock(&root->fs_info->trans_lock); spin_lock(&root->fs_info->trans_lock);
...@@ -1754,7 +1754,8 @@ static int transaction_kthread(void *arg) ...@@ -1754,7 +1754,8 @@ static int transaction_kthread(void *arg)
now = get_seconds(); now = get_seconds();
if (cur->state < TRANS_STATE_BLOCKED && if (cur->state < TRANS_STATE_BLOCKED &&
(now < cur->start_time || now - cur->start_time < 30)) { (now < cur->start_time ||
now - cur->start_time < root->fs_info->commit_interval)) {
spin_unlock(&root->fs_info->trans_lock); spin_unlock(&root->fs_info->trans_lock);
delay = HZ * 5; delay = HZ * 5;
goto sleep; goto sleep;
...@@ -2194,6 +2195,7 @@ int open_ctree(struct super_block *sb, ...@@ -2194,6 +2195,7 @@ int open_ctree(struct super_block *sb,
fs_info->defrag_inodes = RB_ROOT; fs_info->defrag_inodes = RB_ROOT;
fs_info->free_chunk_space = 0; fs_info->free_chunk_space = 0;
fs_info->tree_mod_log = RB_ROOT; fs_info->tree_mod_log = RB_ROOT;
fs_info->commit_interval = BTRFS_DEFAULT_COMMIT_INTERVAL;
/* readahead state */ /* readahead state */
INIT_RADIX_TREE(&fs_info->reada_tree, GFP_NOFS & ~__GFP_WAIT); INIT_RADIX_TREE(&fs_info->reada_tree, GFP_NOFS & ~__GFP_WAIT);
......
...@@ -321,6 +321,7 @@ enum { ...@@ -321,6 +321,7 @@ enum {
Opt_no_space_cache, Opt_recovery, Opt_skip_balance, Opt_no_space_cache, Opt_recovery, Opt_skip_balance,
Opt_check_integrity, Opt_check_integrity_including_extent_data, Opt_check_integrity, Opt_check_integrity_including_extent_data,
Opt_check_integrity_print_mask, Opt_fatal_errors, Opt_check_integrity_print_mask, Opt_fatal_errors,
Opt_commit_interval,
Opt_err, Opt_err,
}; };
...@@ -361,6 +362,7 @@ static match_table_t tokens = { ...@@ -361,6 +362,7 @@ static match_table_t tokens = {
{Opt_check_integrity_including_extent_data, "check_int_data"}, {Opt_check_integrity_including_extent_data, "check_int_data"},
{Opt_check_integrity_print_mask, "check_int_print_mask=%d"}, {Opt_check_integrity_print_mask, "check_int_print_mask=%d"},
{Opt_fatal_errors, "fatal_errors=%s"}, {Opt_fatal_errors, "fatal_errors=%s"},
{Opt_commit_interval, "commit=%d"},
{Opt_err, NULL}, {Opt_err, NULL},
}; };
...@@ -645,6 +647,29 @@ int btrfs_parse_options(struct btrfs_root *root, char *options) ...@@ -645,6 +647,29 @@ int btrfs_parse_options(struct btrfs_root *root, char *options)
goto out; goto out;
} }
break; break;
case Opt_commit_interval:
intarg = 0;
ret = match_int(&args[0], &intarg);
if (ret < 0) {
printk(KERN_ERR
"btrfs: invalid commit interval\n");
ret = -EINVAL;
goto out;
}
if (intarg > 0) {
if (intarg > 300) {
printk(KERN_WARNING
"btrfs: excessive commit interval %d\n",
intarg);
}
info->commit_interval = intarg;
} else {
printk(KERN_INFO
"btrfs: using default commit interval %ds\n",
BTRFS_DEFAULT_COMMIT_INTERVAL);
info->commit_interval = BTRFS_DEFAULT_COMMIT_INTERVAL;
}
break;
case Opt_err: case Opt_err:
printk(KERN_INFO "btrfs: unrecognized mount option " printk(KERN_INFO "btrfs: unrecognized mount option "
"'%s'\n", p); "'%s'\n", p);
...@@ -981,6 +1006,8 @@ static int btrfs_show_options(struct seq_file *seq, struct dentry *dentry) ...@@ -981,6 +1006,8 @@ static int btrfs_show_options(struct seq_file *seq, struct dentry *dentry)
info->metadata_ratio); info->metadata_ratio);
if (btrfs_test_opt(root, PANIC_ON_FATAL_ERROR)) if (btrfs_test_opt(root, PANIC_ON_FATAL_ERROR))
seq_puts(seq, ",fatal_errors=panic"); seq_puts(seq, ",fatal_errors=panic");
if (info->commit_interval != BTRFS_DEFAULT_COMMIT_INTERVAL)
seq_printf(seq, ",commit=%d", info->commit_interval);
return 0; return 0;
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment