Commit 97456574 authored by Fan Li's avatar Fan Li Committed by Jaegeuk Kim

f2fs: optimize the way of traversing free_nid_bitmap

We call scan_free_nid_bits only when there isn't many
free nids left, it means that marked bits in free_nid_bitmap
are supposed to be few, use find_next_bit_le is more
efficient in such case.
According to my tests, use find_next_bit_le instead of
test_bit_le will cut down the traversal time to one
third of its original.
Signed-off-by: default avatarFan li <fanofcode.li@samsung.com>
Reviewed-by: default avatarChao Yu <yuchao0@huawei.com>
Signed-off-by: default avatarJaegeuk Kim <jaegeuk@kernel.org>
parent 74986213
...@@ -1955,6 +1955,7 @@ static void scan_free_nid_bits(struct f2fs_sb_info *sbi) ...@@ -1955,6 +1955,7 @@ static void scan_free_nid_bits(struct f2fs_sb_info *sbi)
struct curseg_info *curseg = CURSEG_I(sbi, CURSEG_HOT_DATA); struct curseg_info *curseg = CURSEG_I(sbi, CURSEG_HOT_DATA);
struct f2fs_journal *journal = curseg->journal; struct f2fs_journal *journal = curseg->journal;
unsigned int i, idx; unsigned int i, idx;
nid_t nid;
down_read(&nm_i->nat_tree_lock); down_read(&nm_i->nat_tree_lock);
...@@ -1964,10 +1965,10 @@ static void scan_free_nid_bits(struct f2fs_sb_info *sbi) ...@@ -1964,10 +1965,10 @@ static void scan_free_nid_bits(struct f2fs_sb_info *sbi)
if (!nm_i->free_nid_count[i]) if (!nm_i->free_nid_count[i])
continue; continue;
for (idx = 0; idx < NAT_ENTRY_PER_BLOCK; idx++) { for (idx = 0; idx < NAT_ENTRY_PER_BLOCK; idx++) {
nid_t nid; idx = find_next_bit_le(nm_i->free_nid_bitmap[i],
NAT_ENTRY_PER_BLOCK, idx);
if (!test_bit_le(idx, nm_i->free_nid_bitmap[i])) if (idx >= NAT_ENTRY_PER_BLOCK)
continue; break;
nid = i * NAT_ENTRY_PER_BLOCK + idx; nid = i * NAT_ENTRY_PER_BLOCK + idx;
add_free_nid(sbi, nid, true); add_free_nid(sbi, nid, true);
...@@ -1980,7 +1981,6 @@ static void scan_free_nid_bits(struct f2fs_sb_info *sbi) ...@@ -1980,7 +1981,6 @@ static void scan_free_nid_bits(struct f2fs_sb_info *sbi)
down_read(&curseg->journal_rwsem); down_read(&curseg->journal_rwsem);
for (i = 0; i < nats_in_cursum(journal); i++) { for (i = 0; i < nats_in_cursum(journal); i++) {
block_t addr; block_t addr;
nid_t nid;
addr = le32_to_cpu(nat_in_journal(journal, i).block_addr); addr = le32_to_cpu(nat_in_journal(journal, i).block_addr);
nid = le32_to_cpu(nid_in_journal(journal, i)); nid = le32_to_cpu(nid_in_journal(journal, i));
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment