f2fs: clean up with F2FS_BLK_ALIGN
Chao Yu
maintainerPATCH 1/2 f2fs: clean up with F2FS_BLK_ALIGN
From: Chao Yu <[email protected]>
Clean up F2FS_BYTES_TO_BLK(x + F2FS_BLKSIZE - 1) with F2FS_BLK_ALIGN(x).
Signed-off-by Chao Yu <[email protected]>
--- fs/f2fs/file.c | 3 +-- fs/f2fs/node.c | 3 +-- 2 files changed, 2 insertions(+), 4 deletions(-)
fs/f2fs/file.c +1 -2
@@ -573,7 +573,6 @@ static int truncate_partial_data_page(struct inode *inode, u64 from,int truncate_blocks (struct inode *inode,u64 from,bool lock) {struct f2fs_sb_info *sbi =F2FS_I_SB (inode); -unsigned int blocksize = inode->i_sb->s_blocksize;struct dnode_of_data dn;pgoff_t free_from;int count =0 , err =0 ;
@@ -582,7 +581,7 @@ int truncate_blocks(struct inode *inode, u64 from, bool lock)trace_f2fs_truncate_blocks_enter (inode, from); - free_from = (pgoff_t )F2FS_BYTES_TO_BLK (from + blocksize -1 ); + free_from = (pgoff_t )F2FS_BLK_ALIGN (from);if (free_from >= sbi->max_file_blocks) goto free_partial;
fs/f2fs/node.c +1 -2
@@ -2581,8 +2581,7 @@ static int __get_nat_bitmaps(struct f2fs_sb_info *sbi)if (!enabled_nat_bits (sbi,NULL ))return 0 ; - nm_i->nat_bits_blocks =F2FS_BYTES_TO_BLK ((nat_bits_bytes <<1 ) +8 + -F2FS_BLKSIZE -1 ); + nm_i->nat_bits_blocks =F2FS_BLK_ALIGN ((nat_bits_bytes <<1 ) +8 ); nm_i->nat_bits =f2fs_kzalloc (sbi, nm_i->nat_bits_blocks <<F2FS_BLKSIZE_BITS ,GFP_KERNEL );if (!nm_i->nat_bits)
Signature · 1 line
2.16.2.17.g38e79b1fd
Chao Yu
maintainerPATCH 2/2 f2fs: don't track new nat entry in nat set
From: Chao Yu <[email protected]>
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 <[email protected]>
Signed-off-by Chao Yu <[email protected]>
--- fs/f2fs/node.c | 29 +++++++++++++++++++++++++---- fs/f2fs/node.h | 1 + 2 files changed, 26 insertions(+), 4 deletions(-)
fs/f2fs/node.c +25 -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,36 @@ 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); + +/* +* update entry_cnt in below condition: +* 1. update NEW_ADDR to valid block address; +* 2. update old block address to new one; +*/ +if (!new_ne && (get_nat_flag (ne,IS_PREALLOC ) || + !get_nat_flag (ne,IS_DIRTY ))) + head->entry_cnt++; + +set_nat_flag (ne,IS_PREALLOC , new_ne);if (get_nat_flag (ne,IS_DIRTY )) goto refresh_list; nm_i->dirty_nat_cnt++; - 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);
fs/f2fs/node.h +1 -0
@@ -44,6 +44,7 @@ enum {HAS_FSYNCED_INODE ,/* is the inode fsynced before? */ HAS_LAST_FSYNC ,/* has the latest node fsync mark? */ IS_DIRTY ,/* this nat entry is dirty? */ + IS_PREALLOC, /* nat entry is preallocated */ };/*
Signature · 1 line
2.16.2.17.g38e79b1fd