linux-f2fs-devel.lists.sourceforge.net archive mirror
 help / color / mirror / Atom feed
* [PATCH 1/2] f2fs: fix a missing discard prefree segments
@ 2016-12-16 12:07 Yunlei He
  2016-12-16 12:07 ` [PATCH 2/2] f2fs: add a case of no need to read a page in write begin Yunlei He
  2016-12-19 23:24 ` [PATCH 1/2] f2fs: fix a missing discard prefree segments Jaegeuk Kim
  0 siblings, 2 replies; 4+ messages in thread
From: Yunlei He @ 2016-12-16 12:07 UTC (permalink / raw)
  To: linux-f2fs-devel, jaegeuk, yuchao0; +Cc: heyunlei

If userspace issue a fstrim with a range not involve prefree segments,
it will reuse these segments without discard. This patch fix it.

Signed-off-by: Yunlei He <heyunlei@huawei.com>
---
 fs/f2fs/segment.c | 9 ++++++---
 1 file changed, 6 insertions(+), 3 deletions(-)

diff --git a/fs/f2fs/segment.c b/fs/f2fs/segment.c
index d7d5727..5b4468f 100644
--- a/fs/f2fs/segment.c
+++ b/fs/f2fs/segment.c
@@ -899,6 +899,9 @@ void clear_prefree_segments(struct f2fs_sb_info *sbi, struct cp_control *cpc)
 	unsigned int secno, start_segno;
 	bool force = (cpc->reason == CP_DISCARD);
 
+	if (!test_opt(sbi, DISCARD))
+		return;
+
 	blk_start_plug(&plug);
 
 	mutex_lock(&dirty_i->seglist_lock);
@@ -910,15 +913,15 @@ void clear_prefree_segments(struct f2fs_sb_info *sbi, struct cp_control *cpc)
 			break;
 		end = find_next_zero_bit(prefree_map, MAIN_SEGS(sbi),
 								start + 1);
+		if (force && start * sbi->blocks_per_seg >= cpc->trim_start &&
+					end * sbi->blocks_per_seg <= cpc->trim_end)
+			continue;
 
 		for (i = start; i < end; i++)
 			clear_bit(i, prefree_map);
 
 		dirty_i->nr_dirty[PRE] -= end - start;
 
-		if (force || !test_opt(sbi, DISCARD))
-			continue;
-
 		if (!test_opt(sbi, LFS) || sbi->segs_per_sec == 1) {
 			f2fs_issue_discard(sbi, START_BLOCK(sbi, start),
 				(end - start) << sbi->log_blocks_per_seg);
-- 
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] 4+ messages in thread

end of thread, other threads:[~2016-12-19 23:53 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2016-12-16 12:07 [PATCH 1/2] f2fs: fix a missing discard prefree segments Yunlei He
2016-12-16 12:07 ` [PATCH 2/2] f2fs: add a case of no need to read a page in write begin Yunlei He
2016-12-19 23:52   ` Jaegeuk Kim
2016-12-19 23:24 ` [PATCH 1/2] f2fs: fix a missing discard prefree segments Jaegeuk Kim

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).