Skip to content

Commit 780de47

Browse files
chaseyuJaegeuk Kim
authored andcommitted
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(). Signed-off-by: Yunlei He <heyunlei@huawei.com> Signed-off-by: Chao Yu <yuchao0@huawei.com> Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
1 parent df033ca commit 780de47

2 files changed

Lines changed: 26 additions & 4 deletions

File tree

‎fs/f2fs/node.c‎

Lines changed: 25 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -193,8 +193,8 @@ static void __del_from_nat_cache(struct f2fs_nm_info *nm_i, struct nat_entry *e)
193193
__free_nat_entry(e);
194194
}
195195

196-
static void __set_nat_cache_dirty(struct f2fs_nm_info *nm_i,
197-
struct nat_entry *ne)
196+
static struct nat_entry_set *__grab_nat_entry_set(struct f2fs_nm_info *nm_i,
197+
struct nat_entry *ne)
198198
{
199199
nid_t set = NAT_BLOCK_OFFSET(ne->ni.nid);
200200
struct nat_entry_set *head;
@@ -209,15 +209,36 @@ static void __set_nat_cache_dirty(struct f2fs_nm_info *nm_i,
209209
head->entry_cnt = 0;
210210
f2fs_radix_tree_insert(&nm_i->nat_set_root, set, head);
211211
}
212+
return head;
213+
}
214+
215+
static void __set_nat_cache_dirty(struct f2fs_nm_info *nm_i,
216+
struct nat_entry *ne)
217+
{
218+
struct nat_entry_set *head;
219+
bool new_ne = nat_get_blkaddr(ne) == NEW_ADDR;
220+
221+
if (!new_ne)
222+
head = __grab_nat_entry_set(nm_i, ne);
223+
224+
/*
225+
* update entry_cnt in below condition:
226+
* 1. update NEW_ADDR to valid block address;
227+
* 2. update old block address to new one;
228+
*/
229+
if (!new_ne && (get_nat_flag(ne, IS_PREALLOC) ||
230+
!get_nat_flag(ne, IS_DIRTY)))
231+
head->entry_cnt++;
232+
233+
set_nat_flag(ne, IS_PREALLOC, new_ne);
212234

213235
if (get_nat_flag(ne, IS_DIRTY))
214236
goto refresh_list;
215237

216238
nm_i->dirty_nat_cnt++;
217-
head->entry_cnt++;
218239
set_nat_flag(ne, IS_DIRTY, true);
219240
refresh_list:
220-
if (nat_get_blkaddr(ne) == NEW_ADDR)
241+
if (new_ne)
221242
list_del_init(&ne->list);
222243
else
223244
list_move_tail(&ne->list, &head->entry_list);

‎fs/f2fs/node.h‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ enum {
4444
HAS_FSYNCED_INODE, /* is the inode fsynced before? */
4545
HAS_LAST_FSYNC, /* has the latest node fsync mark? */
4646
IS_DIRTY, /* this nat entry is dirty? */
47+
IS_PREALLOC, /* nat entry is preallocated */
4748
};
4849

4950
/*

0 commit comments

Comments
 (0)