提交 2411cf5b 编写于 作者: C Chao Yu 提交者: Jaegeuk Kim

f2fs: exclude free nids building and allocation

During nid allocation, it needs to exclude building and allocating flow
of free nids, this is because while building free nid cache, there are two
steps: a) load free nids from unused nat entries in NAT pages, b) update
free nid cache by checking nat journal. The two steps should be atomical,
otherwise an used nid can be allocated as free one after a) and before b).

This patch adds missing lock which covers build_free_nids in
unlock_operation and f2fs_balance_fs_bg to avoid that.
Signed-off-by: NChao Yu <yuchao0@huawei.com>
Signed-off-by: NJaegeuk Kim <jaegeuk@kernel.org>
上级 e87f7329
...@@ -1785,7 +1785,7 @@ static void scan_nat_page(struct f2fs_sb_info *sbi, ...@@ -1785,7 +1785,7 @@ static void scan_nat_page(struct f2fs_sb_info *sbi,
} }
} }
void build_free_nids(struct f2fs_sb_info *sbi) void __build_free_nids(struct f2fs_sb_info *sbi)
{ {
struct f2fs_nm_info *nm_i = NM_I(sbi); struct f2fs_nm_info *nm_i = NM_I(sbi);
struct curseg_info *curseg = CURSEG_I(sbi, CURSEG_HOT_DATA); struct curseg_info *curseg = CURSEG_I(sbi, CURSEG_HOT_DATA);
...@@ -1839,6 +1839,13 @@ void build_free_nids(struct f2fs_sb_info *sbi) ...@@ -1839,6 +1839,13 @@ void build_free_nids(struct f2fs_sb_info *sbi)
nm_i->ra_nid_pages, META_NAT, false); nm_i->ra_nid_pages, META_NAT, false);
} }
void build_free_nids(struct f2fs_sb_info *sbi)
{
mutex_lock(&NM_I(sbi)->build_lock);
__build_free_nids(sbi);
mutex_unlock(&NM_I(sbi)->build_lock);
}
/* /*
* If this function returns success, caller can obtain a new nid * If this function returns success, caller can obtain a new nid
* from second parameter of this function. * from second parameter of this function.
...@@ -1875,9 +1882,7 @@ bool alloc_nid(struct f2fs_sb_info *sbi, nid_t *nid) ...@@ -1875,9 +1882,7 @@ bool alloc_nid(struct f2fs_sb_info *sbi, nid_t *nid)
spin_unlock(&nm_i->free_nid_list_lock); spin_unlock(&nm_i->free_nid_list_lock);
/* Let's scan nat pages and its caches to get free nids */ /* Let's scan nat pages and its caches to get free nids */
mutex_lock(&nm_i->build_lock);
build_free_nids(sbi); build_free_nids(sbi);
mutex_unlock(&nm_i->build_lock);
goto retry; goto retry;
} }
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册