Skip to content

Commit 5062b5b

Browse files
Daeho JeongJaegeuk Kim
authored andcommitted
f2fs: make BG GC more aggressive for zoned devices
Since we don't have any GC on device side for zoned devices, need more aggressive BG GC. So, tune the parameters for that. Signed-off-by: Daeho Jeong <[email protected]> Reviewed-by: Chao Yu <[email protected]> Signed-off-by: Jaegeuk Kim <[email protected]>
1 parent 0638a31 commit 5062b5b

File tree

4 files changed

+65
-6
lines changed

4 files changed

+65
-6
lines changed

fs/f2fs/f2fs.h

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2879,13 +2879,26 @@ static inline bool is_inflight_io(struct f2fs_sb_info *sbi, int type)
28792879
return false;
28802880
}
28812881

2882+
static inline bool is_inflight_read_io(struct f2fs_sb_info *sbi)
2883+
{
2884+
return get_pages(sbi, F2FS_RD_DATA) || get_pages(sbi, F2FS_DIO_READ);
2885+
}
2886+
28822887
static inline bool is_idle(struct f2fs_sb_info *sbi, int type)
28832888
{
2889+
bool zoned_gc = (type == GC_TIME &&
2890+
F2FS_HAS_FEATURE(sbi, F2FS_FEATURE_BLKZONED));
2891+
28842892
if (sbi->gc_mode == GC_URGENT_HIGH)
28852893
return true;
28862894

2887-
if (is_inflight_io(sbi, type))
2888-
return false;
2895+
if (zoned_gc) {
2896+
if (is_inflight_read_io(sbi))
2897+
return false;
2898+
} else {
2899+
if (is_inflight_io(sbi, type))
2900+
return false;
2901+
}
28892902

28902903
if (sbi->gc_mode == GC_URGENT_MID)
28912904
return true;
@@ -2894,6 +2907,9 @@ static inline bool is_idle(struct f2fs_sb_info *sbi, int type)
28942907
(type == DISCARD_TIME || type == GC_TIME))
28952908
return true;
28962909

2910+
if (zoned_gc)
2911+
return true;
2912+
28972913
return f2fs_time_over(sbi, type);
28982914
}
28992915

fs/f2fs/gc.c

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,17 @@ static int gc_thread_func(void *data)
116116
goto next;
117117
}
118118

119-
if (has_enough_invalid_blocks(sbi))
119+
if (f2fs_sb_has_blkzoned(sbi)) {
120+
if (has_enough_free_blocks(sbi, LIMIT_NO_ZONED_GC)) {
121+
wait_ms = gc_th->no_gc_sleep_time;
122+
f2fs_up_write(&sbi->gc_lock);
123+
goto next;
124+
}
125+
if (wait_ms == gc_th->no_gc_sleep_time)
126+
wait_ms = gc_th->max_sleep_time;
127+
}
128+
129+
if (need_to_boost_gc(sbi))
120130
decrease_sleep_time(gc_th, &wait_ms);
121131
else
122132
increase_sleep_time(gc_th, &wait_ms);
@@ -179,9 +189,16 @@ int f2fs_start_gc_thread(struct f2fs_sb_info *sbi)
179189
return -ENOMEM;
180190

181191
gc_th->urgent_sleep_time = DEF_GC_THREAD_URGENT_SLEEP_TIME;
182-
gc_th->min_sleep_time = DEF_GC_THREAD_MIN_SLEEP_TIME;
183-
gc_th->max_sleep_time = DEF_GC_THREAD_MAX_SLEEP_TIME;
184-
gc_th->no_gc_sleep_time = DEF_GC_THREAD_NOGC_SLEEP_TIME;
192+
193+
if (f2fs_sb_has_blkzoned(sbi)) {
194+
gc_th->min_sleep_time = DEF_GC_THREAD_MIN_SLEEP_TIME_ZONED;
195+
gc_th->max_sleep_time = DEF_GC_THREAD_MAX_SLEEP_TIME_ZONED;
196+
gc_th->no_gc_sleep_time = DEF_GC_THREAD_NOGC_SLEEP_TIME_ZONED;
197+
} else {
198+
gc_th->min_sleep_time = DEF_GC_THREAD_MIN_SLEEP_TIME;
199+
gc_th->max_sleep_time = DEF_GC_THREAD_MAX_SLEEP_TIME;
200+
gc_th->no_gc_sleep_time = DEF_GC_THREAD_NOGC_SLEEP_TIME;
201+
}
185202

186203
gc_th->gc_wake = false;
187204

fs/f2fs/gc.h

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,11 @@
1515
#define DEF_GC_THREAD_MAX_SLEEP_TIME 60000
1616
#define DEF_GC_THREAD_NOGC_SLEEP_TIME 300000 /* wait 5 min */
1717

18+
/* GC sleep parameters for zoned deivces */
19+
#define DEF_GC_THREAD_MIN_SLEEP_TIME_ZONED 10
20+
#define DEF_GC_THREAD_MAX_SLEEP_TIME_ZONED 20
21+
#define DEF_GC_THREAD_NOGC_SLEEP_TIME_ZONED 60000
22+
1823
/* choose candidates from sections which has age of more than 7 days */
1924
#define DEF_GC_THREAD_AGE_THRESHOLD (60 * 60 * 24 * 7)
2025
#define DEF_GC_THREAD_CANDIDATE_RATIO 20 /* select 20% oldest sections as candidates */
@@ -25,6 +30,9 @@
2530
#define LIMIT_INVALID_BLOCK 40 /* percentage over total user space */
2631
#define LIMIT_FREE_BLOCK 40 /* percentage over invalid + free space */
2732

33+
#define LIMIT_NO_ZONED_GC 60 /* percentage over total user space of no gc for zoned devices */
34+
#define LIMIT_BOOST_ZONED_GC 25 /* percentage over total user space of boosted gc for zoned devices */
35+
2836
#define DEF_GC_FAILED_PINNED_FILES 2048
2937
#define MAX_GC_FAILED_PINNED_FILES USHRT_MAX
3038

@@ -152,6 +160,12 @@ static inline void decrease_sleep_time(struct f2fs_gc_kthread *gc_th,
152160
*wait -= min_time;
153161
}
154162

163+
static inline bool has_enough_free_blocks(struct f2fs_sb_info *sbi,
164+
unsigned int limit_perc)
165+
{
166+
return free_sections(sbi) > ((sbi->total_sections * limit_perc) / 100);
167+
}
168+
155169
static inline bool has_enough_invalid_blocks(struct f2fs_sb_info *sbi)
156170
{
157171
block_t user_block_count = sbi->user_block_count;
@@ -167,3 +181,10 @@ static inline bool has_enough_invalid_blocks(struct f2fs_sb_info *sbi)
167181
free_user_blocks(sbi) <
168182
limit_free_user_blocks(invalid_user_blocks));
169183
}
184+
185+
static inline bool need_to_boost_gc(struct f2fs_sb_info *sbi)
186+
{
187+
if (f2fs_sb_has_blkzoned(sbi))
188+
return !has_enough_free_blocks(sbi, LIMIT_BOOST_ZONED_GC);
189+
return has_enough_invalid_blocks(sbi);
190+
}

fs/f2fs/super.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -706,6 +706,11 @@ static int parse_options(struct super_block *sb, char *options, bool is_remount)
706706
if (!strcmp(name, "on")) {
707707
F2FS_OPTION(sbi).bggc_mode = BGGC_MODE_ON;
708708
} else if (!strcmp(name, "off")) {
709+
if (f2fs_sb_has_blkzoned(sbi)) {
710+
f2fs_warn(sbi, "zoned devices need bggc");
711+
kfree(name);
712+
return -EINVAL;
713+
}
709714
F2FS_OPTION(sbi).bggc_mode = BGGC_MODE_OFF;
710715
} else if (!strcmp(name, "sync")) {
711716
F2FS_OPTION(sbi).bggc_mode = BGGC_MODE_SYNC;

0 commit comments

Comments
 (0)