Skip to contentSkip to conversation

f2fs: introduce a method to make nat journal more fresh

PATCH In review Yunlei He 4 participants 4 messages Apr 10, 2018 – Apr 14, 2018 F2FS file system

lore
Share & tools
lore

Yunlei He

author
#0 lore raw

PATCH v5 1/1 f2fs: introduce a method to make nat journal more fresh

This patch introduce a method to make nat journal more fresh:
i. sort set list using dirty entry number and cp version
average value.
ii. if meet with cache hit, update average version valus with
current cp version.

With this patch, newly modified nat set will flush to journal, and flush old nat set with same dirty entry number to nat area.

---
 fs/f2fs/node.c | 38 +++++++++++++++++++++++---------------
 fs/f2fs/node.h |  4 +++-
 2 files changed, 26 insertions(+), 16 deletions(-)
fs/f2fs/node.c +23 -15
index 9a99243..88ba4c2 100644
@@ -207,13 +207,14 @@ static struct nat_entry_set *__grab_nat_entry_set(struct f2fs_nm_info *nm_i,
 		INIT_LIST_HEAD(&head->set_list);
 		head->set = set;
 		head->entry_cnt = 0;
+		head->cp_ver = 0;
 		f2fs_radix_tree_insert(&nm_i->nat_set_root, set, head);
 	}
 	return head;
 }
 
-static void __set_nat_cache_dirty(struct f2fs_nm_info *nm_i,
-						struct nat_entry *ne)
+static void __set_nat_cache_dirty(struct f2fs_sb_info *sbi, bool remove_journal,
+			struct f2fs_nm_info *nm_i, struct nat_entry *ne)
 {
 	struct nat_entry_set *head;
 	bool new_ne = nat_get_blkaddr(ne) == NEW_ADDR;
@@ -235,6 +236,10 @@ static void __set_nat_cache_dirty(struct f2fs_nm_info *nm_i,
 	if (get_nat_flag(ne, IS_DIRTY))
 		goto refresh_list;
 
+	/* journal hit case, try to locate set in journal */
+	if (!remove_journal && head->entry_cnt <= NAT_JOURNAL_ENTRIES)
+		head->cp_ver += div_u64(cur_cp_version(F2FS_CKPT(sbi)),
+						NAT_JOURNAL_ENTRIES);
 	nm_i->dirty_nat_cnt++;
 	set_nat_flag(ne, IS_DIRTY, true);
 refresh_list:
@@ -378,7 +383,7 @@ static void set_node_addr(struct f2fs_sb_info *sbi, struct node_info *ni,
 	nat_set_blkaddr(e, new_blkaddr);
 	if (new_blkaddr == NEW_ADDR || new_blkaddr == NULL_ADDR)
 		set_nat_flag(e, IS_CHECKPOINTED, false);
-	__set_nat_cache_dirty(nm_i, e);
+	__set_nat_cache_dirty(sbi, false, nm_i, e);
 
 	/* update fsync_mark if its inode nat entry is still alive */
 	if (ni->nid != ni->ino)
@@ -2417,14 +2422,14 @@ static void remove_nats_in_journal(struct f2fs_sb_info *sbi)
 			spin_unlock(&nm_i->nid_list_lock);
 		}
 
-		__set_nat_cache_dirty(nm_i, ne);
+		__set_nat_cache_dirty(sbi, true, nm_i, ne);
 	}
 	update_nats_in_cursum(journal, -i);
 	up_write(&curseg->journal_rwsem);
 }
 
-static void __adjust_nat_entry_set(struct nat_entry_set *nes,
-						struct list_head *head, int max)
+static void __adjust_nat_entry_set(struct f2fs_sb_info *sbi,
+		struct nat_entry_set *nes, struct list_head *head, int max)
 {
 	struct nat_entry_set *cur;
 
@@ -2432,7 +2437,9 @@ static void __adjust_nat_entry_set(struct nat_entry_set *nes,
 		goto add_out;
 
 	list_for_each_entry(cur, head, set_list) {
-		if (cur->entry_cnt >= nes->entry_cnt) {
+		if (cur->entry_cnt > nes->entry_cnt ||
+			(cur->entry_cnt == nes->entry_cnt &&
+			cur->cp_ver < nes->cp_ver)) {
 			list_add(&nes->set_list, cur->set_list.prev);
 			return;
 		}
@@ -2480,7 +2487,6 @@ static void __flush_nat_entry_set(struct f2fs_sb_info *sbi,
 	struct curseg_info *curseg = CURSEG_I(sbi, CURSEG_HOT_DATA);
 	struct f2fs_journal *journal = curseg->journal;
 	nid_t start_nid = set->set * NAT_ENTRY_PER_BLOCK;
-	bool to_journal = true;
 	struct f2fs_nat_block *nat_blk;
 	struct nat_entry *ne, *cur;
 	struct page *page = NULL;
@@ -2490,11 +2496,14 @@ static void __flush_nat_entry_set(struct f2fs_sb_info *sbi,
 	 * #1, flush nat entries to journal in current hot data summary block.
 	 * #2, flush nat entries to nat page.
 	 */
+
+	set->to_journal = true;
+
 	if (enabled_nat_bits(sbi, cpc) ||
 		!__has_cursum_space(journal, set->entry_cnt, NAT_JOURNAL))
-		to_journal = false;
+		set->to_journal = false;
 
-	if (to_journal) {
+	if (set->to_journal) {
 		down_write(&curseg->journal_rwsem);
 	} else {
 		page = get_next_nat_page(sbi, start_nid);
@@ -2510,7 +2519,7 @@ static void __flush_nat_entry_set(struct f2fs_sb_info *sbi,
 
 		f2fs_bug_on(sbi, nat_get_blkaddr(ne) == NEW_ADDR);
 
-		if (to_journal) {
+		if (set->to_journal) {
 			offset = lookup_journal_in_cursum(journal,
 							NAT_JOURNAL, nid, 1);
 			f2fs_bug_on(sbi, offset < 0);
@@ -2531,7 +2540,7 @@ static void __flush_nat_entry_set(struct f2fs_sb_info *sbi,
 		}
 	}
 
-	if (to_journal) {
+	if (set->to_journal) {
 		up_write(&curseg->journal_rwsem);
 	} else {
 		__update_nat_bits(sbi, start_nid, page);
@@ -2539,7 +2548,7 @@ static void __flush_nat_entry_set(struct f2fs_sb_info *sbi,
 	}
 
 	/* Allow dirty nats by node block allocation in write_begin */
-	if (!set->entry_cnt) {
+	if (!set->to_journal && !set->entry_cnt) {
 		radix_tree_delete(&NM_I(sbi)->nat_set_root, set->set);
 		kmem_cache_free(nat_entry_set_slab, set);
 	}
@@ -2578,7 +2587,7 @@ void flush_nat_entries(struct f2fs_sb_info *sbi, struct cp_control *cpc)
 		unsigned idx;
 		set_idx = setvec[found - 1]->set + 1;
 		for (idx = 0; idx < found; idx++)
-			__adjust_nat_entry_set(setvec[idx], &sets,
+			__adjust_nat_entry_set(sbi, setvec[idx], &sets,
 						MAX_NAT_JENTRIES(journal));
 	}
 
@@ -2587,7 +2596,6 @@ void flush_nat_entries(struct f2fs_sb_info *sbi, struct cp_control *cpc)
 		__flush_nat_entry_set(sbi, set, cpc);
 
 	up_write(&nm_i->nat_tree_lock);
-	/* Allow dirty nats by node block allocation in write_begin */
 }
 
 static int __get_nat_bitmaps(struct f2fs_sb_info *sbi)
fs/f2fs/node.h +3 -1
index b95e49e..2129d63 100644
@@ -149,7 +149,9 @@ struct nat_entry_set {
 	struct list_head set_list;	/* link with other nat sets */
 	struct list_head entry_list;	/* link with dirty nat entries */
 	nid_t set;			/* set number*/
-	unsigned int entry_cnt;		/* the # of nat entries in set */
+	unsigned int entry_cnt:9;	/* the # of nat entries in set */
+	unsigned int to_journal:1;	/* set flush to journal */
+	__u64 cp_ver;			/* cp version of this set modify */
 };
 
 struct free_nid {
Signature · 6 lines
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
Reviewed-by on v5 1/1
#1 lore raw
Quoted 10 lines · Yunlei He

This patch introduce a method to make nat journal more fresh:
i. sort set list using dirty entry number and cp version
average value.
ii. if meet with cache hit, update average version valus with
current cp version.

With this patch, newly modified nat set will flush to journal, and flush old nat set with same dirty entry number to nat area.

Thanks,

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

maintainer
#2 lore raw

I removed this patch in my test branch, since it simply gave a kernel panic. Please test before sending patches.

repro
1. encrypt a dir
2. dd to create 10MB-sized file in the dir

Quoted 7 lines · Chao Yu
Quoted 6 lines · Yunlei He

This patch introduce a method to make nat journal more fresh:
i. sort set list using dirty entry number and cp version
average value.
ii. if meet with cache hit, update average version valus with
current cp version.

Quoted 8 lines
Quoted 4 lines

With this patch, newly modified nat set will flush to journal, and flush old nat set with same dirty entry number to nat area.

Thanks,

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

maintainer
#3 lore raw
Quoted 2 lines · Jaegeuk Kim

I removed this patch in my test branch, since it simply gave a kernel panic. Please test before sending patches.

Sorry, I didn't find this bug in previous review.

Look at this patch again,

fs/f2fs/node.c static void __set_nat_cache_dirty(struct f2fs_nm_info *nm_i, · line 240

Quoted 2 lines
fs/f2fs/node.c +2 -0
+	/* journal hit case, try to locate set in journal */
+	if (!remove_journal && head->entry_cnt <= NAT_JOURNAL_ENTRIES)

head pointer can be a random value before using.

To Yunlei, could you please fix this, and do the test (at least with xfstest) before resending it.

Thanks,

Quoted 22 lines

repro
1. encrypt a dir
2. dd to create 10MB-sized file in the dir

Quoted 7 lines · Chao Yu
Quoted 6 lines · Yunlei He

This patch introduce a method to make nat journal more fresh:
i. sort set list using dirty entry number and cp version
average value.
ii. if meet with cache hit, update average version valus with
current cp version.

Quoted 8 lines
Quoted 4 lines

With this patch, newly modified nat set will flush to journal, and flush old nat set with same dirty entry number to nat area.

Thanks,

Quoted 8 lines

------------------------------------------------------------------------------
Check out the vibrant tech community on one of the world's most engaging tech sites, Slashdot.org! http://sdm.link/slashdot
_______________________________________________
Linux-f2fs-devel mailing list [email protected]
https://lists.sourceforge.net/lists/listinfo/linux-f2fs-devel

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