[PATCH] f2fs: separate hot/cold free nid simply

From: Chao Yu
Date: Fri Apr 20 2018 - 04:18:26 EST


Signed-off-by: Chao Yu <yuchao0@xxxxxxxxxx>
---
fs/f2fs/f2fs.h | 2 +-
fs/f2fs/namei.c | 2 +-
fs/f2fs/node.c | 14 +++++++++-----
fs/f2fs/xattr.c | 2 +-
4 files changed, 12 insertions(+), 8 deletions(-)

diff --git a/fs/f2fs/f2fs.h b/fs/f2fs/f2fs.h
index 7651a118faa3..adca5e8bc19a 100644
--- a/fs/f2fs/f2fs.h
+++ b/fs/f2fs/f2fs.h
@@ -2800,7 +2800,7 @@ int fsync_node_pages(struct f2fs_sb_info *sbi, struct
inode *inode,
int sync_node_pages(struct f2fs_sb_info *sbi, struct writeback_control *wbc,
bool do_balance, enum iostat_type io_type);
void build_free_nids(struct f2fs_sb_info *sbi, bool sync, bool mount);
-bool alloc_nid(struct f2fs_sb_info *sbi, nid_t *nid);
+bool alloc_nid(struct f2fs_sb_info *sbi, nid_t *nid, bool hot);
void alloc_nid_done(struct f2fs_sb_info *sbi, nid_t nid);
void alloc_nid_failed(struct f2fs_sb_info *sbi, nid_t nid);
int try_to_free_nids(struct f2fs_sb_info *sbi, int nr_shrink);
diff --git a/fs/f2fs/namei.c b/fs/f2fs/namei.c
index 3d59149590f7..bbf6edbb7298 100644
--- a/fs/f2fs/namei.c
+++ b/fs/f2fs/namei.c
@@ -37,7 +37,7 @@ static struct inode *f2fs_new_inode(struct inode *dir, umode_t
mode)
return ERR_PTR(-ENOMEM);

f2fs_lock_op(sbi);
- if (!alloc_nid(sbi, &ino)) {
+ if (!alloc_nid(sbi, &ino, true)) {
f2fs_unlock_op(sbi);
err = -ENOSPC;
goto fail;
diff --git a/fs/f2fs/node.c b/fs/f2fs/node.c
index ea231f8a0cce..bbaae2f3461e 100644
--- a/fs/f2fs/node.c
+++ b/fs/f2fs/node.c
@@ -631,7 +631,7 @@ int get_dnode_of_data(struct dnode_of_data *dn, pgoff_t
index, int mode)

if (!nids[i] && mode == ALLOC_NODE) {
/* alloc new node */
- if (!alloc_nid(sbi, &(nids[i]))) {
+ if (!alloc_nid(sbi, &(nids[i]), i == 1)) {
err = -ENOSPC;
goto release_pages;
}
@@ -2108,7 +2108,7 @@ void build_free_nids(struct f2fs_sb_info *sbi, bool sync,
bool mount)
* from second parameter of this function.
* The returned nid could be used ino as well as nid when inode is created.
*/
-bool alloc_nid(struct f2fs_sb_info *sbi, nid_t *nid)
+bool alloc_nid(struct f2fs_sb_info *sbi, nid_t *nid, bool hot)
{
struct f2fs_nm_info *nm_i = NM_I(sbi);
struct free_nid *i = NULL;
@@ -2129,8 +2129,12 @@ bool alloc_nid(struct f2fs_sb_info *sbi, nid_t *nid)
/* We should not use stale free nids created by build_free_nids */
if (nm_i->nid_cnt[FREE_NID] && !on_build_free_nids(nm_i)) {
f2fs_bug_on(sbi, list_empty(&nm_i->free_nid_list));
- i = list_first_entry(&nm_i->free_nid_list,
- struct free_nid, list);
+ if (hot)
+ i = list_first_entry(&nm_i->free_nid_list,
+ struct free_nid, list);
+ else
+ i = list_last_entry(&nm_i->free_nid_list,
+ struct free_nid, list);
*nid = i->nid;

__move_free_nid(sbi, i, FREE_NID, PREALLOC_NID);
@@ -2275,7 +2279,7 @@ int recover_xattr_data(struct inode *inode, struct page *page)

recover_xnid:
/* 2: update xattr nid in inode */
- if (!alloc_nid(sbi, &new_xnid))
+ if (!alloc_nid(sbi, &new_xnid, false))
return -ENOSPC;

set_new_dnode(&dn, inode, NULL, NULL, new_xnid);
diff --git a/fs/f2fs/xattr.c b/fs/f2fs/xattr.c
index d847b2b11659..46c090614563 100644
--- a/fs/f2fs/xattr.c
+++ b/fs/f2fs/xattr.c
@@ -398,7 +398,7 @@ static inline int write_all_xattrs(struct inode *inode,
__u32 hsize,
int err = 0;

if (hsize > inline_size && !F2FS_I(inode)->i_xattr_nid)
- if (!alloc_nid(sbi, &new_nid))
+ if (!alloc_nid(sbi, &new_nid, false))
return -ENOSPC;

/* write to inline xattr */
--
2.15.0.55.gc2ece9dc4de6