linux-f2fs-devel.lists.sourceforge.net archive mirror
 help / color / mirror / Atom feed
* [PATCH] f2fs: rebuild sit page from sit info in mem
@ 2018-01-24  2:39 Yunlei He
  2018-01-24  7:44 ` heyunlei
  2018-01-24 15:42 ` Chao Yu
  0 siblings, 2 replies; 4+ messages in thread
From: Yunlei He @ 2018-01-24  2:39 UTC (permalink / raw)
  To: jaegeuk, yuchao0, linux-f2fs-devel; +Cc: ning.jia, heyunlei

This patch rebuild sit page from sit info in mem instead
of issue a read io.

Signed-off-by: Yunlei He <heyunlei@huawei.com>
---
 fs/f2fs/segment.c | 53 ++++++++++++++++++++++++-----------------------------
 fs/f2fs/segment.h | 10 ++++++++++
 2 files changed, 34 insertions(+), 29 deletions(-)

diff --git a/fs/f2fs/segment.c b/fs/f2fs/segment.c
index e5739ce..9435261 100644
--- a/fs/f2fs/segment.c
+++ b/fs/f2fs/segment.c
@@ -3109,34 +3109,6 @@ static struct page *get_current_sit_page(struct f2fs_sb_info *sbi,
 	return get_meta_page(sbi, current_sit_addr(sbi, segno));
 }
 
-static struct page *get_next_sit_page(struct f2fs_sb_info *sbi,
-					unsigned int start)
-{
-	struct sit_info *sit_i = SIT_I(sbi);
-	struct page *src_page, *dst_page;
-	pgoff_t src_off, dst_off;
-	void *src_addr, *dst_addr;
-
-	src_off = current_sit_addr(sbi, start);
-	dst_off = next_sit_addr(sbi, src_off);
-
-	/* get current sit block page without lock */
-	src_page = get_meta_page(sbi, src_off);
-	dst_page = grab_meta_page(sbi, dst_off);
-	f2fs_bug_on(sbi, PageDirty(src_page));
-
-	src_addr = page_address(src_page);
-	dst_addr = page_address(dst_page);
-	memcpy(dst_addr, src_addr, PAGE_SIZE);
-
-	set_page_dirty(dst_page);
-	f2fs_put_page(src_page, 1);
-
-	set_to_next_sit(sit_i, start);
-
-	return dst_page;
-}
-
 static struct sit_entry_set *grab_sit_entry_set(void)
 {
 	struct sit_entry_set *ses =
@@ -3261,6 +3233,7 @@ void flush_sit_entries(struct f2fs_sb_info *sbi, struct cp_control *cpc)
 	 */
 	list_for_each_entry_safe(ses, tmp, head, set_list) {
 		struct page *page = NULL;
+		struct address_space *mapping = META_MAPPING(sbi);
 		struct f2fs_sit_block *raw_sit = NULL;
 		unsigned int start_segno = ses->start_segno;
 		unsigned int end = min(start_segno + SIT_ENTRY_PER_BLOCK,
@@ -3274,8 +3247,30 @@ void flush_sit_entries(struct f2fs_sb_info *sbi, struct cp_control *cpc)
 		if (to_journal) {
 			down_write(&curseg->journal_rwsem);
 		} else {
-			page = get_next_sit_page(sbi, start_segno);
+			pgoff_t src_off, dst_off;
+			int i;
+
+			src_off = current_sit_addr(sbi, start_segno);
+			dst_off = next_sit_addr(sbi, src_off);
+			set_to_next_sit(sit_i, start_segno);
+repeat:
+			page = f2fs_grab_cache_page(mapping, dst_off, false);
+			if (!page) {
+				cond_resched();
+				goto repeat;
+			}
+
+			f2fs_wait_on_page_writeback(page, META, true);
+			set_page_dirty(page);
 			raw_sit = page_address(page);
+			if (!PageUptodate(page)) {
+				for (i = 0; i < end - start_segno; i++) {
+					se = get_seg_entry(sbi, start_segno + i);
+					seg_info_to_sit_page(se,
+							&raw_sit->entries[i]);
+				}
+				SetPageUptodate(page);
+			}
 		}
 
 		/* flush dirty sit entries in region of current sit set */
diff --git a/fs/f2fs/segment.h b/fs/f2fs/segment.h
index 1a807e6..e346d90 100644
--- a/fs/f2fs/segment.h
+++ b/fs/f2fs/segment.h
@@ -348,6 +348,16 @@ static inline void seg_info_from_raw_sit(struct seg_entry *se,
 	se->mtime = le64_to_cpu(rs->mtime);
 }
 
+static inline void seg_info_to_sit_page(struct seg_entry *se,
+					struct f2fs_sit_entry *rs)
+{
+	unsigned short raw_vblocks = (se->type << SIT_VBLOCKS_SHIFT) |
+					se->valid_blocks;
+	rs->vblocks = cpu_to_le16(raw_vblocks);
+	memcpy(rs->valid_map, se->cur_valid_map, SIT_VBLOCK_MAP_SIZE);
+	rs->mtime = cpu_to_le64(se->mtime);
+}
+
 static inline void seg_info_to_raw_sit(struct seg_entry *se,
 					struct f2fs_sit_entry *rs)
 {
-- 
1.9.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:[~2018-01-25  7:23 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2018-01-24  2:39 [PATCH] f2fs: rebuild sit page from sit info in mem Yunlei He
2018-01-24  7:44 ` heyunlei
2018-01-25  7:22   ` Chao Yu
2018-01-24 15:42 ` 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).