aboutsummaryrefslogtreecommitdiffstats
path: root/fs/f2fs
diff options
context:
space:
mode:
Diffstat (limited to 'fs/f2fs')
-rw-r--r--fs/f2fs/segment.c36
-rw-r--r--fs/f2fs/segment.h15
2 files changed, 16 insertions, 35 deletions
diff --git a/fs/f2fs/segment.c b/fs/f2fs/segment.c
index fe2cc0bdc115..66f5e82ec324 100644
--- a/fs/f2fs/segment.c
+++ b/fs/f2fs/segment.c
@@ -19,48 +19,16 @@
19#include "segment.h" 19#include "segment.h"
20#include "node.h" 20#include "node.h"
21 21
22static int need_to_flush(struct f2fs_sb_info *sbi)
23{
24 unsigned int pages_per_sec = (1 << sbi->log_blocks_per_seg) *
25 sbi->segs_per_sec;
26 int node_secs = ((get_pages(sbi, F2FS_DIRTY_NODES) + pages_per_sec - 1)
27 >> sbi->log_blocks_per_seg) / sbi->segs_per_sec;
28 int dent_secs = ((get_pages(sbi, F2FS_DIRTY_DENTS) + pages_per_sec - 1)
29 >> sbi->log_blocks_per_seg) / sbi->segs_per_sec;
30
31 if (sbi->por_doing)
32 return 0;
33
34 if (free_sections(sbi) <= (node_secs + 2 * dent_secs +
35 reserved_sections(sbi)))
36 return 1;
37 return 0;
38}
39
40/* 22/*
41 * This function balances dirty node and dentry pages. 23 * This function balances dirty node and dentry pages.
42 * In addition, it controls garbage collection. 24 * In addition, it controls garbage collection.
43 */ 25 */
44void f2fs_balance_fs(struct f2fs_sb_info *sbi) 26void f2fs_balance_fs(struct f2fs_sb_info *sbi)
45{ 27{
46 struct writeback_control wbc = {
47 .sync_mode = WB_SYNC_ALL,
48 .nr_to_write = LONG_MAX,
49 .for_reclaim = 0,
50 };
51
52 if (sbi->por_doing)
53 return;
54
55 /* 28 /*
56 * We should do checkpoint when there are so many dirty node pages 29 * We should do GC or end up with checkpoint, if there are so many dirty
57 * with enough free segments. After then, we should do GC. 30 * dir/node pages without enough free segments.
58 */ 31 */
59 if (need_to_flush(sbi)) {
60 sync_dirty_dir_inodes(sbi);
61 sync_node_pages(sbi, 0, &wbc);
62 }
63
64 if (has_not_enough_free_secs(sbi)) { 32 if (has_not_enough_free_secs(sbi)) {
65 mutex_lock(&sbi->gc_mutex); 33 mutex_lock(&sbi->gc_mutex);
66 f2fs_gc(sbi, 1); 34 f2fs_gc(sbi, 1);
diff --git a/fs/f2fs/segment.h b/fs/f2fs/segment.h
index 0948405af6f5..66a288a52fd3 100644
--- a/fs/f2fs/segment.h
+++ b/fs/f2fs/segment.h
@@ -459,7 +459,20 @@ static inline int get_ssr_segment(struct f2fs_sb_info *sbi, int type)
459 459
460static inline bool has_not_enough_free_secs(struct f2fs_sb_info *sbi) 460static inline bool has_not_enough_free_secs(struct f2fs_sb_info *sbi)
461{ 461{
462 return free_sections(sbi) <= reserved_sections(sbi); 462 unsigned int pages_per_sec = (1 << sbi->log_blocks_per_seg) *
463 sbi->segs_per_sec;
464 int node_secs = ((get_pages(sbi, F2FS_DIRTY_NODES) + pages_per_sec - 1)
465 >> sbi->log_blocks_per_seg) / sbi->segs_per_sec;
466 int dent_secs = ((get_pages(sbi, F2FS_DIRTY_DENTS) + pages_per_sec - 1)
467 >> sbi->log_blocks_per_seg) / sbi->segs_per_sec;
468
469 if (sbi->por_doing)
470 return false;
471
472 if (free_sections(sbi) <= (node_secs + 2 * dent_secs +
473 reserved_sections(sbi)))
474 return true;
475 return false;
463} 476}
464 477
465static inline int utilization(struct f2fs_sb_info *sbi) 478static inline int utilization(struct f2fs_sb_info *sbi)