linux-f2fs-devel.lists.sourceforge.net archive mirror
 help / color / mirror / Atom feed
* [RFC] add ovp valid_blocks check for bg gc victim to fg_gc
@ 2017-02-16 12:34 Hou Pengyang
  2017-02-16 23:48 ` Jaegeuk Kim
  0 siblings, 1 reply; 7+ messages in thread
From: Hou Pengyang @ 2017-02-16 12:34 UTC (permalink / raw)
  To: jaegeuk, yuchao0; +Cc: linux-f2fs-devel

For foreground gc, greedy algorithm should be adapted, which makes
this formula work well:

	(2 * (100 / config.overprovision + 1) + 6)

But currently, we fg_gc have a prior to select bg_gc victim segments to gc first,
these victims are selected by cost-benefit algorithm, we can't guarantee such segments
have the small valid blocks, which may destroy the f2fs rule, on the worstest case, would 
consume all the free segments.

This patch fix this by add a filter in check_bg_victims, if segment's has # of valid blocks
over overprovision ratio, skip such segments.

Signed-off-by: Hou Pengyang <houpengyang@huawei.com>
---
 fs/f2fs/f2fs.h    |  1 +
 fs/f2fs/gc.c      |  4 ++++
 fs/f2fs/segment.h | 12 ++++++++++++
 fs/f2fs/super.c   | 10 ++++++++++
 4 files changed, 27 insertions(+)

diff --git a/fs/f2fs/f2fs.h b/fs/f2fs/f2fs.h
index c9a97c3..0afe94f 100644
--- a/fs/f2fs/f2fs.h
+++ b/fs/f2fs/f2fs.h
@@ -881,6 +881,7 @@ struct f2fs_sb_info {
 	struct mutex gc_mutex;			/* mutex for GC */
 	struct f2fs_gc_kthread	*gc_thread;	/* GC thread */
 	unsigned int cur_victim_sec;		/* current victim section num */
+	unsigned int fggc_threshold;	/* threshold for converting bg victims for fg */
 
 	/* maximum # of trials to find a victim segment for SSR and GC */
 	unsigned int max_victim_search;
diff --git a/fs/f2fs/gc.c b/fs/f2fs/gc.c
index 88e5e7b..18f3efa 100644
--- a/fs/f2fs/gc.c
+++ b/fs/f2fs/gc.c
@@ -199,6 +199,10 @@ static unsigned int check_bg_victims(struct f2fs_sb_info *sbi)
 	for_each_set_bit(secno, dirty_i->victim_secmap, MAIN_SECS(sbi)) {
 		if (sec_usage_check(sbi, secno))
 			continue;
+
+		if (valid_blocks_ovp_check(sbi, secno))
+			continue;
+
 		clear_bit(secno, dirty_i->victim_secmap);
 		return secno * sbi->segs_per_sec;
 	}
diff --git a/fs/f2fs/segment.h b/fs/f2fs/segment.h
index 5cb5755..2a6a1a9 100644
--- a/fs/f2fs/segment.h
+++ b/fs/f2fs/segment.h
@@ -716,6 +716,18 @@ static inline block_t sum_blk_addr(struct f2fs_sb_info *sbi, int base, int type)
 				- (base + 1) + type;
 }
 
+static inline bool valid_blocks_ovp_check(struct f2fs_sb_info *sbi, unsigned int secno)
+{
+	struct sit_info *sit_i = SIT_I(sbi);
+	unsigned int valid_blocks;
+
+	valid_blocks = sit_i->sec_entries[secno].valid_blocks;
+	if (valid_blocks >= sbi->fggc_threshold)
+		return true;
+	return false;
+
+}
+
 static inline bool sec_usage_check(struct f2fs_sb_info *sbi, unsigned int secno)
 {
 	if (IS_CURSEC(sbi, secno) || (sbi->cur_victim_sec == secno))
diff --git a/fs/f2fs/super.c b/fs/f2fs/super.c
index 68a555b..54c4dac 100644
--- a/fs/f2fs/super.c
+++ b/fs/f2fs/super.c
@@ -2090,6 +2090,16 @@ static int f2fs_fill_super(struct super_block *sb, void *data, int silent)
 		if (err)
 			goto free_kobj;
 	}
+
+	sbi->fggc_threshold = (le32_to_cpu(sbi->ckpt->overprov_segment_count) -
+					le32_to_cpu(sbi->ckpt->rsvd_segment_count)) * 100 /
+					(le32_to_cpu(sbi->raw_super->segment_count_main) -
+					le32_to_cpu(sbi->ckpt->rsvd_segment_count)) *
+					sbi->blocks_per_seg * sbi->segs_per_sec / 100;
+
+	sbi->fggc_threshold = sbi->blocks_per_seg * sbi->segs_per_sec -
+					sbi->fggc_threshold;
+
 	kfree(options);
 
 	/* recover broken superblock */
-- 
2.10.1


------------------------------------------------------------------------------
Check out the vibrant tech community on one of the world's most
engaging tech sites, SlashDot.org! http://sdm.link/slashdot

^ permalink raw reply related	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2017-02-23 12:35 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2017-02-16 12:34 [RFC] add ovp valid_blocks check for bg gc victim to fg_gc Hou Pengyang
2017-02-16 23:48 ` Jaegeuk Kim
2017-02-17  2:33   ` Hou Pengyang
2017-02-17  2:54     ` Jaegeuk Kim
2017-02-17  5:09       ` Hou Pengyang
2017-02-17 20:17         ` Jaegeuk Kim
2017-02-23 12:35           ` Chao Yu

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).