f2fs: introduce a method to make nat journal more fresh
PATCH v3 1/1 f2fs: introduce a method to make nat journal more fresh
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.
--- fs/f2fs/node.c | 45 ++++++++++++++++++++++++++------------------- fs/f2fs/node.h | 4 +++- 2 files changed, 29 insertions(+), 20 deletions(-)
fs/f2fs/node.c +26 -19
@@ -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,9 +207,15 @@ static void __set_nat_cache_dirty(struct f2fs_nm_info *nm_i,INIT_LIST_HEAD (&head->set_list); head->set = set; head->entry_cnt =0 ; + head->cp_ver =0 ;f2fs_radix_tree_insert (&nm_i->nat_set_root, set, head); } +/* 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 ); +if (get_nat_flag (ne,IS_DIRTY )) goto refresh_list;
@@ -217,10 +223,7 @@ static void __set_nat_cache_dirty(struct f2fs_nm_info *nm_i, head->entry_cnt++;set_nat_flag (ne,IS_DIRTY , true); refresh_list: -if (nat_get_blkaddr (ne) ==NEW_ADDR ) -list_del_init (&ne->list); -else -list_move_tail (&ne->list, &head->entry_list); +list_move_tail (&ne->list, &head->entry_list); } static void __clear_nat_cache_dirty(struct f2fs_nm_info *nm_i,
@@ -357,7 +360,8 @@ 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); +if (new_blkaddr !=NEW_ADDR ) +__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 +2399,14 @@ static void remove_nats_in_journal(struct f2fs_sb_info *sbi)spin_unlock (&nm_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 (&curseg->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 +2414,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 (&nes->set_list, cur->set_list.prev);return ; }
@@ -2458,7 +2464,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 +2473,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 (&curseg->journal_rwsem); }else { page =get_next_nat_page (sbi, start_nid);
@@ -2488,7 +2496,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 , nid,1 );f2fs_bug_on (sbi, offset <0 );
@@ -2509,7 +2517,7 @@ static void __flush_nat_entry_set(struct f2fs_sb_info *sbi, } } -if (to_journal) { +if (set->to_journal) {up_write (&curseg->journal_rwsem); }else {__update_nat_bits (sbi, start_nid, page);
@@ -2517,7 +2525,7 @@ static void __flush_nat_entry_set(struct f2fs_sb_info *sbi, }/* Allow dirty nats by node block allocation in write_begin */ -if (!set->entry_cnt) { +if (!set->to_journal) {radix_tree_delete (&NM_I (sbi)->nat_set_root, set->set);kmem_cache_free (nat_entry_set_slab, set); }
@@ -2556,7 +2564,7 @@ void flush_nat_entries(struct f2fs_sb_info *sbi, struct cp_control *cpc)unsigned idx; set_idx = setvec[found -1 ]->set +1 ;for (idx =0 ; idx < found; idx++) -__adjust_nat_entry_set (setvec[idx], &sets, +__adjust_nat_entry_set (sbi, setvec[idx], &sets,MAX_NAT_JENTRIES (journal)); }
@@ -2565,7 +2573,6 @@ void flush_nat_entries(struct f2fs_sb_info *sbi, struct cp_control *cpc)__flush_nat_entry_set (sbi, set, cpc);up_write (&nm_i->nat_tree_lock); -/* Allow dirty nats by node block allocation in write_begin */ }static int __get_nat_bitmaps (struct f2fs_sb_info *sbi)
fs/f2fs/node.h +3 -1
@@ -148,7 +148,9 @@ struct nat_entry_set {struct list_head set_list;/* link with other nat sets */ struct list_head entry_list;/* link with dirty nat entries */ nid_t set;/* set number*/ -unsigned int entry_cnt;/* the # of nat entries in set */ + unsigned int entry_cnt:9; /* the # of nat entries in set */ + unsigned int to_journal:1; /* set flush to journal */ +__u64 cp_ver;/* cp version of this set modify */ };struct free_nid {
Signature · 6 lines
1.9.1 ------------------------------------------------------------------------------ Check out the vibrant tech community on one of the world's most engaging tech sites, Slashdot.org! http://sdm.link/slashdot
Quoted 35 lines · 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 <[email protected]>--- fs/f2fs/node.c | 45 ++++++++++++++++++++++++++------------------- fs/f2fs/node.h | 4 +++- 2 files changed, 29 insertions(+), 20 deletions(-)fs/f2fs/node.c +3
-2@@ -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,9 +207,15 @@ static void __set_nat_cache_dirty(struct f2fs_nm_info *nm_i,INIT_LIST_HEAD (&head->set_list); head->set = set; head->entry_cnt =0 ; + head->cp_ver =0 ;
fs/f2fs/node.c static void __set_nat_cache_dirty(struct f2fs_nm_info *nm_i, · line 220
Quoted 10 lines
fs/f2fs/node.c +5
-0f2fs_radix_tree_insert (&nm_i->nat_set_root, set, head); } +/* 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 ); +if (get_nat_flag (ne,IS_DIRTY )) goto refresh_list;
else {
update head version here?
}fs/f2fs/node.c static void __set_nat_cache_dirty(struct f2fs_nm_info *nm_i, · line 226
Quoted 10 lines
fs/f2fs/node.c +1
-4@@ -217,10 +223,7 @@ static void __set_nat_cache_dirty(struct f2fs_nm_info *nm_i, head->entry_cnt++;set_nat_flag (ne,IS_DIRTY , true); refresh_list: -if (nat_get_blkaddr (ne) ==NEW_ADDR ) -list_del_init (&ne->list); -else -list_move_tail (&ne->list, &head->entry_list); +list_move_tail (&ne->list, &head->entry_list);
For NEW_ADDR case, why we need to track this nat entry in entry_list?
Quoted 86 lines
fs/f2fs/node.c +15
-10} static void __clear_nat_cache_dirty(struct f2fs_nm_info *nm_i,@@ -357,7 +360,8 @@ 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); +if (new_blkaddr !=NEW_ADDR ) +__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 +2399,14 @@ static void remove_nats_in_journal(struct f2fs_sb_info *sbi)spin_unlock (&nm_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 (&curseg->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 +2414,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 (&nes->set_list, cur->set_list.prev);return ; }@@ -2458,7 +2464,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 +2473,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 (&curseg->journal_rwsem); }else { page =get_next_nat_page (sbi, start_nid);@@ -2488,7 +2496,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 , nid,1 );f2fs_bug_on (sbi, offset <0 );@@ -2509,7 +2517,7 @@ static void __flush_nat_entry_set(struct f2fs_sb_info *sbi, } } -if (to_journal) { +if (set->to_journal) {up_write (&curseg->journal_rwsem); }else {__update_nat_bits (sbi, start_nid, page);
fs/f2fs/node.c static void __flush_nat_entry_set(struct f2fs_sb_info *sbi, · line 2528
Quoted 5 lines
fs/f2fs/node.c +1
-1@@ -2517,7 +2525,7 @@ static void __flush_nat_entry_set(struct f2fs_sb_info *sbi, }/* Allow dirty nats by node block allocation in write_begin */ -if (!set->entry_cnt) { +if (!set->to_journal) {
if (!set->to_journal && !set->entry_cnt) ?
Thanks,
Quoted 26 lines
fs/f2fs/node.c +1
-2radix_tree_delete (&NM_I (sbi)->nat_set_root, set->set);kmem_cache_free (nat_entry_set_slab, set); }@@ -2556,7 +2564,7 @@ void flush_nat_entries(struct f2fs_sb_info *sbi, struct cp_control *cpc)unsigned idx; set_idx = setvec[found -1 ]->set +1 ;for (idx =0 ; idx < found; idx++) -__adjust_nat_entry_set (setvec[idx], &sets, +__adjust_nat_entry_set (sbi, setvec[idx], &sets,MAX_NAT_JENTRIES (journal)); }@@ -2565,7 +2573,6 @@ void flush_nat_entries(struct f2fs_sb_info *sbi, struct cp_control *cpc)__flush_nat_entry_set (sbi, set, cpc);up_write (&nm_i->nat_tree_lock); -/* Allow dirty nats by node block allocation in write_begin */ }static int __get_nat_bitmaps (struct f2fs_sb_info *sbi)fs/f2fs/node.h +0
-0
fs/f2fs/node.h struct nat_entry_set { · line 156
Quoted 10 lines
fs/f2fs/node.h +3
-1@@ -148,7 +148,9 @@ struct nat_entry_set {struct list_head set_list;/* link with other nat sets */ struct list_head entry_list;/* link with dirty nat entries */ nid_t set;/* set number*/ -unsigned int entry_cnt;/* the # of nat entries in set */ + unsigned int entry_cnt:9; /* the # of nat entries in set */ + unsigned int to_journal:1; /* set flush to journal */ +__u64 cp_ver;/* cp version of this set modify */ };struct free_nid {
------------------------------------------------------------------------------
Check out the vibrant tech community on one of the world's most engaging tech sites, Slashdot.org! http://sdm.link/slashdot
Quoted 50 lines
-----Original Message-----
From: Yuchao (T)
Sent: Friday, March 16, 2018 4:49 PM
To: heyunlei; [email protected]; [email protected]
Cc: Wangbintian; Zhangdianfang (Euler)
Subject: Re: [f2fs-dev][PATCH v3] f2fs: introduce a method to make nat journal more freshQuoted 38 lines · 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 <[email protected]>--- fs/f2fs/node.c | 45 ++++++++++++++++++++++++++------------------- fs/f2fs/node.h | 4 +++- 2 files changed, 29 insertions(+), 20 deletions(-)fs/f2fs/node.c +3
-2@@ -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,9 +207,15 @@ static void __set_nat_cache_dirty(struct f2fs_nm_info *nm_i,INIT_LIST_HEAD (&head->set_list); head->set = set; head->entry_cnt =0 ; + head->cp_ver =0 ;f2fs_radix_tree_insert (&nm_i->nat_set_root, set, head); }
Quoted 11 lines
fs/f2fs/node.c static void __set_nat_cache_dirty(struct f2fs_nm_info *nm_i, · line 220
Quoted 7 lines
fs/f2fs/node.c +5
-0+/* 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 ); +if (get_nat_flag (ne,IS_DIRTY )) goto refresh_list;else { update head version here? }
Okay, if one nat entry update more than once, here will be overflow.
Quoted 13 lines
fs/f2fs/node.c static void __set_nat_cache_dirty(struct f2fs_nm_info *nm_i, · line 226
Quoted 11 lines
fs/f2fs/node.c +1
-4@@ -217,10 +223,7 @@ static void __set_nat_cache_dirty(struct f2fs_nm_info *nm_i, head->entry_cnt++;set_nat_flag (ne,IS_DIRTY , true); refresh_list: -if (nat_get_blkaddr (ne) ==NEW_ADDR ) -list_del_init (&ne->list); -else -list_move_tail (&ne->list, &head->entry_list); +list_move_tail (&ne->list, &head->entry_list);For
NEW_ADDRcase, why we need to track this nat entry inentry_list?
If new_blkaddr == NEW_ADDR, we don't need to call __set_nat_cache_dirty:
i nat entry with NEW_ADDR will increase dirty nat entry count in nat set,which will cause
a nat set has large nat entry count(most is NEW_ADDR), but fewer of nat entries should
be written back in this checkpoint
ii nat entry with NEW_ADDR will call __set_nat_cache_dirty again, when we write back its node
page, in this time, new_blkaddr != NEW_ADDR
So, I think we'd better bypass _set_nat_cache_dirty if blkaddr == NEW_ADDR
Thanks.
Quoted 131 lines
Quoted 87 lines
fs/f2fs/node.c +15
-10} static void __clear_nat_cache_dirty(struct f2fs_nm_info *nm_i,@@ -357,7 +360,8 @@ 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); +if (new_blkaddr !=NEW_ADDR ) +__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 +2399,14 @@ static void remove_nats_in_journal(struct f2fs_sb_info *sbi)spin_unlock (&nm_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 (&curseg->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 +2414,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 (&nes->set_list, cur->set_list.prev);return ; }@@ -2458,7 +2464,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 +2473,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 (&curseg->journal_rwsem); }else { page =get_next_nat_page (sbi, start_nid);@@ -2488,7 +2496,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 , nid,1 );f2fs_bug_on (sbi, offset <0 );@@ -2509,7 +2517,7 @@ static void __flush_nat_entry_set(struct f2fs_sb_info *sbi, } } -if (to_journal) { +if (set->to_journal) {up_write (&curseg->journal_rwsem); }else {__update_nat_bits (sbi, start_nid, page);fs/f2fs/node.c static void __flush_nat_entry_set(struct f2fs_sb_info *sbi, · line 2528
Quoted 5 lines
fs/f2fs/node.c +1
-1@@ -2517,7 +2525,7 @@ static void __flush_nat_entry_set(struct f2fs_sb_info *sbi, }/* Allow dirty nats by node block allocation in write_begin */ -if (!set->entry_cnt) { +if (!set->to_journal) {if (!set->to_journal && !set->entry_cnt) ?
Thanks,
Quoted 34 lines
fs/f2fs/node.c +1
-2radix_tree_delete (&NM_I (sbi)->nat_set_root, set->set);kmem_cache_free (nat_entry_set_slab, set); }@@ -2556,7 +2564,7 @@ void flush_nat_entries(struct f2fs_sb_info *sbi, struct cp_control *cpc)unsigned idx; set_idx = setvec[found -1 ]->set +1 ;for (idx =0 ; idx < found; idx++) -__adjust_nat_entry_set (setvec[idx], &sets, +__adjust_nat_entry_set (sbi, setvec[idx], &sets,MAX_NAT_JENTRIES (journal)); }@@ -2565,7 +2573,6 @@ void flush_nat_entries(struct f2fs_sb_info *sbi, struct cp_control *cpc)__flush_nat_entry_set (sbi, set, cpc);up_write (&nm_i->nat_tree_lock); -/* Allow dirty nats by node block allocation in write_begin */ }static int __get_nat_bitmaps (struct f2fs_sb_info *sbi)fs/f2fs/node.h +3
-1@@ -148,7 +148,9 @@ struct nat_entry_set {struct list_head set_list;/* link with other nat sets */ struct list_head entry_list;/* link with dirty nat entries */ nid_t set;/* set number*/ -unsigned int entry_cnt;/* the # of nat entries in set */ + unsigned int entry_cnt:9; /* the # of nat entries in set */ + unsigned int to_journal:1; /* set flush to journal */ +__u64 cp_ver;/* cp version of this set modify */ };
Quoted 2 lines
fs/f2fs/node.h struct nat_entry_set { · line 156
Quoted 2 lines
fs/f2fs/node.h +0
-0struct free_nid {
------------------------------------------------------------------------------
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 [email protected]
https://lists.sourceforge.net/lists/listinfo/linux-f2fs-devel
Quoted 78 lines · heyunlei
Quoted 50 lines
-----Original Message-----
From: Yuchao (T)
Sent: Friday, March 16, 2018 4:49 PM
To: heyunlei; [email protected]; [email protected]
Cc: Wangbintian; Zhangdianfang (Euler)
Subject: Re: [f2fs-dev][PATCH v3] f2fs: introduce a method to make nat journal more freshQuoted 38 lines · 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 <[email protected]>--- fs/f2fs/node.c | 45 ++++++++++++++++++++++++++------------------- fs/f2fs/node.h | 4 +++- 2 files changed, 29 insertions(+), 20 deletions(-)fs/f2fs/node.c +3
-2@@ -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,9 +207,15 @@ static void __set_nat_cache_dirty(struct f2fs_nm_info *nm_i,INIT_LIST_HEAD (&head->set_list); head->set = set; head->entry_cnt =0 ; + head->cp_ver =0 ;f2fs_radix_tree_insert (&nm_i->nat_set_root, set, head); }Quoted 11 lines
fs/f2fs/node.c static void __set_nat_cache_dirty(struct f2fs_nm_info *nm_i, · line 220
Quoted 7 lines
fs/f2fs/node.c +5
-0+/* 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 ); +if (get_nat_flag (ne,IS_DIRTY )) goto refresh_list;else { update head version here? }Okay, if one nat entry update more than once, here will be overflow.
Quoted 13 lines
fs/f2fs/node.c static void __set_nat_cache_dirty(struct f2fs_nm_info *nm_i, · line 226
Quoted 11 lines
fs/f2fs/node.c +1
-4@@ -217,10 +223,7 @@ static void __set_nat_cache_dirty(struct f2fs_nm_info *nm_i, head->entry_cnt++;set_nat_flag (ne,IS_DIRTY , true); refresh_list: -if (nat_get_blkaddr (ne) ==NEW_ADDR ) -list_del_init (&ne->list); -else -list_move_tail (&ne->list, &head->entry_list); +list_move_tail (&ne->list, &head->entry_list);For
NEW_ADDRcase, why we need to track this nat entry inentry_list?
Quoted 1 line
If
new_blkaddr==NEW_ADDR, we don't need to call__set_nat_cache_dirty:
But such entry is still in clean list, shrinker can easily remove it in out-of-memory condition.
Thanks,
Quoted 140 lines
i nat entry with
NEW_ADDRwill increase dirty nat entry count in nat set,which will cause
a nat set has large nat entry count(most is NEW_ADDR), but fewer of nat entries should
be written back in this checkpoint
ii nat entry withNEW_ADDRwill call__set_nat_cache_dirtyagain, when we write back its node
page, in this time,new_blkaddr!=NEW_ADDR
So, I think we'd better bypass_set_nat_cache_dirtyif blkaddr ==NEW_ADDRThanks.
Quoted 131 lines
Quoted 87 lines
fs/f2fs/node.c +15
-10} static void __clear_nat_cache_dirty(struct f2fs_nm_info *nm_i,@@ -357,7 +360,8 @@ 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); +if (new_blkaddr !=NEW_ADDR ) +__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 +2399,14 @@ static void remove_nats_in_journal(struct f2fs_sb_info *sbi)spin_unlock (&nm_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 (&curseg->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 +2414,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 (&nes->set_list, cur->set_list.prev);return ; }@@ -2458,7 +2464,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 +2473,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 (&curseg->journal_rwsem); }else { page =get_next_nat_page (sbi, start_nid);@@ -2488,7 +2496,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 , nid,1 );f2fs_bug_on (sbi, offset <0 );@@ -2509,7 +2517,7 @@ static void __flush_nat_entry_set(struct f2fs_sb_info *sbi, } } -if (to_journal) { +if (set->to_journal) {up_write (&curseg->journal_rwsem); }else {__update_nat_bits (sbi, start_nid, page);fs/f2fs/node.c static void __flush_nat_entry_set(struct f2fs_sb_info *sbi, · line 2528
Quoted 5 lines
fs/f2fs/node.c +1
-1@@ -2517,7 +2525,7 @@ static void __flush_nat_entry_set(struct f2fs_sb_info *sbi, }/* Allow dirty nats by node block allocation in write_begin */ -if (!set->entry_cnt) { +if (!set->to_journal) {if (!set->to_journal && !set->entry_cnt) ?
Thanks,
Quoted 34 lines
fs/f2fs/node.c +1
-2radix_tree_delete (&NM_I (sbi)->nat_set_root, set->set);kmem_cache_free (nat_entry_set_slab, set); }@@ -2556,7 +2564,7 @@ void flush_nat_entries(struct f2fs_sb_info *sbi, struct cp_control *cpc)unsigned idx; set_idx = setvec[found -1 ]->set +1 ;for (idx =0 ; idx < found; idx++) -__adjust_nat_entry_set (setvec[idx], &sets, +__adjust_nat_entry_set (sbi, setvec[idx], &sets,MAX_NAT_JENTRIES (journal)); }@@ -2565,7 +2573,6 @@ void flush_nat_entries(struct f2fs_sb_info *sbi, struct cp_control *cpc)__flush_nat_entry_set (sbi, set, cpc);up_write (&nm_i->nat_tree_lock); -/* Allow dirty nats by node block allocation in write_begin */ }static int __get_nat_bitmaps (struct f2fs_sb_info *sbi)fs/f2fs/node.h +3
-1@@ -148,7 +148,9 @@ struct nat_entry_set {struct list_head set_list;/* link with other nat sets */ struct list_head entry_list;/* link with dirty nat entries */ nid_t set;/* set number*/ -unsigned int entry_cnt;/* the # of nat entries in set */ + unsigned int entry_cnt:9; /* the # of nat entries in set */ + unsigned int to_journal:1; /* set flush to journal */ +__u64 cp_ver;/* cp version of this set modify */ };
Quoted 3 lines
Quoted 2 lines
fs/f2fs/node.h struct nat_entry_set { · line 156
Quoted 2 lines
fs/f2fs/node.h +0
-0struct free_nid {
------------------------------------------------------------------------------
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 [email protected]
https://lists.sourceforge.net/lists/listinfo/linux-f2fs-devel
Quoted 88 lines
-----Original Message-----
From: Yuchao (T)
Sent: Friday, March 16, 2018 5:47 PM
To: heyunlei; [email protected]; [email protected]
Cc: Wangbintian; Zhangdianfang (Euler)
Subject: Re: [f2fs-dev][PATCH v3] f2fs: introduce a method to make nat journal more freshQuoted 78 lines · heyunlei
Quoted 50 lines
-----Original Message-----
From: Yuchao (T)
Sent: Friday, March 16, 2018 4:49 PM
To: heyunlei; [email protected]; [email protected]
Cc: Wangbintian; Zhangdianfang (Euler)
Subject: Re: [f2fs-dev][PATCH v3] f2fs: introduce a method to make nat journal more freshQuoted 38 lines · 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 <[email protected]>--- fs/f2fs/node.c | 45 ++++++++++++++++++++++++++------------------- fs/f2fs/node.h | 4 +++- 2 files changed, 29 insertions(+), 20 deletions(-)fs/f2fs/node.c +3
-2@@ -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,9 +207,15 @@ static void __set_nat_cache_dirty(struct f2fs_nm_info *nm_i,INIT_LIST_HEAD (&head->set_list); head->set = set; head->entry_cnt =0 ; + head->cp_ver =0 ;f2fs_radix_tree_insert (&nm_i->nat_set_root, set, head); }Quoted 11 lines
fs/f2fs/node.c static void __set_nat_cache_dirty(struct f2fs_nm_info *nm_i, · line 220
Quoted 7 lines
fs/f2fs/node.c +5
-0+/* 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 ); +if (get_nat_flag (ne,IS_DIRTY )) goto refresh_list;else { update head version here? }Okay, if one nat entry update more than once, here will be overflow.
Quoted 13 lines
fs/f2fs/node.c static void __set_nat_cache_dirty(struct f2fs_nm_info *nm_i, · line 226
Quoted 11 lines
fs/f2fs/node.c +1
-4@@ -217,10 +223,7 @@ static void __set_nat_cache_dirty(struct f2fs_nm_info *nm_i, head->entry_cnt++;set_nat_flag (ne,IS_DIRTY , true); refresh_list: -if (nat_get_blkaddr (ne) ==NEW_ADDR ) -list_del_init (&ne->list); -else -list_move_tail (&ne->list, &head->entry_list); +list_move_tail (&ne->list, &head->entry_list);For
NEW_ADDRcase, why we need to track this nat entry inentry_list?
Quoted 4 lines
Quoted 1 line
If
new_blkaddr==NEW_ADDR, we don't need to call__set_nat_cache_dirty:But such entry is still in clean list, shrinker can easily remove it in out-of-memory condition.
Yes, you are right, my test doesn't cover low memory case. I 'll send a new version.
Thanks.
Quoted 146 lines
Thanks,
Quoted 143 lines
i nat entry with
NEW_ADDRwill increase dirty nat entry count in nat set,which will cause
a nat set has large nat entry count(most is NEW_ADDR), but fewer of nat entries should
be written back in this checkpoint
ii nat entry withNEW_ADDRwill call__set_nat_cache_dirtyagain, when we write back its node
page, in this time,new_blkaddr!=NEW_ADDR
So, I think we'd better bypass_set_nat_cache_dirtyif blkaddr ==NEW_ADDRThanks.
Quoted 133 lines
Quoted 87 lines
fs/f2fs/node.c +15
-10} static void __clear_nat_cache_dirty(struct f2fs_nm_info *nm_i,@@ -357,7 +360,8 @@ 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); +if (new_blkaddr !=NEW_ADDR ) +__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 +2399,14 @@ static void remove_nats_in_journal(struct f2fs_sb_info *sbi)spin_unlock (&nm_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 (&curseg->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 +2414,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 (&nes->set_list, cur->set_list.prev);return ; }@@ -2458,7 +2464,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 +2473,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 (&curseg->journal_rwsem); }else { page =get_next_nat_page (sbi, start_nid);@@ -2488,7 +2496,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 , nid,1 );f2fs_bug_on (sbi, offset <0 );@@ -2509,7 +2517,7 @@ static void __flush_nat_entry_set(struct f2fs_sb_info *sbi, } } -if (to_journal) { +if (set->to_journal) {up_write (&curseg->journal_rwsem); }else {__update_nat_bits (sbi, start_nid, page);fs/f2fs/node.c static void __flush_nat_entry_set(struct f2fs_sb_info *sbi, · line 2528
Quoted 5 lines
fs/f2fs/node.c +1
-1@@ -2517,7 +2525,7 @@ static void __flush_nat_entry_set(struct f2fs_sb_info *sbi, }/* Allow dirty nats by node block allocation in write_begin */ -if (!set->entry_cnt) { +if (!set->to_journal) {if (!set->to_journal && !set->entry_cnt) ?
Thanks,
Quoted 36 lines
fs/f2fs/node.c +1
-2radix_tree_delete (&NM_I (sbi)->nat_set_root, set->set);kmem_cache_free (nat_entry_set_slab, set); }@@ -2556,7 +2564,7 @@ void flush_nat_entries(struct f2fs_sb_info *sbi, struct cp_control *cpc)unsigned idx; set_idx = setvec[found -1 ]->set +1 ;for (idx =0 ; idx < found; idx++) -__adjust_nat_entry_set (setvec[idx], &sets, +__adjust_nat_entry_set (sbi, setvec[idx], &sets,MAX_NAT_JENTRIES (journal)); }@@ -2565,7 +2573,6 @@ void flush_nat_entries(struct f2fs_sb_info *sbi, struct cp_control *cpc)__flush_nat_entry_set (sbi, set, cpc);up_write (&nm_i->nat_tree_lock); -/* Allow dirty nats by node block allocation in write_begin */ }static int __get_nat_bitmaps (struct f2fs_sb_info *sbi)fs/f2fs/node.h +3
-1@@ -148,7 +148,9 @@ struct nat_entry_set {struct list_head set_list;/* link with other nat sets */ struct list_head entry_list;/* link with dirty nat entries */ nid_t set;/* set number*/ -unsigned int entry_cnt;/* the # of nat entries in set */ + unsigned int entry_cnt:9; /* the # of nat entries in set */ + unsigned int to_journal:1; /* set flush to journal */ +__u64 cp_ver;/* cp version of this set modify */ };struct free_nid {
------------------------------------------------------------------------------
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 [email protected]
https://lists.sourceforge.net/lists/listinfo/linux-f2fs-devel
Quoted 88 lines · heyunlei
Quoted 88 lines
-----Original Message-----
From: Yuchao (T)
Sent: Friday, March 16, 2018 5:47 PM
To: heyunlei; [email protected]; [email protected]
Cc: Wangbintian; Zhangdianfang (Euler)
Subject: Re: [f2fs-dev][PATCH v3] f2fs: introduce a method to make nat journal more freshQuoted 78 lines · heyunlei
Quoted 50 lines
-----Original Message-----
From: Yuchao (T)
Sent: Friday, March 16, 2018 4:49 PM
To: heyunlei; [email protected]; [email protected]
Cc: Wangbintian; Zhangdianfang (Euler)
Subject: Re: [f2fs-dev][PATCH v3] f2fs: introduce a method to make nat journal more freshQuoted 38 lines · 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 <[email protected]>--- fs/f2fs/node.c | 45 ++++++++++++++++++++++++++------------------- fs/f2fs/node.h | 4 +++- 2 files changed, 29 insertions(+), 20 deletions(-)fs/f2fs/node.c +3
-2@@ -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,9 +207,15 @@ static void __set_nat_cache_dirty(struct f2fs_nm_info *nm_i,INIT_LIST_HEAD (&head->set_list); head->set = set; head->entry_cnt =0 ; + head->cp_ver =0 ;f2fs_radix_tree_insert (&nm_i->nat_set_root, set, head); }Quoted 11 lines
fs/f2fs/node.c static void __set_nat_cache_dirty(struct f2fs_nm_info *nm_i, · line 220
Quoted 7 lines
fs/f2fs/node.c +5
-0+/* 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 ); +if (get_nat_flag (ne,IS_DIRTY )) goto refresh_list;else { update head version here? }Okay, if one nat entry update more than once, here will be overflow.
Quoted 13 lines
fs/f2fs/node.c static void __set_nat_cache_dirty(struct f2fs_nm_info *nm_i, · line 226
Quoted 11 lines
fs/f2fs/node.c +1
-4@@ -217,10 +223,7 @@ static void __set_nat_cache_dirty(struct f2fs_nm_info *nm_i, head->entry_cnt++;set_nat_flag (ne,IS_DIRTY , true); refresh_list: -if (nat_get_blkaddr (ne) ==NEW_ADDR ) -list_del_init (&ne->list); -else -list_move_tail (&ne->list, &head->entry_list); +list_move_tail (&ne->list, &head->entry_list);For
NEW_ADDRcase, why we need to track this nat entry inentry_list?
Quoted 6 lines
Quoted 4 lines
Quoted 1 line
If
new_blkaddr==NEW_ADDR, we don't need to call__set_nat_cache_dirty:But such entry is still in clean list, shrinker can easily remove it in out-of-memory condition.
Yes, you are right, my test doesn't cover low memory case. I 'll send a new version.
How about adding below patch before current one?
Subject: [PATCH] f2fs: don't track new nat entry in nat set
Nat entry set is used only in checkpoint(), and during checkpoint() we won't flush new nat entry with unallocated address, so we don't need to add new nat entry into nat set, then nat_entry_set::entry_cnt can indicate actual entry count we need to flush in checkpoint().
--- fs/f2fs/node.c | 20 ++++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-)
fs/f2fs/node.c +16 -4
@@ -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 struct nat_entry_set *__grab_nat_entry_set (struct f2fs_nm_info *nm_i, +struct nat_entry *ne) {nid_t set =NAT_BLOCK_OFFSET (ne->ni.nid);struct nat_entry_set *head;
@@ -209,15 +209,27 @@ static void __set_nat_cache_dirty(struct f2fs_nm_info *nm_i, head->entry_cnt =0 ;f2fs_radix_tree_insert (&nm_i->nat_set_root, set, head); } +return head; +} + +static void __set_nat_cache_dirty (struct f2fs_nm_info *nm_i, +struct nat_entry *ne) +{ +struct nat_entry_set *head; +bool new_ne =nat_get_blkaddr (ne) ==NEW_ADDR ; + +if (!new_ne) + head =__grab_nat_entry_set (nm_i, ne);if (get_nat_flag (ne,IS_DIRTY )) goto refresh_list; nm_i->dirty_nat_cnt++; - head->entry_cnt++; +if (!new_ne) + head->entry_cnt++;set_nat_flag (ne,IS_DIRTY , true); refresh_list: -if (nat_get_blkaddr (ne) ==NEW_ADDR ) +if (new_ne)list_del_init (&ne->list);else list_move_tail (&ne->list, &head->entry_list);
Signature · 3 lines
2.15.0.55.gc2ece9dc4de6 Thanks,
Quoted 150 lines
Thanks.
Quoted 146 lines
Thanks,
Quoted 143 lines
i nat entry with
NEW_ADDRwill increase dirty nat entry count in nat set,which will cause
a nat set has large nat entry count(most is NEW_ADDR), but fewer of nat entries should
be written back in this checkpoint
ii nat entry withNEW_ADDRwill call__set_nat_cache_dirtyagain, when we write back its node
page, in this time,new_blkaddr!=NEW_ADDR
So, I think we'd better bypass_set_nat_cache_dirtyif blkaddr ==NEW_ADDRThanks.
Quoted 133 lines
Quoted 87 lines
fs/f2fs/node.c +15
-10} static void __clear_nat_cache_dirty(struct f2fs_nm_info *nm_i,@@ -357,7 +360,8 @@ 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); +if (new_blkaddr !=NEW_ADDR ) +__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 +2399,14 @@ static void remove_nats_in_journal(struct f2fs_sb_info *sbi)spin_unlock (&nm_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 (&curseg->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 +2414,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 (&nes->set_list, cur->set_list.prev);return ; }@@ -2458,7 +2464,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 +2473,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 (&curseg->journal_rwsem); }else { page =get_next_nat_page (sbi, start_nid);@@ -2488,7 +2496,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 , nid,1 );f2fs_bug_on (sbi, offset <0 );@@ -2509,7 +2517,7 @@ static void __flush_nat_entry_set(struct f2fs_sb_info *sbi, } } -if (to_journal) { +if (set->to_journal) {up_write (&curseg->journal_rwsem); }else {__update_nat_bits (sbi, start_nid, page);fs/f2fs/node.c static void __flush_nat_entry_set(struct f2fs_sb_info *sbi, · line 2528
Quoted 5 lines
fs/f2fs/node.c +1
-1@@ -2517,7 +2525,7 @@ static void __flush_nat_entry_set(struct f2fs_sb_info *sbi, }/* Allow dirty nats by node block allocation in write_begin */ -if (!set->entry_cnt) { +if (!set->to_journal) {if (!set->to_journal && !set->entry_cnt) ?
Thanks,
Quoted 36 lines
fs/f2fs/node.c +1
-2radix_tree_delete (&NM_I (sbi)->nat_set_root, set->set);kmem_cache_free (nat_entry_set_slab, set); }@@ -2556,7 +2564,7 @@ void flush_nat_entries(struct f2fs_sb_info *sbi, struct cp_control *cpc)unsigned idx; set_idx = setvec[found -1 ]->set +1 ;for (idx =0 ; idx < found; idx++) -__adjust_nat_entry_set (setvec[idx], &sets, +__adjust_nat_entry_set (sbi, setvec[idx], &sets,MAX_NAT_JENTRIES (journal)); }@@ -2565,7 +2573,6 @@ void flush_nat_entries(struct f2fs_sb_info *sbi, struct cp_control *cpc)__flush_nat_entry_set (sbi, set, cpc);up_write (&nm_i->nat_tree_lock); -/* Allow dirty nats by node block allocation in write_begin */ }static int __get_nat_bitmaps (struct f2fs_sb_info *sbi)fs/f2fs/node.h +3
-1@@ -148,7 +148,9 @@ struct nat_entry_set {struct list_head set_list;/* link with other nat sets */ struct list_head entry_list;/* link with dirty nat entries */ nid_t set;/* set number*/ -unsigned int entry_cnt;/* the # of nat entries in set */ + unsigned int entry_cnt:9; /* the # of nat entries in set */ + unsigned int to_journal:1; /* set flush to journal */ +__u64 cp_ver;/* cp version of this set modify */ };struct free_nid {
------------------------------------------------------------------------------
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 [email protected]
https://lists.sourceforge.net/lists/listinfo/linux-f2fs-devel
Quoted 160 lines
-----Original Message-----
From: Yuchao (T)
Sent: Monday, March 19, 2018 10:10 AM
To: heyunlei; [email protected]; [email protected]
Cc: Wangbintian; Zhangdianfang (Euler)
Subject: Re: [f2fs-dev][PATCH v3] f2fs: introduce a method to make nat journal more freshQuoted 88 lines · heyunlei
Quoted 88 lines
-----Original Message-----
From: Yuchao (T)
Sent: Friday, March 16, 2018 5:47 PM
To: heyunlei; [email protected]; [email protected]
Cc: Wangbintian; Zhangdianfang (Euler)
Subject: Re: [f2fs-dev][PATCH v3] f2fs: introduce a method to make nat journal more freshQuoted 78 lines · heyunlei
Quoted 50 lines
-----Original Message-----
From: Yuchao (T)
Sent: Friday, March 16, 2018 4:49 PM
To: heyunlei; [email protected]; [email protected]
Cc: Wangbintian; Zhangdianfang (Euler)
Subject: Re: [f2fs-dev][PATCH v3] f2fs: introduce a method to make nat journal more freshQuoted 38 lines · 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 <[email protected]>--- fs/f2fs/node.c | 45 ++++++++++++++++++++++++++------------------- fs/f2fs/node.h | 4 +++- 2 files changed, 29 insertions(+), 20 deletions(-)fs/f2fs/node.c +3
-2@@ -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,9 +207,15 @@ static void __set_nat_cache_dirty(struct f2fs_nm_info *nm_i,INIT_LIST_HEAD (&head->set_list); head->set = set; head->entry_cnt =0 ; + head->cp_ver =0 ;f2fs_radix_tree_insert (&nm_i->nat_set_root, set, head); }Quoted 11 lines
fs/f2fs/node.c static void __set_nat_cache_dirty(struct f2fs_nm_info *nm_i, · line 220
Quoted 7 lines
fs/f2fs/node.c +5
-0+/* 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 ); +if (get_nat_flag (ne,IS_DIRTY )) goto refresh_list;else { update head version here? }Okay, if one nat entry update more than once, here will be overflow.
Quoted 13 lines
fs/f2fs/node.c static void __set_nat_cache_dirty(struct f2fs_nm_info *nm_i, · line 226
Quoted 11 lines
fs/f2fs/node.c +1
-4@@ -217,10 +223,7 @@ static void __set_nat_cache_dirty(struct f2fs_nm_info *nm_i, head->entry_cnt++;set_nat_flag (ne,IS_DIRTY , true); refresh_list: -if (nat_get_blkaddr (ne) ==NEW_ADDR ) -list_del_init (&ne->list); -else -list_move_tail (&ne->list, &head->entry_list); +list_move_tail (&ne->list, &head->entry_list);For
NEW_ADDRcase, why we need to track this nat entry inentry_list?Quoted 6 lines
Quoted 4 lines
Quoted 1 line
If
new_blkaddr==NEW_ADDR, we don't need to call__set_nat_cache_dirty:But such entry is still in clean list, shrinker can easily remove it in out-of-memory condition.
Yes, you are right, my test doesn't cover low memory case. I 'll send a new version.
How about adding below patch before current one?
Subject: [PATCH] f2fs: don't track new nat entry in nat set
Nat entry set is used only in
checkpoint(), and duringcheckpoint()we won't flush new nat entry with unallocated address, so we don't need to add new nat entry into nat set, thennat_entry_set::entry_cntcan indicate actual entry count we need to flush incheckpoint().---
fs/f2fs/node.c| 20 ++++++++++++++++----1 file changed, 16 insertions(+), 4 deletions(-)fs/f2fs/node.c +15
-3@@ -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 struct nat_entry_set *__grab_nat_entry_set (struct f2fs_nm_info *nm_i, +struct nat_entry *ne) {nid_t set =NAT_BLOCK_OFFSET (ne->ni.nid);struct nat_entry_set *head;@@ -209,15 +209,27 @@ static void __set_nat_cache_dirty(struct f2fs_nm_info *nm_i, head->entry_cnt =0 ;f2fs_radix_tree_insert (&nm_i->nat_set_root, set, head); } +return head; +} + +static void __set_nat_cache_dirty (struct f2fs_nm_info *nm_i, +struct nat_entry *ne) +{ +struct nat_entry_set *head; +bool new_ne =nat_get_blkaddr (ne) ==NEW_ADDR ; + +if (!new_ne) + head =__grab_nat_entry_set (nm_i, ne);if (get_nat_flag (ne,IS_DIRTY )) goto refresh_list; nm_i->dirty_nat_cnt++; - head->entry_cnt++; +if (!new_ne) + head->entry_cnt++;set_nat_flag (ne,IS_DIRTY , true);
refresh_list:fs/f2fs/node.c +1
-1-if (nat_get_blkaddr (ne) ==NEW_ADDR ) +if (new_ne)
Quoted 3 lines
list_del_init(&ne->list); else list_move_tail(&ne->list, &head->entry_list);
Okay, it looks good to me.
Thanks.
Quoted 155 lines
--
2.15.0.55.gc2ece9dc4de6Thanks,
Quoted 150 lines
Thanks.
Quoted 146 lines
Thanks,
Quoted 143 lines
i nat entry with
NEW_ADDRwill increase dirty nat entry count in nat set,which will cause
a nat set has large nat entry count(most is NEW_ADDR), but fewer of nat entries should
be written back in this checkpoint
ii nat entry withNEW_ADDRwill call__set_nat_cache_dirtyagain, when we write back its node
page, in this time,new_blkaddr!=NEW_ADDR
So, I think we'd better bypass_set_nat_cache_dirtyif blkaddr ==NEW_ADDRThanks.
Quoted 133 lines
Quoted 87 lines
fs/f2fs/node.c +15
-10} static void __clear_nat_cache_dirty(struct f2fs_nm_info *nm_i,@@ -357,7 +360,8 @@ 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); +if (new_blkaddr !=NEW_ADDR ) +__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 +2399,14 @@ static void remove_nats_in_journal(struct f2fs_sb_info *sbi)spin_unlock (&nm_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 (&curseg->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 +2414,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 (&nes->set_list, cur->set_list.prev);return ; }@@ -2458,7 +2464,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 +2473,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 (&curseg->journal_rwsem); }else { page =get_next_nat_page (sbi, start_nid);@@ -2488,7 +2496,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 , nid,1 );f2fs_bug_on (sbi, offset <0 );@@ -2509,7 +2517,7 @@ static void __flush_nat_entry_set(struct f2fs_sb_info *sbi, } } -if (to_journal) { +if (set->to_journal) {up_write (&curseg->journal_rwsem); }else {__update_nat_bits (sbi, start_nid, page);fs/f2fs/node.c static void __flush_nat_entry_set(struct f2fs_sb_info *sbi, · line 2528
Quoted 5 lines
fs/f2fs/node.c +1
-1@@ -2517,7 +2525,7 @@ static void __flush_nat_entry_set(struct f2fs_sb_info *sbi, }/* Allow dirty nats by node block allocation in write_begin */ -if (!set->entry_cnt) { +if (!set->to_journal) {if (!set->to_journal && !set->entry_cnt) ?
Thanks,
Quoted 36 lines
fs/f2fs/node.c +1
-2radix_tree_delete (&NM_I (sbi)->nat_set_root, set->set);kmem_cache_free (nat_entry_set_slab, set); }@@ -2556,7 +2564,7 @@ void flush_nat_entries(struct f2fs_sb_info *sbi, struct cp_control *cpc)unsigned idx; set_idx = setvec[found -1 ]->set +1 ;for (idx =0 ; idx < found; idx++) -__adjust_nat_entry_set (setvec[idx], &sets, +__adjust_nat_entry_set (sbi, setvec[idx], &sets,MAX_NAT_JENTRIES (journal)); }@@ -2565,7 +2573,6 @@ void flush_nat_entries(struct f2fs_sb_info *sbi, struct cp_control *cpc)__flush_nat_entry_set (sbi, set, cpc);up_write (&nm_i->nat_tree_lock); -/* Allow dirty nats by node block allocation in write_begin */ }static int __get_nat_bitmaps (struct f2fs_sb_info *sbi)fs/f2fs/node.h +3
-1@@ -148,7 +148,9 @@ struct nat_entry_set {struct list_head set_list;/* link with other nat sets */ struct list_head entry_list;/* link with dirty nat entries */ nid_t set;/* set number*/ -unsigned int entry_cnt;/* the # of nat entries in set */ + unsigned int entry_cnt:9; /* the # of nat entries in set */ + unsigned int to_journal:1; /* set flush to journal */ +__u64 cp_ver;/* cp version of this set modify */ };struct free_nid {
------------------------------------------------------------------------------
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 [email protected]
https://lists.sourceforge.net/lists/listinfo/linux-f2fs-devel