f2fs: rebuild nat_bits during umount
Chao Yu
maintainerPATCH v4 1/1 f2fs: rebuild nat_bits during umount
If all free_nat_bitmap are available, we can rebuild nat_bits from free_nat_bitmap entirely during umount, let's make another chance to reenable nat_bits for image.
Signed-off-by Chao Yu <[email protected]>
---
v4:
- rebase to last dev-branch
fs/f2fs/checkpoint.c | 21 ++++++--- fs/f2fs/f2fs.h | 32 +------------- fs/f2fs/node.c | 101 +++++++++++++++++++++++++++++++++---------- 3 files changed, 95 insertions(+), 59 deletions(-)
fs/f2fs/checkpoint.c +15 -6
@@ -1302,12 +1302,20 @@ static void update_ckpt_flags(struct f2fs_sb_info *sbi, struct cp_control *cpc)struct f2fs_checkpoint *ckpt =F2FS_CKPT (sbi);unsigned long flags; -spin_lock_irqsave (&sbi->cp_lock, flags); +if (cpc->reason &CP_UMOUNT ) { +if (le32_to_cpu (ckpt->cp_pack_total_block_count) > + sbi->blocks_per_seg -NM_I (sbi)->nat_bits_blocks) { +clear_ckpt_flags (sbi,CP_NAT_BITS_FLAG ); +f2fs_notice (sbi,"Disable nat_bits due to no space" ); + }else if (!is_set_ckpt_flags (sbi,CP_NAT_BITS_FLAG ) && +f2fs_nat_bitmap_enabled (sbi)) { +f2fs_enable_nat_bits (sbi); +set_ckpt_flags (sbi,CP_NAT_BITS_FLAG ); +f2fs_notice (sbi,"Rebuild and enable nat_bits" ); + } + } -if ((cpc->reason &CP_UMOUNT ) && -le32_to_cpu (ckpt->cp_pack_total_block_count) > - sbi->blocks_per_seg -NM_I (sbi)->nat_bits_blocks) -disable_nat_bits (sbi, false); +spin_lock_irqsave (&sbi->cp_lock, flags);if (cpc->reason &CP_TRIMMED )__set_ckpt_flags (ckpt,CP_TRIMMED_FLAG );
@@ -1493,7 +1501,8 @@ static int do_checkpoint(struct f2fs_sb_info *sbi, struct cp_control *cpc) start_blk =__start_cp_next_addr (sbi);/* write nat bits */ -if (enabled_nat_bits (sbi, cpc)) { +if ((cpc->reason &CP_UMOUNT ) && +is_set_ckpt_flags (sbi,CP_NAT_BITS_FLAG )) {__u64 cp_ver =cur_cp_version (ckpt);block_t blk;
fs/f2fs/f2fs.h +2 -30
@@ -2078,36 +2078,6 @@ static inline void clear_ckpt_flags(struct f2fs_sb_info *sbi, unsigned int f)spin_unlock_irqrestore (&sbi->cp_lock, flags); } -static inline void disable_nat_bits (struct f2fs_sb_info *sbi,bool lock) -{ -unsigned long flags; -unsigned char *nat_bits; - -/* -* In order to re-enable nat_bits we need to call fsck.f2fs by -* set_sbi_flag(sbi, SBI_NEED_FSCK). But it may give huge cost, -* so let's rely on regular fsck or unclean shutdown. -*/ - -if (lock) -spin_lock_irqsave (&sbi->cp_lock, flags); -__clear_ckpt_flags (F2FS_CKPT (sbi),CP_NAT_BITS_FLAG ); - nat_bits =NM_I (sbi)->nat_bits; -NM_I (sbi)->nat_bits =NULL ; -if (lock) -spin_unlock_irqrestore (&sbi->cp_lock, flags); - -kvfree (nat_bits); -} - -static inline bool enabled_nat_bits (struct f2fs_sb_info *sbi, -struct cp_control *cpc) -{ -bool set =is_set_ckpt_flags (sbi,CP_NAT_BITS_FLAG ); - -return (cpc) ? (cpc->reason &CP_UMOUNT ) && set : set; -} -static inline void f2fs_lock_op (struct f2fs_sb_info *sbi) {down_read (&sbi->cp_rwsem);
@@ -3543,6 +3513,7 @@ int f2fs_truncate_inode_blocks(struct inode *inode, pgoff_t from);int f2fs_truncate_xattr_node (struct inode *inode);int f2fs_wait_on_node_pages_writeback (struct f2fs_sb_info *sbi,unsigned int seq_id); +bool f2fs_nat_bitmap_enabled (struct f2fs_sb_info *sbi);int f2fs_remove_inode_page (struct inode *inode);struct page *f2fs_new_inode_page (struct inode *inode);struct page *f2fs_new_node_page (struct dnode_of_data *dn,unsigned int ofs);
@@ -3567,6 +3538,7 @@ int f2fs_recover_xattr_data(struct inode *inode, struct page *page);int f2fs_recover_inode_page (struct f2fs_sb_info *sbi,struct page *page);int f2fs_restore_node_summary (struct f2fs_sb_info *sbi,unsigned int segno,struct f2fs_summary_block *sum); +void f2fs_enable_nat_bits (struct f2fs_sb_info *sbi);int f2fs_flush_nat_entries (struct f2fs_sb_info *sbi,struct cp_control *cpc);int f2fs_build_node_manager (struct f2fs_sb_info *sbi);void f2fs_destroy_node_manager (struct f2fs_sb_info *sbi);
fs/f2fs/node.c +78 -23
178 lines not on this page · raw message
Signature · 8 lines
2.32.0 _______________________________________________ Linux-f2fs-devel mailing list [email protected] https://lists.sourceforge.net/lists/listinfo/linux-f2fs-devel