diff options
author | Jin Xu <jinuxstyle@gmail.com> | 2013-09-05 00:45:26 -0400 |
---|---|---|
committer | Jaegeuk Kim <jaegeuk.kim@samsung.com> | 2013-09-05 00:50:32 -0400 |
commit | a26b7c8a0149ce1e3b6a10f2801aada6e447e4e7 (patch) | |
tree | 763a7a0fac2dee3fdb4b965f68995ba49aac84e0 | |
parent | 423e95ccbe2e2612ed9fe41667acfc338f3af07b (diff) |
f2fs: optimize gc for better performance
This patch improves the gc efficiency by optimizing the victim
selection policy. With this optimization, the random re-write
performance could increase up to 20%.
For f2fs, when disk is in shortage of free spaces, gc will selects
dirty segments and moves valid blocks around for making more space
available. The gc cost of a segment is determined by the valid blocks
in the segment. The less the valid blocks, the higher the efficiency.
The ideal victim segment is the one that has the most garbage blocks.
Currently, it searches up to 20 dirty segments for a victim segment.
The selected victim is not likely the best victim for gc when there
are much more dirty segments. Why not searching more dirty segments
for a better victim? The cost of searching dirty segments is
negligible in comparison to moving blocks.
In this patch, it enlarges the MAX_VICTIM_SEARCH to 4096 to make
the search more aggressively for a possible better victim. Since
it also applies to victim selection for SSR, it will likely improve
the SSR efficiency as well.
The test case is simple. It creates as many files until the disk full.
The size for each file is 32KB. Then it writes as many as 100000
records of 4KB size to random offsets of random files in sync mode.
The testing was done on a 2GB partition of a SDHC card. Let's see the
test result of f2fs without and with the patch.
---------------------------------------
2GB partition, SDHC
create 52023 files of size 32768 bytes
random re-write 100000 records of 4KB
---------------------------------------
| file creation (s) | rewrite time (s) | gc count | gc garbage blocks |
[no patch] 341 4227 1174 174840
[patched] 324 2958 645 106682
It's obvious that, with the patch, f2fs finishes the test in 20+% less
time than without the patch. And internally it does much less gc with
higher efficiency than before.
Since the performance improvement is related to gc, it might not be so
obvious for other tests that do not trigger gc as often as this one (
This is because f2fs selects dirty segments for SSR use most of the
time when free space is in shortage). The well-known iozone test tool
was not used for benchmarking the patch becuase it seems do not have
a test case that performs random re-write on a full disk.
This patch is the revised version based on the suggestion from
Jaegeuk Kim.
Signed-off-by: Jin Xu <jinuxstyle@gmail.com>
[Jaegeuk Kim: suggested simpler solution]
Reviewed-by: Jaegeuk Kim <jaegeuk.kim@samsung.com>
Signed-off-by: Jaegeuk Kim <jaegeuk.kim@samsung.com>
-rw-r--r-- | fs/f2fs/gc.c | 8 | ||||
-rw-r--r-- | fs/f2fs/gc.h | 2 | ||||
-rw-r--r-- | fs/f2fs/segment.h | 1 |
3 files changed, 9 insertions, 2 deletions
diff --git a/fs/f2fs/gc.c b/fs/f2fs/gc.c index eb89037e3312..2f157e883687 100644 --- a/fs/f2fs/gc.c +++ b/fs/f2fs/gc.c | |||
@@ -153,12 +153,18 @@ static void select_policy(struct f2fs_sb_info *sbi, int gc_type, | |||
153 | if (p->alloc_mode == SSR) { | 153 | if (p->alloc_mode == SSR) { |
154 | p->gc_mode = GC_GREEDY; | 154 | p->gc_mode = GC_GREEDY; |
155 | p->dirty_segmap = dirty_i->dirty_segmap[type]; | 155 | p->dirty_segmap = dirty_i->dirty_segmap[type]; |
156 | p->max_search = dirty_i->nr_dirty[type]; | ||
156 | p->ofs_unit = 1; | 157 | p->ofs_unit = 1; |
157 | } else { | 158 | } else { |
158 | p->gc_mode = select_gc_type(sbi->gc_thread, gc_type); | 159 | p->gc_mode = select_gc_type(sbi->gc_thread, gc_type); |
159 | p->dirty_segmap = dirty_i->dirty_segmap[DIRTY]; | 160 | p->dirty_segmap = dirty_i->dirty_segmap[DIRTY]; |
161 | p->max_search = dirty_i->nr_dirty[DIRTY]; | ||
160 | p->ofs_unit = sbi->segs_per_sec; | 162 | p->ofs_unit = sbi->segs_per_sec; |
161 | } | 163 | } |
164 | |||
165 | if (p->max_search > MAX_VICTIM_SEARCH) | ||
166 | p->max_search = MAX_VICTIM_SEARCH; | ||
167 | |||
162 | p->offset = sbi->last_victim[p->gc_mode]; | 168 | p->offset = sbi->last_victim[p->gc_mode]; |
163 | } | 169 | } |
164 | 170 | ||
@@ -305,7 +311,7 @@ static int get_victim_by_default(struct f2fs_sb_info *sbi, | |||
305 | if (cost == max_cost) | 311 | if (cost == max_cost) |
306 | continue; | 312 | continue; |
307 | 313 | ||
308 | if (nsearched++ >= MAX_VICTIM_SEARCH) { | 314 | if (nsearched++ >= p.max_search) { |
309 | sbi->last_victim[p.gc_mode] = segno; | 315 | sbi->last_victim[p.gc_mode] = segno; |
310 | break; | 316 | break; |
311 | } | 317 | } |
diff --git a/fs/f2fs/gc.h b/fs/f2fs/gc.h index c22dee9f1422..507056d22205 100644 --- a/fs/f2fs/gc.h +++ b/fs/f2fs/gc.h | |||
@@ -20,7 +20,7 @@ | |||
20 | #define LIMIT_FREE_BLOCK 40 /* percentage over invalid + free space */ | 20 | #define LIMIT_FREE_BLOCK 40 /* percentage over invalid + free space */ |
21 | 21 | ||
22 | /* Search max. number of dirty segments to select a victim segment */ | 22 | /* Search max. number of dirty segments to select a victim segment */ |
23 | #define MAX_VICTIM_SEARCH 20 | 23 | #define MAX_VICTIM_SEARCH 4096 /* covers 8GB */ |
24 | 24 | ||
25 | struct f2fs_gc_kthread { | 25 | struct f2fs_gc_kthread { |
26 | struct task_struct *f2fs_gc_task; | 26 | struct task_struct *f2fs_gc_task; |
diff --git a/fs/f2fs/segment.h b/fs/f2fs/segment.h index e0d6d3abf396..bdd10eab8c40 100644 --- a/fs/f2fs/segment.h +++ b/fs/f2fs/segment.h | |||
@@ -142,6 +142,7 @@ struct victim_sel_policy { | |||
142 | int alloc_mode; /* LFS or SSR */ | 142 | int alloc_mode; /* LFS or SSR */ |
143 | int gc_mode; /* GC_CB or GC_GREEDY */ | 143 | int gc_mode; /* GC_CB or GC_GREEDY */ |
144 | unsigned long *dirty_segmap; /* dirty segment bitmap */ | 144 | unsigned long *dirty_segmap; /* dirty segment bitmap */ |
145 | unsigned int max_search; /* maximum # of segments to search */ | ||
145 | unsigned int offset; /* last scanned bitmap offset */ | 146 | unsigned int offset; /* last scanned bitmap offset */ |
146 | unsigned int ofs_unit; /* bitmap search unit */ | 147 | unsigned int ofs_unit; /* bitmap search unit */ |
147 | unsigned int min_cost; /* minimum cost */ | 148 | unsigned int min_cost; /* minimum cost */ |