f2fs: optimize alloc_nid_failed()
Subsystems (2)
PATCH 1/1 f2fs: optimize alloc_nid_failed()
Current alloc_nid_failed() has two issues:
1. unecessarily kmem_cache_free() the free_nid and then realloc a new slab cache for it immediately;
2. needs to __lookup_free_nid_list() twice in order to find out the free_nid from free_nid_list.
This patch fixes these issues.
--- fs/f2fs/node.c | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-)
fs/f2fs/node.c +15 -2
@@ -1403,8 +1403,21 @@ void alloc_nid_done(struct f2fs_sb_info *sbi, nid_t nid)*/ void alloc_nid_failed (struct f2fs_sb_info *sbi,nid_t nid) { -alloc_nid_done (sbi, nid); -add_free_nid (NM_I (sbi), nid); +struct f2fs_nm_info *nm_i =NM_I (sbi); +struct free_nid *i; + +spin_lock (&nm_i->free_nid_list_lock); + i =__lookup_free_nid_list (nid, &nm_i->free_nid_list); +if (i) { +BUG_ON (i->state !=NID_ALLOC ); +if (nm_i->fcnt >2 *MAX_FREE_NIDS ) +__del_from_free_nid_list (i); +else { + i->state =NID_NEW ; + nm_i->fcnt++; + } + } +spin_unlock (&nm_i->free_nid_list_lock); } void recover_node_page(struct f2fs_sb_info *sbi, struct page *page,
Signature · 1 line
1.7.9.5
Just realized I should develop the patches against Kim's f2fs-dev branch rather than the f2fs-master branch. (thanks to Huajun for the reminding).
Obviously on f2fs-dev branch, some optimizations of alloc_nid_failed() have already been done.
Pls. ignore this patch, I'll send out the rebased version of my recent f2fs patches soon later, which will be based on the f2fs-dev tree.
Quoted 43 lines · Haicheng Li
Current
alloc_nid_failed()has two issues:
1. unecessarilykmem_cache_free()thefree_nidand then realloc a new slab cache for it immediately;
2. needs to__lookup_free_nid_list()twice in order to find out thefree_nidfromfree_nid_list.This patch fixes these issues.
Signed-off-by Haicheng Li <[email protected]>--- fs/f2fs/node.c | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-)fs/f2fs/node.c +15
-2@@ -1403,8 +1403,21 @@ void alloc_nid_done(struct f2fs_sb_info *sbi, nid_t nid)*/ void alloc_nid_failed (struct f2fs_sb_info *sbi,nid_t nid) { -alloc_nid_done (sbi, nid); -add_free_nid (NM_I (sbi), nid); +struct f2fs_nm_info *nm_i =NM_I (sbi); +struct free_nid *i; + +spin_lock (&nm_i->free_nid_list_lock); + i =__lookup_free_nid_list (nid, &nm_i->free_nid_list); +if (i) { +BUG_ON (i->state !=NID_ALLOC ); +if (nm_i->fcnt >2 *MAX_FREE_NIDS ) +__del_from_free_nid_list (i); +else { + i->state =NID_NEW ; + nm_i->fcnt++; + } + } +spin_unlock (&nm_i->free_nid_list_lock); } void recover_node_page(struct f2fs_sb_info *sbi, struct page *page,Signature · 1 line
1.7.9.5