f2fs: zone: introduce first_zoned_segno in f2fs_sb_info
Chao Yu
maintainerPATCH 1/3 f2fs: zone: introduce first_zoned_segno in f2fs_sb_info
first_zoned_segno() returns a fixed value, let's cache it in structure f2fs_sb_info to avoid redundant calculation.
--- fs/f2fs/f2fs.h | 1 + fs/f2fs/segment.c | 4 ++-- fs/f2fs/segment.h | 10 ---------- fs/f2fs/super.c | 13 +++++++++++++ 4 files changed, 16 insertions(+), 12 deletions(-)
fs/f2fs/f2fs.h +1 -0
@@ -1760,6 +1760,7 @@ struct f2fs_sb_info {unsigned int dirty_device;/* for checkpoint data flush */ spinlock_t dev_lock;/* protect dirty_device */ bool aligned_blksize;/* all devices has the same logical blksize */ +unsigned int first_zoned_segno;/* first zoned segno */ /* For write statistics */ u64 sectors_written_start;
fs/f2fs/segment.c +2 -2
@@ -2732,7 +2732,7 @@ static int get_new_segment(struct f2fs_sb_info *sbi,if (sbi->blkzone_alloc_policy ==BLKZONE_ALLOC_PRIOR_CONV || pinning) segno =0 ;else - segno =max (first_zoned_segno (sbi), *newseg); + segno =max (sbi->first_zoned_segno, *newseg); hint = GET_SEC_FROM_SEG(sbi, segno); }#endif
@@ -2744,7 +2744,7 @@ static int get_new_segment(struct f2fs_sb_info *sbi,if (secno >=MAIN_SECS (sbi) &&f2fs_sb_has_blkzoned (sbi)) {/* Write only to sequential zones */ if (sbi->blkzone_alloc_policy ==BLKZONE_ALLOC_ONLY_SEQ ) { - hint =GET_SEC_FROM_SEG (sbi,first_zoned_segno (sbi)); + hint =GET_SEC_FROM_SEG (sbi, sbi->first_zoned_segno); secno =find_next_zero_bit (free_i->free_secmap,MAIN_SECS (sbi), hint); }else secno = find_first_zero_bit(free_i->free_secmap,
fs/f2fs/segment.h +0 -10
@@ -971,13 +971,3 @@ static inline void wake_up_discard_thread(struct f2fs_sb_info *sbi, bool force) dcc->discard_wake = true;wake_up_interruptible_all (&dcc->discard_wait_queue); } - -static inline unsigned int first_zoned_segno (struct f2fs_sb_info *sbi) -{ -int devi; - -for (devi =0 ; devi < sbi->s_ndevs; devi++) -if (bdev_is_zoned (FDEV (devi).bdev)) -return GET_SEGNO (sbi,FDEV (devi).start_blk); -return 0 ; -}
fs/f2fs/super.c +13 -0
@@ -4223,6 +4223,16 @@ static void f2fs_record_error_work(struct work_struct *work)f2fs_record_stop_reason (sbi); } +static inline unsigned int get_first_zoned_segno (struct f2fs_sb_info *sbi) +{ +int devi; + +for (devi =0 ; devi < sbi->s_ndevs; devi++) +if (bdev_is_zoned (FDEV (devi).bdev)) +return GET_SEGNO (sbi,FDEV (devi).start_blk); +return 0 ; +} +static int f2fs_scan_devices (struct f2fs_sb_info *sbi) {struct f2fs_super_block *raw_super =F2FS_RAW_SUPER (sbi);
@@ -4623,6 +4633,9 @@ static int f2fs_fill_super(struct super_block *sb, void *data, int silent)/* For write statistics */ sbi->sectors_written_start =f2fs_get_sectors_written (sbi); +/* get segno of first zoned block device */ + sbi->first_zoned_segno =get_first_zoned_segno (sbi); +/* Read accumulated write IO statistics if exists */ seg_i =CURSEG_I (sbi,CURSEG_HOT_NODE );if (__exist_node_summaries (sbi))
Signature · 1 line
2.40.1
Chao Yu
maintainerPATCH 2/3 f2fs: zone: allow IPU for regular file in regular block device
blkzoned feature enables lfs mode by default, for data updates from regular file, it only allow to use OPU, this patch changes to allow to use IPU if regular file's data block locates in regular block device, if data block locates in zoned block device, it still uses OPU.
--- fs/f2fs/data.c | 12 ++++++++++-- fs/f2fs/f2fs.h | 5 +++++ 2 files changed, 15 insertions(+), 2 deletions(-)
fs/f2fs/data.c +10 -2
@@ -2648,8 +2648,16 @@ bool f2fs_should_update_outplace(struct inode *inode, struct f2fs_io_info *fio)return false;if (fio &&is_sbi_flag_set (sbi,SBI_NEED_FSCK ))return true; -if (f2fs_lfs_mode (sbi)) -return true; +if (f2fs_lfs_mode (sbi)) { +/* no regular block device in mainarea */ +if (!f2fs_blkzoned_has_regular_section (sbi)) +return true; +/* blkaddr locates in sequential zone */ +if (fio &&__is_valid_data_blkaddr (fio->old_blkaddr) && +GET_SEGNO (sbi, fio->old_blkaddr) >= + sbi->first_zoned_segno) +return true; + }if (S_ISDIR (inode->i_mode))return true;if (IS_NOQUOTA (inode))
fs/f2fs/f2fs.h +5 -0
@@ -4790,6 +4790,11 @@ static inline void f2fs_invalidate_internal_cache(struct f2fs_sb_info *sbi,f2fs_invalidate_compress_page (sbi, blkaddr); } +static inline bool f2fs_blkzoned_has_regular_section (struct f2fs_sb_info *sbi) +{ +return f2fs_sb_has_blkzoned (sbi) && sbi->first_zoned_segno; +} +#define EFSBADCRC EBADMSG/* Bad CRC detected */ #define EFSCORRUPTED EUCLEAN/* Filesystem is corrupted */
Signature · 1 line
2.40.1
Jaegeuk Kim
maintainerRe: [PATCH 2/3] f2fs: zone: allow IPU for regular file in regular block device
Quoted 20 lines · Chao Yu
blkzoned feature enables lfs mode by default, for data updates from regular file, it only allow to use OPU, this patch changes to allow to use IPU if regular file's data block locates in regular block device, if data block locates in zoned block device, it still uses OPU.
Signed-off-by Chao Yu <[email protected]>--- fs/f2fs/data.c | 12 ++++++++++-- fs/f2fs/f2fs.h | 5 +++++ 2 files changed, 15 insertions(+), 2 deletions(-)fs/f2fs/data.c +0
-0@@ -2648,8 +2648,16 @@ bool f2fs_should_update_outplace(struct inode *inode, struct f2fs_io_info *fio)return false;if (fio &&is_sbi_flag_set (sbi,SBI_NEED_FSCK ))return true;
fs/f2fs/data.c bool f2fs_should_update_outplace(struct inode *inode, struct f2fs_io_info *fio) · line 2658
Quoted 10 lines
fs/f2fs/data.c +8
-2-if (f2fs_lfs_mode (sbi)) -return true; +if (f2fs_lfs_mode (sbi)) { +/* no regular block device in mainarea */ +if (!f2fs_blkzoned_has_regular_section (sbi)) +return true; +/* blkaddr locates in sequential zone */ +if (fio &&__is_valid_data_blkaddr (fio->old_blkaddr) && +GET_SEGNO (sbi, fio->old_blkaddr) >= + sbi->first_zoned_segno)
What if there's another regular device beyond zoned partition? I prefer to keep the entire area as lfs mode to simplify the performance. Do we really need IPU on conventional partition? Why not asking to use file pinning, if someone needs IPU?
Quoted 23 lines
fs/f2fs/data.c +2
-0+return true; + }if (S_ISDIR (inode->i_mode))return true;if (IS_NOQUOTA (inode))fs/f2fs/f2fs.h +5
-0@@ -4790,6 +4790,11 @@ static inline void f2fs_invalidate_internal_cache(struct f2fs_sb_info *sbi,f2fs_invalidate_compress_page (sbi, blkaddr); } +static inline bool f2fs_blkzoned_has_regular_section (struct f2fs_sb_info *sbi) +{ +return f2fs_sb_has_blkzoned (sbi) && sbi->first_zoned_segno; +} +#define EFSBADCRC EBADMSG/* Bad CRC detected */ #define EFSCORRUPTED EUCLEAN/* Filesystem is corrupted */ Signature · 1 line
2.40.1
Chao Yu
maintainerRe: [PATCH 2/3] f2fs: zone: allow IPU for regular file in regular block device
Quoted 25 lines · Jaegeuk Kim
Quoted 24 lines · Chao Yu
blkzoned feature enables lfs mode by default, for data updates from regular file, it only allow to use OPU, this patch changes to allow to use IPU if regular file's data block locates in regular block device, if data block locates in zoned block device, it still uses OPU.
Signed-off-by Chao Yu <[email protected]>--- fs/f2fs/data.c | 12 ++++++++++-- fs/f2fs/f2fs.h | 5 +++++ 2 files changed, 15 insertions(+), 2 deletions(-)fs/f2fs/data.c +2
-2@@ -2648,8 +2648,16 @@ bool f2fs_should_update_outplace(struct inode *inode, struct f2fs_io_info *fio)return false;if (fio &&is_sbi_flag_set (sbi,SBI_NEED_FSCK ))return true; -if (f2fs_lfs_mode (sbi)) -return true; +if (f2fs_lfs_mode (sbi)) { +/* no regular block device in mainarea */
Quoted 8 lines
fs/f2fs/data.c bool f2fs_should_update_outplace(struct inode *inode, struct f2fs_io_info *fio) · line 2658
Quoted 6 lines
fs/f2fs/data.c +6
-0+if (!f2fs_blkzoned_has_regular_section (sbi)) +return true; +/* blkaddr locates in sequential zone */ +if (fio &&__is_valid_data_blkaddr (fio->old_blkaddr) && +GET_SEGNO (sbi, fio->old_blkaddr) >= + sbi->first_zoned_segno)What if there's another regular device beyond zoned partition?
With above logic, it will trigger OPU if data locates in regular device which is beyond zoned partition.
Quoted 1 line
I prefer to keep the entire area as lfs mode to simplify the performance.
Oh, what do you think of introducing another option mode=hybrid? so that we can provide an option to allow LFS/IPU/SSR in regular device beside we limit LFS mode in zoned device.
Quoted 2 lines
Do we really need IPU on conventional partition? Why not asking to use file pinning, if someone needs IPU?
One concern is size of pinned file should be multiple of section, pined file will cost too much space if section size is large. Another problem is flow of third-party applications can not be controlled by us, so it's not possible to execute pinfile & falloc after file creation.
Thanks,
Quoted 24 lines
Quoted 24 lines
fs/f2fs/data.c +2
-0+return true; + }if (S_ISDIR (inode->i_mode))return true;if (IS_NOQUOTA (inode))fs/f2fs/f2fs.h +5
-0@@ -4790,6 +4790,11 @@ static inline void f2fs_invalidate_internal_cache(struct f2fs_sb_info *sbi,f2fs_invalidate_compress_page (sbi, blkaddr); } +static inline bool f2fs_blkzoned_has_regular_section (struct f2fs_sb_info *sbi) +{ +return f2fs_sb_has_blkzoned (sbi) && sbi->first_zoned_segno; +} +#define EFSBADCRC EBADMSG/* Bad CRC detected */ #define EFSCORRUPTED EUCLEAN/* Filesystem is corrupted */ Signature · 1 line
2.40.1
Chao Yu
maintainerPATCH 3/3 f2fs: support NOCoW flag
In reply to Chao YuOverhead of pinfile is heavy due to:
1) GC tries to skip migrating section which contains pinfile's data block, it will cost more time during GC,
2) and also it will take high risk when GC unpins file and migrates it's data block once inode.i_gc_failure exceeds threshold.
This patch proposes to support NOCoW flag on inode, which has similar semantics to pinfile:
Pinfile NOCoW
[Enable]
only regular yes yes
only empty file yes no
blkzoned=on,mode=lfs Support Support
blkzoned=off,mode=lfs Not support Not support
[fsync/wb/dio IO behavior]
block in regular device IPU IPU
block in zoned device N/A OPU
[Misc IO behavior]
GC skip/OPU OPU
defrag ioc/swapon Not support Support
If userspace doesn't need pinned physical block address for following direct access, we can tag file w/ NOCoW flag instead of pinfile flag, we will be benefit from it for below cases:
1) user's write won't fragment NOCoW file's data block due to IPU
2) GC/defrag/swapon won't fail on NOCoW file.
Please note that, this patch changes to not show NOCoW flag for a pinned file, the logic is as below:
Before
Pinned file
lsattr Cf2fs_io pinfile get pinned
After
Pinned file NOCoW file
lsattr - Cf2fs_io pinfile get pinned un-pinned
So, to consider backward compatibility, if NOCoW flag shown on a target inode, we need to check pinned flag to see whether NOCoW flag was really tagged or not.
--- fs/f2fs/data.c | 21 ++++++++++++++++++++- fs/f2fs/f2fs.h | 10 ++++++++-- fs/f2fs/file.c | 22 ++++++++++++++++++---- 3 files changed, 46 insertions(+), 7 deletions(-)
fs/f2fs/data.c +20 -1
@@ -1636,7 +1636,7 @@ int f2fs_map_blocks(struct inode *inode, struct f2fs_map_blocks *map, int flag)/* use out-place-update for direct IO under LFS mode */ if (map->m_may_create && (is_hole || (flag ==F2FS_GET_BLOCK_DIO &&f2fs_lfs_mode (sbi) && - !f2fs_is_pinned_file (inode)))) { + !f2fs_is_pinned_file (inode) && !f2fs_is_nocow_file (inode)))) {if (unlikely (f2fs_cp_error (sbi))) { err = -EIO ; goto sync_out;
@@ -2636,6 +2636,11 @@ bool f2fs_should_update_inplace(struct inode *inode, struct f2fs_io_info *fio)if (file_is_cold (inode) && !is_inode_flag_set (inode,FI_OPU_WRITE ))return true; +/* allows NOCoW file to be migrated during defragmentation and swapon */ +if (f2fs_is_nocow_file (inode) && + !is_inode_flag_set (inode,FI_OPU_WRITE )) +return true; +return check_inplace_update_policy (inode, fio); }
@@ -2658,6 +2663,9 @@ bool f2fs_should_update_outplace(struct inode *inode, struct f2fs_io_info *fio) sbi->first_zoned_segno)return true; } +/* should check NOCoW flag after lfs_mode check condition */ +if (f2fs_is_nocow_file (inode)) +return false;if (S_ISDIR (inode->i_mode))return true;if (IS_NOQUOTA (inode))
@@ -2722,11 +2730,22 @@ int f2fs_do_write_data_page(struct f2fs_io_info *fio) DATA_GENERIC_ENHANCE))return -EFSCORRUPTED ; +/* +* if data block of NOCoW inode locates in sequential-zone, +* let's trigger OPU. +*/ +if (f2fs_is_nocow_file (inode) && +f2fs_blkzoned_has_regular_section (fio->sbi) && +GET_SEGNO (fio->sbi, fio->old_blkaddr) >= + fio->sbi->first_zoned_segno) + goto get_dnode; + ipu_force = true; fio->need_lock =LOCK_DONE ; goto got_it; } +get_dnode:/* Deadlock due to between page->lock and f2fs_lock_op */ if (fio->need_lock ==LOCK_REQ && !f2fs_trylock_op (fio->sbi))return -EAGAIN ;
fs/f2fs/f2fs.h +8 -2
@@ -3047,6 +3047,7 @@ static inline void f2fs_change_bit(unsigned int nr, char *addr)#define F2FS_NOCOMP_FL 0x00000400/* Don't compress */ #define F2FS_INDEX_FL 0x00001000/* hash-indexed directory */ #define F2FS_DIRSYNC_FL 0x00010000/* dirsync behaviour (directories only) */ +#define F2FS_NOCOW_FL 0x00800000/* Do not cow file */ #define F2FS_PROJINHERIT_FL 0x20000000/* Create with parents projid */ #define F2FS_CASEFOLD_FL 0x40000000/* Casefolded file */ #define F2FS_DEVICE_ALIAS_FL 0x80000000/* File for aliasing a device */
@@ -3332,6 +3333,11 @@ static inline bool f2fs_is_cow_file(struct inode *inode)return is_inode_flag_set (inode,FI_COW_FILE ); } +static inline bool f2fs_is_nocow_file (struct inode *inode) +{ +return F2FS_I (inode)->i_flags &F2FS_NOCOW_FL ; +} +static inline void *inline_data_addr (struct inode *inode,struct page *page) {__le32 *addr =get_dnode_addr (inode, page);
@@ -4658,8 +4664,8 @@ static inline bool f2fs_low_mem_mode(struct f2fs_sb_info *sbi)static inline bool f2fs_may_compress (struct inode *inode) {if (IS_SWAPFILE (inode) ||f2fs_is_pinned_file (inode) || -f2fs_is_atomic_file (inode) ||f2fs_has_inline_data (inode) || -f2fs_is_mmap_file (inode)) +f2fs_is_nocow_file (inode) ||f2fs_is_atomic_file (inode) || +f2fs_has_inline_data (inode) ||f2fs_is_mmap_file (inode))return false;return S_ISREG (inode->i_mode) ||S_ISDIR (inode->i_mode); }
fs/f2fs/file.c +18 -4
@@ -1998,6 +1998,20 @@ static int f2fs_setflags_common(struct inode *inode, u32 iflags, u32 mask)if (IS_NOQUOTA (inode))return -EPERM ; +if ((iflags ^ masked_flags) &F2FS_NOCOW_FL ) { +if (iflags &F2FS_NOCOW_FL ) { +int ret; + +if (!S_ISREG (inode->i_mode)) +return -EINVAL ; +if (f2fs_should_update_outplace (inode,NULL )) +return -EINVAL ; + ret =f2fs_convert_inline_inode (inode); +if (ret) +return ret; + } + } +if ((iflags ^ masked_flags) &F2FS_CASEFOLD_FL ) {if (!f2fs_sb_has_casefold (F2FS_I_SB (inode)))return -EOPNOTSUPP ;
@@ -2077,6 +2091,7 @@ static const struct { { F2FS_NOCOMP_FL, FS_NOCOMP_FL }, { F2FS_INDEX_FL, FS_INDEX_FL }, { F2FS_DIRSYNC_FL, FS_DIRSYNC_FL }, + { F2FS_NOCOW_FL, FS_NOCOW_FL }, { F2FS_PROJINHERIT_FL, FS_PROJINHERIT_FL }, { F2FS_CASEFOLD_FL, FS_CASEFOLD_FL }, };
@@ -2108,7 +2123,8 @@ static const struct { FS_NOCOMP_FL | \ FS_DIRSYNC_FL | \ FS_PROJINHERIT_FL | \ - FS_CASEFOLD_FL) + FS_CASEFOLD_FL | \ + FS_NOCOW_FL)/* Convert f2fs on-disk i_flags to FS_IOC_{GET,SET}FLAGS flags */ static inline u32 f2fs_iflags_to_fsflags (u32 iflags)
@@ -2171,7 +2187,7 @@ static int f2fs_ioc_start_atomic_write(struct file *filp, bool truncate)inode_lock (inode);if (!f2fs_disable_compressed_file (inode) || -f2fs_is_pinned_file (inode)) { +f2fs_is_pinned_file (inode) ||f2fs_is_nocow_file (inode)) { ret = -EINVAL ; goto out; }
@@ -3273,8 +3289,6 @@ int f2fs_fileattr_get(struct dentry *dentry, struct fileattr *fa) fsflags |=FS_VERITY_FL ;if (f2fs_has_inline_data (inode) ||f2fs_has_inline_dentry (inode)) fsflags |=FS_INLINE_DATA_FL ; -if (is_inode_flag_set (inode,FI_PIN_FILE )) - fsflags |=FS_NOCOW_FL ;fileattr_fill_flags (fa, fsflags &F2FS_GETTABLE_FS_FL );
Signature · 1 line
2.40.1
This series was applied to jaegeuk/f2fs.git (dev) by Jaegeuk Kim <[email protected]>:
Hello:
This series was applied to jaegeuk/f2fs.git (dev)
by Jaegeuk Kim <[email protected]>:
Quoted 10 lines · On Fri, 18 Oct 2024 14:26:36 +0800 you wrote:
first_zoned_segno()returns a fixed value, let's cache it in structuref2fs_sb_infoto avoid redundant calculation.Signed-off-by Chao Yu <[email protected]>--- fs/f2fs/f2fs.h | 1 + fs/f2fs/segment.c | 4 ++-- fs/f2fs/segment.h | 10 ---------- fs/f2fs/super.c | 13 +++++++++++++ 4 files changed, 16 insertions(+), 12 deletions(-)
Here is the summary with links:
- [f2fs-dev,1/3] f2fs: zone: introduce first_zoned_segno in f2fs_sb_info
https://git.kernel.org/jaegeuk/f2fs/c/08060c0b1414
- [f2fs-dev,2/3] f2fs: zone: allow IPU for regular file in regular block device (no matching commit)
- [f2fs-dev,3/3] f2fs: support NOCoW flag
(no matching commit)
You are awesome, thank you!
Signature · 2 lines
Deet-doot-dot, I am a bot. https://korg.docs.kernel.org/patchwork/pwbot.html