提交 bbbc34fd 编写于 作者: C Chao Yu 提交者: Jaegeuk Kim

f2fs: clean up bggc mount option

There are three status for background gc: on, off and sync, it's
a little bit confused to use test_opt(BG_GC) and test_opt(FORCE_FG_GC)
combinations to indicate status of background gc.

So let's remove F2FS_MOUNT_BG_GC and F2FS_MOUNT_FORCE_FG_GC mount
options, and add F2FS_OPTION().bggc_mode with below three status
to clean up codes and enhance bggc mode's scalability.

enum {
	BGGC_MODE_ON,		/* background gc is on */
	BGGC_MODE_OFF,		/* background gc is off */
	BGGC_MODE_SYNC,		/*
				 * background gc is on, migrating blocks
				 * like foreground gc
				 */
};
Signed-off-by: NChao Yu <yuchao0@huawei.com>
Signed-off-by: NJaegeuk Kim <jaegeuk@kernel.org>
上级 b0332a0f
...@@ -74,7 +74,6 @@ extern const char *f2fs_fault_name[FAULT_MAX]; ...@@ -74,7 +74,6 @@ extern const char *f2fs_fault_name[FAULT_MAX];
/* /*
* For mount options * For mount options
*/ */
#define F2FS_MOUNT_BG_GC 0x00000001
#define F2FS_MOUNT_DISABLE_ROLL_FORWARD 0x00000002 #define F2FS_MOUNT_DISABLE_ROLL_FORWARD 0x00000002
#define F2FS_MOUNT_DISCARD 0x00000004 #define F2FS_MOUNT_DISCARD 0x00000004
#define F2FS_MOUNT_NOHEAP 0x00000008 #define F2FS_MOUNT_NOHEAP 0x00000008
...@@ -88,7 +87,6 @@ extern const char *f2fs_fault_name[FAULT_MAX]; ...@@ -88,7 +87,6 @@ extern const char *f2fs_fault_name[FAULT_MAX];
#define F2FS_MOUNT_NOBARRIER 0x00000800 #define F2FS_MOUNT_NOBARRIER 0x00000800
#define F2FS_MOUNT_FASTBOOT 0x00001000 #define F2FS_MOUNT_FASTBOOT 0x00001000
#define F2FS_MOUNT_EXTENT_CACHE 0x00002000 #define F2FS_MOUNT_EXTENT_CACHE 0x00002000
#define F2FS_MOUNT_FORCE_FG_GC 0x00004000
#define F2FS_MOUNT_DATA_FLUSH 0x00008000 #define F2FS_MOUNT_DATA_FLUSH 0x00008000
#define F2FS_MOUNT_FAULT_INJECTION 0x00010000 #define F2FS_MOUNT_FAULT_INJECTION 0x00010000
#define F2FS_MOUNT_USRQUOTA 0x00080000 #define F2FS_MOUNT_USRQUOTA 0x00080000
...@@ -138,6 +136,7 @@ struct f2fs_mount_info { ...@@ -138,6 +136,7 @@ struct f2fs_mount_info {
int alloc_mode; /* segment allocation policy */ int alloc_mode; /* segment allocation policy */
int fsync_mode; /* fsync policy */ int fsync_mode; /* fsync policy */
int fs_mode; /* fs mode: LFS or ADAPTIVE */ int fs_mode; /* fs mode: LFS or ADAPTIVE */
int bggc_mode; /* bggc mode: off, on or sync */
bool test_dummy_encryption; /* test dummy encryption */ bool test_dummy_encryption; /* test dummy encryption */
block_t unusable_cap; /* Amount of space allowed to be block_t unusable_cap; /* Amount of space allowed to be
* unusable when disabling checkpoint * unusable when disabling checkpoint
...@@ -1172,6 +1171,15 @@ enum { ...@@ -1172,6 +1171,15 @@ enum {
GC_URGENT, GC_URGENT,
}; };
enum {
BGGC_MODE_ON, /* background gc is on */
BGGC_MODE_OFF, /* background gc is off */
BGGC_MODE_SYNC, /*
* background gc is on, migrating blocks
* like foreground gc
*/
};
enum { enum {
FS_MODE_ADAPTIVE, /* use both lfs/ssr allocation */ FS_MODE_ADAPTIVE, /* use both lfs/ssr allocation */
FS_MODE_LFS, /* use lfs allocation only */ FS_MODE_LFS, /* use lfs allocation only */
......
...@@ -31,6 +31,8 @@ static int gc_thread_func(void *data) ...@@ -31,6 +31,8 @@ static int gc_thread_func(void *data)
set_freezable(); set_freezable();
do { do {
bool sync_mode;
wait_event_interruptible_timeout(*wq, wait_event_interruptible_timeout(*wq,
kthread_should_stop() || freezing(current) || kthread_should_stop() || freezing(current) ||
gc_th->gc_wake, gc_th->gc_wake,
...@@ -101,8 +103,10 @@ static int gc_thread_func(void *data) ...@@ -101,8 +103,10 @@ static int gc_thread_func(void *data)
do_gc: do_gc:
stat_inc_bggc_count(sbi->stat_info); stat_inc_bggc_count(sbi->stat_info);
sync_mode = F2FS_OPTION(sbi).bggc_mode == BGGC_MODE_SYNC;
/* if return value is not zero, no victim was selected */ /* if return value is not zero, no victim was selected */
if (f2fs_gc(sbi, test_opt(sbi, FORCE_FG_GC), true, NULL_SEGNO)) if (f2fs_gc(sbi, sync_mode, true, NULL_SEGNO))
wait_ms = gc_th->no_gc_sleep_time; wait_ms = gc_th->no_gc_sleep_time;
trace_f2fs_background_gc(sbi->sb, wait_ms, trace_f2fs_background_gc(sbi->sb, wait_ms,
......
...@@ -427,14 +427,11 @@ static int parse_options(struct super_block *sb, char *options) ...@@ -427,14 +427,11 @@ static int parse_options(struct super_block *sb, char *options)
if (!name) if (!name)
return -ENOMEM; return -ENOMEM;
if (strlen(name) == 2 && !strncmp(name, "on", 2)) { if (strlen(name) == 2 && !strncmp(name, "on", 2)) {
set_opt(sbi, BG_GC); F2FS_OPTION(sbi).bggc_mode = BGGC_MODE_ON;
clear_opt(sbi, FORCE_FG_GC);
} else if (strlen(name) == 3 && !strncmp(name, "off", 3)) { } else if (strlen(name) == 3 && !strncmp(name, "off", 3)) {
clear_opt(sbi, BG_GC); F2FS_OPTION(sbi).bggc_mode = BGGC_MODE_OFF;
clear_opt(sbi, FORCE_FG_GC);
} else if (strlen(name) == 4 && !strncmp(name, "sync", 4)) { } else if (strlen(name) == 4 && !strncmp(name, "sync", 4)) {
set_opt(sbi, BG_GC); F2FS_OPTION(sbi).bggc_mode = BGGC_MODE_SYNC;
set_opt(sbi, FORCE_FG_GC);
} else { } else {
kvfree(name); kvfree(name);
return -EINVAL; return -EINVAL;
...@@ -1437,14 +1434,13 @@ static int f2fs_show_options(struct seq_file *seq, struct dentry *root) ...@@ -1437,14 +1434,13 @@ static int f2fs_show_options(struct seq_file *seq, struct dentry *root)
{ {
struct f2fs_sb_info *sbi = F2FS_SB(root->d_sb); struct f2fs_sb_info *sbi = F2FS_SB(root->d_sb);
if (!f2fs_readonly(sbi->sb) && test_opt(sbi, BG_GC)) { if (F2FS_OPTION(sbi).bggc_mode == BGGC_MODE_SYNC)
if (test_opt(sbi, FORCE_FG_GC))
seq_printf(seq, ",background_gc=%s", "sync"); seq_printf(seq, ",background_gc=%s", "sync");
else else if (F2FS_OPTION(sbi).bggc_mode == BGGC_MODE_ON)
seq_printf(seq, ",background_gc=%s", "on"); seq_printf(seq, ",background_gc=%s", "on");
} else { else if (F2FS_OPTION(sbi).bggc_mode == BGGC_MODE_OFF)
seq_printf(seq, ",background_gc=%s", "off"); seq_printf(seq, ",background_gc=%s", "off");
}
if (test_opt(sbi, DISABLE_ROLL_FORWARD)) if (test_opt(sbi, DISABLE_ROLL_FORWARD))
seq_puts(seq, ",disable_roll_forward"); seq_puts(seq, ",disable_roll_forward");
if (test_opt(sbi, NORECOVERY)) if (test_opt(sbi, NORECOVERY))
...@@ -1576,8 +1572,8 @@ static void default_options(struct f2fs_sb_info *sbi) ...@@ -1576,8 +1572,8 @@ static void default_options(struct f2fs_sb_info *sbi)
F2FS_OPTION(sbi).compress_algorithm = COMPRESS_LZO; F2FS_OPTION(sbi).compress_algorithm = COMPRESS_LZO;
F2FS_OPTION(sbi).compress_log_size = MIN_COMPRESS_LOG_SIZE; F2FS_OPTION(sbi).compress_log_size = MIN_COMPRESS_LOG_SIZE;
F2FS_OPTION(sbi).compress_ext_cnt = 0; F2FS_OPTION(sbi).compress_ext_cnt = 0;
F2FS_OPTION(sbi).bggc_mode = BGGC_MODE_ON;
set_opt(sbi, BG_GC);
set_opt(sbi, INLINE_XATTR); set_opt(sbi, INLINE_XATTR);
set_opt(sbi, INLINE_DATA); set_opt(sbi, INLINE_DATA);
set_opt(sbi, INLINE_DENTRY); set_opt(sbi, INLINE_DENTRY);
...@@ -1783,7 +1779,8 @@ static int f2fs_remount(struct super_block *sb, int *flags, char *data) ...@@ -1783,7 +1779,8 @@ static int f2fs_remount(struct super_block *sb, int *flags, char *data)
* or if background_gc = off is passed in mount * or if background_gc = off is passed in mount
* option. Also sync the filesystem. * option. Also sync the filesystem.
*/ */
if ((*flags & SB_RDONLY) || !test_opt(sbi, BG_GC)) { if ((*flags & SB_RDONLY) ||
F2FS_OPTION(sbi).bggc_mode == BGGC_MODE_OFF) {
if (sbi->gc_thread) { if (sbi->gc_thread) {
f2fs_stop_gc_thread(sbi); f2fs_stop_gc_thread(sbi);
need_restart_gc = true; need_restart_gc = true;
...@@ -3668,7 +3665,7 @@ static int f2fs_fill_super(struct super_block *sb, void *data, int silent) ...@@ -3668,7 +3665,7 @@ static int f2fs_fill_super(struct super_block *sb, void *data, int silent)
* If filesystem is not mounted as read-only then * If filesystem is not mounted as read-only then
* do start the gc_thread. * do start the gc_thread.
*/ */
if (test_opt(sbi, BG_GC) && !f2fs_readonly(sb)) { if (F2FS_OPTION(sbi).bggc_mode != BGGC_MODE_OFF && !f2fs_readonly(sb)) {
/* After POR, we can run background GC thread.*/ /* After POR, we can run background GC thread.*/
err = f2fs_start_gc_thread(sbi); err = f2fs_start_gc_thread(sbi);
if (err) if (err)
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册