f2fs: introduce inline tail
v2 cover f2fs: introduce inline tail
The inode in F2FS occupies an entire 4k block. For many small files, this means they consume much more space than their actual size. Therefore, there is significant potential to better utilize the inode block space.
Currently, F2FS has two features to make use of the inode block space: inline data and inline xattr.
Inline data stores file which size is smaller then 3.5k in inode block. However, for slightly larger small files, there still have much waste.
For example, a 5k file requires 3 blocks, totaling 12k of space, which is more than twice the size of the file itself!
Additionally, the end of a file often does not occupy an entire block. If we can store the end of the file data within the inode block, we can save an entire block for the file. This is particularly important for small files.
In fact, the current inline data is a special case of inline tail, and inline tail is an extension of inline data.
To make it simple, inline tail only on small files(<64k). And for larger files, inline tails don't provide any significant benefits.
The layout of an inline tail inode block is following:
| inode block | 4096 | inline tail enable | | --------------- | ---- | --------------------------| | inode info | 360 | | | --------------- | ---- | --------------------------| | | | extra info | 0~36 | | | | **compact_addr[16] | 64 | | addr table[923] | 3692 | reserved | 4 | | | | **tail data | | | | | inline_xattr | 200 | | --------------- | ---- | --------------------------| | nid table[5] | 20 | | node footer | 24 |
F2fs-tools to support inline tail:
https://lore.kernel.org/linux-f2fs-devel/[email protected]
I tested inline tail by copying the source code of Linux 6.9.7. The storage space was reduced by approximately 8%. Additionally, due to the reduced IO, the copy time also reduced by around 10%.
This patch series has been tested with xfstests by running 'kvm-xfstests -c f2fs -g quick' both with and without the patch; no regressions were observed. The test result is:
f2fs/default: 583 tests, 6 failures, 213 skipped, 650 seconds
Failures: generic/050 generic/064 generic/250 generic/252 generic/563
generic/735
Totals: 607 tests, 213 skipped, 30 failures, 0 errors, 579s---
v2:
- fix ARCH=arc build warning
---
Wu Bo (13):
f2fs: add inline tail mount option
f2fs: add inline tail disk layout definition
f2fs: implement inline tail write & truncate
f2fs: implement inline tail read & fiemap
f2fs: set inline tail flag when create inode
f2fs: fix address info has been truncated
f2fs: support seek for inline tail
f2fs: convert inline tail when inode expand
f2fs: fix data loss during inline tail writing
f2fs: avoid inlining quota files
f2fs: fix inline tail data lost
f2fs: convert inline tails to avoid potential issues
f2fs: implement inline tail forward recovery
fs/f2fs/data.c | 93 +++++++++++++++++++++++++- fs/f2fs/f2fs.h | 46 ++++++++++++- fs/f2fs/file.c | 85 +++++++++++++++++++++++- fs/f2fs/inline.c | 159 +++++++++++++++++++++++++++++++++++++++------ fs/f2fs/inode.c | 6 ++ fs/f2fs/namei.c | 3 + fs/f2fs/node.c | 6 +- fs/f2fs/recovery.c | 9 ++- fs/f2fs/super.c | 25 +++++++ fs/f2fs/verity.c | 4 ++ 10 files changed, 409 insertions(+), 27 deletions(-)
base-commit: 67784a74e258a467225f0e68335df77acd67b7ab
Signature · 1 line
2.35.3
PATCH v2 2/13 f2fs: add inline tail disk layout definition
When inline tail is enabled, use a compact block address array. And the rest space is used to save file tail data. The layout of an inode block as following:
| inode block | 4096 | inline tail enable | | --------------- | ---- | --------------------------| | inode info | 360 | | | --------------- | ---- | --------------------------| | | | extra info | 0~36 | | | | **compact_addr[16] | 64 | | addr table[923] | 3692 | reserved | 4 | | | | **tail data | | | | | inline_xattr | 200 | | --------------- | ---- | --------------------------| | nid table[5] | 20 | | node footer | 24 |
So if we define compact address array size is 16, then we can have 3392~3428 bytes to store tail data.
--- fs/f2fs/f2fs.h | 27 ++++++++++++++++++++++++++- fs/f2fs/inode.c | 6 ++++++ 2 files changed, 32 insertions(+), 1 deletion(-)
fs/f2fs/f2fs.h +26 -1
@@ -476,12 +476,17 @@ static inline bool __has_cursum_space(struct f2fs_journal *journal,/* for inline stuff */ #define DEF_INLINE_RESERVED_SIZE 1 +#define COMPACT_ADDRS_PER_INODE 16static inline int get_extra_isize (struct inode *inode);static inline int get_inline_xattr_addrs (struct inode *inode); +static inline int get_reserved_addrs (struct inode *inode);#define MAX_INLINE_DATA (inode) (sizeof(__le32) * \ (CUR_ADDRS_PER_INODE(inode) - \ get_inline_xattr_addrs(inode) - \ - DEF_INLINE_RESERVED_SIZE)) + get_reserved_addrs(inode))) + +#define MAX_INLINE_TAIL (inode) (MAX_INLINE_DATA(inode) + \ + (PAGE_SIZE * COMPACT_ADDRS_PER_INODE))/* for inline dir */ #define NR_INLINE_DENTRY (inode) (MAX_INLINE_DATA(inode) * BITS_PER_BYTE / \
@@ -805,6 +810,7 @@ enum {FI_ATOMIC_COMMITTED ,/* indicate atomic commit completed except disk sync */ FI_ATOMIC_REPLACE ,/* indicate atomic replace */ FI_OPENED_FILE ,/* indicate file has been opened */ +FI_INLINE_TAIL ,/* used for inline tail */ FI_MAX, /* max flag, never be used */ };
@@ -3002,6 +3008,7 @@ static inline void f2fs_change_bit(unsigned int nr, char *addr)#define F2FS_DIRSYNC_FL 0x00010000/* dirsync behaviour (directories only) */ #define F2FS_PROJINHERIT_FL 0x20000000/* Create with parents projid */ #define F2FS_CASEFOLD_FL 0x40000000/* Casefolded file */ +#define F2FS_INLINE_TAIL 0x80000000/* Has inline tail */ #define F2FS_QUOTA_DEFAULT_FL (F2FS_NOATIME_FL | F2FS_IMMUTABLE_FL)
@@ -3263,6 +3270,11 @@ static inline int f2fs_has_inline_data(struct inode *inode)return is_inode_flag_set (inode,FI_INLINE_DATA ); } +static inline int f2fs_has_inline_tail (struct inode *inode) +{ +return is_inode_flag_set (inode,FI_INLINE_TAIL ); +} +static inline int f2fs_exist_data (struct inode *inode) {return is_inode_flag_set (inode,FI_DATA_EXIST );
@@ -3299,6 +3311,9 @@ static inline void *inline_data_addr(struct inode *inode, struct page *page) {__le32 *addr =get_dnode_addr (inode, page); +if (f2fs_has_inline_tail (inode)) + addr +=COMPACT_ADDRS_PER_INODE ; +return (void *)(addr +DEF_INLINE_RESERVED_SIZE ); }
@@ -3428,6 +3443,16 @@ static inline int get_extra_isize(struct inode *inode)return F2FS_I (inode)->i_extra_isize /sizeof (__le32); } +static inline int get_reserved_addrs (struct inode *inode) +{ +int size =DEF_INLINE_RESERVED_SIZE ; + +if (f2fs_has_inline_tail (inode)) + size +=COMPACT_ADDRS_PER_INODE ; + +return size; +} +static inline int get_inline_xattr_addrs (struct inode *inode) {return F2FS_I (inode)->i_inline_xattr_size;
fs/f2fs/inode.c +6 -0
@@ -425,6 +425,8 @@ static int do_read_inode(struct inode *inode) fi->i_dir_level = ri->i_dir_level;get_inline_info (inode, ri); +if (fi->i_flags &F2FS_INLINE_TAIL ) +set_bit (FI_INLINE_TAIL , fi->flags); fi->i_extra_isize =f2fs_has_extra_attr (inode) ?le16_to_cpu (ri->i_extra_isize) :0 ;
@@ -666,6 +668,10 @@ void f2fs_update_inode(struct inode *inode, struct page *node_page)memset (&ri->i_ext,0 ,sizeof (ri->i_ext)); }set_raw_inline (inode, ri); +if (is_inode_flag_set (inode,FI_INLINE_TAIL )) +F2FS_I (inode)->i_flags |=F2FS_INLINE_TAIL ; +else +F2FS_I (inode)->i_flags &= ~F2FS_INLINE_TAIL ; ri->i_atime =cpu_to_le64 (inode_get_atime_sec (inode)); ri->i_ctime =cpu_to_le64 (inode_get_ctime_sec (inode));
Signature · 1 line
2.35.3
PATCH v2 1/13 f2fs: add inline tail mount option
In reply to Wu BoSame as inline data, use mount option to control inline tail enable or disable. And enable inline tail as default.
--- fs/f2fs/f2fs.h | 1 + fs/f2fs/super.c | 15 +++++++++++++++ 2 files changed, 16 insertions(+)
fs/f2fs/f2fs.h +1 -0
@@ -116,6 +116,7 @@ extern const char *f2fs_fault_name[FAULT_MAX];#define F2FS_MOUNT_GC_MERGE 0x02000000#define F2FS_MOUNT_COMPRESS_CACHE 0x04000000#define F2FS_MOUNT_AGE_EXTENT_CACHE 0x08000000 +#define F2FS_MOUNT_INLINE_TAIL 0x10000000#define F2FS_OPTION (sbi) ((sbi)->mount_opt)#define clear_opt (sbi, option) (F2FS_OPTION(sbi).opt &= ~F2FS_MOUNT_##option)
fs/f2fs/super.c +15 -0
@@ -136,6 +136,7 @@ enum { Opt_inline_data, Opt_inline_dentry, Opt_noinline_dentry, + Opt_inline_tail, Opt_flush_merge, Opt_noflush_merge, Opt_barrier,
@@ -144,6 +145,7 @@ enum { Opt_extent_cache, Opt_noextent_cache, Opt_noinline_data, + Opt_noinline_tail, Opt_data_flush, Opt_reserve_root, Opt_resgid,
@@ -212,6 +214,7 @@ static match_table_t f2fs_tokens = { {Opt_inline_data, "inline_data"}, {Opt_inline_dentry, "inline_dentry"}, {Opt_noinline_dentry, "noinline_dentry"}, + {Opt_inline_tail, "inline_tail"}, {Opt_flush_merge, "flush_merge"}, {Opt_noflush_merge, "noflush_merge"}, {Opt_barrier, "barrier"},
@@ -220,6 +223,7 @@ static match_table_t f2fs_tokens = { {Opt_extent_cache, "extent_cache"}, {Opt_noextent_cache, "noextent_cache"}, {Opt_noinline_data, "noinline_data"}, + {Opt_noinline_tail, "noinline_tail"}, {Opt_data_flush, "data_flush"}, {Opt_reserve_root, "reserve_root=%u"}, {Opt_resgid, "resgid=%u"},
@@ -811,6 +815,9 @@ static int parse_options(struct super_block *sb, char *options, bool is_remount)case Opt_noinline_dentry:clear_opt (sbi,INLINE_DENTRY );break ; +case Opt_inline_tail: +set_opt (sbi,INLINE_TAIL ); +break ;case Opt_flush_merge:set_opt (sbi,FLUSH_MERGE );break ;
@@ -835,6 +842,9 @@ static int parse_options(struct super_block *sb, char *options, bool is_remount)case Opt_noinline_data:clear_opt (sbi,INLINE_DATA );break ; +case Opt_noinline_tail: +clear_opt (sbi,INLINE_DATA ); +break ;case Opt_data_flush:set_opt (sbi,DATA_FLUSH );break ;
@@ -1989,6 +1999,10 @@ static int f2fs_show_options(struct seq_file *seq, struct dentry *root)seq_puts (seq,",inline_data" ); else seq_puts(seq, ",noinline_data"); + if (test_opt(sbi, INLINE_TAIL)) + seq_puts(seq, ",inline_tail"); + else + seq_puts(seq, ",noinline_tail"); if (test_opt(sbi, INLINE_DENTRY)) seq_puts(seq, ",inline_dentry"); else
@@ -2138,6 +2152,7 @@ static void default_options(struct f2fs_sb_info *sbi, bool remount)set_opt (sbi,INLINE_XATTR );set_opt (sbi,INLINE_DATA );set_opt (sbi,INLINE_DENTRY ); +set_opt (sbi,INLINE_TAIL );set_opt (sbi,MERGE_CHECKPOINT );F2FS_OPTION (sbi).unusable_cap =0 ; sbi->sb->s_flags |=SB_LAZYTIME ;
Signature · 1 line
2.35.3
PATCH v2 3/13 f2fs: implement inline tail write & truncate
In reply to Wu BoAs f2fs inline data is a special case of inline tail, we can expand inline tail based on inline data.
If file tail can inline to inode block, not bother to pre-allocate block at write begin. When tail page writing back, inline it or normally write it if the tail is oversize.
And when inode page writing back, update inline data from tail page.
--- fs/f2fs/data.c | 30 ++++++++++++++++++++++++++++++ fs/f2fs/f2fs.h | 16 ++++++++++++++++ fs/f2fs/file.c | 10 ++++++++++ fs/f2fs/inline.c | 38 +++++++++++++++++++++++++++++++------- fs/f2fs/node.c | 6 +++++- 5 files changed, 92 insertions(+), 8 deletions(-)
fs/f2fs/data.c +30 -0
@@ -2776,6 +2776,7 @@ int f2fs_write_single_data_page(struct page *page, int *submitted,loff_t psize = (loff_t)(page->index +1 ) <<PAGE_SHIFT ;unsigned offset =0 ;bool need_balance_fs = false; +bool need_clear_tail = false;bool quota_inode =IS_NOQUOTA (inode);int err =0 ;struct f2fs_io_info fio = {
@@ -2867,6 +2868,16 @@ int f2fs_write_single_data_page(struct page *page, int *submitted, goto out; } +if (f2fs_has_inline_tail (inode) && page->index == end_index) { +if (support_tail_inline (inode, i_size)) { + err =f2fs_write_inline_data (inode, page); +if (!err) + goto out; + }else { + need_clear_tail = true; + } + } +if (err == -EAGAIN ) { err =f2fs_do_write_data_page (&fio);if (err == -EAGAIN ) {
@@ -2889,6 +2900,11 @@ int f2fs_write_single_data_page(struct page *page, int *submitted,if (err && err != -ENOENT ) goto redirty_out; +if (need_clear_tail) { + err =f2fs_clear_inline_tail (inode, false); +if (err) + goto redirty_out; + } out:inode_dec_dirty_pages (inode);if (err) {
@@ -3393,6 +3409,11 @@ static int prepare_write_begin(struct f2fs_sb_info *sbi, flag =F2FS_GET_BLOCK_DEFAULT ;f2fs_map_lock (sbi, flag); locked = true; + }else if (f2fs_has_inline_tail (inode)) { +if (!support_tail_inline (inode, pos + len)) { +f2fs_map_lock (sbi, flag); + locked = true; + } }else if ((pos &PAGE_MASK ) >=i_size_read (inode)) {f2fs_map_lock (sbi, flag); locked = true;
@@ -3421,6 +3442,15 @@ static int prepare_write_begin(struct f2fs_sb_info *sbi, goto out; } +if (f2fs_has_inline_tail (inode)) { +if (support_tail_inline (inode, pos + len)) { +f2fs_do_read_inline_data (page_folio (page), ipage); +if (inode->i_nlink) +set_page_private_inline (ipage); + goto out; + } + } +if (!f2fs_lookup_read_extent_cache_block (inode, index, &dn.data_blkaddr)) {if (locked) {
fs/f2fs/f2fs.h +16 -0
@@ -3322,6 +3322,21 @@ static inline int f2fs_has_inline_dentry(struct inode *inode)return is_inode_flag_set (inode,FI_INLINE_DENTRY ); } +static inline bool support_tail_inline (struct inode *inode,loff_t i_size) +{ +const pgoff_t tail_index = ((unsigned long long )i_size) >>PAGE_SHIFT ; +unsigned long tail_len = i_size & (PAGE_SIZE -1 ); + +if (tail_index >COMPACT_ADDRS_PER_INODE ) +return false; +if (!tail_len) +return false; +if (tail_len >MAX_INLINE_DATA (inode)) +return false; + +return true; +} +static inline int is_file (struct inode *inode,int type) {return F2FS_I (inode)->i_advise & type;
@@ -4197,6 +4212,7 @@ void f2fs_truncate_inline_inode(struct inode *inode,int f2fs_read_inline_data (struct inode *inode,struct folio *folio);int f2fs_convert_inline_page (struct dnode_of_data *dn,struct page *page);int f2fs_convert_inline_inode (struct inode *inode); +int f2fs_clear_inline_tail (struct inode *inode,bool force);int f2fs_try_convert_inline_dir (struct inode *dir,struct dentry *dentry);int f2fs_write_inline_data (struct inode *inode,struct page *page);int f2fs_recover_inline_data (struct inode *inode,struct page *npage);
fs/f2fs/file.c +10 -0
@@ -748,6 +748,9 @@ int f2fs_do_truncate_blocks(struct inode *inode, u64 from, bool lock) goto out; } +if (f2fs_has_inline_tail (inode) &&f2fs_exist_data (inode)) +f2fs_truncate_inline_inode (inode, ipage,0 ); +set_new_dnode (&dn, inode, ipage,NULL ,0 ); err =f2fs_get_dnode_of_data (&dn, free_from,LOOKUP_NODE_RA );if (err) {
@@ -4703,6 +4706,13 @@ static int f2fs_preallocate_blocks(struct kiocb *iocb, struct iov_iter *iter,return ret; } +if (f2fs_has_inline_tail (inode) && + (pos + count >MAX_INLINE_TAIL (inode))) { + ret =f2fs_clear_inline_tail (inode, true); +if (ret) +return ret; + } +/* Do not preallocate blocks that will be written partially in 4KB. */ map.m_lblk =F2FS_BLK_ALIGN (pos); map.m_len =F2FS_BYTES_TO_BLK (pos + count);
fs/f2fs/inline.c +31 -7
@@ -102,6 +102,7 @@ void f2fs_truncate_inline_inode(struct inode *inode, {void *addr; + from = from & (PAGE_SIZE -1 );if (from >=MAX_INLINE_DATA (inode))return ;
@@ -156,11 +157,12 @@ int f2fs_convert_inline_page(struct dnode_of_data *dn, struct page *page) };struct node_info ni;int dirty, err; +pgoff_t index = page->index;if (!f2fs_exist_data (dn->inode)) goto clear_out; - err =f2fs_reserve_block (dn,0 ); + err =f2fs_reserve_block (dn, index);if (err)return err;
@@ -176,8 +178,8 @@ int f2fs_convert_inline_page(struct dnode_of_data *dn, struct page *page)if (unlikely (dn->data_blkaddr !=NEW_ADDR )) {f2fs_put_dnode (dn);set_sbi_flag (fio.sbi,SBI_NEED_FSCK ); -f2fs_warn (fio.sbi,"%s: corrupted inline inode ino=%lx, i_addr[0]:0x%x, run fsck to fix." , - __func__, dn->inode->i_ino, dn->data_blkaddr); +f2fs_warn (fio.sbi,"%s: corrupted inline inode ino=%lx, i_addr[%lu]:0x%x, run fsck to fix." , + __func__, dn->inode->i_ino, index, dn->data_blkaddr);f2fs_handle_error (fio.sbi,ERROR_INVALID_BLKADDR );return -EFSCORRUPTED ; }
@@ -210,10 +212,33 @@ int f2fs_convert_inline_page(struct dnode_of_data *dn, struct page *page) clear_out:stat_dec_inline_inode (dn->inode);clear_inode_flag (dn->inode,FI_INLINE_DATA ); +if (index >=COMPACT_ADDRS_PER_INODE ) +clear_inode_flag (dn->inode,FI_INLINE_TAIL );f2fs_put_dnode (dn);return 0 ; } +int f2fs_clear_inline_tail (struct inode *inode,bool force) +{ +struct f2fs_sb_info *sbi =F2FS_I_SB (inode); +struct page *ipage; +loff_t i_size =i_size_read (inode); +pgoff_t end_index = i_size >>PAGE_SHIFT ; + + ipage =f2fs_get_node_page (sbi, inode->i_ino); +if (IS_ERR (ipage)) +return PTR_ERR (ipage); + +f2fs_truncate_inline_inode (inode, ipage,0 ); +clear_page_private_inline (ipage); + +if (force || end_index >=COMPACT_ADDRS_PER_INODE ) +clear_inode_flag (inode,FI_INLINE_TAIL ); + +f2fs_put_page (ipage,1 ); +return 0 ; +} +int f2fs_convert_inline_inode (struct inode *inode) {struct f2fs_sb_info *sbi =F2FS_I_SB (inode);
@@ -263,20 +288,19 @@ int f2fs_convert_inline_inode(struct inode *inode)int f2fs_write_inline_data (struct inode *inode,struct page *page) {struct dnode_of_data dn; +pgoff_t index = page->index;int err;set_new_dnode (&dn, inode,NULL ,NULL ,0 ); - err =f2fs_get_dnode_of_data (&dn,0 ,LOOKUP_NODE ); + err =f2fs_get_dnode_of_data (&dn, index,LOOKUP_NODE );if (err)return err; -if (!f2fs_has_inline_data (inode)) { +if (!f2fs_has_inline_data (inode) && !f2fs_has_inline_tail (inode)) {f2fs_put_dnode (&dn);return -EAGAIN ; } -f2fs_bug_on (F2FS_I_SB (inode), page->index); -f2fs_wait_on_page_writeback (dn.inode_page,NODE , true, true);memcpy_from_page (inline_data_addr (inode, dn.inode_page), page,0 ,MAX_INLINE_DATA (inode));
fs/f2fs/node.c +5 -1
@@ -1514,6 +1514,8 @@ static void flush_inline_data(struct f2fs_sb_info *sbi, nid_t ino) {struct inode *inode;struct page *page; +loff_t i_size; +pgoff_t end_index;int ret;/* should flush inline_data before evict_inode */
@@ -1521,7 +1523,9 @@ static void flush_inline_data(struct f2fs_sb_info *sbi, nid_t ino)if (!inode)return ; - page =f2fs_pagecache_get_page (inode->i_mapping,0 , + i_size =i_size_read (inode); + end_index = i_size >>PAGE_SHIFT ; + page =f2fs_pagecache_get_page (inode->i_mapping, end_index,FGP_LOCK |FGP_NOWAIT ,0 );if (!page) goto iput_out;
Signature · 1 line
2.35.3
PATCH v2 4/13 f2fs: implement inline tail read & fiemap
In reply to Wu BoExpand the inline data read & fiemap to support inline tail.
--- fs/f2fs/data.c | 31 ++++++++++++++++++++++++++++++- fs/f2fs/inline.c | 26 ++++++++++++-------------- 2 files changed, 42 insertions(+), 15 deletions(-)
fs/f2fs/data.c +30 -1
@@ -1922,9 +1922,11 @@ int f2fs_fiemap(struct inode *inode, struct fiemap_extent_info *fieinfo,u64 logical =0 , phys =0 , size =0 ;u32 flags =0 ;int ret =0 ; -bool compr_cluster = false, compr_appended; +bool compr_cluster = false, compr_appended, inline_tail = false;unsigned int cluster_size =F2FS_I (inode)->i_cluster_size;unsigned int count_in_cluster =0 ; +loff_t i_size =i_size_read (inode); +pgoff_t end_index = i_size >>PAGE_SHIFT ;loff_t maxbytes;if (fieinfo->fi_flags &FIEMAP_FLAG_CACHE ) {
@@ -1983,6 +1985,16 @@ int f2fs_fiemap(struct inode *inode, struct fiemap_extent_info *fieinfo,/* HOLE */ if (!compr_cluster && !(map.m_flags & F2FS_MAP_FLAGS)) { + /* + * There is a reserved space between address array and inline + * data. So it must meet this hole state before inline data. + */ + if (f2fs_has_inline_tail(inode) && start_blk == end_index + && f2fs_exist_data(inode)) { + inline_tail = true; + goto fill_extent; + } + start_blk = next_pgofs; if (blks_to_bytes(inode, start_blk) < blks_to_bytes(inode,
@@ -2000,6 +2012,7 @@ int f2fs_fiemap(struct inode *inode, struct fiemap_extent_info *fieinfo, goto skip_fill; } +fill_extent:if (size) { flags |=FIEMAP_EXTENT_MERGED ;if (IS_ENCRYPTED (inode))
@@ -2013,6 +2026,13 @@ int f2fs_fiemap(struct inode *inode, struct fiemap_extent_info *fieinfo, size =0 ; } +if (inline_tail) { + start =blks_to_bytes (inode, start_blk); + ret =f2fs_inline_data_fiemap (inode, fieinfo, start, len); +if (ret != -EAGAIN ) + goto out; + } +if (start_blk > last_blk) goto out;
@@ -2377,6 +2397,8 @@ static int f2fs_mpage_readpages(struct inode *inode,#endif unsigned nr_pages = rac ?readahead_count (rac) :1 ;unsigned max_nr_pages = nr_pages; +loff_t i_size =i_size_read (inode); +pgoff_t end_index = i_size >>PAGE_SHIFT ;pgoff_t index;int ret =0 ;
@@ -2397,6 +2419,12 @@ static int f2fs_mpage_readpages(struct inode *inode, index =folio_index (folio); +if (f2fs_has_inline_tail (inode) && index == end_index && +f2fs_exist_data (inode)) { + ret =f2fs_read_inline_data (inode, folio); + goto out; + } +#ifdef CONFIG_F2FS_FS_COMPRESSION if (!f2fs_compressed_file (inode)) goto read_single_page;
@@ -2462,6 +2490,7 @@ static int f2fs_mpage_readpages(struct inode *inode, }#endif } +out:if (bio)f2fs_submit_read_bio (F2FS_I_SB (inode), bio,DATA );return ret;
fs/f2fs/inline.c +12 -14
@@ -86,8 +86,6 @@ void f2fs_do_read_inline_data(struct folio *folio, struct page *ipage)if (folio_test_uptodate (folio))return ; -f2fs_bug_on (F2FS_I_SB (inode),folio_index (folio)); -folio_zero_segment (folio,MAX_INLINE_DATA (inode),folio_size (folio));/* Copy the whole inline data block */
@@ -126,15 +124,12 @@ int f2fs_read_inline_data(struct inode *inode, struct folio *folio)return PTR_ERR (ipage); } -if (!f2fs_has_inline_data (inode)) { +if (!f2fs_has_inline_data (inode) && !f2fs_has_inline_tail (inode)) {f2fs_put_page (ipage,1 );return -EAGAIN ; } -if (folio_index (folio)) -folio_zero_segment (folio,0 ,folio_size (folio)); -else -f2fs_do_read_inline_data (folio, ipage); +f2fs_do_read_inline_data (folio, ipage);if (!folio_test_uptodate (folio))folio_mark_uptodate (folio);
@@ -814,7 +809,7 @@ int f2fs_read_inline_dir(struct file *file, struct dir_context *ctx,int f2fs_inline_data_fiemap (struct inode *inode,struct fiemap_extent_info *fieinfo,__u64 start,__u64 len) { -__u64 byteaddr, ilen; +__u64 byteaddr, ilen, offset;__u32 flags =FIEMAP_EXTENT_DATA_INLINE |FIEMAP_EXTENT_NOT_ALIGNED |FIEMAP_EXTENT_LAST ;struct node_info ni;
@@ -826,7 +821,8 @@ int f2fs_inline_data_fiemap(struct inode *inode,return PTR_ERR (ipage);if ((S_ISREG (inode->i_mode) ||S_ISLNK (inode->i_mode)) && - !f2fs_has_inline_data (inode)) { + !f2fs_has_inline_data (inode) && + !f2fs_has_inline_tail (inode)) { err = -EAGAIN ; goto out; }
@@ -836,12 +832,14 @@ int f2fs_inline_data_fiemap(struct inode *inode, goto out; } - ilen =min_t (size_t,MAX_INLINE_DATA (inode),i_size_read (inode)); -if (start >= ilen) + ilen =min_t (size_t,MAX_INLINE_DATA (inode), +i_size_read (inode) & (PAGE_SIZE -1 )); + offset = start & (PAGE_SIZE -1 ); +if (offset >= ilen) goto out; -if (start + len < ilen) - ilen = start + len; - ilen -= start; +if (offset + len < ilen) + ilen = offset + len; + ilen -= offset; err =f2fs_get_node_info (F2FS_I_SB (inode), inode->i_ino, &ni, false);if (err)
Signature · 1 line
2.35.3
PATCH v2 6/13 f2fs: fix address info has been truncated
In reply to Wu BoIf there is no data inline, the address table should not be truncate, in case there may be reserved address info.
--- fs/f2fs/inline.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
fs/f2fs/inline.c +2 -1
@@ -224,7 +224,8 @@ int f2fs_clear_inline_tail(struct inode *inode, bool force)if (IS_ERR (ipage))return PTR_ERR (ipage); -f2fs_truncate_inline_inode (inode, ipage,0 ); +if (f2fs_exist_data (inode)) +f2fs_truncate_inline_inode (inode, ipage,0 );clear_page_private_inline (ipage);if (force || end_index >=COMPACT_ADDRS_PER_INODE )
Signature · 1 line
2.35.3
PATCH v2 5/13 f2fs: set inline tail flag when create inode
In reply to Wu BoSet inline tail flag to enable this feature when new inode is created. Inherit the conditions from inline data.
--- fs/f2fs/namei.c | 3 +++ 1 file changed, 3 insertions(+)
fs/f2fs/namei.c +3 -0
@@ -315,6 +315,9 @@ static struct inode *f2fs_new_inode(struct mnt_idmap *idmap,/* Should enable inline_data after compression set */ if (test_opt (sbi,INLINE_DATA ) &&f2fs_may_inline_data (inode))set_inode_flag (inode,FI_INLINE_DATA ); +/* Inherit the conditions from inline data */ +if (test_opt (sbi,INLINE_TAIL ) &&f2fs_has_inline_data (inode)) +set_inode_flag (inode,FI_INLINE_TAIL );if (name && !test_opt (sbi,DISABLE_EXT_IDENTIFY ))set_file_temperature (sbi, inode, name);
Signature · 1 line
2.35.3
PATCH v2 7/13 f2fs: support seek for inline tail
In reply to Wu BoFix to support seek for inline tail files
--- fs/f2fs/file.c | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-)
fs/f2fs/file.c +16 -1
@@ -400,6 +400,7 @@ static bool __found_offset(struct address_space *mapping,block_t blkaddr =f2fs_data_blkaddr (dn);struct inode *inode = mapping->host;bool compressed_cluster = false; +bool inline_tail = false;if (f2fs_compressed_file (inode)) { block_t first_blkaddr = data_blkaddr(dn->inode, dn->node_page,
@@ -408,6 +409,14 @@ static bool __found_offset(struct address_space *mapping, compressed_cluster = first_blkaddr ==COMPRESS_ADDR ; } +if (f2fs_has_inline_tail (inode)) { +loff_t isize =i_size_read (inode); +if ((isize >>PAGE_SHIFT == index) && + (f2fs_exist_data (inode) || +xa_get_mark (&mapping->i_pages, index,PAGECACHE_TAG_DIRTY ))) + inline_tail = true; + } +switch (whence) {case SEEK_DATA :if (__is_valid_data_blkaddr (blkaddr))
@@ -417,11 +426,13 @@ static bool __found_offset(struct address_space *mapping,return true;if (compressed_cluster)return true; +if (inline_tail) +return true;break ;case SEEK_HOLE :if (compressed_cluster)return false; -if (blkaddr ==NULL_ADDR ) +if (blkaddr ==NULL_ADDR && !inline_tail)return true;break ; }
@@ -473,6 +484,8 @@ static loff_t f2fs_seek_block(struct file *file, loff_t offset, int whence) } end_offset =ADDRS_PER_PAGE (dn.node_page, inode); +if (f2fs_has_inline_tail (inode)) + end_offset =COMPACT_ADDRS_PER_INODE +1 ;/* find data/hole in dnode block */ for (; dn.ofs_in_node < end_offset;
@@ -496,6 +509,8 @@ static loff_t f2fs_seek_block(struct file *file, loff_t offset, int whence) } }f2fs_put_dnode (&dn); +if (f2fs_has_inline_tail (inode) && dn.ofs_in_node == end_offset) + goto fail; }if (whence ==SEEK_DATA )
Signature · 1 line
2.35.3
PATCH v2 8/13 f2fs: convert inline tail when inode expand
In reply to Wu BoConvert an inline tail file to a normal file when the inode expansion exceeds the maximum size allowed for the inline tail.
--- fs/f2fs/f2fs.h | 1 + fs/f2fs/file.c | 6 ++++++ fs/f2fs/inline.c | 43 +++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 50 insertions(+)
fs/f2fs/f2fs.h +1 -0
@@ -4211,6 +4211,7 @@ void f2fs_truncate_inline_inode(struct inode *inode, struct page *ipage, u64 from);int f2fs_read_inline_data (struct inode *inode,struct folio *folio);int f2fs_convert_inline_page (struct dnode_of_data *dn,struct page *page); +int f2fs_convert_inline_tail (struct inode *inode);int f2fs_convert_inline_inode (struct inode *inode);int f2fs_clear_inline_tail (struct inode *inode,bool force);int f2fs_try_convert_inline_dir (struct inode *dir,struct dentry *dentry);
fs/f2fs/file.c +6 -0
@@ -1783,6 +1783,12 @@ static int f2fs_expand_inode_data(struct inode *inode, loff_t offset,if (err)return err; +if (len + offset >MAX_INLINE_TAIL (inode)) { + err =f2fs_convert_inline_tail (inode); +if (err) +return err; + } +f2fs_balance_fs (sbi, true); pg_start = ((unsigned long long )offset) >>PAGE_SHIFT ;
fs/f2fs/inline.c +43 -0
49 lines not on this page · raw message
Signature · 8 lines
2.35.3 _______________________________________________ Linux-f2fs-devel mailing list [email protected] https://lists.sourceforge.net/lists/listinfo/linux-f2fs-devel
PATCH v2 9/13 f2fs: fix data loss during inline tail writing
In reply to Wu BoThis is detected by xfstest generic/114. The inline data needs to be read out before writing to avoid losing the already inline data.
--- fs/f2fs/data.c | 3 ++- fs/f2fs/file.c | 7 ++++++- 2 files changed, 8 insertions(+), 2 deletions(-)
fs/f2fs/data.c +2 -1
@@ -3477,7 +3477,8 @@ static int prepare_write_begin(struct f2fs_sb_info *sbi,if (inode->i_nlink)set_page_private_inline (ipage); goto out; - } + } else if (f2fs_exist_data(inode)) + f2fs_do_read_inline_data(page_folio(page), ipage); } if (!f2fs_lookup_read_extent_cache_block(inode, index,
fs/f2fs/file.c +6 -1
@@ -4729,7 +4729,7 @@ static int f2fs_preallocate_blocks(struct kiocb *iocb, struct iov_iter *iter,if (f2fs_has_inline_tail (inode) && (pos + count >MAX_INLINE_TAIL (inode))) { - ret =f2fs_clear_inline_tail (inode, true); + ret =f2fs_convert_inline_tail (inode);if (ret)return ret; }
@@ -4842,6 +4842,7 @@ static ssize_t f2fs_dio_write_iter(struct kiocb *iocb, struct iov_iter *from,if (iocb->ki_flags &IOCB_NOWAIT ) {/* f2fs_convert_inline_inode() and block allocation can block */ if (f2fs_has_inline_data (inode) || +f2fs_has_inline_tail (inode) || !f2fs_overwrite_io (inode, pos, count)) { ret = -EAGAIN ; goto out;
@@ -4861,6 +4862,10 @@ static ssize_t f2fs_dio_write_iter(struct kiocb *iocb, struct iov_iter *from,if (ret) goto out; + ret =f2fs_convert_inline_tail (inode); +if (ret) + goto out; +f2fs_down_read (&fi->i_gc_rwsem[WRITE ]);if (do_opu)f2fs_down_read (&fi->i_gc_rwsem[READ ]);
Signature · 1 line
2.35.3
PATCH v2 10/13 f2fs: avoid inlining quota files
In reply to Wu BoQuota files have a different write path and are incompatible with inlined inodes (whether data or tail inlined). To simplify the process, inlining is disabled for quota files here.
--- fs/f2fs/data.c | 9 +++++++++ fs/f2fs/super.c | 10 ++++++++++ 2 files changed, 19 insertions(+)
fs/f2fs/data.c +9 -0
@@ -3641,6 +3641,15 @@ static int f2fs_write_begin(struct file *file, struct address_space *mapping, goto fail; } +if (IS_NOQUOTA (inode)) { + err =f2fs_convert_inline_inode (inode); +if (err) + goto fail; + err =f2fs_convert_inline_tail (inode); +if (err) + goto fail; + } +#ifdef CONFIG_F2FS_FS_COMPRESSION if (f2fs_compressed_file (inode)) {int ret;
fs/f2fs/super.c +10 -0
@@ -2807,6 +2807,14 @@ static int f2fs_quota_enable(struct super_block *sb, int type, int format_id,return PTR_ERR (qf_inode); } + err =f2fs_convert_inline_inode (qf_inode); +if (err) + goto out; + + err =f2fs_convert_inline_tail (qf_inode); +if (err) + goto out; +/* Don't account quota for quota files to avoid recursion */ inode_lock (qf_inode); qf_inode->i_flags |=S_NOQUOTA ;
@@ -2818,6 +2826,8 @@ static int f2fs_quota_enable(struct super_block *sb, int type, int format_id,inode_unlock (qf_inode); err =dquot_load_quota_inode (qf_inode, type, format_id, flags); + +out:iput (qf_inode);return err; }
Signature · 1 line
2.35.3
PATCH v2 11/13 f2fs: fix inline tail data lost
In reply to Wu BoBefore adding a new page to the tail, the old inlined tail page must be converted first; otherwise, the data on that page could be lost.
--- fs/f2fs/data.c | 26 +++++++++++++++++++++----- 1 file changed, 21 insertions(+), 5 deletions(-)
fs/f2fs/data.c +21 -5
@@ -3418,7 +3418,9 @@ static int prepare_write_begin(struct f2fs_sb_info *sbi, block_t *blk_addr, bool *node_changed) {struct inode *inode = page->mapping->host; +loff_t i_size =i_size_read (inode);pgoff_t index = page->index; +pgoff_t end_index = i_size >>PAGE_SHIFT ;struct dnode_of_data dn;struct page *ipage;bool locked = false;
@@ -3438,12 +3440,12 @@ static int prepare_write_begin(struct f2fs_sb_info *sbi, flag =F2FS_GET_BLOCK_DEFAULT ;f2fs_map_lock (sbi, flag); locked = true; - }else if (f2fs_has_inline_tail (inode)) { + }else if (f2fs_has_inline_tail (inode) && index >= end_index) {if (!support_tail_inline (inode, pos + len)) {f2fs_map_lock (sbi, flag); locked = true; } - }else if ((pos &PAGE_MASK ) >=i_size_read (inode)) { + }else if ((pos &PAGE_MASK ) >= i_size) {f2fs_map_lock (sbi, flag); locked = true; }
@@ -3471,14 +3473,28 @@ static int prepare_write_begin(struct f2fs_sb_info *sbi, goto out; } -if (f2fs_has_inline_tail (inode)) { +if (f2fs_has_inline_tail (inode) && index >= end_index) { +if (index > end_index &&f2fs_exist_data (inode)) { +struct page *tail_page =f2fs_grab_cache_page ( + inode->i_mapping, end_index, false); +if (!page) { + err = -ENOMEM ; + goto out; + } + err =f2fs_convert_inline_page (&dn, tail_page); +f2fs_put_page (tail_page,1 ); +if (err || dn.data_blkaddr !=NULL_ADDR ) + goto out; + }if (support_tail_inline (inode, pos + len)) {f2fs_do_read_inline_data (page_folio (page), ipage);if (inode->i_nlink)set_page_private_inline (ipage); goto out; - }else if (f2fs_exist_data (inode)) -f2fs_do_read_inline_data (page_folio (page), ipage); + } + err =f2fs_convert_inline_page (&dn, page); +if (err || dn.data_blkaddr !=NULL_ADDR ) + goto out; } if (!f2fs_lookup_read_extent_cache_block(inode, index,
Signature · 8 lines
2.35.3 _______________________________________________ Linux-f2fs-devel mailing list [email protected] https://lists.sourceforge.net/lists/listinfo/linux-f2fs-devel
PATCH v2 12/13 f2fs: convert inline tails to avoid potential issues
In reply to Wu BoLike the commit:
commit b3d208f96d6b ("f2fs: revisit inline_data to avoid data races and potential bugs")
Due to the limitations of inline data, there are many scenarios where inline isn't supported well, such as move file range.
Therefore, in these scenarios, convert the inline tail file to a regular file.
--- fs/f2fs/data.c | 4 ++++ fs/f2fs/file.c | 47 +++++++++++++++++++++++++++++++++++++++++++++++ fs/f2fs/verity.c | 4 ++++ 3 files changed, 55 insertions(+)
fs/f2fs/data.c +4 -0
@@ -4141,6 +4141,10 @@ static int f2fs_swap_activate(struct swap_info_struct *sis, struct file *file,if (ret)return ret; + ret =f2fs_convert_inline_tail (inode); +if (ret) +return ret; +if (!f2fs_disable_compressed_file (inode))return -EINVAL ;
fs/f2fs/file.c +47 -0
117 lines not on this page · raw message
fs/f2fs/verity.c +4 -0
@@ -139,6 +139,10 @@ static int f2fs_begin_enable_verity(struct file *filp)if (err)return err; + err =f2fs_convert_inline_tail (inode); +if (err) +return err; +set_inode_flag (inode,FI_VERITY_IN_PROGRESS );return 0 ; }
Signature · 8 lines
2.35.3 _______________________________________________ Linux-f2fs-devel mailing list [email protected] https://lists.sourceforge.net/lists/listinfo/linux-f2fs-devel
PATCH v2 13/13 f2fs: implement inline tail forward recovery
In reply to Wu BoThe recovery logic is similar to that of inline data, except that the inline tail may require recovery of some blocks. This is because the inline tail has a 16-size block address array, whereas inline data does not.
--- fs/f2fs/f2fs.h | 1 + fs/f2fs/inline.c | 51 ++++++++++++++++++++++++++++++++++++++++++++++ fs/f2fs/recovery.c | 9 +++++++- 3 files changed, 60 insertions(+), 1 deletion(-)
fs/f2fs/f2fs.h +1 -0
@@ -4217,6 +4217,7 @@ int f2fs_clear_inline_tail(struct inode *inode, bool force);int f2fs_try_convert_inline_dir (struct inode *dir,struct dentry *dentry);int f2fs_write_inline_data (struct inode *inode,struct page *page);int f2fs_recover_inline_data (struct inode *inode,struct page *npage); +int f2fs_recover_inline_tail (struct inode *inode,struct page *npage);struct f2fs_dir_entry *f2fs_find_in_inline_dir (struct inode *dir,const struct f2fs_filename *fname,struct page **res_page);
fs/f2fs/inline.c +51 -0
57 lines not on this page · raw message
fs/f2fs/recovery.c +8 -1
@@ -645,9 +645,16 @@ static int do_recover_data(struct f2fs_sb_info *sbi, struct inode *inode, goto out; } + err =f2fs_recover_inline_tail (inode, page); +if (err) + goto out; +/* step 3: recover data indices */ start =f2fs_start_bidx_of_node (ofs_of_node (page), inode); - end = start +ADDRS_PER_PAGE (page, inode); +if (f2fs_has_inline_tail (inode)) + end =COMPACT_ADDRS_PER_INODE ; +else + end = start +ADDRS_PER_PAGE (page, inode);set_new_dnode (&dn, inode,NULL ,NULL ,0 ); retry_dn:
Signature · 8 lines
2.35.3 _______________________________________________ Linux-f2fs-devel mailing list [email protected] https://lists.sourceforge.net/lists/listinfo/linux-f2fs-devel
Chao Yu
maintainerQuoted 44 lines · Wu Bo
The inode in F2FS occupies an entire 4k block. For many small files, this means they consume much more space than their actual size. Therefore, there is significant potential to better utilize the inode block space.
Currently, F2FS has two features to make use of the inode block space: inline data and inline xattr.
Inline data stores file which size is smaller then 3.5k in inode block. However, for slightly larger small files, there still have much waste.
For example, a 5k file requires 3 blocks, totaling 12k of space, which is more than twice the size of the file itself!Additionally, the end of a file often does not occupy an entire block. If we can store the end of the file data within the inode block, we can save an entire block for the file. This is particularly important for small files.
In fact, the current inline data is a special case of inline tail, and inline tail is an extension of inline data.
To make it simple, inline tail only on small files(<64k). And for larger files, inline tails don't provide any significant benefits.
The layout of an inline tail inode block is following:
| inode block | 4096 | inline tail enable | | --------------- | ---- | --------------------------| | inode info | 360 | | | --------------- | ---- | --------------------------| | | | extra info | 0~36 | | | | **compact_addr[16] | 64 | | addr table[923] | 3692 | reserved | 4 | | | | **tail data | | | | | inline_xattr | 200 | | --------------- | ---- | --------------------------| | nid table[5] | 20 | | node footer | 24 |F2fs-tools to support inline tail:
https://lore.kernel.org/linux-f2fs-devel/[email protected]I tested inline tail by copying the source code of Linux 6.9.7. The storage space was reduced by approximately 8%. Additionally, due to the reduced IO, the copy time also reduced by around 10%.
Quoted 7 lines
This patch series has been tested with xfstests by running 'kvm-xfstests -c f2fs -g quick' both with and without the patch; no regressions were observed. The test result is:
f2fs/default: 583 tests, 6 failures, 213 skipped, 650 seconds
Failures: generic/050 generic/064 generic/250 generic/252 generic/563generic/735 Totals: 607 tests, 213 skipped, 30 failures, 0 errors, 579s
MKFS_OPTIONS -- -O extra_attr,encrypt,inode_checksum,flexible_inline_xattr,inode_crtime,verity,compression -f /dev/vdc MOUNT_OPTIONS -- -o acl,user_xattr -o discard,inline_tail /dev/vdc /mnt/scratch_f2fs
Before:
Failures: generic/042 generic/050 generic/250 generic/252 generic/270 generic/389 generic/563 generic/700 generic/735 Failed 9 of 746 tests
After:
Failures: generic/042 generic/050 generic/125 generic/250 generic/252 generic/270 generic/389 generic/418 generic/551 generic/563 generic/700 generic/735 Failed 12 of 746 tests
Failures: f2fs/004
Can you please check failed testcases?
Thanks,
Quoted 35 lines
---
v2:
- fix ARCH=arc build warning---
Wu Bo (13):
f2fs: add inline tail mount option
f2fs: add inline tail disk layout definition
f2fs: implement inline tail write & truncate
f2fs: implement inline tail read & fiemap
f2fs: set inline tail flag when create inode
f2fs: fix address info has been truncated
f2fs: support seek for inline tail
f2fs: convert inline tail when inode expand
f2fs: fix data loss during inline tail writing
f2fs: avoid inlining quota files
f2fs: fix inline tail data lost
f2fs: convert inline tails to avoid potential issues
f2fs: implement inline tail forward recoveryfs/f2fs/data.c | 93 +++++++++++++++++++++++++- fs/f2fs/f2fs.h | 46 ++++++++++++- fs/f2fs/file.c | 85 +++++++++++++++++++++++- fs/f2fs/inline.c | 159 +++++++++++++++++++++++++++++++++++++++------ fs/f2fs/inode.c | 6 ++ fs/f2fs/namei.c | 3 + fs/f2fs/node.c | 6 +- fs/f2fs/recovery.c | 9 ++- fs/f2fs/super.c | 25 +++++++ fs/f2fs/verity.c | 4 ++ 10 files changed, 409 insertions(+), 27 deletions(-)base-commit:
67784a74e258a467225f0e68335df77acd67b7ab
kernel test robot
build botRe: [PATCH v2 13/13] f2fs: implement inline tail forward recovery
In reply to Wu Bokernel test robot noticed the following build warnings:
Hi Wu,
kernel test robot noticed the following build warnings:
[auto build test WARNING on 67784a74e258a467225f0e68335df77acd67b7ab]
url: https://github.com/intel-lab-lkp/linux/commits/Wu-Bo/f2fs-add-inline-tail-mount-option/20240911-114705 base: 67784a74e258a467225f0e68335df77acd67b7ab patch link: https://lore.kernel.org/r/57e1dbb2f348ab61cbc82be7161d788a08b5fbed.1726024117.git.bo.wu%40vivo.com patch subject: [PATCH v2 13/13] f2fs: implement inline tail forward recovery config: x86_64-randconfig-121-20240913 (https://download.01.org/0day-ci/archive/20240913/[email protected]/config) compiler: clang version 18.1.8 (https://github.com/llvm/llvm-project 3b5b5c1ec4a3095ab096dd780e84d7ab81f3d7ff) reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20240913/[email protected]/reproduce)
If you fix the issue in a separate patch/commit (i.e. not just a new version of the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <[email protected]>
| Closes: https://lore.kernel.org/oe-kbuild-all/[email protected]/
sparse warnings: (new ones prefixed by >>)
>> fs/f2fs/inline.c:457:27: sparse: sparse: cast to restricted __le32
vim +457 fs/f2fs/inline.c
416
417 int f2fs_recover_inline_tail(struct inode *inode, struct page *npage)
418 {
419 struct f2fs_sb_info *sbi = F2FS_I_SB(inode);
420 struct f2fs_inode *ri = NULL;
421 void *src_addr, *dst_addr;
422 struct page *ipage;
423
424 if (IS_INODE(npage))
425 ri = F2FS_INODE(npage);
426
427 if (f2fs_has_inline_tail(inode) &&
428 ri && (le32_to_cpu(ri->i_flags) & F2FS_INLINE_TAIL)) {
429 process_inline:
430 if (!(ri->i_inline & F2FS_DATA_EXIST))
431 return 0;
432
433 ipage = f2fs_get_node_page(sbi, inode->i_ino);
434 if (IS_ERR(ipage))
435 return PTR_ERR(ipage);
436
437 f2fs_wait_on_page_writeback(ipage, NODE, true, true);
438
439 src_addr = inline_data_addr(inode, npage);
440 dst_addr = inline_data_addr(inode, ipage);
441 memcpy(dst_addr, src_addr, MAX_INLINE_DATA(inode));
442
443 set_inode_flag(inode, FI_DATA_EXIST);
444
445 set_page_dirty(ipage);
446 f2fs_put_page(ipage, 1);
447 return 0;
448 }
449
450 if (f2fs_has_inline_tail(inode)) {
451 ipage = f2fs_get_node_page(sbi, inode->i_ino);
452 if (IS_ERR(ipage))
453 return PTR_ERR(ipage);
454 f2fs_truncate_inline_inode(inode, ipage, 0);
455 clear_inode_flag(inode, FI_INLINE_TAIL);
456 f2fs_put_page(ipage, 1);
> 457 } else if (ri && (le32_to_cpu(ri->i_inline) & F2FS_INLINE_TAIL)) { 458 int ret;
459
460 ret = f2fs_truncate_blocks(inode,
461 COMPACT_ADDRS_PER_INODE >> PAGE_SHIFT, false);
462 if (ret)
463 return ret;
464 goto process_inline;
465 }
466 return 0;
467 }
468 struct f2fs_dir_entry *f2fs_find_in_inline_dir(struct inode *dir,
469 const struct f2fs_filename *fname,
470 struct page **res_page)
471 {
472 struct f2fs_sb_info *sbi = F2FS_SB(dir->i_sb);
473 struct f2fs_dir_entry *de;
474 struct f2fs_dentry_ptr d;
475 struct page *ipage;
476 void *inline_dentry;
477
478 ipage = f2fs_get_node_page(sbi, dir->i_ino);
479 if (IS_ERR(ipage)) {
480 *res_page = ipage;
481 return NULL;
482 }
483
484 inline_dentry = inline_data_addr(dir, ipage);
485
486 make_dentry_ptr_inline(dir, &d, inline_dentry);
487 de = f2fs_find_target_dentry(&d, fname, NULL);
488 unlock_page(ipage);
489 if (IS_ERR(de)) {
490 *res_page = ERR_CAST(de);
491 de = NULL;
492 }
493 if (de)
494 *res_page = ipage;
495 else
496 f2fs_put_page(ipage, 0);
497
498 return de;
499 }
500
Signature · 2 lines
0-DAY CI Kernel Test Service https://github.com/intel/lkp-tests/wiki
Quoted 53 lines · On Thu, Sep 12, 2024 at 03:14:24PM +0800, Chao Yu via Linux-f2fs-devel wrote:
Quoted 44 lines · Wu Bo
The inode in F2FS occupies an entire 4k block. For many small files, this means they consume much more space than their actual size. Therefore, there is significant potential to better utilize the inode block space.
Currently, F2FS has two features to make use of the inode block space: inline data and inline xattr.
Inline data stores file which size is smaller then 3.5k in inode block. However, for slightly larger small files, there still have much waste.
For example, a 5k file requires 3 blocks, totaling 12k of space, which is more than twice the size of the file itself!Additionally, the end of a file often does not occupy an entire block. If we can store the end of the file data within the inode block, we can save an entire block for the file. This is particularly important for small files.
In fact, the current inline data is a special case of inline tail, and inline tail is an extension of inline data.
To make it simple, inline tail only on small files(<64k). And for larger files, inline tails don't provide any significant benefits.
The layout of an inline tail inode block is following:
| inode block | 4096 | inline tail enable | | --------------- | ---- | --------------------------| | inode info | 360 | | | --------------- | ---- | --------------------------| | | | extra info | 0~36 | | | | **compact_addr[16] | 64 | | addr table[923] | 3692 | reserved | 4 | | | | **tail data | | | | | inline_xattr | 200 | | --------------- | ---- | --------------------------| | nid table[5] | 20 | | node footer | 24 |F2fs-tools to support inline tail:
https://lore.kernel.org/linux-f2fs-devel/[email protected]I tested inline tail by copying the source code of Linux 6.9.7. The storage space was reduced by approximately 8%. Additionally, due to the reduced IO, the copy time also reduced by around 10%.
Quoted 7 lines
This patch series has been tested with xfstests by running 'kvm-xfstests -c f2fs -g quick' both with and without the patch; no regressions were observed. The test result is:
f2fs/default: 583 tests, 6 failures, 213 skipped, 650 seconds
Failures: generic/050 generic/064 generic/250 generic/252 generic/563generic/735 Totals: 607 tests, 213 skipped, 30 failures, 0 errors, 579s
Quoted 2 lines
MKFS_OPTIONS-- -O extra_attr,encrypt,inode_checksum,flexible_inline_xattr,inode_crtime,verity,compression -f/dev/vdcMOUNT_OPTIONS-- -o acl,user_xattr -o discard,inline_tail/dev/vdc/mnt/scratch_f2fs
Hi Chao,
I used the default cfg to run xfstest-bld and didn't encounter the failed failures. This suggests the issue might be related to these additional options. However, I'm not sure how to include these options when running xfstest-bld. Could you let me know how to add them?
Thanks
Quoted 57 lines
Before:
Failures: generic/042 generic/050 generic/250 generic/252 generic/270 generic/389 generic/563 generic/700 generic/735 Failed 9 of 746 testsAfter:
Failures: generic/042 generic/050 generic/125 generic/250 generic/252 generic/270 generic/389 generic/418 generic/551 generic/563 generic/700 generic/735 Failed 12 of 746 testsFailures: f2fs/004
Can you please check failed testcases?
Thanks,
Quoted 34 lines
---
v2:
- fix ARCH=arc build warning---
Wu Bo (13):
f2fs: add inline tail mount option
f2fs: add inline tail disk layout definition
f2fs: implement inline tail write & truncate
f2fs: implement inline tail read & fiemap
f2fs: set inline tail flag when create inode
f2fs: fix address info has been truncated
f2fs: support seek for inline tail
f2fs: convert inline tail when inode expand
f2fs: fix data loss during inline tail writing
f2fs: avoid inlining quota files
f2fs: fix inline tail data lost
f2fs: convert inline tails to avoid potential issues
f2fs: implement inline tail forward recoveryfs/f2fs/data.c | 93 +++++++++++++++++++++++++- fs/f2fs/f2fs.h | 46 ++++++++++++- fs/f2fs/file.c | 85 +++++++++++++++++++++++- fs/f2fs/inline.c | 159 +++++++++++++++++++++++++++++++++++++++------ fs/f2fs/inode.c | 6 ++ fs/f2fs/namei.c | 3 + fs/f2fs/node.c | 6 +- fs/f2fs/recovery.c | 9 ++- fs/f2fs/super.c | 25 +++++++ fs/f2fs/verity.c | 4 ++ 10 files changed, 409 insertions(+), 27 deletions(-)Quoted 1 line
base-commit:
67784a74e258a467225f0e68335df77acd67b7ab_______________________________________________
Linux-f2fs-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/linux-f2fs-devel
Quoted 57 lines · On Fri, Sep 13, 2024 at 08:41:12PM -0600, Wu Bo via Linux-f2fs-devel wrote:
Quoted 53 lines · On Thu, Sep 12, 2024 at 03:14:24PM +0800, Chao Yu via Linux-f2fs-devel wrote:
Quoted 44 lines · Wu Bo
The inode in F2FS occupies an entire 4k block. For many small files, this means they consume much more space than their actual size. Therefore, there is significant potential to better utilize the inode block space.
Currently, F2FS has two features to make use of the inode block space: inline data and inline xattr.
Inline data stores file which size is smaller then 3.5k in inode block. However, for slightly larger small files, there still have much waste.
For example, a 5k file requires 3 blocks, totaling 12k of space, which is more than twice the size of the file itself!Additionally, the end of a file often does not occupy an entire block. If we can store the end of the file data within the inode block, we can save an entire block for the file. This is particularly important for small files.
In fact, the current inline data is a special case of inline tail, and inline tail is an extension of inline data.
To make it simple, inline tail only on small files(<64k). And for larger files, inline tails don't provide any significant benefits.
The layout of an inline tail inode block is following:
| inode block | 4096 | inline tail enable | | --------------- | ---- | --------------------------| | inode info | 360 | | | --------------- | ---- | --------------------------| | | | extra info | 0~36 | | | | **compact_addr[16] | 64 | | addr table[923] | 3692 | reserved | 4 | | | | **tail data | | | | | inline_xattr | 200 | | --------------- | ---- | --------------------------| | nid table[5] | 20 | | node footer | 24 |F2fs-tools to support inline tail:
https://lore.kernel.org/linux-f2fs-devel/[email protected]I tested inline tail by copying the source code of Linux 6.9.7. The storage space was reduced by approximately 8%. Additionally, due to the reduced IO, the copy time also reduced by around 10%.
Quoted 7 lines
This patch series has been tested with xfstests by running 'kvm-xfstests -c f2fs -g quick' both with and without the patch; no regressions were observed. The test result is:
f2fs/default: 583 tests, 6 failures, 213 skipped, 650 seconds
Failures: generic/050 generic/064 generic/250 generic/252 generic/563generic/735 Totals: 607 tests, 213 skipped, 30 failures, 0 errors, 579sQuoted 2 lines
MKFS_OPTIONS-- -O extra_attr,encrypt,inode_checksum,flexible_inline_xattr,inode_crtime,verity,compression -f/dev/vdcMOUNT_OPTIONS-- -o acl,user_xattr -o discard,inline_tail/dev/vdc/mnt/scratch_f2fs
Quoted 8 lines
Hi Chao,
I used the default cfg to run xfstest-bld and didn't encounter the failed failures. This suggests the issue might be related to these additional options. However, I'm not sure how to include these options when running xfstest-bld. Could you let me know how to add them?
Thanks
I found how to pass these options:
1. Add custom config file
``` # cat test-appliance/files/root/fs/f2fs/cfg/custom SIZE=small export MKFS_OPTIONS="-O extra_attr,encrypt,inode_checksum,flexible_inline_xattr,inode_crtime,verity,compression -f" export F2FS_MOUNT_OPTIONS="discard,inline_tail" TESTNAME="f2fs custom" ``` 2. Then run command as following: ``` kvm-xfstests -c f2fs/custom "generic/418" ```
However, I am only able to reproduce generic/418 and f2fs/004. I will look into these two cases first.
Quoted 64 lines
Quoted 50 lines
Before:
Failures: generic/042 generic/050 generic/250 generic/252 generic/270 generic/389 generic/563 generic/700 generic/735 Failed 9 of 746 testsAfter:
Failures: generic/042 generic/050 generic/125 generic/250 generic/252 generic/270 generic/389 generic/418 generic/551 generic/563 generic/700 generic/735 Failed 12 of 746 testsFailures: f2fs/004
Can you please check failed testcases?
Thanks,
Quoted 34 lines
---
v2:
- fix ARCH=arc build warning---
Wu Bo (13):
f2fs: add inline tail mount option
f2fs: add inline tail disk layout definition
f2fs: implement inline tail write & truncate
f2fs: implement inline tail read & fiemap
f2fs: set inline tail flag when create inode
f2fs: fix address info has been truncated
f2fs: support seek for inline tail
f2fs: convert inline tail when inode expand
f2fs: fix data loss during inline tail writing
f2fs: avoid inlining quota files
f2fs: fix inline tail data lost
f2fs: convert inline tails to avoid potential issues
f2fs: implement inline tail forward recoveryfs/f2fs/data.c | 93 +++++++++++++++++++++++++- fs/f2fs/f2fs.h | 46 ++++++++++++- fs/f2fs/file.c | 85 +++++++++++++++++++++++- fs/f2fs/inline.c | 159 +++++++++++++++++++++++++++++++++++++++------ fs/f2fs/inode.c | 6 ++ fs/f2fs/namei.c | 3 + fs/f2fs/node.c | 6 +- fs/f2fs/recovery.c | 9 ++- fs/f2fs/super.c | 25 +++++++ fs/f2fs/verity.c | 4 ++ 10 files changed, 409 insertions(+), 27 deletions(-)Quoted 8 lines
Quoted 1 line
base-commit:
67784a74e258a467225f0e68335df77acd67b7ab_______________________________________________
Linux-f2fs-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/linux-f2fs-devel_______________________________________________
Linux-f2fs-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/linux-f2fs-devel