Skip to contentSkip to conversation

f2fs: optimize scan_nat_page()

PATCH New Haicheng Li 1 participant 2 messages May 3, 2013

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/2 f2fs: optimize scan_nat_page()

When nm_i->fcnt > 2 * MAX_FREE_NIDS, stop scanning other NAT entries.

---
 fs/f2fs/node.c |   14 ++++++++++----
 1 file changed, 10 insertions(+), 4 deletions(-)
fs/f2fs/node.c +10 -4
index e275218..6276467 100644
@@ -1216,7 +1216,7 @@ static int add_free_nid(struct f2fs_nm_info *nm_i, nid_t nid)
 	struct free_nid *i;
 
 	if (nm_i->fcnt > 2 * MAX_FREE_NIDS)
-		return 0;
+		return -1;
 retry:
 	i = kmem_cache_alloc(free_nid_slab, GFP_NOFS);
 	if (!i) {
@@ -1265,10 +1265,16 @@ static int scan_nat_page(struct f2fs_nm_info *nm_i,
 	i = start_nid % NAT_ENTRY_PER_BLOCK;
 
 	for (; i < NAT_ENTRY_PER_BLOCK; i++, start_nid++) {
-		blk_addr  = le32_to_cpu(nat_blk->entries[i].block_addr);
+		int cnt;
+
+		blk_addr = le32_to_cpu(nat_blk->entries[i].block_addr);
 		BUG_ON(blk_addr == NEW_ADDR);
-		if (blk_addr == NULL_ADDR)
-			fcnt += add_free_nid(nm_i, start_nid);
+		if (blk_addr == NULL_ADDR) {
+			cnt = add_free_nid(nm_i, start_nid);
+			if (cnt < 0)
+				break;
+			fcnt += cnt;
+		}
 	}
 	return fcnt;
 }
Signature · 1 line
1.7.9.5
#1 lore raw

PATCH 2/2 f2fs: optimize build_free_nids()

When nm_i->fcnt > 2 * MAX_FREE_NIDS, stop scanning other NAT pages.

---
 fs/f2fs/node.c |    2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
fs/f2fs/node.c +1 -1
index 6276467..31d038f 100644
@@ -1307,7 +1307,7 @@ static void build_free_nids(struct f2fs_sb_info *sbi)
 			nid = 0;
 			is_cycled = true;
 		}
-		if (fcnt > MAX_FREE_NIDS)
+		if (fcnt > MAX_FREE_NIDS || nm_i->fcnt > 2 * MAX_FREE_NIDS)
 			break;
 		if (is_cycled && nm_i->init_scan_nid <= nid)
 			break;
Signature · 1 line
1.7.9.5