f2fs: introduce inline extent mapping for inode data blocks
Subsystems (2)
v2 cover f2fs: introduce inline extent mapping for inode data blocks
From: Yongpeng Yang <[email protected]>
Changes since v1:
- Introduce tracepoints for f2fs_iext_update_data_blkaddr and f2fs_iext_lookup_blkaddr to aid debugging (new patch 5/5).
- Bypass inline extent lookup for F2FS_GET_BLOCK_PRECACHE to ensure all mappings are loaded into the read extent cache.
- Unify the check for fofs exceeding direct_blocks range to use "fofs >= direct_blocks" consistently.
- Remove support for caching NULL_ADDR in inline extent area. If a fofs within [0, direct_blocks) is not found in inline extent, it implies NULL_ADDR. This simplifies merge and split logic.
- Fix f2fs_iext_enable_inline_extent to use PTR_ERR instead of -ENOMEM.
- Change f2fs_iext_convert_to_inline_extent return type to bool.
- Add benchmark data covering 4K/8K/32K/64K random read.
- Rename __is_extent_mergeable to __is_iextent_mergeable to avoid naming collision with extent cache code.
- Remove inode parameter from f2fs_iext_sanity_check (always NULL).
- Reduce #ifdef CONFIG_F2FS_INLINE_EXTENT nesting in node.c.
- Code style fixes to comply with kernel coding style.
This patchset introduces an inline extent mapping mechanism for f2fs. Instead of storing individual block addresses in the inode's data block address area (i_addr[]), this feature packs contiguous block ranges into compact extent entries, significantly reducing the number of entries needed and enabling faster block address lookups via binary search.
The inline extent format is identified by magic numbers in the inode data area and is transparent to the rest of f2fs -- when the extent area is full or cannot represent the mapping efficiently, it automatically converts back to the direct block address format.
Patch 1: Preparatory refactoring -- replace raw pointer arithmetic
with f2fs_data_blkaddr() to abstract block address access.
Patch 2: Core implementation -- data structures, extent operations
(lookup, insert, merge, split, truncate), format conversion, and integration with f2fs data/node paths.
Patch 3: ioctl interface -- allow per-file enable/disable of inline
extent format via F2FS_EXTENT_FL flag.
Patch 4: sysfs interface -- runtime enable/disable toggle and file
extension list for automatic inline extent activation.
Patch 5: Tracepoints for inline extent lookup and update operations.
Test setup and results:
=======================
Platform: Xiaomi smartphone, UFS 4.0 storage
# Enable inline extent
echo 1 > /sys/fs/f2fs/<dev>/inline_extent_enable echo 'mp4' > /sys/fs/f2fs/<dev>/inline_extent_extension_list
# Prepare data: write with 4K offset stride to create fragmented
# extents, then overwrite sequentially so inline extent can cache
# all mappings in compact form.
fio --name=test --filename=data.mp4 --rw=write:4k --bs=64M \
--size=8G --ioengine=libaio --direct=1
sync
fio --name=test --filename=data.mp4 --rw=write --bs=64M \
--size=8G --ioengine=libaio --direct=1
sync
echo 3 > /proc/sys/vm/drop_caches
# Benchmark: random buffered read, 1GB total IO
fio --name=buffer-read --ioengine=libaio --rw=randread --bs=$BS \
--size=8G --io_size=1G --numjobs=1 --filename=data.mp4Results (random read bandwidth, MiB/s):
+---------------------------------------------------+ | BS | baseline | inline ext | improvement | |--------+----------+------------+------------------| | 4K | 35 | 36 | +2.5% | | 8K | 60 | 62 | +3% | | 32K | 179 | 191 | +6.8% | | 64K | 284 | 321 | +13% | +---------------------------------------------------+
The improvement comes from eliminating direct/indirect node page reads during block address lookup -- all mappings are stored directly in the inode page and found via O(log n) binary search.
Yongpeng Yang (5):
f2fs: replace raw dnode pointer arithmetic with f2fs_data_blkaddr()
f2fs: introduce inline extent mapping for inode data blocks
f2fs: support setting inline extent flag via ioctl
f2fs: add sysfs interface for inline extent management
f2fs: introduce tracepoints for inline extent lookup and update
fs/f2fs/Kconfig | 18 + fs/f2fs/Makefile | 1 + fs/f2fs/data.c | 157 ++++++- fs/f2fs/debug.c | 4 + fs/f2fs/dir.c | 9 + fs/f2fs/f2fs.h | 23 +- fs/f2fs/file.c | 93 +++- fs/f2fs/iextent.c | 873 ++++++++++++++++++++++++++++++++++++ fs/f2fs/iextent.h | 187 ++++++++ fs/f2fs/inline.c | 7 + fs/f2fs/namei.c | 48 ++ fs/f2fs/node.c | 66 ++- fs/f2fs/node.h | 4 + fs/f2fs/recovery.c | 17 + fs/f2fs/super.c | 13 + fs/f2fs/sysfs.c | 52 +++ include/trace/events/f2fs.h | 79 ++++ 17 files changed, 1635 insertions(+), 16 deletions(-) create mode 100644 fs/f2fs/iextent.c create mode 100644 fs/f2fs/iextent.h
Signature · 8 lines
2.43.0 _______________________________________________ Linux-f2fs-devel mailing list [email protected] https://lists.sourceforge.net/lists/listinfo/linux-f2fs-devel
RFC PATCH v2 1/5 f2fs: replace raw dnode pointer arithmetic with f2fs_data_blkaddr()
From: Yongpeng Yang <[email protected]>
The raw __le32 pointer arithmetic in f2fs_truncate_data_blocks_range() directly accesses block addresses via get_dnode_addr() and pointer increment. This pattern is not friendly for inline extent access where the inode data layout may differ from direct block format.
Replace the raw pointer access with f2fs_data_blkaddr() which provides a proper abstraction layer. This prepares for inline extent support where the data block address retrieval needs to go through a different path.
--- fs/f2fs/file.c | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-)
fs/f2fs/file.c +7 -6
@@ -659,7 +659,6 @@ void f2fs_truncate_data_blocks_range(struct dnode_of_data *dn, int count) {struct f2fs_sb_info *sbi =F2FS_I_SB (dn->inode);int nr_free =0 , ofs = dn->ofs_in_node, len = count; -__le32 *addr;bool compressed_cluster = false;int cluster_index =0 , valid_blocks =0 ;int cluster_size =F2FS_I (dn->inode)->i_cluster_size;
@@ -667,12 +666,11 @@ void f2fs_truncate_data_blocks_range(struct dnode_of_data *dn, int count)block_t blkstart;int blklen =0 ; - addr =get_dnode_addr (dn->inode, dn->node_folio) + ofs; - blkstart =le32_to_cpu (*addr); + blkstart =f2fs_data_blkaddr (dn);/* Assumption: truncation starts with cluster */ -for (; count >0 ; count--, addr++, dn->ofs_in_node++, cluster_index++) { -block_t blkaddr =le32_to_cpu (*addr); +for (; count >0 ; count--, dn->ofs_in_node++, cluster_index++) { +block_t blkaddr =f2fs_data_blkaddr (dn);if (f2fs_compressed_file (dn->inode) && !(cluster_index & (cluster_size -1 ))) {
@@ -715,7 +713,10 @@ void f2fs_truncate_data_blocks_range(struct dnode_of_data *dn, int count)if (blklen)f2fs_invalidate_blocks (sbi, blkstart, blklen); - blkstart =le32_to_cpu (*(addr +1 )); +/* data_blkaddr may exceed the boundary of blocks. */ +if (count >1 ) + blkstart =data_blkaddr (dn->inode, + dn->node_folio, dn->ofs_in_node +1 ); blklen =0 ; }
Signature · 8 lines
2.43.0 _______________________________________________ Linux-f2fs-devel mailing list [email protected] https://lists.sourceforge.net/lists/listinfo/linux-f2fs-devel
RFC PATCH v2 2/5 f2fs: introduce inline extent mapping for inode data blocks
In reply to Yongpeng YangFrom: Yongpeng Yang <[email protected]>
Implement an inline extent mapping mechanism that stores extent information directly in the inode's data block address area. This provides a more space-efficient representation when contiguous block ranges can be described by fewer extent entries than individual block addresses.
The inline extent format uses a magic-number-based identification in the inode block address space and maintains a sorted array of extents with binary search for lookup operations.
Main changes:
- Add extent lookup, insert, update, and merge operations
- Add extent management (format conversion between direct blocks and inline extents, truncation)
- Add f2fs_iext_info to sbi for global inline extent state
- Add Kconfig options (CONFIG_F2FS_INLINE_EXTENT and CONFIG_F2FS_INLINE_EXTENT_DEBUG for statistics)
- Integrate with existing f2fs data path, node operations, and recovery
Test setup (Xiaomi smartphone, UFS 4.0 storage, f2fs):
echo 1 > /sys/fs/f2fs/<dev>/inline_extent_enable
echo 'mp4' > /sys/fs/f2fs/<dev>/inline_extent_extension_list
fio --name=test --filename=data.mp4 --rw=write:4k --bs=64M \
--size=8G --ioengine=libaio --direct=1
sync
fio --name=test --filename=data.mp4 --rw=write --bs=64M \
--size=8G --ioengine=libaio --direct=1
sync
echo 3 > /proc/sys/vm/drop_caches
fio --name=buffer-read --ioengine=libaio --rw=randread --bs=$BS \
--size=8G --io_size=1G --numjobs=1 --filename=data.mp4Results (random read bandwidth, MiB/s):
+---------------------------------------------------+ | BS | baseline | inline ext | improvement | |--------+----------+------------+------------------| | 4K | 35 | 36 | +2.5% | | 8K | 60 | 62 | +3% | | 32K | 179 | 191 | +6.8% | | 64K | 284 | 321 | +13% | +---------------------------------------------------+
---
v2:
- Bypass inline extent lookup for F2FS_GET_BLOCK_PRECACHE.
- Unify fofs range check to "fofs >= direct_blocks".
- Remove NULL_ADDR caching support; simplify merge/split logic.
- Change f2fs_iext_convert_to_inline_extent return type to bool.
- Rename __is_extent_mergeable to __is_iextent_mergeable.
- Remove inode parameter from f2fs_iext_sanity_check.
- Reduce #ifdef nesting in node.c.
- Add complete benchmark data (4K/8K/32K/64K).
- Code style fixes.
--- fs/f2fs/Kconfig | 18 + fs/f2fs/Makefile | 1 + fs/f2fs/data.c | 157 ++++++++- fs/f2fs/dir.c | 9 + fs/f2fs/f2fs.h | 23 +- fs/f2fs/file.c | 1 + fs/f2fs/iextent.c | 823 +++++++++++++++++++++++++++++++++++++++++++++ fs/f2fs/iextent.h | 184 ++++++++++ fs/f2fs/inline.c | 7 + fs/f2fs/namei.c | 48 +++ fs/f2fs/node.c | 66 +++- fs/f2fs/node.h | 4 + fs/f2fs/recovery.c | 17 + fs/f2fs/super.c | 13 + 14 files changed, 1361 insertions(+), 10 deletions(-) create mode 100644 fs/f2fs/iextent.c create mode 100644 fs/f2fs/iextent.h
fs/f2fs/Kconfig +18 -0
@@ -150,3 +150,21 @@ config F2FS_UNFAIR_RWSEM help Use unfair rw_semaphore, if system configured IO priority by block cgroup. + +config F2FS_INLINE_EXTENT + bool "F2FS inline extent" + depends on F2FS_FS + default y + help + Support the inline extent feature: leverage the inode's data block + address area to store extent-format mapping relationships, replacing + individual block addresses with compact extent entries to optimize + large file random reads. + +config F2FS_INLINE_EXTENT_DEBUG + bool "F2FS inline extent debug" + depends on F2FS_INLINE_EXTENT + default n + help + Support inline extent debug to stat code coverage and extents + consistency check.
fs/f2fs/Makefile +1 -0
@@ -4,6 +4,7 @@ obj-$(CONFIG_F2FS_FS) += f2fs.o f2fs-y := dir.o file.o inode.o namei.o hash.o super.o inline.o f2fs-y += checkpoint.o gc.o data.o node.o segment.o recovery.o f2fs-y += shrinker.o extent_cache.o sysfs.o +f2fs-$(CONFIG_F2FS_INLINE_EXTENT) += iextent.o f2fs-$(CONFIG_F2FS_STAT_FS) += debug.o f2fs-$(CONFIG_F2FS_FS_XATTR) += xattr.o f2fs-$(CONFIG_F2FS_FS_POSIX_ACL) += acl.o
fs/f2fs/data.c +156 -1
198 lines not on this page · raw message
fs/f2fs/dir.c +9 -0
@@ -16,6 +16,7 @@#include "node.h" #include "acl.h" #include "xattr.h" +#include "iextent.h" #include <trace/events/f2fs.h> static inline bool f2fs_should_fallback_to_linear (struct inode *dir)
@@ -543,6 +544,14 @@ struct folio *f2fs_init_inode_metadata(struct inode *inode, struct inode *dir,if (IS_ERR (folio))return folio; +#ifdef CONFIG_F2FS_INLINE_EXTENT +if (S_ISREG (inode->i_mode) && + (F2FS_I (inode)->i_flags &F2FS_EXTENT_FL ) && + !is_inode_flag_set (inode,FI_INLINE_DATA )) { +f2fs_iext_init_inline_extent (inode, folio); +folio_mark_dirty (folio); + } +#endif if (S_ISDIR (inode->i_mode)) {/* in order to handle error case */ folio_get (folio);
fs/f2fs/f2fs.h +22 -1
@@ -1137,6 +1137,8 @@ static inline void set_new_dnode(struct dnode_of_data *dn, struct inode *inode, dn->inode_folio = ifolio; dn->node_folio = nfolio; dn->nid = nid; +if (ifolio !=NULL ) + dn->inode_folio_locked =folio_test_locked (ifolio); }/*
@@ -1769,6 +1771,10 @@ struct f2fs_sb_info {struct f2fs_nm_info *nm_info;/* node manager */ struct inode *node_inode;/* cache node blocks */ +#ifdef CONFIG_F2FS_INLINE_EXTENT +struct f2fs_iext_info *iext_info; +#endif +/* for segment-related operations */ struct f2fs_sm_info *sm_info;/* segment manager */
@@ -3106,12 +3112,15 @@ static inline void f2fs_put_page(struct page *page, bool unlock)f2fs_folio_put (page_folio (page), unlock); } +static inline __le32 *get_dnode_addr (struct inode *inode, +struct folio *node_folio);static inline void f2fs_put_dnode (struct dnode_of_data *dn) {if (dn->node_folio)f2fs_folio_put (dn->node_folio, true);if (dn->inode_folio && dn->node_folio != dn->inode_folio) -f2fs_folio_put (dn->inode_folio, false); +f2fs_folio_put (dn->inode_folio, + dn->inode_folio_locked); dn->node_folio =NULL ; dn->inode_folio =NULL ; }
@@ -3240,9 +3249,20 @@ static inline __le32 *get_dnode_addr(struct inode *inode,get_dnode_base (inode, node_folio); } +#ifdef CONFIG_F2FS_INLINE_EXTENT +int f2fs_iext_data_blkaddr (struct inode *inode, +struct folio *node_folio,unsigned int offset, +block_t *blkaddr); +#endif static inline block_t data_blkaddr (struct inode *inode,struct folio *node_folio,unsigned int offset) { +#ifdef CONFIG_F2FS_INLINE_EXTENT +block_t blkaddr; + +if (!f2fs_iext_data_blkaddr (inode, node_folio, offset, &blkaddr)) +return blkaddr; +#endif return le32_to_cpu (*(get_dnode_addr (inode, node_folio) + offset)); }
@@ -3323,6 +3343,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_EXTENT_FL 0x00080000/* Extents */ #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 */
fs/f2fs/file.c +1 -0
@@ -2209,6 +2209,7 @@ static const struct { { F2FS_NOCOMP_FL, FS_NOCOMP_FL }, { F2FS_INDEX_FL, FS_INDEX_FL }, { F2FS_DIRSYNC_FL, FS_DIRSYNC_FL }, + { F2FS_EXTENT_FL, FS_EXTENT_FL }, { F2FS_PROJINHERIT_FL, FS_PROJINHERIT_FL }, { F2FS_CASEFOLD_FL, FS_CASEFOLD_FL }, };
fs/f2fs/iextent.c new file +823 -0
823 lines not on this page · raw message
fs/f2fs/iextent.h new file +184 -0
184 lines not on this page · raw message
fs/f2fs/inline.c +7 -0
@@ -13,6 +13,7 @@#include "f2fs.h" #include "node.h" +#include "iextent.h" #include <trace/events/f2fs.h> static bool support_inline_data (struct inode *inode)
@@ -212,6 +213,12 @@ int f2fs_convert_inline_folio(struct dnode_of_data *dn, struct folio *folio) clear_out:stat_dec_inline_inode (dn->inode);clear_inode_flag (dn->inode,FI_INLINE_DATA ); +#ifdef CONFIG_F2FS_INLINE_EXTENT +if (F2FS_I (dn->inode)->i_flags &F2FS_EXTENT_FL ) +if (f2fs_iext_convert_to_inline_extent ( + dn->inode, dn->inode_folio)) +folio_mark_dirty (dn->inode_folio); +#endif f2fs_put_dnode (dn);return 0 ; }
fs/f2fs/namei.c +48 -0
72 lines not on this page · raw message
fs/f2fs/node.c +58 -8
137 lines not on this page · raw message
fs/f2fs/node.h +4 -0
@@ -259,6 +259,10 @@ static inline unsigned int ofs_of_node(const struct folio *node_folio)return flag >>OFFSET_BIT_SHIFT ; } +int f2fs_iext_data_blkaddr (struct inode *inode, +struct folio *node_folio,unsigned int offset, +block_t *blkaddr); +static inline __u64 cpver_of_node (const struct folio *node_folio) {struct f2fs_node *rn =F2FS_NODE (node_folio);
fs/f2fs/recovery.c +17 -0
@@ -13,6 +13,7 @@#include "f2fs.h" #include "node.h" #include "segment.h" +#include "iextent.h" /* * Roll forward recovery scenarios.
@@ -665,6 +666,22 @@ static int do_recover_data(struct f2fs_sb_info *sbi, struct inode *inode, } goto out; } +#ifdef CONFIG_F2FS_INLINE_EXTENT +if (f2fs_iext_support_inline_extent (inode, + dn.inode_folio)) { +f2fs_bug_on (F2FS_I_SB (inode), + !dn.inode_folio_locked); +f2fs_bug_on (F2FS_I_SB (inode), + !folio_test_locked (dn.inode_folio)); +f2fs_folio_wait_writeback (dn.inode_folio,NODE , true, true); +if (f2fs_iext_last_fofs (inode, dn.inode_folio) >= +ADDRS_PER_INODE (inode)) { +f2fs_iext_truncate_from_blkaddr (inode, + dn.inode_folio,ADDRS_PER_INODE (inode)); +folio_mark_dirty (dn.inode_folio); + } + } +#endif f2fs_folio_wait_writeback (dn.node_folio,NODE , true, true);
fs/f2fs/super.c +13 -0
@@ -37,6 +37,7 @@#include "xattr.h" #include "gc.h" #include "iostat.h" +#include "iextent.h" #define CREATE_TRACE_POINTS #include <trace/events/f2fs.h>
@@ -5037,6 +5038,12 @@ static int f2fs_fill_super(struct super_block *sb, struct fs_context *fc) sbi->sb = sb; +#ifdef CONFIG_F2FS_INLINE_EXTENT + err =f2fs_iext_info_init (sbi); +if (err) + goto free_sbi; +#endif +/* initialize locks within allocated memory */ init_f2fs_rwsem_trace (&sbi->gc_lock, sbi,LOCK_NAME_GC_LOCK );mutex_init (&sbi->writepages);
@@ -5524,6 +5531,9 @@ static int f2fs_fill_super(struct super_block *sb, struct fs_context *fc) free_sbi:#ifdef CONFIG_DEBUG_LOCK_ALLOC lockdep_unregister_key (&sbi->cp_global_sem_key); +#endif +#ifdef CONFIG_F2FS_INLINE_EXTENT +f2fs_iext_info_destroy (sbi);#endif kfree (sbi); sb->s_fs_info =NULL ;
@@ -5608,6 +5618,9 @@ static void kill_f2fs_super(struct super_block *sb)destroy_device_list (sbi);#ifdef CONFIG_DEBUG_LOCK_ALLOC lockdep_unregister_key (&sbi->cp_global_sem_key); +#endif +#ifdef CONFIG_F2FS_INLINE_EXTENT +f2fs_iext_info_destroy (sbi);#endif kfree (sbi); sb->s_fs_info =NULL ;
Signature · 8 lines
2.43.0 _______________________________________________ Linux-f2fs-devel mailing list [email protected] https://lists.sourceforge.net/lists/listinfo/linux-f2fs-devel
RFC PATCH v2 3/5 f2fs: support setting inline extent flag via ioctl
In reply to Yongpeng YangFrom: Yongpeng Yang <[email protected]>
Allow userspace to enable or disable inline extent format on a per-file basis through the FS_IOC_SETFLAGS/FS_IOC_GETFLAGS ioctl interface using the F2FS_EXTENT_FL flag.
When setting the flag, the file's direct block addresses are converted to inline extent format. Compressed files are excluded from this conversion as the two features are mutually exclusive. Clearing the flag converts back to direct block format without restrictions.
---
v2:
- Fix f2fs_iext_enable_inline_extent to use PTR_ERR(ifolio) instead of hardcoded -ENOMEM.
--- fs/f2fs/file.c | 79 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 79 insertions(+)
fs/f2fs/file.c +79 -0
@@ -33,6 +33,7 @@#include "acl.h" #include "gc.h" #include "iostat.h" +#include "iextent.h" #include <trace/events/f2fs.h> #include <uapi/linux/f2fs.h>
@@ -2117,6 +2118,58 @@ static int f2fs_file_flush(struct file *file, fl_owner_t id)return 0 ; } +#ifdef CONFIG_F2FS_INLINE_EXTENT +static int f2fs_iext_enable_inline_extent (struct inode *inode) +{ +int ret =0 ; +struct folio *ifolio =NULL ; + +if (f2fs_has_inline_data (inode)) + goto out; + + ret =filemap_write_and_wait (inode->i_mapping); +if (ret) + goto out; + + ifolio =f2fs_get_inode_folio (F2FS_I_SB (inode), inode->i_ino); +if (IS_ERR (ifolio)) +return PTR_ERR (ifolio); + +if (!f2fs_iext_convert_to_inline_extent (inode, ifolio)) { +f2fs_folio_put (ifolio, true); +f2fs_err (F2FS_I_SB (inode),"convert to inline extent failed!" ); + ret = -EINVAL ; + goto out; + } +folio_mark_dirty (ifolio); +f2fs_folio_put (ifolio, true); + +out: +return ret; +} + +static int f2fs_iext_disable_inline_extent (struct inode *inode) +{ +struct folio *ifolio; +int ret; + + ret =filemap_write_and_wait (inode->i_mapping); +if (ret) +return ret; + + ifolio =f2fs_get_inode_folio (F2FS_I_SB (inode), inode->i_ino); +if (IS_ERR (ifolio)) +return PTR_ERR (ifolio); +if (!f2fs_iext_support_inline_extent (inode, ifolio)) + goto out; +f2fs_iext_convert_to_direct_blocks (inode, ifolio); +folio_mark_dirty (ifolio); +out: +f2fs_folio_put (ifolio, true); +return 0 ; +} +#endif +static int f2fs_setflags_common (struct inode *inode,u32 iflags,u32 mask) {struct f2fs_inode_info *fi =F2FS_I (inode);
@@ -2129,6 +2182,30 @@ static int f2fs_setflags_common(struct inode *inode, u32 iflags, u32 mask)if (IS_NOQUOTA (inode))return -EPERM ; +#ifdef CONFIG_F2FS_INLINE_EXTENT +if (iflags &F2FS_EXTENT_FL ) { +int ret; + +if (!S_ISREG (inode->i_mode)) +return -EOPNOTSUPP ; +if (iflags &F2FS_COMPR_FL ) +return -EOPNOTSUPP ; +if (f2fs_compressed_file (inode)) +return -EOPNOTSUPP ; + ret =f2fs_iext_enable_inline_extent (inode); +if (ret) +return ret; + } +if ((iflags ^ masked_flags) &F2FS_EXTENT_FL ) { +if (masked_flags &F2FS_EXTENT_FL ) { +int ret =f2fs_iext_disable_inline_extent (inode); + +if (ret) +return ret; + } + } +#endif +if ((iflags ^ masked_flags) &F2FS_CASEFOLD_FL ) {if (!f2fs_sb_has_casefold (F2FS_I_SB (inode)))return -EOPNOTSUPP ;
@@ -2224,6 +2301,7 @@ static const struct {FS_NOCOMP_FL | \FS_INDEX_FL | \FS_DIRSYNC_FL | \ +FS_EXTENT_FL | \FS_PROJINHERIT_FL | \FS_ENCRYPT_FL | \ FS_INLINE_DATA_FL | \
@@ -2240,6 +2318,7 @@ static const struct {FS_NOATIME_FL | \FS_NOCOMP_FL | \FS_DIRSYNC_FL | \ +FS_EXTENT_FL | \FS_PROJINHERIT_FL | \ FS_CASEFOLD_FL)
Signature · 8 lines
2.43.0 _______________________________________________ Linux-f2fs-devel mailing list [email protected] https://lists.sourceforge.net/lists/listinfo/linux-f2fs-devel
RFC PATCH v2 4/5 f2fs: add sysfs interface for inline extent management
In reply to Yongpeng YangFrom: Yongpeng Yang <[email protected]>
Add sysfs attributes to manage the inline extent feature at runtime:
- inline_extent_extension_list: read/write interface to manage file extension list that determines which files should use inline extent format. Writing an extension name adds it to the list; writing "!extension" removes it.
- inline_extent_enable: toggle to dynamically enable or disable the inline extent feature without remounting.
Also add inline extent code coverage statistics output under /sys/kernel/debug/f2fs/ when CONFIG_F2FS_INLINE_EXTENT_DEBUG is enabled, showing counters for various extent operations (merges, splits, inserts, evictions, etc.).
--- fs/f2fs/debug.c | 4 ++++ fs/f2fs/iextent.c | 39 +++++++++++++++++++++++++++++++++++ fs/f2fs/iextent.h | 3 +++ fs/f2fs/sysfs.c | 52 +++++++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 98 insertions(+)
fs/f2fs/debug.c +4 -0
@@ -19,6 +19,7 @@#include "node.h" #include "segment.h" #include "gc.h" +#include "iextent.h" static LIST_HEAD (f2fs_stat_list);static DEFINE_SPINLOCK (f2fs_stat_lock);
@@ -762,6 +763,9 @@ static int stat_show(struct seq_file *s, void *v) si->ext_mem[EX_BLOCK_AGE] >> 10);seq_printf (s," - paged : %llu KB\n" , si->page_mem >>10 ); +#ifdef CONFIG_F2FS_INLINE_EXTENT_DEBUG +f2fs_iext_show_stat (sbi, s); +#endif }spin_unlock (&f2fs_stat_lock);return 0 ;
fs/f2fs/iextent.c +39 -0
@@ -821,3 +821,42 @@ int f2fs_iext_update_extension_list(struct f2fs_sb_info *sbi, const char *name,spin_unlock_irqrestore (&iext_info->iext_ext_lock, flag);return ret; } + +#ifdef CONFIG_F2FS_INLINE_EXTENT_DEBUG +void f2fs_iext_show_stat (struct f2fs_sb_info *sbi,struct seq_file *s) +{ +struct f2fs_iext_info *iext_info = sbi->iext_info; + +seq_printf (s,"Inline extent code coverage statistics:\n" +" - left_merge_count: %llu\n" +" - right_merge_count: %llu\n" +" - fast_right_merge_count: %llu\n" +" - lr_merge_count: %llu\n" +" - split_left_count: %llu\n" +" - split_right_count: %llu\n" +" - split_mid_count: %llu\n" +" - insert_new_ext_count: %llu\n" +" - overwrite_ext_count: %llu\n" +" - add_ext_count: %llu\n" +" - del_ext_count: %llu\n" +" - evict_last_ext_cnt: %llu\n" +" - truncate_last_ext_cnt: %llu\n" +" - drop_insert_new_ext_cnt: %llu\n" +" - trigger_ext_format_convert: %llu\n" , +atomic64_read (&iext_info->left_merge_count), +atomic64_read (&iext_info->right_merge_count), +atomic64_read (&iext_info->fast_right_merge_count), +atomic64_read (&iext_info->lr_merge_count), +atomic64_read (&iext_info->split_left_count), +atomic64_read (&iext_info->split_right_count), +atomic64_read (&iext_info->split_mid_count), +atomic64_read (&iext_info->insert_new_ext_count), +atomic64_read (&iext_info->overwrite_ext_count), +atomic64_read (&iext_info->add_ext_count), +atomic64_read (&iext_info->del_ext_count), +atomic64_read (&iext_info->evict_last_ext_cnt), +atomic64_read (&iext_info->truncate_last_ext_cnt), +atomic64_read (&iext_info->drop_insert_new_ext_cnt), +atomic64_read (&iext_info->trigger_ext_format_convert)); +} +#endif
fs/f2fs/iextent.h +3 -0
@@ -181,4 +181,7 @@ int f2fs_iext_update_extension_list(struct f2fs_sb_info *sbi, const char *name, bool set);int f2fs_iext_info_init (struct f2fs_sb_info *sbi);void f2fs_iext_info_destroy (struct f2fs_sb_info *sbi); +#ifdef CONFIG_F2FS_INLINE_EXTENT_DEBUG +void f2fs_iext_show_stat (struct f2fs_sb_info *sbi,struct seq_file *s); +#endif #endif
fs/f2fs/sysfs.c +52 -0
94 lines not on this page · raw message
Signature · 8 lines
2.43.0 _______________________________________________ Linux-f2fs-devel mailing list [email protected] https://lists.sourceforge.net/lists/listinfo/linux-f2fs-devel
RFC PATCH v2 5/5 f2fs: introduce tracepoints for inline extent lookup and update
In reply to Yongpeng YangFrom: Yongpeng Yang <[email protected]>
Introduce trace events for inline extent operations for debugging and performance analysis:
- trace_f2fs_iext_lookup_blkaddr_start
- trace_f2fs_iext_lookup_blkaddr_end
- trace_f2fs_iext_update_data_blkaddr
Guard trace calls with NULL inode check in lookup path where inode may be NULL.
--- fs/f2fs/iextent.c | 11 ++++++ include/trace/events/f2fs.h | 79 +++++++++++++++++++++++++++++++++++++ 2 files changed, 90 insertions(+)
fs/f2fs/iextent.c +11 -0
@@ -10,6 +10,7 @@#include "f2fs.h" #include "iextent.h" +#include <trace/events/f2fs.h> /* * ASSERT - debug assertion for inline extent code.
@@ -477,6 +478,9 @@ int f2fs_iext_lookup_blkaddr(struct inode *inode, struct folio *ifolio, (struct f2fs_iext_header *)get_dnode_addr (inode, ifolio);struct f2fs_extent *last_ext =EXT_LAST_INDEX (eh); +if (inode) +trace_f2fs_iext_lookup_blkaddr_start (inode, fofs); +if (EXT_ENTRY_COUNT (eh) ==0 ||F2FS_EXT_LOGICAL_END (last_ext) < fofs) error = -ENOENT ;else
@@ -490,6 +494,11 @@ int f2fs_iext_lookup_blkaddr(struct inode *inode, struct folio *ifolio,if (len) *len =1 ; } + +if (inode && !error) +trace_f2fs_iext_lookup_blkaddr_end (inode, fofs, + *blkaddr, len ? *len :1 ); +return error; }
@@ -525,6 +534,8 @@ int f2fs_iext_update_data_blkaddr(struct inode *inode, struct folio *ifolio,struct f2fs_iext_info *iext_info = sbi->iext_info;#endif +trace_f2fs_iext_update_data_blkaddr (inode, fofs, blkaddr); + retry:ASSERT (sbi, retry_cnt >=0 );ASSERT (sbi,EXT_ENTRY_COUNT (eh) <=MAX_INLINE_EXTENTS (inode));
include/trace/events/f2fs.h +79 -0
85 lines not on this page · raw message
Signature · 8 lines
2.43.0 _______________________________________________ Linux-f2fs-devel mailing list [email protected] https://lists.sourceforge.net/lists/listinfo/linux-f2fs-devel
Sorry for the delay.
Quoted 98 lines · Yongpeng Yang
From: Yongpeng Yang <[email protected]>
Changes since v1:
- Introduce tracepoints forf2fs_iext_update_data_blkaddrandf2fs_iext_lookup_blkaddrto aid debugging (new patch 5/5).
- Bypass inline extent lookup forF2FS_GET_BLOCK_PRECACHEto ensure all mappings are loaded into the read extent cache.
- Unify the check for fofs exceedingdirect_blocksrange to use "fofs >=direct_blocks" consistently.
- Remove support for cachingNULL_ADDRin inline extent area. If a fofs within [0,direct_blocks) is not found in inline extent, it impliesNULL_ADDR. This simplifies merge and split logic.
- Fixf2fs_iext_enable_inline_extentto usePTR_ERRinstead of-ENOMEM.
- Changef2fs_iext_convert_to_inline_extentreturn type to bool.
- Add benchmark data covering 4K/8K/32K/64K random read.
- Rename__is_extent_mergeableto__is_iextent_mergeableto avoid naming collision with extent cache code.
- Remove inode parameter fromf2fs_iext_sanity_check(always NULL).
- Reduce #ifdefCONFIG_F2FS_INLINE_EXTENTnesting innode.c.
- Code style fixes to comply with kernel coding style.This patchset introduces an inline extent mapping mechanism for f2fs. Instead of storing individual block addresses in the inode's data block address area (i_addr[]), this feature packs contiguous block ranges into compact extent entries, significantly reducing the number of entries needed and enabling faster block address lookups via binary search.
The inline extent format is identified by magic numbers in the inode data area and is transparent to the rest of f2fs -- when the extent area is full or cannot represent the mapping efficiently, it automatically converts back to the direct block address format.
Patch 1: Preparatory refactoring -- replace raw pointer arithmetic
withf2fs_data_blkaddr()to abstract block address access.
Patch 2: Core implementation -- data structures, extent operations
(lookup, insert, merge, split, truncate), format conversion, and integration with f2fs data/node paths.
Patch 3: ioctl interface -- allow per-file enable/disable of inline
extent format viaF2FS_EXTENT_FLflag.
Patch 4: sysfs interface -- runtime enable/disable toggle and file
extension list for automatic inline extent activation.
Patch 5: Tracepoints for inline extent lookup and update operations.Test setup and results:
=======================Platform: Xiaomi smartphone, UFS 4.0 storage
# Enable inline extent
echo 1 > /sys/fs/f2fs/<dev>/inline_extent_enable echo 'mp4' > /sys/fs/f2fs/<dev>/inline_extent_extension_list# Prepare data: write with 4K offset stride to create fragmented # extents, then overwrite sequentially so inline extent can cache # all mappings in compact form. fio --name=test --filename=data.mp4 --rw=write:4k --bs=64M \ --size=8G --ioengine=libaio --direct=1 sync fio --name=test --filename=data.mp4 --rw=write --bs=64M \ --size=8G --ioengine=libaio --direct=1 sync echo 3 > /proc/sys/vm/drop_caches # Benchmark: random buffered read, 1GB total IO fio --name=buffer-read --ioengine=libaio --rw=randread --bs=$BS \ --size=8G --io_size=1G --numjobs=1 --filename=data.mp4Results (random read bandwidth, MiB/s):
+---------------------------------------------------+ | BS | baseline | inline ext | improvement | |--------+----------+------------+------------------| | 4K | 35 | 36 | +2.5% | | 8K | 60 | 62 | +3% | | 32K | 179 | 191 | +6.8% | | 64K | 284 | 321 | +13% | +---------------------------------------------------+The improvement comes from eliminating direct/indirect node page reads during block address lookup -- all mappings are stored directly in the inode page and found via O(log n) binary search.
Yongpeng Yang (5):
f2fs: replace raw dnode pointer arithmetic withf2fs_data_blkaddr()
f2fs: introduce inline extent mapping for inode data blocks
f2fs: support setting inline extent flag via ioctl
f2fs: add sysfs interface for inline extent management
f2fs: introduce tracepoints for inline extent lookup and updatefs/f2fs/Kconfig | 18 + fs/f2fs/Makefile | 1 + fs/f2fs/data.c | 157 ++++++- fs/f2fs/debug.c | 4 + fs/f2fs/dir.c | 9 + fs/f2fs/f2fs.h | 23 +- fs/f2fs/file.c | 93 +++- fs/f2fs/iextent.c | 873 ++++++++++++++++++++++++++++++++++++ fs/f2fs/iextent.h | 187 ++++++++ fs/f2fs/inline.c | 7 +
Quoted 8 lines
fs/f2fs/namei.c | 48 ++ fs/f2fs/node.c | 66 ++- fs/f2fs/node.h | 4 + fs/f2fs/recovery.c | 17 + fs/f2fs/super.c | 13 + fs/f2fs/sysfs.c | 52 +++ include/trace/events/f2fs.h | 79 ++++ 17 files changed, 1635 insertions(+), 16 deletions(-)
It's quite a large number of change (including f2fs-tools change) to support this new feature, it causes the performance price ratio a little bit low.
About inode disk layout, as we discuss offline, maybe we can add 4 or 8 ... extents in i_extra_attr area of f2fs_inode structure, it can reduce the change line and code complex, however, not sure how will it affect the benefits.
To Jaegeuk, please share your thoughts on this feature.
Thanks,
Quoted 3 lines
create mode 100644 fs/f2fs/iextent.c create mode 100644 fs/f2fs/iextent.h
_______________________________________________
Linux-f2fs-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/linux-f2fs-devel
Quoted 110 lines · On 6/25/26 16:34, Chao Yu via Linux-f2fs-devel wrote:
Sorry for the delay.
Quoted 98 lines · Yongpeng Yang
From: Yongpeng Yang <[email protected]>
Changes since v1:
- Introduce tracepoints forf2fs_iext_update_data_blkaddrandf2fs_iext_lookup_blkaddrto aid debugging (new patch 5/5).
- Bypass inline extent lookup forF2FS_GET_BLOCK_PRECACHEto ensure all mappings are loaded into the read extent cache.
- Unify the check for fofs exceedingdirect_blocksrange to use "fofs >=direct_blocks" consistently.
- Remove support for cachingNULL_ADDRin inline extent area. If a fofs within [0,direct_blocks) is not found in inline extent, it impliesNULL_ADDR. This simplifies merge and split logic.
- Fixf2fs_iext_enable_inline_extentto usePTR_ERRinstead of-ENOMEM.
- Changef2fs_iext_convert_to_inline_extentreturn type to bool.
- Add benchmark data covering 4K/8K/32K/64K random read.
- Rename__is_extent_mergeableto__is_iextent_mergeableto avoid naming collision with extent cache code.
- Remove inode parameter fromf2fs_iext_sanity_check(always NULL).
- Reduce #ifdefCONFIG_F2FS_INLINE_EXTENTnesting innode.c.
- Code style fixes to comply with kernel coding style.This patchset introduces an inline extent mapping mechanism for f2fs. Instead of storing individual block addresses in the inode's data block address area (i_addr[]), this feature packs contiguous block ranges into compact extent entries, significantly reducing the number of entries needed and enabling faster block address lookups via binary search.
The inline extent format is identified by magic numbers in the inode data area and is transparent to the rest of f2fs -- when the extent area is full or cannot represent the mapping efficiently, it automatically converts back to the direct block address format.
Patch 1: Preparatory refactoring -- replace raw pointer arithmetic
withf2fs_data_blkaddr()to abstract block address access.
Patch 2: Core implementation -- data structures, extent operations
(lookup, insert, merge, split, truncate), format conversion, and integration with f2fs data/node paths.
Patch 3: ioctl interface -- allow per-file enable/disable of inline
extent format viaF2FS_EXTENT_FLflag.
Patch 4: sysfs interface -- runtime enable/disable toggle and file
extension list for automatic inline extent activation.
Patch 5: Tracepoints for inline extent lookup and update operations.Test setup and results:
=======================Platform: Xiaomi smartphone, UFS 4.0 storage
# Enable inline extent
echo 1 > /sys/fs/f2fs/<dev>/inline_extent_enable echo 'mp4' > /sys/fs/f2fs/<dev>/inline_extent_extension_list# Prepare data: write with 4K offset stride to create fragmented # extents, then overwrite sequentially so inline extent can cache # all mappings in compact form. fio --name=test --filename=data.mp4 --rw=write:4k --bs=64M \ --size=8G --ioengine=libaio --direct=1 sync fio --name=test --filename=data.mp4 --rw=write --bs=64M \ --size=8G --ioengine=libaio --direct=1 sync echo 3 > /proc/sys/vm/drop_caches # Benchmark: random buffered read, 1GB total IO fio --name=buffer-read --ioengine=libaio --rw=randread --bs=$BS \ --size=8G --io_size=1G --numjobs=1 --filename=data.mp4Results (random read bandwidth, MiB/s):
+---------------------------------------------------+ | BS | baseline | inline ext | improvement | |--------+----------+------------+------------------| | 4K | 35 | 36 | +2.5% | | 8K | 60 | 62 | +3% | | 32K | 179 | 191 | +6.8% | | 64K | 284 | 321 | +13% | +---------------------------------------------------+The improvement comes from eliminating direct/indirect node page reads during block address lookup -- all mappings are stored directly in the inode page and found via O(log n) binary search.
Yongpeng Yang (5):
f2fs: replace raw dnode pointer arithmetic withf2fs_data_blkaddr()
f2fs: introduce inline extent mapping for inode data blocks
f2fs: support setting inline extent flag via ioctl
f2fs: add sysfs interface for inline extent management
f2fs: introduce tracepoints for inline extent lookup and updatefs/f2fs/Kconfig | 18 + fs/f2fs/Makefile | 1 + fs/f2fs/data.c | 157 ++++++- fs/f2fs/debug.c | 4 + fs/f2fs/dir.c | 9 + fs/f2fs/f2fs.h | 23 +- fs/f2fs/file.c | 93 +++- fs/f2fs/iextent.c | 873 ++++++++++++++++++++++++++++++++++++ fs/f2fs/iextent.h | 187 ++++++++ fs/f2fs/inline.c | 7 +Quoted 8 lines
fs/f2fs/namei.c | 48 ++ fs/f2fs/node.c | 66 ++- fs/f2fs/node.h | 4 + fs/f2fs/recovery.c | 17 + fs/f2fs/super.c | 13 + fs/f2fs/sysfs.c | 52 +++ include/trace/events/f2fs.h | 79 ++++ 17 files changed, 1635 insertions(+), 16 deletions(-)
Quoted 7 lines
It's quite a large number of change (including f2fs-tools change) to support this new feature, it causes the performance price ratio a little bit low.
About inode disk layout, as we discuss offline, maybe we can add 4 or 8 ... extents in
i_extra_attrarea off2fs_inodestructure, it can reduce the change line and code complex, however, not sure how will it affect the benefits.
If we change it this way, it can indeed reduce the complexity of both f2fs-tools and the kernel:
1. We no longer need to handle format conversion. This removes roughly 200+ lines of code and also eliminates the need for 1 conversion folio.
2. It also simplifies the mapping logic, since we no longer need to handle the case where inode extents cannot cover the direct block region.
With this patchset, Android typically have 287 extents. After this change, the number of extents becomes much smaller. However, even if the direct blocks are highly contiguous, they will no longer be cached, so the performance benefit will be reduced. The actual performance gain depends on file contiguity. For example, with files allocated in contiguous 2 MB chunks, if inline extent array length is 8, a single inode can still cover approximately 19 MB of mappings. Small files can also benefit from this optimization.
If we reuse the i_extra_attr area, inline extents have to depend on the F2FS_EXTRA_ATTR bit in struct {struct f2fs_inode}->i_inline, because the size of the i_extra area is zero unless this flag is set.
Would it make sense to redefine the semantics of i_extra_isize so that it is meaningful not only when F2FS_EXTRA_ATTR is set, but also when the F2FS_EXTENT_FL bit in struct {struct f2fs_inode}->i_flags is set?
Then struct f2fs_inode could be organized as follows:
struct f2fs_inode {
/*not change*/
struct f2fs_extent i_ext;
union {
struct {
__le16 i_extra_isize;
/*not change*/
__le32 i_extra_end[0];
struct f2fs_extent i_inline_extents[F2FS_IEXT_ARRAY_SIZE];
} __packed;
/* F2FS_EXTRA_ATTR not set and F2FS_EXTENT_FL set */
struct {
__le16 i_extra_isize;
struct f2fs_extent i_inline_extents[F2FS_IEXT_ARRAY_SIZE];
} __packed;
__le32 i_addr[DEF_ADDRS_PER_INODE];
};
__le32 i_nid[DEF_NIDS_PER_INODE];
} __packed;Thanks
Yongpeng,
Quoted 11 lines
To Jaegeuk, please share your thoughts on this feature.
Thanks,
Quoted 3 lines
create mode 100644 fs/f2fs/iextent.c create mode 100644 fs/f2fs/iextent.h
Quoted 4 lines
_______________________________________________
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
Quoted 113 lines · On 06/25, Chao Yu via Linux-f2fs-devel wrote:
Sorry for the delay.
Quoted 98 lines · Yongpeng Yang
From: Yongpeng Yang <[email protected]>
Changes since v1:
- Introduce tracepoints forf2fs_iext_update_data_blkaddrandf2fs_iext_lookup_blkaddrto aid debugging (new patch 5/5).
- Bypass inline extent lookup forF2FS_GET_BLOCK_PRECACHEto ensure all mappings are loaded into the read extent cache.
- Unify the check for fofs exceedingdirect_blocksrange to use "fofs >=direct_blocks" consistently.
- Remove support for cachingNULL_ADDRin inline extent area. If a fofs within [0,direct_blocks) is not found in inline extent, it impliesNULL_ADDR. This simplifies merge and split logic.
- Fixf2fs_iext_enable_inline_extentto usePTR_ERRinstead of-ENOMEM.
- Changef2fs_iext_convert_to_inline_extentreturn type to bool.
- Add benchmark data covering 4K/8K/32K/64K random read.
- Rename__is_extent_mergeableto__is_iextent_mergeableto avoid naming collision with extent cache code.
- Remove inode parameter fromf2fs_iext_sanity_check(always NULL).
- Reduce #ifdefCONFIG_F2FS_INLINE_EXTENTnesting innode.c.
- Code style fixes to comply with kernel coding style.This patchset introduces an inline extent mapping mechanism for f2fs. Instead of storing individual block addresses in the inode's data block address area (i_addr[]), this feature packs contiguous block ranges into compact extent entries, significantly reducing the number of entries needed and enabling faster block address lookups via binary search.
The inline extent format is identified by magic numbers in the inode data area and is transparent to the rest of f2fs -- when the extent area is full or cannot represent the mapping efficiently, it automatically converts back to the direct block address format.
Patch 1: Preparatory refactoring -- replace raw pointer arithmetic
withf2fs_data_blkaddr()to abstract block address access.
Patch 2: Core implementation -- data structures, extent operations
(lookup, insert, merge, split, truncate), format conversion, and integration with f2fs data/node paths.
Patch 3: ioctl interface -- allow per-file enable/disable of inline
extent format viaF2FS_EXTENT_FLflag.
Patch 4: sysfs interface -- runtime enable/disable toggle and file
extension list for automatic inline extent activation.
Patch 5: Tracepoints for inline extent lookup and update operations.Test setup and results:
=======================Platform: Xiaomi smartphone, UFS 4.0 storage
# Enable inline extent
echo 1 > /sys/fs/f2fs/<dev>/inline_extent_enable echo 'mp4' > /sys/fs/f2fs/<dev>/inline_extent_extension_list# Prepare data: write with 4K offset stride to create fragmented # extents, then overwrite sequentially so inline extent can cache # all mappings in compact form. fio --name=test --filename=data.mp4 --rw=write:4k --bs=64M \ --size=8G --ioengine=libaio --direct=1 sync fio --name=test --filename=data.mp4 --rw=write --bs=64M \ --size=8G --ioengine=libaio --direct=1 sync echo 3 > /proc/sys/vm/drop_caches # Benchmark: random buffered read, 1GB total IO fio --name=buffer-read --ioengine=libaio --rw=randread --bs=$BS \ --size=8G --io_size=1G --numjobs=1 --filename=data.mp4Results (random read bandwidth, MiB/s):
+---------------------------------------------------+ | BS | baseline | inline ext | improvement | |--------+----------+------------+------------------| | 4K | 35 | 36 | +2.5% | | 8K | 60 | 62 | +3% | | 32K | 179 | 191 | +6.8% | | 64K | 284 | 321 | +13% | +---------------------------------------------------+The improvement comes from eliminating direct/indirect node page reads during block address lookup -- all mappings are stored directly in the inode page and found via O(log n) binary search.
Yongpeng Yang (5):
f2fs: replace raw dnode pointer arithmetic withf2fs_data_blkaddr()
f2fs: introduce inline extent mapping for inode data blocks
f2fs: support setting inline extent flag via ioctl
f2fs: add sysfs interface for inline extent management
f2fs: introduce tracepoints for inline extent lookup and updatefs/f2fs/Kconfig | 18 + fs/f2fs/Makefile | 1 + fs/f2fs/data.c | 157 ++++++- fs/f2fs/debug.c | 4 + fs/f2fs/dir.c | 9 + fs/f2fs/f2fs.h | 23 +- fs/f2fs/file.c | 93 +++- fs/f2fs/iextent.c | 873 ++++++++++++++++++++++++++++++++++++ fs/f2fs/iextent.h | 187 ++++++++ fs/f2fs/inline.c | 7 +Quoted 8 lines
fs/f2fs/namei.c | 48 ++ fs/f2fs/node.c | 66 ++- fs/f2fs/node.h | 4 + fs/f2fs/recovery.c | 17 + fs/f2fs/super.c | 13 + fs/f2fs/sysfs.c | 52 +++ include/trace/events/f2fs.h | 79 ++++ 17 files changed, 1635 insertions(+), 16 deletions(-)It's quite a large number of change (including f2fs-tools change) to support this new feature, it causes the performance price ratio a little bit low.
Quoted 6 lines
About inode disk layout, as we discuss offline, maybe we can add 4 or 8 ... extents in
i_extra_attrarea off2fs_inodestructure, it can reduce the change line and code complex, however, not sure how will it affect the benefits.To Jaegeuk, please share your thoughts on this feature.
Agreed. Can we try to add more extents simply?
Quoted 9 lines
Thanks,
Quoted 3 lines
create mode 100644 fs/f2fs/iextent.c create mode 100644 fs/f2fs/iextent.h
Quoted 4 lines
_______________________________________________
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
Quoted 114 lines · On 7/2/26 22:30, Jaegeuk Kim via Linux-f2fs-devel wrote:
Quoted 113 lines · On 06/25, Chao Yu via Linux-f2fs-devel wrote:
Sorry for the delay.
Quoted 98 lines · Yongpeng Yang
From: Yongpeng Yang <[email protected]>
Changes since v1:
- Introduce tracepoints forf2fs_iext_update_data_blkaddrandf2fs_iext_lookup_blkaddrto aid debugging (new patch 5/5).
- Bypass inline extent lookup forF2FS_GET_BLOCK_PRECACHEto ensure all mappings are loaded into the read extent cache.
- Unify the check for fofs exceedingdirect_blocksrange to use "fofs >=direct_blocks" consistently.
- Remove support for cachingNULL_ADDRin inline extent area. If a fofs within [0,direct_blocks) is not found in inline extent, it impliesNULL_ADDR. This simplifies merge and split logic.
- Fixf2fs_iext_enable_inline_extentto usePTR_ERRinstead of-ENOMEM.
- Changef2fs_iext_convert_to_inline_extentreturn type to bool.
- Add benchmark data covering 4K/8K/32K/64K random read.
- Rename__is_extent_mergeableto__is_iextent_mergeableto avoid naming collision with extent cache code.
- Remove inode parameter fromf2fs_iext_sanity_check(always NULL).
- Reduce #ifdefCONFIG_F2FS_INLINE_EXTENTnesting innode.c.
- Code style fixes to comply with kernel coding style.This patchset introduces an inline extent mapping mechanism for f2fs. Instead of storing individual block addresses in the inode's data block address area (i_addr[]), this feature packs contiguous block ranges into compact extent entries, significantly reducing the number of entries needed and enabling faster block address lookups via binary search.
The inline extent format is identified by magic numbers in the inode data area and is transparent to the rest of f2fs -- when the extent area is full or cannot represent the mapping efficiently, it automatically converts back to the direct block address format.
Patch 1: Preparatory refactoring -- replace raw pointer arithmetic
withf2fs_data_blkaddr()to abstract block address access.
Patch 2: Core implementation -- data structures, extent operations
(lookup, insert, merge, split, truncate), format conversion, and integration with f2fs data/node paths.
Patch 3: ioctl interface -- allow per-file enable/disable of inline
extent format viaF2FS_EXTENT_FLflag.
Patch 4: sysfs interface -- runtime enable/disable toggle and file
extension list for automatic inline extent activation.
Patch 5: Tracepoints for inline extent lookup and update operations.Test setup and results:
=======================Platform: Xiaomi smartphone, UFS 4.0 storage
# Enable inline extent
echo 1 > /sys/fs/f2fs/<dev>/inline_extent_enable echo 'mp4' > /sys/fs/f2fs/<dev>/inline_extent_extension_list# Prepare data: write with 4K offset stride to create fragmented # extents, then overwrite sequentially so inline extent can cache # all mappings in compact form. fio --name=test --filename=data.mp4 --rw=write:4k --bs=64M \ --size=8G --ioengine=libaio --direct=1 sync fio --name=test --filename=data.mp4 --rw=write --bs=64M \ --size=8G --ioengine=libaio --direct=1 sync echo 3 > /proc/sys/vm/drop_caches # Benchmark: random buffered read, 1GB total IO fio --name=buffer-read --ioengine=libaio --rw=randread --bs=$BS \ --size=8G --io_size=1G --numjobs=1 --filename=data.mp4Results (random read bandwidth, MiB/s):
+---------------------------------------------------+ | BS | baseline | inline ext | improvement | |--------+----------+------------+------------------| | 4K | 35 | 36 | +2.5% | | 8K | 60 | 62 | +3% | | 32K | 179 | 191 | +6.8% | | 64K | 284 | 321 | +13% | +---------------------------------------------------+The improvement comes from eliminating direct/indirect node page reads during block address lookup -- all mappings are stored directly in the inode page and found via O(log n) binary search.
Yongpeng Yang (5):
f2fs: replace raw dnode pointer arithmetic withf2fs_data_blkaddr()
f2fs: introduce inline extent mapping for inode data blocks
f2fs: support setting inline extent flag via ioctl
f2fs: add sysfs interface for inline extent management
f2fs: introduce tracepoints for inline extent lookup and updatefs/f2fs/Kconfig | 18 + fs/f2fs/Makefile | 1 + fs/f2fs/data.c | 157 ++++++- fs/f2fs/debug.c | 4 + fs/f2fs/dir.c | 9 + fs/f2fs/f2fs.h | 23 +- fs/f2fs/file.c | 93 +++- fs/f2fs/iextent.c | 873 ++++++++++++++++++++++++++++++++++++ fs/f2fs/iextent.h | 187 ++++++++ fs/f2fs/inline.c | 7 +Quoted 8 lines
fs/f2fs/namei.c | 48 ++ fs/f2fs/node.c | 66 ++- fs/f2fs/node.h | 4 + fs/f2fs/recovery.c | 17 + fs/f2fs/super.c | 13 + fs/f2fs/sysfs.c | 52 +++ include/trace/events/f2fs.h | 79 ++++ 17 files changed, 1635 insertions(+), 16 deletions(-)It's quite a large number of change (including f2fs-tools change) to support this new feature, it causes the performance price ratio a little bit low.
Quoted 8 lines
Quoted 6 lines
About inode disk layout, as we discuss offline, maybe we can add 4 or 8 ... extents in
i_extra_attrarea off2fs_inodestructure, it can reduce the change line and code complex, however, not sure how will it affect the benefits.To Jaegeuk, please share your thoughts on this feature.
Agreed. Can we try to add more extents simply?
Thanks for the feedback and sorry for the delay! Here is a simpler design I'd like to propose for adding more extents:
1) Shrink i_compr_blocks from __le64 to __le32, reuse the freed upper 32 bits as a new field: i_inline_ext_capacity.
The in-kernel fi->i_compr_blocks is already atomic_t (32-bit), so the 64-bit on-disk width was never fully utilized.
/* before */
__le64 i_compr_blocks;
/* after */
__le32 i_compr_blocks;
__le32 i_inline_ext_capacity; /* # of extent entries */2) Place the inline extent area immediately after i_extra_end[0]. The area format is: struct f2fs_iext_header followed by a struct f2fs_extent array, reusing the same inline extent format from v2, but without the magic number (since i_inline_ext_capacity already indicates the presence and size of the area).
3) Prohibit compressed files from using inline extents.
On little-endian, the split maps to:
offset +0: i_compr_blocks (original le64 low 32 bits)
offset +4: i_inline_ext_capacity (original le64 high 32 bits)
For compressed files i_inline_ext_capacity is always 0, so old fsck reading the full 64-bit i_compr_blocks gets the same value as the new 32-bit field. For non-compressed files i_compr_blocks is 0 regardless, so there is no conflict either.
4) Include the inline extent area size in i_extra_isize.
i_extra_isize = base_extra_size
+ sizeof(struct f2fs_iext_header)
+ i_inline_ext_capacity * sizeof(struct f2fs_extent)
Old kernels use i_extra_isize to skip the extra attribute region, so the inline extent area is simply invisible to them, it will not be misinterpreted as i_addr[] block addresses.
5) i_inline_ext_capacity is configurable at mkfs/tunefs time. When it is 0, no extra space is consumed beyond i_extra_end, so there is no impact on inodes that do not use inline extents.
Please review this layout modification.
Thanks
Yongpeng,
Quoted 16 lines
Quoted 10 lines
Thanks,
Quoted 3 lines
create mode 100644 fs/f2fs/iextent.c create mode 100644 fs/f2fs/iextent.hQuoted 4 lines
_______________________________________________
Linux-f2fs-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/linux-f2fs-devel
Quoted 4 lines
_______________________________________________
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