Re: [f2fs-dev] [PATCH v4] f2fs: introduce a method to make nat journal more fresh

2018-04-09 Thread heyunlei


>-Original Message-
>From: Jaegeuk Kim [mailto:jaeg...@kernel.org]
>Sent: Tuesday, April 10, 2018 12:14 PM
>To: heyunlei
>Cc: Yuchao (T); linux-f2fs-devel@lists.sourceforge.net; Wangbintian
>Subject: Re: [f2fs-dev][PATCH v4] f2fs: introduce a method to make nat journal 
>more fresh
>
>Yunlei,
>
>Could you please post all the related patches including Chao's diff?

Okay, I'll do it.

Thanks.
>
>On 03/16, Yunlei He wrote:
>> This patch introduce a method to make nat journal more fresh:
>> i.  sort set list using dirty entry number and cp version
>> average value.
>> ii. if meet with cache hit, update average version valus with
>> current cp version.
>>
>> With this patch, newly modified nat set will flush to journal,
>> and flush old nat set with same dirty entry number to nat area.
>>
>> Signed-off-by: Yunlei He <heyun...@huawei.com>
>> ---
>>  fs/f2fs/node.c | 39 ---
>>  fs/f2fs/node.h |  4 +++-
>>  2 files changed, 27 insertions(+), 16 deletions(-)
>>
>> diff --git a/fs/f2fs/node.c b/fs/f2fs/node.c
>> index 177c438..c511ef6 100644
>> --- a/fs/f2fs/node.c
>> +++ b/fs/f2fs/node.c
>> @@ -193,8 +193,8 @@ static void __del_from_nat_cache(struct f2fs_nm_info 
>> *nm_i, struct nat_entry *e)
>>  __free_nat_entry(e);
>>  }
>>
>> -static void __set_nat_cache_dirty(struct f2fs_nm_info *nm_i,
>> -struct nat_entry *ne)
>> +static void __set_nat_cache_dirty(struct f2fs_sb_info *sbi, bool 
>> remove_journal,
>> +struct f2fs_nm_info *nm_i, struct nat_entry *ne)
>>  {
>>  nid_t set = NAT_BLOCK_OFFSET(ne->ni.nid);
>>  struct nat_entry_set *head;
>> @@ -207,12 +207,18 @@ static void __set_nat_cache_dirty(struct f2fs_nm_info 
>> *nm_i,
>>  INIT_LIST_HEAD(>set_list);
>>  head->set = set;
>>  head->entry_cnt = 0;
>> +head->cp_ver = 0;
>>  f2fs_radix_tree_insert(_i->nat_set_root, set, head);
>>  }
>>
>>  if (get_nat_flag(ne, IS_DIRTY))
>>  goto refresh_list;
>>
>> +/* journal hit case, try to locate set in journal */
>> +if (!remove_journal && head->entry_cnt <= NAT_JOURNAL_ENTRIES)
>> +head->cp_ver += div_u64(cur_cp_version(F2FS_CKPT(sbi)),
>> +NAT_JOURNAL_ENTRIES);
>> +
>>  nm_i->dirty_nat_cnt++;
>>  head->entry_cnt++;
>>  set_nat_flag(ne, IS_DIRTY, true);
>> @@ -357,7 +363,7 @@ static void set_node_addr(struct f2fs_sb_info *sbi, 
>> struct node_info *ni,
>>  nat_set_blkaddr(e, new_blkaddr);
>>  if (new_blkaddr == NEW_ADDR || new_blkaddr == NULL_ADDR)
>>  set_nat_flag(e, IS_CHECKPOINTED, false);
>> -__set_nat_cache_dirty(nm_i, e);
>> +__set_nat_cache_dirty(sbi, false, nm_i, e);
>>
>>  /* update fsync_mark if its inode nat entry is still alive */
>>  if (ni->nid != ni->ino)
>> @@ -2395,14 +2401,14 @@ static void remove_nats_in_journal(struct 
>> f2fs_sb_info *sbi)
>>  spin_unlock(_i->nid_list_lock);
>>  }
>>
>> -__set_nat_cache_dirty(nm_i, ne);
>> +__set_nat_cache_dirty(sbi, true, nm_i, ne);
>>  }
>>  update_nats_in_cursum(journal, -i);
>>  up_write(>journal_rwsem);
>>  }
>>
>> -static void __adjust_nat_entry_set(struct nat_entry_set *nes,
>> -struct list_head *head, int max)
>> +static void __adjust_nat_entry_set(struct f2fs_sb_info *sbi,
>> +struct nat_entry_set *nes, struct list_head *head, int max)
>>  {
>>  struct nat_entry_set *cur;
>>
>> @@ -2410,7 +2416,9 @@ static void __adjust_nat_entry_set(struct 
>> nat_entry_set *nes,
>>  goto add_out;
>>
>>  list_for_each_entry(cur, head, set_list) {
>> -if (cur->entry_cnt >= nes->entry_cnt) {
>> +if (cur->entry_cnt > nes->entry_cnt ||
>> +(cur->entry_cnt == nes->entry_cnt &&
>> +cur->cp_ver < nes->cp_ver)) {
>>  list_add(>set_list, cur->set_list.prev);
>>  return;
>>  }
>> @@ -2458,7 +2466,6 @@ static void __flush_nat_entry_set(struct f2fs_sb_info 
>> *sbi,
>>  struct curseg_inf

Re: [f2fs-dev] [PATCH v4] f2fs: introduce a method to make nat journal more fresh

2018-04-09 Thread Jaegeuk Kim
Yunlei,

Could you please post all the related patches including Chao's diff?

On 03/16, Yunlei He wrote:
> This patch introduce a method to make nat journal more fresh:
> i.  sort set list using dirty entry number and cp version
> average value.
> ii. if meet with cache hit, update average version valus with
> current cp version.
> 
> With this patch, newly modified nat set will flush to journal,
> and flush old nat set with same dirty entry number to nat area.
> 
> Signed-off-by: Yunlei He 
> ---
>  fs/f2fs/node.c | 39 ---
>  fs/f2fs/node.h |  4 +++-
>  2 files changed, 27 insertions(+), 16 deletions(-)
> 
> diff --git a/fs/f2fs/node.c b/fs/f2fs/node.c
> index 177c438..c511ef6 100644
> --- a/fs/f2fs/node.c
> +++ b/fs/f2fs/node.c
> @@ -193,8 +193,8 @@ static void __del_from_nat_cache(struct f2fs_nm_info 
> *nm_i, struct nat_entry *e)
>   __free_nat_entry(e);
>  }
>  
> -static void __set_nat_cache_dirty(struct f2fs_nm_info *nm_i,
> - struct nat_entry *ne)
> +static void __set_nat_cache_dirty(struct f2fs_sb_info *sbi, bool 
> remove_journal,
> + struct f2fs_nm_info *nm_i, struct nat_entry *ne)
>  {
>   nid_t set = NAT_BLOCK_OFFSET(ne->ni.nid);
>   struct nat_entry_set *head;
> @@ -207,12 +207,18 @@ static void __set_nat_cache_dirty(struct f2fs_nm_info 
> *nm_i,
>   INIT_LIST_HEAD(>set_list);
>   head->set = set;
>   head->entry_cnt = 0;
> + head->cp_ver = 0;
>   f2fs_radix_tree_insert(_i->nat_set_root, set, head);
>   }
>  
>   if (get_nat_flag(ne, IS_DIRTY))
>   goto refresh_list;
>  
> + /* journal hit case, try to locate set in journal */
> + if (!remove_journal && head->entry_cnt <= NAT_JOURNAL_ENTRIES)
> + head->cp_ver += div_u64(cur_cp_version(F2FS_CKPT(sbi)),
> + NAT_JOURNAL_ENTRIES);
> +
>   nm_i->dirty_nat_cnt++;
>   head->entry_cnt++;
>   set_nat_flag(ne, IS_DIRTY, true);
> @@ -357,7 +363,7 @@ static void set_node_addr(struct f2fs_sb_info *sbi, 
> struct node_info *ni,
>   nat_set_blkaddr(e, new_blkaddr);
>   if (new_blkaddr == NEW_ADDR || new_blkaddr == NULL_ADDR)
>   set_nat_flag(e, IS_CHECKPOINTED, false);
> - __set_nat_cache_dirty(nm_i, e);
> + __set_nat_cache_dirty(sbi, false, nm_i, e);
>  
>   /* update fsync_mark if its inode nat entry is still alive */
>   if (ni->nid != ni->ino)
> @@ -2395,14 +2401,14 @@ static void remove_nats_in_journal(struct 
> f2fs_sb_info *sbi)
>   spin_unlock(_i->nid_list_lock);
>   }
>  
> - __set_nat_cache_dirty(nm_i, ne);
> + __set_nat_cache_dirty(sbi, true, nm_i, ne);
>   }
>   update_nats_in_cursum(journal, -i);
>   up_write(>journal_rwsem);
>  }
>  
> -static void __adjust_nat_entry_set(struct nat_entry_set *nes,
> - struct list_head *head, int max)
> +static void __adjust_nat_entry_set(struct f2fs_sb_info *sbi,
> + struct nat_entry_set *nes, struct list_head *head, int max)
>  {
>   struct nat_entry_set *cur;
>  
> @@ -2410,7 +2416,9 @@ static void __adjust_nat_entry_set(struct nat_entry_set 
> *nes,
>   goto add_out;
>  
>   list_for_each_entry(cur, head, set_list) {
> - if (cur->entry_cnt >= nes->entry_cnt) {
> + if (cur->entry_cnt > nes->entry_cnt ||
> + (cur->entry_cnt == nes->entry_cnt &&
> + cur->cp_ver < nes->cp_ver)) {
>   list_add(>set_list, cur->set_list.prev);
>   return;
>   }
> @@ -2458,7 +2466,6 @@ static void __flush_nat_entry_set(struct f2fs_sb_info 
> *sbi,
>   struct curseg_info *curseg = CURSEG_I(sbi, CURSEG_HOT_DATA);
>   struct f2fs_journal *journal = curseg->journal;
>   nid_t start_nid = set->set * NAT_ENTRY_PER_BLOCK;
> - bool to_journal = true;
>   struct f2fs_nat_block *nat_blk;
>   struct nat_entry *ne, *cur;
>   struct page *page = NULL;
> @@ -2468,11 +2475,14 @@ static void __flush_nat_entry_set(struct f2fs_sb_info 
> *sbi,
>* #1, flush nat entries to journal in current hot data summary block.
>* #2, flush nat entries to nat page.
>*/
> +
> + set->to_journal = true;
> +
>   if (enabled_nat_bits(sbi, cpc) ||
>   !__has_cursum_space(journal, set->entry_cnt, NAT_JOURNAL))
> - to_journal = false;
> + set->to_journal = false;
>  
> - if (to_journal) {
> + if (set->to_journal) {
>   down_write(>journal_rwsem);
>   } else {
>   page = get_next_nat_page(sbi, start_nid);
> @@ -2488,7 +2498,7 @@ static void __flush_nat_entry_set(struct f2fs_sb_info 
> *sbi,
>  
>   f2fs_bug_on(sbi, nat_get_blkaddr(ne) == 

Re: [f2fs-dev] [PATCH v4] f2fs: introduce a method to make nat journal more fresh

2018-04-09 Thread Chao Yu
On 2018/3/16 18:24, Yunlei He wrote:
> This patch introduce a method to make nat journal more fresh:
> i.  sort set list using dirty entry number and cp version
> average value.
> ii. if meet with cache hit, update average version valus with
> current cp version.
> 
> With this patch, newly modified nat set will flush to journal,
> and flush old nat set with same dirty entry number to nat area.
> 
> Signed-off-by: Yunlei He 

Reviewed-by: Chao Yu 

Thanks,


--
Check out the vibrant tech community on one of the world's most
engaging tech sites, Slashdot.org! http://sdm.link/slashdot
___
Linux-f2fs-devel mailing list
Linux-f2fs-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/linux-f2fs-devel


Re: [f2fs-dev] [PATCH v4] f2fs: introduce a method to make nat journal more fresh

2018-04-09 Thread heyunlei


>-Original Message-
>From: Yuchao (T)
>Sent: Wednesday, March 28, 2018 9:28 AM
>To: heyunlei; jaeg...@kernel.org; linux-f2fs-devel@lists.sourceforge.net
>Cc: Wangbintian
>Subject: Re: [f2fs-dev][PATCH v4] f2fs: introduce a method to make nat journal 
>more fresh
>
>On 2018/3/16 18:24, Yunlei He wrote:
>> This patch introduce a method to make nat journal more fresh:
>> i.  sort set list using dirty entry number and cp version
>> average value.
>> ii. if meet with cache hit, update average version valus with
>> current cp version.
>>
>> With this patch, newly modified nat set will flush to journal,
>> and flush old nat set with same dirty entry number to nat area.
>>
>> Signed-off-by: Yunlei He <heyun...@huawei.com>
>> ---
>>  fs/f2fs/node.c | 39 ---
>>  fs/f2fs/node.h |  4 +++-
>>  2 files changed, 27 insertions(+), 16 deletions(-)
>>
>> diff --git a/fs/f2fs/node.c b/fs/f2fs/node.c
>> index 177c438..c511ef6 100644
>> --- a/fs/f2fs/node.c
>> +++ b/fs/f2fs/node.c
>> @@ -193,8 +193,8 @@ static void __del_from_nat_cache(struct f2fs_nm_info 
>> *nm_i, struct nat_entry *e)
>>  __free_nat_entry(e);
>>  }
>>
>> -static void __set_nat_cache_dirty(struct f2fs_nm_info *nm_i,
>> -struct nat_entry *ne)
>> +static void __set_nat_cache_dirty(struct f2fs_sb_info *sbi, bool 
>> remove_journal,
>> +struct f2fs_nm_info *nm_i, struct nat_entry *ne)
>>  {
>>  nid_t set = NAT_BLOCK_OFFSET(ne->ni.nid);
>>  struct nat_entry_set *head;
>> @@ -207,12 +207,18 @@ static void __set_nat_cache_dirty(struct f2fs_nm_info 
>> *nm_i,
>>  INIT_LIST_HEAD(>set_list);
>>  head->set = set;
>>  head->entry_cnt = 0;
>> +head->cp_ver = 0;
>
>head->cp_ver = div_u64(cur_cp_version(F2FS_CKPT(sbi)), NAT_JOURNAL_ENTRIES)?
>
>Thanks,
>
>>  f2fs_radix_tree_insert(_i->nat_set_root, set, head);
>>  }
>>
>>  if (get_nat_flag(ne, IS_DIRTY))
>>  goto refresh_list;
>>
>> +/* journal hit case, try to locate set in journal */
>> +if (!remove_journal && head->entry_cnt <= NAT_JOURNAL_ENTRIES)
>> +head->cp_ver += div_u64(cur_cp_version(F2FS_CKPT(sbi)),
>> +NAT_JOURNAL_ENTRIES);

Cp version will increase here.

Thanks.
>> +
>>  nm_i->dirty_nat_cnt++;
>>  head->entry_cnt++;
>>  set_nat_flag(ne, IS_DIRTY, true);
>> @@ -357,7 +363,7 @@ static void set_node_addr(struct f2fs_sb_info *sbi, 
>> struct node_info *ni,
>>  nat_set_blkaddr(e, new_blkaddr);
>>  if (new_blkaddr == NEW_ADDR || new_blkaddr == NULL_ADDR)
>>  set_nat_flag(e, IS_CHECKPOINTED, false);
>> -__set_nat_cache_dirty(nm_i, e);
>> +__set_nat_cache_dirty(sbi, false, nm_i, e);
>>
>>  /* update fsync_mark if its inode nat entry is still alive */
>>  if (ni->nid != ni->ino)
>> @@ -2395,14 +2401,14 @@ static void remove_nats_in_journal(struct 
>> f2fs_sb_info *sbi)
>>  spin_unlock(_i->nid_list_lock);
>>  }
>>
>> -__set_nat_cache_dirty(nm_i, ne);
>> +__set_nat_cache_dirty(sbi, true, nm_i, ne);
>>  }
>>  update_nats_in_cursum(journal, -i);
>>  up_write(>journal_rwsem);
>>  }
>>
>> -static void __adjust_nat_entry_set(struct nat_entry_set *nes,
>> -struct list_head *head, int max)
>> +static void __adjust_nat_entry_set(struct f2fs_sb_info *sbi,
>> +struct nat_entry_set *nes, struct list_head *head, int max)
>>  {
>>  struct nat_entry_set *cur;
>>
>> @@ -2410,7 +2416,9 @@ static void __adjust_nat_entry_set(struct 
>> nat_entry_set *nes,
>>  goto add_out;
>>
>>  list_for_each_entry(cur, head, set_list) {
>> -if (cur->entry_cnt >= nes->entry_cnt) {
>> +if (cur->entry_cnt > nes->entry_cnt ||
>> +(cur->entry_cnt == nes->entry_cnt &&
>> +cur->cp_ver < nes->cp_ver)) {
>>  list_add(>set_list, cur->set_list.prev);
>>  return;
>>  }
>> @@ -2458,7 +2466,6 @@ static void __flush_nat_entry_set(struct f2fs_sb_info 
>> *sbi,
>>  str

Re: [f2fs-dev] [PATCH v4] f2fs: introduce a method to make nat journal more fresh

2018-03-27 Thread Chao Yu
On 2018/3/16 18:24, Yunlei He wrote:
> This patch introduce a method to make nat journal more fresh:
> i.  sort set list using dirty entry number and cp version
> average value.
> ii. if meet with cache hit, update average version valus with
> current cp version.
> 
> With this patch, newly modified nat set will flush to journal,
> and flush old nat set with same dirty entry number to nat area.
> 
> Signed-off-by: Yunlei He 
> ---
>  fs/f2fs/node.c | 39 ---
>  fs/f2fs/node.h |  4 +++-
>  2 files changed, 27 insertions(+), 16 deletions(-)
> 
> diff --git a/fs/f2fs/node.c b/fs/f2fs/node.c
> index 177c438..c511ef6 100644
> --- a/fs/f2fs/node.c
> +++ b/fs/f2fs/node.c
> @@ -193,8 +193,8 @@ static void __del_from_nat_cache(struct f2fs_nm_info 
> *nm_i, struct nat_entry *e)
>   __free_nat_entry(e);
>  }
>  
> -static void __set_nat_cache_dirty(struct f2fs_nm_info *nm_i,
> - struct nat_entry *ne)
> +static void __set_nat_cache_dirty(struct f2fs_sb_info *sbi, bool 
> remove_journal,
> + struct f2fs_nm_info *nm_i, struct nat_entry *ne)
>  {
>   nid_t set = NAT_BLOCK_OFFSET(ne->ni.nid);
>   struct nat_entry_set *head;
> @@ -207,12 +207,18 @@ static void __set_nat_cache_dirty(struct f2fs_nm_info 
> *nm_i,
>   INIT_LIST_HEAD(>set_list);
>   head->set = set;
>   head->entry_cnt = 0;
> + head->cp_ver = 0;

head->cp_ver = div_u64(cur_cp_version(F2FS_CKPT(sbi)), NAT_JOURNAL_ENTRIES)?

Thanks,

>   f2fs_radix_tree_insert(_i->nat_set_root, set, head);
>   }
>  
>   if (get_nat_flag(ne, IS_DIRTY))
>   goto refresh_list;
>  
> + /* journal hit case, try to locate set in journal */
> + if (!remove_journal && head->entry_cnt <= NAT_JOURNAL_ENTRIES)
> + head->cp_ver += div_u64(cur_cp_version(F2FS_CKPT(sbi)),
> + NAT_JOURNAL_ENTRIES);
> +
>   nm_i->dirty_nat_cnt++;
>   head->entry_cnt++;
>   set_nat_flag(ne, IS_DIRTY, true);
> @@ -357,7 +363,7 @@ static void set_node_addr(struct f2fs_sb_info *sbi, 
> struct node_info *ni,
>   nat_set_blkaddr(e, new_blkaddr);
>   if (new_blkaddr == NEW_ADDR || new_blkaddr == NULL_ADDR)
>   set_nat_flag(e, IS_CHECKPOINTED, false);
> - __set_nat_cache_dirty(nm_i, e);
> + __set_nat_cache_dirty(sbi, false, nm_i, e);
>  
>   /* update fsync_mark if its inode nat entry is still alive */
>   if (ni->nid != ni->ino)
> @@ -2395,14 +2401,14 @@ static void remove_nats_in_journal(struct 
> f2fs_sb_info *sbi)
>   spin_unlock(_i->nid_list_lock);
>   }
>  
> - __set_nat_cache_dirty(nm_i, ne);
> + __set_nat_cache_dirty(sbi, true, nm_i, ne);
>   }
>   update_nats_in_cursum(journal, -i);
>   up_write(>journal_rwsem);
>  }
>  
> -static void __adjust_nat_entry_set(struct nat_entry_set *nes,
> - struct list_head *head, int max)
> +static void __adjust_nat_entry_set(struct f2fs_sb_info *sbi,
> + struct nat_entry_set *nes, struct list_head *head, int max)
>  {
>   struct nat_entry_set *cur;
>  
> @@ -2410,7 +2416,9 @@ static void __adjust_nat_entry_set(struct nat_entry_set 
> *nes,
>   goto add_out;
>  
>   list_for_each_entry(cur, head, set_list) {
> - if (cur->entry_cnt >= nes->entry_cnt) {
> + if (cur->entry_cnt > nes->entry_cnt ||
> + (cur->entry_cnt == nes->entry_cnt &&
> + cur->cp_ver < nes->cp_ver)) {
>   list_add(>set_list, cur->set_list.prev);
>   return;
>   }
> @@ -2458,7 +2466,6 @@ static void __flush_nat_entry_set(struct f2fs_sb_info 
> *sbi,
>   struct curseg_info *curseg = CURSEG_I(sbi, CURSEG_HOT_DATA);
>   struct f2fs_journal *journal = curseg->journal;
>   nid_t start_nid = set->set * NAT_ENTRY_PER_BLOCK;
> - bool to_journal = true;
>   struct f2fs_nat_block *nat_blk;
>   struct nat_entry *ne, *cur;
>   struct page *page = NULL;
> @@ -2468,11 +2475,14 @@ static void __flush_nat_entry_set(struct f2fs_sb_info 
> *sbi,
>* #1, flush nat entries to journal in current hot data summary block.
>* #2, flush nat entries to nat page.
>*/
> +
> + set->to_journal = true;
> +
>   if (enabled_nat_bits(sbi, cpc) ||
>   !__has_cursum_space(journal, set->entry_cnt, NAT_JOURNAL))
> - to_journal = false;
> + set->to_journal = false;
>  
> - if (to_journal) {
> + if (set->to_journal) {
>   down_write(>journal_rwsem);
>   } else {
>   page = get_next_nat_page(sbi, start_nid);
> @@ -2488,7 +2498,7 @@ static void __flush_nat_entry_set(struct f2fs_sb_info 
> *sbi,
>  
>   f2fs_bug_on(sbi, 

[f2fs-dev] [PATCH v4] f2fs: introduce a method to make nat journal more fresh

2018-03-16 Thread Yunlei He
This patch introduce a method to make nat journal more fresh:
i.  sort set list using dirty entry number and cp version
average value.
ii. if meet with cache hit, update average version valus with
current cp version.

With this patch, newly modified nat set will flush to journal,
and flush old nat set with same dirty entry number to nat area.

Signed-off-by: Yunlei He 
---
 fs/f2fs/node.c | 39 ---
 fs/f2fs/node.h |  4 +++-
 2 files changed, 27 insertions(+), 16 deletions(-)

diff --git a/fs/f2fs/node.c b/fs/f2fs/node.c
index 177c438..c511ef6 100644
--- a/fs/f2fs/node.c
+++ b/fs/f2fs/node.c
@@ -193,8 +193,8 @@ static void __del_from_nat_cache(struct f2fs_nm_info *nm_i, 
struct nat_entry *e)
__free_nat_entry(e);
 }
 
-static void __set_nat_cache_dirty(struct f2fs_nm_info *nm_i,
-   struct nat_entry *ne)
+static void __set_nat_cache_dirty(struct f2fs_sb_info *sbi, bool 
remove_journal,
+   struct f2fs_nm_info *nm_i, struct nat_entry *ne)
 {
nid_t set = NAT_BLOCK_OFFSET(ne->ni.nid);
struct nat_entry_set *head;
@@ -207,12 +207,18 @@ static void __set_nat_cache_dirty(struct f2fs_nm_info 
*nm_i,
INIT_LIST_HEAD(>set_list);
head->set = set;
head->entry_cnt = 0;
+   head->cp_ver = 0;
f2fs_radix_tree_insert(_i->nat_set_root, set, head);
}
 
if (get_nat_flag(ne, IS_DIRTY))
goto refresh_list;
 
+   /* journal hit case, try to locate set in journal */
+   if (!remove_journal && head->entry_cnt <= NAT_JOURNAL_ENTRIES)
+   head->cp_ver += div_u64(cur_cp_version(F2FS_CKPT(sbi)),
+   NAT_JOURNAL_ENTRIES);
+
nm_i->dirty_nat_cnt++;
head->entry_cnt++;
set_nat_flag(ne, IS_DIRTY, true);
@@ -357,7 +363,7 @@ static void set_node_addr(struct f2fs_sb_info *sbi, struct 
node_info *ni,
nat_set_blkaddr(e, new_blkaddr);
if (new_blkaddr == NEW_ADDR || new_blkaddr == NULL_ADDR)
set_nat_flag(e, IS_CHECKPOINTED, false);
-   __set_nat_cache_dirty(nm_i, e);
+   __set_nat_cache_dirty(sbi, false, nm_i, e);
 
/* update fsync_mark if its inode nat entry is still alive */
if (ni->nid != ni->ino)
@@ -2395,14 +2401,14 @@ static void remove_nats_in_journal(struct f2fs_sb_info 
*sbi)
spin_unlock(_i->nid_list_lock);
}
 
-   __set_nat_cache_dirty(nm_i, ne);
+   __set_nat_cache_dirty(sbi, true, nm_i, ne);
}
update_nats_in_cursum(journal, -i);
up_write(>journal_rwsem);
 }
 
-static void __adjust_nat_entry_set(struct nat_entry_set *nes,
-   struct list_head *head, int max)
+static void __adjust_nat_entry_set(struct f2fs_sb_info *sbi,
+   struct nat_entry_set *nes, struct list_head *head, int max)
 {
struct nat_entry_set *cur;
 
@@ -2410,7 +2416,9 @@ static void __adjust_nat_entry_set(struct nat_entry_set 
*nes,
goto add_out;
 
list_for_each_entry(cur, head, set_list) {
-   if (cur->entry_cnt >= nes->entry_cnt) {
+   if (cur->entry_cnt > nes->entry_cnt ||
+   (cur->entry_cnt == nes->entry_cnt &&
+   cur->cp_ver < nes->cp_ver)) {
list_add(>set_list, cur->set_list.prev);
return;
}
@@ -2458,7 +2466,6 @@ static void __flush_nat_entry_set(struct f2fs_sb_info 
*sbi,
struct curseg_info *curseg = CURSEG_I(sbi, CURSEG_HOT_DATA);
struct f2fs_journal *journal = curseg->journal;
nid_t start_nid = set->set * NAT_ENTRY_PER_BLOCK;
-   bool to_journal = true;
struct f2fs_nat_block *nat_blk;
struct nat_entry *ne, *cur;
struct page *page = NULL;
@@ -2468,11 +2475,14 @@ static void __flush_nat_entry_set(struct f2fs_sb_info 
*sbi,
 * #1, flush nat entries to journal in current hot data summary block.
 * #2, flush nat entries to nat page.
 */
+
+   set->to_journal = true;
+
if (enabled_nat_bits(sbi, cpc) ||
!__has_cursum_space(journal, set->entry_cnt, NAT_JOURNAL))
-   to_journal = false;
+   set->to_journal = false;
 
-   if (to_journal) {
+   if (set->to_journal) {
down_write(>journal_rwsem);
} else {
page = get_next_nat_page(sbi, start_nid);
@@ -2488,7 +2498,7 @@ static void __flush_nat_entry_set(struct f2fs_sb_info 
*sbi,
 
f2fs_bug_on(sbi, nat_get_blkaddr(ne) == NEW_ADDR);
 
-   if (to_journal) {
+   if (set->to_journal) {
offset = lookup_journal_in_cursum(journal,
NAT_JOURNAL,