UPSTREAM: f2fs: sysfs: support gc_io_aware
PATCH 1/1 UPSTREAM: f2fs: sysfs: support gc_io_aware
From: liujinbao1 <[email protected]>
Currently, IO can only be ignored when GC_URGENT_HIGH is set,
and the default algorithm used for GC_URGENT_HIGH is greedy.
It gives a way to enable/disable IO aware feature for background gc, so that we can tune background gc more precisely. e.g. force to disable IO aware and choose more suitable algorithm if there are large number of dirty segments.
--- Documentation/ABI/testing/sysfs-fs-f2fs | 6 ++++++ fs/f2fs/f2fs.h | 6 ++++++ fs/f2fs/gc.c | 3 ++- fs/f2fs/gc.h | 1 + fs/f2fs/sysfs.c | 9 +++++++++ 5 files changed, 24 insertions(+), 1 deletion(-)
Documentation/ABI/testing/sysfs-fs-f2fs +6 -0
@@ -16,6 +16,12 @@ Contact: "Namjae Jeon" <[email protected]> Description: Controls the default sleep time for gc_thread. Time is in milliseconds. +What: /sys/fs/f2fs/<disk>/gc_io_aware +Date: January 2024 +Contact: "Jinbao Liu" <[email protected]> +Description: It controls to enable/disable IO aware feature for background gc. ++ By default, the value is 1 which indicates IO aware is on. + What: /sys/fs/f2fs/<disk>/gc_idle Date: July 2013 Contact: "Namjae Jeon" <[email protected]>
fs/f2fs/f2fs.h +6 -0
@@ -374,6 +374,12 @@ enum { MAX_DPOLICY, }; +enum { +GC_IO_AWARE_DISABLE ,/* force to not be aware of IO */ +GC_IO_AWARE_ENABLE ,/* force to be aware of IO */ +GC_IO_AWARE_MAX , +}; +struct discard_policy {int type;/* type of discard */ unsigned int min_interval;/* used for candidates exist */
fs/f2fs/gc.c +2 -1
@@ -109,7 +109,7 @@ static int gc_thread_func(void *data) goto next; } -if (!is_idle (sbi,GC_TIME )) { +if (gc_th->io_aware && !is_idle (sbi,GC_TIME )) {increase_sleep_time (gc_th, &wait_ms);f2fs_up_write (&sbi->gc_lock);stat_io_skip_bggc_count (sbi);
@@ -182,6 +182,7 @@ int f2fs_start_gc_thread(struct f2fs_sb_info *sbi) gc_th->min_sleep_time =DEF_GC_THREAD_MIN_SLEEP_TIME ; gc_th->max_sleep_time =DEF_GC_THREAD_MAX_SLEEP_TIME ; gc_th->no_gc_sleep_time =DEF_GC_THREAD_NOGC_SLEEP_TIME ; + gc_th->io_aware =GC_IO_AWARE_ENABLE ; gc_th->gc_wake = false;
fs/f2fs/gc.h +1 -0
@@ -41,6 +41,7 @@ struct f2fs_gc_kthread {unsigned int min_sleep_time;unsigned int max_sleep_time;unsigned int no_gc_sleep_time; +bool io_aware;/* for changing gc mode */ bool gc_wake;
fs/f2fs/sysfs.c +9 -0
@@ -516,6 +516,13 @@ static ssize_t __sbi_store(struct f2fs_attr *a,return count; } +if (!strcmp (a->attr.name,"gc_io_aware" )) { +if (t >=GC_IO_AWARE_MAX ) +return -EINVAL ; + *ui = t; +return count; + } +if (!strcmp (a->attr.name,"migration_granularity" )) {if (t ==0 || t > sbi->segs_per_sec)return -EINVAL ;
@@ -906,6 +913,7 @@ GC_THREAD_RW_ATTR(gc_urgent_sleep_time, urgent_sleep_time);GC_THREAD_RW_ATTR (gc_min_sleep_time, min_sleep_time);GC_THREAD_RW_ATTR (gc_max_sleep_time, max_sleep_time);GC_THREAD_RW_ATTR (gc_no_gc_sleep_time, no_gc_sleep_time); +GC_THREAD_RW_ATTR (gc_io_aware, io_aware);/* SM_INFO ATTR */ SM_INFO_RW_ATTR (reclaim_segments, rec_prefree_segments);
@@ -1061,6 +1069,7 @@ static struct attribute *f2fs_attrs[] = {ATTR_LIST (gc_min_sleep_time),ATTR_LIST (gc_max_sleep_time),ATTR_LIST (gc_no_gc_sleep_time), +ATTR_LIST (gc_io_aware),ATTR_LIST (gc_idle),ATTR_LIST (gc_urgent), ATTR_LIST(reclaim_segments),
Signature · 1 line
2.39.0
Chao Yu
maintainerQuoted 10 lines · On 2024/1/30 20:51, liujinbao1 wrote:
From: liujinbao1 <[email protected]>
Currently, IO can only be ignored when
GC_URGENT_HIGHis set,
and the default algorithm used forGC_URGENT_HIGHis greedy.
It gives a way to enable/disable IO aware feature for background gc, so that we can tune background gc more precisely. e.g. force to disable IO aware and choose more suitable algorithm if there are large number of dirty segments.Change-Id: Ic0ea1bf8fb6602f0dd88b924088f1c1b33fcd809
Should remove Change-Id line.
Quoted 31 lines
Signed-off-by liujinbao1 <[email protected]>--- Documentation/ABI/testing/sysfs-fs-f2fs | 6 ++++++ fs/f2fs/f2fs.h | 6 ++++++ fs/f2fs/gc.c | 3 ++- fs/f2fs/gc.h | 1 + fs/f2fs/sysfs.c | 9 +++++++++ 5 files changed, 24 insertions(+), 1 deletion(-)Documentation/ABI/testing/sysfs-fs-f2fs +6
-0@@ -16,6 +16,12 @@ Contact: "Namjae Jeon" <[email protected]> Description: Controls the default sleep time for gc_thread. Time is in milliseconds. +What: /sys/fs/f2fs/<disk>/gc_io_aware +Date: January 2024 +Contact: "Jinbao Liu" <[email protected]> +Description: It controls to enable/disable IO aware feature for background gc. ++ By default, the value is 1 which indicates IO aware is on. + What: /sys/fs/f2fs/<disk>/gc_idle Date: July 2013 Contact: "Namjae Jeon" <[email protected]>fs/f2fs/f2fs.h +0
-0
fs/f2fs/f2fs.h enum { · line 381
Quoted 8 lines
fs/f2fs/f2fs.h +5
-0@@ -374,6 +374,12 @@ enum { MAX_DPOLICY, }; +enum { +GC_IO_AWARE_DISABLE ,/* force to not be aware of IO */ +GC_IO_AWARE_ENABLE ,/* force to be aware of IO */ +GC_IO_AWARE_MAX , +};
Not needed.
Quoted 18 lines
fs/f2fs/f2fs.h +1
-0+struct discard_policy {int type;/* type of discard */ unsigned int min_interval;/* used for candidates exist */ fs/f2fs/gc.c +1
-1@@ -109,7 +109,7 @@ static int gc_thread_func(void *data) goto next; } -if (!is_idle (sbi,GC_TIME )) { +if (gc_th->io_aware && !is_idle (sbi,GC_TIME )) {increase_sleep_time (gc_th, &wait_ms);f2fs_up_write (&sbi->gc_lock);stat_io_skip_bggc_count (sbi);
fs/f2fs/gc.c int f2fs_start_gc_thread(struct f2fs_sb_info *sbi) · line 185
Quoted 4 lines
fs/f2fs/gc.c +1
-0@@ -182,6 +182,7 @@ int f2fs_start_gc_thread(struct f2fs_sb_info *sbi) gc_th->min_sleep_time =DEF_GC_THREAD_MIN_SLEEP_TIME ; gc_th->max_sleep_time =DEF_GC_THREAD_MAX_SLEEP_TIME ; gc_th->no_gc_sleep_time =DEF_GC_THREAD_NOGC_SLEEP_TIME ; + gc_th->io_aware =GC_IO_AWARE_ENABLE ;
gc_th->io_aware = true;
Quoted 20 lines
fs/f2fs/gc.c +0
-0gc_th->gc_wake = false;fs/f2fs/gc.h +1
-0@@ -41,6 +41,7 @@ struct f2fs_gc_kthread {unsigned int min_sleep_time;unsigned int max_sleep_time;unsigned int no_gc_sleep_time; +bool io_aware;/* for changing gc mode */ bool gc_wake;fs/f2fs/sysfs.c +0
-0
fs/f2fs/sysfs.c static ssize_t __sbi_store(struct f2fs_attr *a, · line 520
Quoted 5 lines
fs/f2fs/sysfs.c +2
-0@@ -516,6 +516,13 @@ static ssize_t __sbi_store(struct f2fs_attr *a,return count; } +if (!strcmp (a->attr.name,"gc_io_aware" )) { +if (t >=GC_IO_AWARE_MAX )
if (t > 1)
fs/f2fs/sysfs.c static ssize_t __sbi_store(struct f2fs_attr *a, · line 522
Quoted 2 lines
fs/f2fs/sysfs.c +2
-0+return -EINVAL ; + *ui = t;
*ui = t ? true : false;
Thanks,
Quoted 22 lines
fs/f2fs/sysfs.c +5
-0+return count; + } +if (!strcmp (a->attr.name,"migration_granularity" )) {if (t ==0 || t > sbi->segs_per_sec)return -EINVAL ;@@ -906,6 +913,7 @@ GC_THREAD_RW_ATTR(gc_urgent_sleep_time, urgent_sleep_time);GC_THREAD_RW_ATTR (gc_min_sleep_time, min_sleep_time);GC_THREAD_RW_ATTR (gc_max_sleep_time, max_sleep_time);GC_THREAD_RW_ATTR (gc_no_gc_sleep_time, no_gc_sleep_time); +GC_THREAD_RW_ATTR (gc_io_aware, io_aware);/* SM_INFO ATTR */ SM_INFO_RW_ATTR (reclaim_segments, rec_prefree_segments);@@ -1061,6 +1069,7 @@ static struct attribute *f2fs_attrs[] = {ATTR_LIST (gc_min_sleep_time),ATTR_LIST (gc_max_sleep_time),ATTR_LIST (gc_no_gc_sleep_time), +ATTR_LIST (gc_io_aware),ATTR_LIST (gc_idle),ATTR_LIST (gc_urgent), ATTR_LIST(reclaim_segments),