2013-05-03 12:43:59

by Haicheng Li

[permalink] [raw]
Subject: [PATCH 1/2] f2fs: optimize scan_nat_page()

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

Signed-off-by: Haicheng Li <[email protected]>
---
fs/f2fs/node.c | 14 ++++++++++----
1 file changed, 10 insertions(+), 4 deletions(-)

diff --git a/fs/f2fs/node.c b/fs/f2fs/node.c
index e275218..6276467 100644
--- a/fs/f2fs/node.c
+++ b/fs/f2fs/node.c
@@ -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;
}
--
1.7.9.5


2013-05-03 12:44:10

by Haicheng Li

[permalink] [raw]
Subject: [PATCH 2/2] f2fs: optimize build_free_nids()

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

Signed-off-by: Haicheng Li <[email protected]>
---
fs/f2fs/node.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/fs/f2fs/node.c b/fs/f2fs/node.c
index 6276467..31d038f 100644
--- a/fs/f2fs/node.c
+++ b/fs/f2fs/node.c
@@ -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;
--
1.7.9.5