diff options
author | Jaegeuk Kim <jaegeuk.kim@samsung.com> | 2013-10-24 00:31:34 -0400 |
---|---|---|
committer | Jaegeuk Kim <jaegeuk.kim@samsung.com> | 2013-10-25 03:54:37 -0400 |
commit | 81eb8d6e2869b119d4a7b8c02091c3779733a3ac (patch) | |
tree | cdff776596fa79bfc9c2f2baf7aa59470dc29aec /fs/f2fs | |
parent | aabe51364f44681cbd83fb1c27ef7d3dbe567c45 (diff) |
f2fs: reclaim prefree segments periodically
Previously, f2fs postpones reclaiming prefree segments into free segments
as much as possible.
However, if user writes and deletes a bunch of data without any sync or fsync
calls, some flash storages can suffer from garbage collections.
So, this patch adds the reclaiming codes to f2fs_write_node_pages and background
GC thread.
If there are a lot of prefree segments, let's do checkpoint so that f2fs
submits discard commands for the prefree regions to the flash storage.
Signed-off-by: Changman Lee <cm224.lee@samsung.com>
Signed-off-by: Jaegeuk Kim <jaegeuk.kim@samsung.com>
Diffstat (limited to 'fs/f2fs')
-rw-r--r-- | fs/f2fs/f2fs.h | 3 | ||||
-rw-r--r-- | fs/f2fs/gc.c | 5 | ||||
-rw-r--r-- | fs/f2fs/node.c | 3 | ||||
-rw-r--r-- | fs/f2fs/segment.c | 1 | ||||
-rw-r--r-- | fs/f2fs/segment.h | 7 |
5 files changed, 18 insertions, 1 deletions
diff --git a/fs/f2fs/f2fs.h b/fs/f2fs/f2fs.h index e8f3fd345ca3..6dff777cd94a 100644 --- a/fs/f2fs/f2fs.h +++ b/fs/f2fs/f2fs.h | |||
@@ -299,6 +299,9 @@ struct f2fs_sm_info { | |||
299 | unsigned int main_segments; /* # of segments in main area */ | 299 | unsigned int main_segments; /* # of segments in main area */ |
300 | unsigned int reserved_segments; /* # of reserved segments */ | 300 | unsigned int reserved_segments; /* # of reserved segments */ |
301 | unsigned int ovp_segments; /* # of overprovision segments */ | 301 | unsigned int ovp_segments; /* # of overprovision segments */ |
302 | |||
303 | /* a threshold to reclaim prefree segments */ | ||
304 | unsigned int rec_prefree_segments; | ||
302 | }; | 305 | }; |
303 | 306 | ||
304 | /* | 307 | /* |
diff --git a/fs/f2fs/gc.c b/fs/f2fs/gc.c index cb286d7b02b2..783c6cc6253c 100644 --- a/fs/f2fs/gc.c +++ b/fs/f2fs/gc.c | |||
@@ -82,6 +82,11 @@ static int gc_thread_func(void *data) | |||
82 | /* if return value is not zero, no victim was selected */ | 82 | /* if return value is not zero, no victim was selected */ |
83 | if (f2fs_gc(sbi)) | 83 | if (f2fs_gc(sbi)) |
84 | wait_ms = gc_th->no_gc_sleep_time; | 84 | wait_ms = gc_th->no_gc_sleep_time; |
85 | |||
86 | /* balancing prefree segments */ | ||
87 | if (excess_prefree_segs(sbi)) | ||
88 | f2fs_sync_fs(sbi->sb, true); | ||
89 | |||
85 | } while (!kthread_should_stop()); | 90 | } while (!kthread_should_stop()); |
86 | return 0; | 91 | return 0; |
87 | } | 92 | } |
diff --git a/fs/f2fs/node.c b/fs/f2fs/node.c index cc119b65a0d3..89dd8a5a3ca3 100644 --- a/fs/f2fs/node.c +++ b/fs/f2fs/node.c | |||
@@ -1206,7 +1206,8 @@ static int f2fs_write_node_pages(struct address_space *mapping, | |||
1206 | long nr_to_write = wbc->nr_to_write; | 1206 | long nr_to_write = wbc->nr_to_write; |
1207 | 1207 | ||
1208 | /* First check balancing cached NAT entries */ | 1208 | /* First check balancing cached NAT entries */ |
1209 | if (try_to_free_nats(sbi, NAT_ENTRY_PER_BLOCK)) { | 1209 | if (try_to_free_nats(sbi, NAT_ENTRY_PER_BLOCK) || |
1210 | excess_prefree_segs(sbi)) { | ||
1210 | f2fs_sync_fs(sbi->sb, true); | 1211 | f2fs_sync_fs(sbi->sb, true); |
1211 | return 0; | 1212 | return 0; |
1212 | } | 1213 | } |
diff --git a/fs/f2fs/segment.c b/fs/f2fs/segment.c index 177a33b16b2c..62b52f2f293a 100644 --- a/fs/f2fs/segment.c +++ b/fs/f2fs/segment.c | |||
@@ -1645,6 +1645,7 @@ int build_segment_manager(struct f2fs_sb_info *sbi) | |||
1645 | sm_info->ovp_segments = le32_to_cpu(ckpt->overprov_segment_count); | 1645 | sm_info->ovp_segments = le32_to_cpu(ckpt->overprov_segment_count); |
1646 | sm_info->main_segments = le32_to_cpu(raw_super->segment_count_main); | 1646 | sm_info->main_segments = le32_to_cpu(raw_super->segment_count_main); |
1647 | sm_info->ssa_blkaddr = le32_to_cpu(raw_super->ssa_blkaddr); | 1647 | sm_info->ssa_blkaddr = le32_to_cpu(raw_super->ssa_blkaddr); |
1648 | sm_info->rec_prefree_segments = DEF_RECLAIM_PREFREE_SEGMENTS; | ||
1648 | 1649 | ||
1649 | err = build_sit_info(sbi); | 1650 | err = build_sit_info(sbi); |
1650 | if (err) | 1651 | if (err) |
diff --git a/fs/f2fs/segment.h b/fs/f2fs/segment.h index 7f94d78cda3d..abe7094c4f7a 100644 --- a/fs/f2fs/segment.h +++ b/fs/f2fs/segment.h | |||
@@ -14,6 +14,8 @@ | |||
14 | #define NULL_SEGNO ((unsigned int)(~0)) | 14 | #define NULL_SEGNO ((unsigned int)(~0)) |
15 | #define NULL_SECNO ((unsigned int)(~0)) | 15 | #define NULL_SECNO ((unsigned int)(~0)) |
16 | 16 | ||
17 | #define DEF_RECLAIM_PREFREE_SEGMENTS 100 /* 200MB of prefree segments */ | ||
18 | |||
17 | /* L: Logical segment # in volume, R: Relative segment # in main area */ | 19 | /* L: Logical segment # in volume, R: Relative segment # in main area */ |
18 | #define GET_L2R_SEGNO(free_i, segno) (segno - free_i->start_segno) | 20 | #define GET_L2R_SEGNO(free_i, segno) (segno - free_i->start_segno) |
19 | #define GET_R2L_SEGNO(free_i, segno) (segno + free_i->start_segno) | 21 | #define GET_R2L_SEGNO(free_i, segno) (segno + free_i->start_segno) |
@@ -472,6 +474,11 @@ static inline bool has_not_enough_free_secs(struct f2fs_sb_info *sbi, int freed) | |||
472 | reserved_sections(sbi))); | 474 | reserved_sections(sbi))); |
473 | } | 475 | } |
474 | 476 | ||
477 | static inline bool excess_prefree_segs(struct f2fs_sb_info *sbi) | ||
478 | { | ||
479 | return (prefree_segments(sbi) > SM_I(sbi)->rec_prefree_segments); | ||
480 | } | ||
481 | |||
475 | static inline int utilization(struct f2fs_sb_info *sbi) | 482 | static inline int utilization(struct f2fs_sb_info *sbi) |
476 | { | 483 | { |
477 | return div_u64((u64)valid_user_blocks(sbi) * 100, sbi->user_block_count); | 484 | return div_u64((u64)valid_user_blocks(sbi) * 100, sbi->user_block_count); |