Skip to contentSkip to conversation

f2fs: build free nid bitmap during flush nat entries

PATCH Superseded Yunlei He 2 participants 3 messages Apr 25, 2018 F2FS file system

v2 of 3 Superseded Latest is v3 →

lore
Share & tools
lore

Yunlei He

author
#0 lore raw

PATCH v2 1/1 f2fs: build free nid bitmap during flush nat entries

This patch introduce free nid bitmap build during flush nat entries in order to reduce synchronous read in the process of build free nids.

---
 fs/f2fs/node.c | 11 ++++++++---
 1 file changed, 8 insertions(+), 3 deletions(-)
fs/f2fs/node.c +8 -3
index f202398..681552b 100644
@@ -1947,7 +1947,7 @@ static void remove_free_nid(struct f2fs_sb_info *sbi, nid_t nid)
 }
 
 static void scan_nat_page(struct f2fs_sb_info *sbi,
-			struct page *nat_page, nid_t start_nid)
+		struct page *nat_page, nid_t start_nid, bool in_build)
 {
 	struct f2fs_nm_info *nm_i = NM_I(sbi);
 	struct f2fs_nat_block *nat_blk = page_address(nat_page);
@@ -1955,6 +1955,9 @@ static void scan_nat_page(struct f2fs_sb_info *sbi,
 	unsigned int nat_ofs = NAT_BLOCK_OFFSET(start_nid);
 	int i;
 
+	if (!test_bit_le(nat_ofs, nm_i->nat_block_bitmap))
+		return;
+
 	__set_bit_le(nat_ofs, nm_i->nat_block_bitmap);
 
 	i = start_nid % NAT_ENTRY_PER_BLOCK;
@@ -1966,7 +1969,8 @@ static void scan_nat_page(struct f2fs_sb_info *sbi,
 		blk_addr = le32_to_cpu(nat_blk->entries[i].block_addr);
 		f2fs_bug_on(sbi, blk_addr == NEW_ADDR);
 		if (blk_addr == NULL_ADDR) {
-			add_free_nid(sbi, start_nid, true, true);
+			if (in_build)
+				add_free_nid(sbi, start_nid, true, true);
 		} else {
 			spin_lock(&NM_I(sbi)->nid_list_lock);
 			update_free_nid_bitmap(sbi, start_nid, false, true);
@@ -2063,7 +2067,7 @@ static void __build_free_nids(struct f2fs_sb_info *sbi, bool sync, bool mount)
 						nm_i->nat_block_bitmap)) {
 			struct page *page = get_current_nat_page(sbi, nid);
 
-			scan_nat_page(sbi, page, nid);
+			scan_nat_page(sbi, page, nid, true);
 			f2fs_put_page(page, 1);
 		}
 
@@ -2534,6 +2538,7 @@ static void __flush_nat_entry_set(struct f2fs_sb_info *sbi,
 	if (to_journal) {
 		up_write(&curseg->journal_rwsem);
 	} else {
+		scan_nat_page(sbi, page, start_nid, false);
 		__update_nat_bits(sbi, start_nid, page);
 		f2fs_put_page(page, 1);
 	}
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
author
#1 lore raw
Quoted 32 lines

-----Original Message-----
From: heyunlei
Sent: Wednesday, April 25, 2018 3:44 PM
To: [email protected]; Yuchao (T); [email protected]
Cc: Wangbintian; heyunlei; Zhangdianfang (Euler)
Subject: [f2fs-dev][PATCH v2] f2fs: build free nid bitmap during flush nat entries

This patch introduce free nid bitmap build during flush nat entries in order to reduce synchronous read in the process of build free nids.

---
fs/f2fs/node.c | 11 ++++++++---

1 file changed, 8 insertions(+), 3 deletions(-)
fs/f2fs/node.c +1 -1
index f202398..681552b 100644
@@ -1947,7 +1947,7 @@ static void remove_free_nid(struct f2fs_sb_info *sbi, nid_t nid)
 }
 
 static void scan_nat_page(struct f2fs_sb_info *sbi,
-			struct page *nat_page, nid_t start_nid)
+		struct page *nat_page, nid_t start_nid, bool in_build)
 {
 	struct f2fs_nm_info *nm_i = NM_I(sbi);
 	struct f2fs_nat_block *nat_blk = page_address(nat_page);

fs/f2fs/node.c static void scan_nat_page(struct f2fs_sb_info *sbi, · line 1960

Quoted 6 lines
fs/f2fs/node.c +3 -0
@@ -1955,6 +1955,9 @@ static void scan_nat_page(struct f2fs_sb_info *sbi,
 	unsigned int nat_ofs = NAT_BLOCK_OFFSET(start_nid);
 	int i;
 
+	if (!test_bit_le(nat_ofs, nm_i->nat_block_bitmap))
+		return;
+

Sorry that it should be:

	if (test_bit_le(nat_ofs, nm_i->nat_block_bitmap))
		return;

Thanks.

Quoted 31 lines
fs/f2fs/node.c +4 -3
 	__set_bit_le(nat_ofs, nm_i->nat_block_bitmap);
 
 	i = start_nid % NAT_ENTRY_PER_BLOCK;
@@ -1966,7 +1969,8 @@ static void scan_nat_page(struct f2fs_sb_info *sbi,
 		blk_addr = le32_to_cpu(nat_blk->entries[i].block_addr);
 		f2fs_bug_on(sbi, blk_addr == NEW_ADDR);
 		if (blk_addr == NULL_ADDR) {
-			add_free_nid(sbi, start_nid, true, true);
+			if (in_build)
+				add_free_nid(sbi, start_nid, true, true);
 		} else {
 			spin_lock(&NM_I(sbi)->nid_list_lock);
 			update_free_nid_bitmap(sbi, start_nid, false, true);
@@ -2063,7 +2067,7 @@ static void __build_free_nids(struct f2fs_sb_info *sbi, bool sync, bool mount)
 						nm_i->nat_block_bitmap)) {
 			struct page *page = get_current_nat_page(sbi, nid);
 
-			scan_nat_page(sbi, page, nid);
+			scan_nat_page(sbi, page, nid, true);
 			f2fs_put_page(page, 1);
 		}
 
@@ -2534,6 +2538,7 @@ static void __flush_nat_entry_set(struct f2fs_sb_info *sbi,
 	if (to_journal) {
 		up_write(&curseg->journal_rwsem);
 	} else {
+		scan_nat_page(sbi, page, start_nid, false);
 		__update_nat_bits(sbi, start_nid, page);
 		f2fs_put_page(page, 1);
 	}
--
Quoted 1 line

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

maintainer
#2 lore raw
Quoted 45 lines · heyunlei
Quoted 32 lines

-----Original Message-----
From: heyunlei
Sent: Wednesday, April 25, 2018 3:44 PM
To: [email protected]; Yuchao (T); [email protected]
Cc: Wangbintian; heyunlei; Zhangdianfang (Euler)
Subject: [f2fs-dev][PATCH v2] f2fs: build free nid bitmap during flush nat entries

This patch introduce free nid bitmap build during flush nat entries in order to reduce synchronous read in the process of build free nids.

---
fs/f2fs/node.c | 11 ++++++++---

1 file changed, 8 insertions(+), 3 deletions(-)
fs/f2fs/node.c +1 -1
index f202398..681552b 100644
@@ -1947,7 +1947,7 @@ static void remove_free_nid(struct f2fs_sb_info *sbi, nid_t nid)
 }
 
 static void scan_nat_page(struct f2fs_sb_info *sbi,
-			struct page *nat_page, nid_t start_nid)
+		struct page *nat_page, nid_t start_nid, bool in_build)
 {
 	struct f2fs_nm_info *nm_i = NM_I(sbi);
 	struct f2fs_nat_block *nat_blk = page_address(nat_page);

fs/f2fs/node.c static void scan_nat_page(struct f2fs_sb_info *sbi, · line 1960

Quoted 6 lines
fs/f2fs/node.c +3 -0
@@ -1955,6 +1955,9 @@ static void scan_nat_page(struct f2fs_sb_info *sbi,
 	unsigned int nat_ofs = NAT_BLOCK_OFFSET(start_nid);
 	int i;
 
+	if (!test_bit_le(nat_ofs, nm_i->nat_block_bitmap))
+		return;
+

Sorry that it should be:

	if (test_bit_le(nat_ofs, nm_i->nat_block_bitmap))
		return;

Thanks.

Quoted 2 lines
fs/f2fs/node.c +0 -0
 	__set_bit_le(nat_ofs, nm_i->nat_block_bitmap);
 
Quoted 8 lines

fs/f2fs/node.c static void scan_nat_page(struct f2fs_sb_info *sbi, · line 1973

Quoted 8 lines
fs/f2fs/node.c +2 -1
 	i = start_nid % NAT_ENTRY_PER_BLOCK;
@@ -1966,7 +1969,8 @@ static void scan_nat_page(struct f2fs_sb_info *sbi,
 		blk_addr = le32_to_cpu(nat_blk->entries[i].block_addr);
 		f2fs_bug_on(sbi, blk_addr == NEW_ADDR);
 		if (blk_addr == NULL_ADDR) {
-			add_free_nid(sbi, start_nid, true, true);
+			if (in_build)
+				add_free_nid(sbi, start_nid, true, true);

We should call update_free_nid_bitmap instead of skipping add_free_nid, so how about:

if (update_bitmap) {
	spin_lock;
	update_free_nid_bitmap;
	spin_unlock;
} else {
	add_free_nid;
}

Thanks,

Quoted 24 lines
Quoted 21 lines
fs/f2fs/node.c +2 -2
 		} else {
 			spin_lock(&NM_I(sbi)->nid_list_lock);
 			update_free_nid_bitmap(sbi, start_nid, false, true);
@@ -2063,7 +2067,7 @@ static void __build_free_nids(struct f2fs_sb_info *sbi, bool sync, bool mount)
 						nm_i->nat_block_bitmap)) {
 			struct page *page = get_current_nat_page(sbi, nid);
 
-			scan_nat_page(sbi, page, nid);
+			scan_nat_page(sbi, page, nid, true);
 			f2fs_put_page(page, 1);
 		}
 
@@ -2534,6 +2538,7 @@ static void __flush_nat_entry_set(struct f2fs_sb_info *sbi,
 	if (to_journal) {
 		up_write(&curseg->journal_rwsem);
 	} else {
+		scan_nat_page(sbi, page, start_nid, false);
 		__update_nat_bits(sbi, start_nid, page);
 		f2fs_put_page(page, 1);
 	}
--
Quoted 1 line

1.9.1

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