f2fs: introduce inline extent mapping for inode data blocks
Subsystems (2)
v4 cover f2fs: introduce inline extent mapping for inode data blocks
From: Yongpeng Yang <[email protected]>
Changes since v3:
- Do not cache NEW_ADDR in the inline extent area. A NEW_ADDR write is now handled exactly like NULL_ADDR: it only unmaps the block.
- Simplify the insert path. A single-block overwrite is now expressed as four small steps:
1) reserve room for a possible split.
2) unmap the old mapping of the block.
3) insert the new mapping.
4) try to merge the inserted mapping with its left and right.
- Remove the inline-extent code-coverage statistics.
v3: https://lore.kernel.org/all/[email protected]/
Changes since v2:
- Inline extent no longer covers direct block mappings. The inline extent area is now placed after struct f2fs_inode->i_extra_end, inside the i_extra_isize region. This removes the need for format conversion and for f2fs-tools to understand/modify the inline extent on-disk format.
- Split struct f2fs_inode->i_compr_blocks (was __le64) into __le32 i_compr_blocks + __le32 i_inline_ext_capacity, where i_inline_ext_capacity records the per-inode inline extent capacity.
- Dropped [RFC PATCH v2 1/5] "replace raw dnode pointer arithmetic with f2fs_data_blkaddr()": f2fs_truncate_data_blocks_range no longer needs changes to accommodate the redesigned inline extent.
- Dropped [RFC PATCH v2 3/5] "support setting inline extent flag via ioctl": format conversion between inline extent and the direct block address array is no longer needed.
- Re-ran the performance tests (see updated numbers below).
v2: https://lore.kernel.org/all/[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.
v1: https://lore.kernel.org/all/[email protected]/
This patchset introduces an inline extent mapping mechanism for f2fs. Instead of storing individual block addresses for indirect-node blocks, this feature packs contiguous block ranges into compact extent entries stored directly in the inode, reducing indirect/double-indirect node page reads and enabling O(log n) block address lookup via binary search.
Design overview:
- The inline extent area is placed immediately after i_extra_end in the on-disk inode, within the i_extra_isize region. Its size (number of extent entries) is determined by the new field i_inline_ext_capacity.
- On-disk layout:
[i_extra_isize .. i_extra_end] [f2fs_iext_header | f2fs_extent[cap]]
|<------------------ i_extra_isize (in bytes) ------------------->|- Inline extent only caches mappings for indirect blocks (fofs >= ADDRS_PER_INODE). Direct block mappings continue to use i_addr[], so no format conversion is required.
- Per-inode capacity is decided at file creation time based on the configured file-extension matching rules (see sysfs below).
- Mutually exclusive with compression.
Patch 1: Core implementation -- data structures, extent operations
(lookup, insert, merge, split, truncate), and integration with the f2fs data/node/inode/recovery paths.
Patch 2: sysfs interface -- runtime enable/disable toggle and the file
extension list (with optional per-extension capacity) for automatic inline extent activation.
Patch 3: Tracepoints for inline extent lookup and update operations.
Test setup (Xiaomi smartphone, UFS 4.0 storage):
echo 1 > /sys/fs/f2fs/<dev>/inline_extent_enable
echo 'mp4:256' > /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 | 31.6 | 32.4 | +2.5% | | 8K | 55.4 | 58.5 | +5.6% | | 32K | 155.3 | 166.8 | +7.4% | | 64K | 229.8 | 255.3 | +11.1% | | 128K | 337.8 | 388 | +14.9% | +---------------------------------------------------+
The improvement comes from eliminating indirect/double-indirect node page reads during block address lookup -- indirect-block mappings are stored directly in the inode page and found via binary search.
Yongpeng Yang (3):
f2fs: introduce inline extent mapping for inode data blocks
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 | 146 +++++++++- fs/f2fs/dir.c | 1 + fs/f2fs/f2fs.h | 44 ++- fs/f2fs/file.c | 1 + fs/f2fs/iextent.c | 535 ++++++++++++++++++++++++++++++++++++ fs/f2fs/iextent.h | 136 +++++++++ fs/f2fs/inline.c | 1 + fs/f2fs/inode.c | 41 ++- fs/f2fs/namei.c | 67 +++++ fs/f2fs/node.c | 38 ++- fs/f2fs/node.h | 4 + fs/f2fs/recovery.c | 15 + fs/f2fs/super.c | 29 ++ fs/f2fs/sysfs.c | 91 ++++++ include/linux/f2fs_fs.h | 3 +- include/trace/events/f2fs.h | 79 ++++++ 18 files changed, 1229 insertions(+), 21 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 v4 1/3 f2fs: introduce inline extent mapping for inode data blocks
From: Yongpeng Yang <[email protected]>
Introduce an inline extent mapping mechanism that stores extent entries directly within the inode's extra attribute area. This eliminates indirect node lookups for frequently accessed file blocks.
Key design points:
- Inline extent area is placed after i_extra_end in the on-disk inode, within the i_extra_isize region. Its size is determined by the new field i_inline_ext_capacity (number of extent entries).
- Split the existing __le64 i_compr_blocks into __le32 i_compr_blocks + __le32 i_inline_ext_capacity to avoid enlarging the inode.
- Inline extent only caches mappings for indirect blocks (fofs >= ADDRS_PER_INODE). Direct block mappings continue to use i_addr[].
- Per-inode capacity is determined at file creation time based on extension matching rules.
- Supports a mount option inline_extent_size=<N> to set the default capacity for new inodes.
- Mutually exclusive with compression (compressed files cannot use inline extent).
The implementation includes:
- Binary search based extent lookup and insertion with merge/split support in fs/f2fs/iextent.c
- Integration with data block allocation and truncation paths
- Proper recovery handling (inline extent cleared during fsync replay)
- Kconfig option CONFIG_F2FS_INLINE_EXTENT to enable the feature
Test setup (Xiaomi smartphone, UFS 4.0 storage, f2fs):
echo 1 > /sys/fs/f2fs/<dev>/inline_extent_enable
echo 'mp4:256' > /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 | 31.6 | 32.4 | +2.5% | | 8K | 55.4 | 58.5 | +5.6% | | 32K | 155.3 | 166.8 | +7.4% | | 64K | 229.8 | 255.3 | +11.1% | | 128K | 337.8 | 388 | +14.9% | +---------------------------------------------------+
---
v4:
- Do not cache NEW_ADDR in the inline extent area.
- Simplify the insert path.
- Remove the inline-extent code-coverage statistics.
v3:
- Modify inline extent format.
- Split struct f2fs_inode->i_compr_blocks (was __le64) into __le32 and __le32 i_inline_ext_capacity.
- Re-ran the performance tests.
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 | 146 ++++++++++- fs/f2fs/dir.c | 1 + fs/f2fs/f2fs.h | 44 +++- fs/f2fs/file.c | 1 + fs/f2fs/iextent.c | 528 ++++++++++++++++++++++++++++++++++++++++ fs/f2fs/iextent.h | 136 +++++++++++ fs/f2fs/inline.c | 1 + fs/f2fs/inode.c | 41 +++- fs/f2fs/namei.c | 67 +++++ fs/f2fs/node.c | 38 ++- fs/f2fs/node.h | 4 + fs/f2fs/recovery.c | 15 ++ fs/f2fs/super.c | 29 +++ include/linux/f2fs_fs.h | 3 +- 16 files changed, 1052 insertions(+), 21 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 +145 -1
187 lines not on this page · raw message
fs/f2fs/dir.c +1 -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)
fs/f2fs/f2fs.h +42 -2
109 lines not on this page · raw message
fs/f2fs/file.c +1 -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>
fs/f2fs/iextent.c new file +528 -0
528 lines not on this page · raw message
fs/f2fs/iextent.h new file +136 -0
136 lines not on this page · raw message
fs/f2fs/inline.c +1 -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)
fs/f2fs/inode.c +32 -9
87 lines not on this page · raw message
fs/f2fs/namei.c +67 -0
91 lines not on this page · raw message
fs/f2fs/node.c +30 -8
@@ -19,6 +19,7 @@#include "segment.h" #include "xattr.h" #include "iostat.h" +#include "iextent.h" #include <trace/events/f2fs.h> #define on_f2fs_build_free_nids (nm_i) mutex_is_locked(&(nm_i)->build_lock)
@@ -819,6 +820,7 @@ int f2fs_get_dnode_of_data(struct dnode_of_data *dn, pgoff_t index, int mode)nid_t nids[4 ];int level, i =0 ;int err =0 ; +bool lock_ifolio = false; level =get_node_path (dn->inode, index, offset, noffset);if (level <0 )
@@ -846,6 +848,8 @@ int f2fs_get_dnode_of_data(struct dnode_of_data *dn, pgoff_t index, int mode) nids[1 ] =get_nid (parent, offset[0 ], true); dn->inode_folio = nfolio[0 ]; dn->inode_folio_locked = true; +if (f2fs_iext_support_inline_extent (dn->inode,NULL )) + lock_ifolio = true;/* get indirect or direct nodes */ for (i =1 ; i <= level; i++) {
@@ -888,8 +892,10 @@ int f2fs_get_dnode_of_data(struct dnode_of_data *dn, pgoff_t index, int mode) done = true; }if (i ==1 ) { - dn->inode_folio_locked = false; -folio_unlock (parent); +if (!lock_ifolio) { + dn->inode_folio_locked = false; +folio_unlock (parent); + } }else {f2fs_folio_put (parent, true); }
@@ -899,7 +905,8 @@ int f2fs_get_dnode_of_data(struct dnode_of_data *dn, pgoff_t index, int mode) NODE_TYPE_NON_INODE);if (IS_ERR (nfolio[i])) { err =PTR_ERR (nfolio[i]); -f2fs_folio_put (nfolio[0 ], false); +f2fs_folio_put (nfolio[0 ], + dn->inode_folio_locked); goto release_out; } }
@@ -945,7 +952,7 @@ int f2fs_get_dnode_of_data(struct dnode_of_data *dn, pgoff_t index, int mode) release_pages:f2fs_folio_put (parent, true);if (i >1 ) -f2fs_folio_put (nfolio[0 ], false); +f2fs_folio_put (nfolio[0 ], dn->inode_folio_locked); release_out: dn->inode_folio =NULL ; dn->node_folio =NULL ;
@@ -1194,6 +1201,7 @@ int f2fs_truncate_inode_blocks(struct inode *inode, pgoff_t from)unsigned int nofs =0 ;struct dnode_of_data dn;struct folio *folio; +bool lock_ifolio = false;trace_f2fs_truncate_inode_blocks_enter (inode, from);
@@ -1217,7 +1225,11 @@ int f2fs_truncate_inode_blocks(struct inode *inode, pgoff_t from) }set_new_dnode (&dn, inode, folio,NULL ,0 ); -folio_unlock (folio); +if (f2fs_iext_support_inline_extent (inode,NULL )) { + lock_ifolio = true; +f2fs_iext_truncate_from_blkaddr (inode, folio, from); + }else +folio_unlock (folio);switch (level) {case 0 :
@@ -1282,17 +1294,19 @@ int f2fs_truncate_inode_blocks(struct inode *inode, pgoff_t from)if (err <0 ) goto fail;if (offset[1 ] ==0 &&get_nid (folio, offset[0 ], true)) { -folio_lock (folio); +if (!lock_ifolio) +folio_lock (folio);BUG_ON (!is_node_folio (folio));set_nid (folio, offset[0 ],0 , true); -folio_unlock (folio); +if (!lock_ifolio) +folio_unlock (folio); } offset[1 ] =0 ; offset[0 ]++; nofs += err; } fail: -f2fs_folio_put (folio, false); +f2fs_folio_put (folio, lock_ifolio);trace_f2fs_truncate_inode_blocks_exit (inode, err);return err >0 ?0 : err; }
@@ -1612,6 +1626,14 @@ static struct folio *__get_node_folio(struct f2fs_sb_info *sbi, pgoff_t nid, err = -EFSBADCRC ; goto out_err; } +#ifdef CONFIG_F2FS_INLINE_EXTENT +if (IS_INODE (folio) && +f2fs_iext_support_inline_extent (NULL , folio) && + !f2fs_iext_sanity_check (folio)) { + err = -EINVAL ; + goto out_err; + } +#endif page_hit: err =f2fs_sanity_check_node_footer (sbi, folio, nid, ntype, false);if (!err)
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 +15 -0
@@ -13,6 +13,7 @@#include "f2fs.h" #include "node.h" #include "segment.h" +#include "iextent.h" /* * Roll forward recovery scenarios.
@@ -665,6 +666,20 @@ 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 (EXT_ENTRY_COUNT (iext_get_header (dn.inode_folio)) >0 ) { +f2fs_iext_init_inline_extent (inode, dn.inode_folio); +folio_mark_dirty (dn.inode_folio); + } + } +#endif f2fs_folio_wait_writeback (dn.node_folio,NODE , true, true);
fs/f2fs/super.c +29 -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>
@@ -235,6 +236,7 @@ enum { Opt_jqfmt, Opt_checkpoint, Opt_lookup_mode, + Opt_inline_extent_size, Opt_err, };
@@ -320,6 +322,7 @@ static const struct fs_parameter_spec f2fs_param_specs[] = {fsparam_s32 ("inline_xattr_size" , Opt_inline_xattr_size),fsparam_flag_no ("inline_data" , Opt_inline_data),fsparam_flag_no ("inline_dentry" , Opt_inline_dentry), +fsparam_u32 ("inline_extent_size" , Opt_inline_extent_size),fsparam_flag_no ("flush_merge" , Opt_flush_merge),fsparam_flag_no ("barrier" , Opt_barrier), fsparam_flag("fastboot", Opt_fastboot),
@@ -404,6 +407,7 @@ static match_table_t f2fs_checkpoint_tokens = {#define F2FS_SPEC_errors (1 << 23)#define F2FS_SPEC_lookup_mode (1 << 24)#define F2FS_SPEC_reserve_node (1 << 25) +#define F2FS_SPEC_inline_extent_size (1 << 26)struct f2fs_fs_context {struct f2fs_mount_info info;
@@ -850,6 +854,13 @@ static int f2fs_parse_param(struct fs_context *fc, struct fs_parameter *param)F2FS_CTX_INFO (ctx).inline_xattr_size = result.int_32; ctx->spec_mask |= F2FS_SPEC_inline_xattr_size;break ; +#ifdef CONFIG_F2FS_INLINE_EXTENT +case Opt_inline_extent_size: +ctx_set_opt (ctx,F2FS_MOUNT_INLINE_EXTENT_SIZE ); +F2FS_CTX_INFO (ctx).inline_extent_size = result.uint_32; + ctx->spec_mask |= F2FS_SPEC_inline_extent_size; +break ; +#endif #else case Opt_user_xattr:case Opt_inline_xattr:
@@ -1763,6 +1774,8 @@ static void f2fs_apply_options(struct fs_context *fc, struct super_block *sb)F2FS_OPTION (sbi).errors =F2FS_CTX_INFO (ctx).errors;if (ctx->spec_mask & F2FS_SPEC_lookup_mode)F2FS_OPTION (sbi).lookup_mode =F2FS_CTX_INFO (ctx).lookup_mode; +if (ctx->spec_mask & F2FS_SPEC_inline_extent_size) +F2FS_OPTION (sbi).inline_extent_size =F2FS_CTX_INFO (ctx).inline_extent_size;f2fs_apply_compression (fc, sb);f2fs_apply_test_dummy_encryption (fc, sb);
@@ -2432,6 +2445,11 @@ static int f2fs_show_options(struct seq_file *seq, struct dentry *root)seq_puts (seq,",inline_dentry" ); else seq_puts(seq, ",noinline_dentry"); +#ifdef CONFIG_F2FS_INLINE_EXTENT +if (test_opt (sbi,INLINE_EXTENT_SIZE )) +seq_printf (seq,",inline_extent_size=%u" , +F2FS_OPTION (sbi).inline_extent_size); +#endif if (test_opt (sbi,FLUSH_MERGE ))seq_puts (seq,",flush_merge" );else
@@ -5139,6 +5157,11 @@ static int f2fs_fill_super(struct super_block *sb, struct fs_context *fc)/* disallow all the data/node/meta page writes */ set_sbi_flag (sbi,SBI_POR_DOING ); +#ifdef CONFIG_F2FS_INLINE_EXTENT + err =f2fs_iext_info_init (sbi); +if (err) + goto free_bio_info; +#endif err =f2fs_init_write_merge_io (sbi);if (err) goto free_bio_info;
@@ -5499,6 +5522,9 @@ static int f2fs_fill_super(struct super_block *sb, struct fs_context *fc)utf8_unload (sb->s_encoding); sb->s_encoding =NULL ;#endif +#ifdef CONFIG_F2FS_INLINE_EXTENT +f2fs_iext_info_destroy (sbi); +#endif free_options:#ifdef CONFIG_QUOTA for (i =0 ; i <MAXQUOTAS ; i++)
@@ -5595,6 +5621,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 ;
include/linux/f2fs_fs.h +2 -1
@@ -330,7 +330,8 @@ struct f2fs_inode {__le32 i_inode_checksum;/* inode meta checksum */ __le64 i_crtime;/* creation time */ __le32 i_crtime_nsec;/* creation time in nano scale */ -__le64 i_compr_blocks;/* # of compressed blocks */ +__le32 i_compr_blocks;/* # of compressed blocks */ +__le32 i_inline_ext_capacity;/* # of inline extent entries */ __u8 i_compress_algorithm;/* compress algorithm */ __u8 i_log_cluster_size;/* log of cluster size */ __le16 i_compress_flag;/* compress flag */
Signature · 1 line
2.43.0
_______________________________________________
Linux-f2fs-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/linux-f2fs-devel
RFC PATCH v4 2/3 f2fs: add sysfs interface for inline extent management
In reply to Yongpeng YangFrom: Yongpeng Yang <[email protected]>
Add sysfs interfaces for runtime management of the inline extent feature:
- inline_extent_extension_list: read/write the file extension list that triggers inline extent allocation. Format for writing:
"ext" or "ext:capacity" to add (with optional per-extension capacity), "!ext" to remove.
Reading shows all extensions with their capacity settings.
- inline_extent_enable: toggle inline extent allocation on/off at runtime (0 or 1).
---
v4:
- Remove the inline-extent code-coverage statistics output.
--- fs/f2fs/sysfs.c | 91 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 91 insertions(+)
fs/f2fs/sysfs.c +91 -0
@@ -18,6 +18,7 @@#include "segment.h" #include "gc.h" #include "iostat.h" +#include "iextent.h" #include <trace/events/f2fs.h> static struct proc_dir_entry *f2fs_proc_root;
@@ -40,6 +41,9 @@ enum {RESERVED_BLOCKS ,/* struct f2fs_sb_info */ CPRC_INFO ,/* struct ckpt_req_control */ ATGC_INFO ,/* struct atgc_management */ +#ifdef CONFIG_F2FS_INLINE_EXTENT + INLINE_EXTENT, /* struct f2fs_iext_info */ +#endif }; static const char *gc_mode_names[MAX_GC_MODE] = {
@@ -98,6 +102,10 @@ static unsigned char *__struct_ptr(struct f2fs_sb_info *sbi, int struct_type)return (unsigned char *)&sbi->cprc_info; else if (struct_type == ATGC_INFO) return (unsigned char *)&sbi->am; +#ifdef CONFIG_F2FS_INLINE_EXTENT + else if (struct_type == INLINE_EXTENT) + return (unsigned char *)sbi->iext_info; +#endifreturn NULL ; }
@@ -405,6 +413,30 @@ static ssize_t f2fs_sbi_show(struct f2fs_attr *a,return len; } +#ifdef CONFIG_F2FS_INLINE_EXTENT +if (!strcmp (a->attr.name,"inline_extent_extension_list" )) { +struct f2fs_iext_info *iext_info = sbi->iext_info; +__u8 (*extlist)[F2FS_EXTENSION_LEN ] = iext_info->extensions; +int len =0 , i; +unsigned long flag; + +spin_lock_irqsave (&iext_info->iext_ext_lock, flag); +for (i =0 ; i < iext_info->iext_ext_cnt; i++) { +unsigned int cap = iext_info->ext_capacity[i]; + +if (cap) + len +=sysfs_emit_at (buf, len,"%s:%u\n" , + extlist[i], cap); +else + len +=sysfs_emit_at (buf, len,"%s\n" , + extlist[i]); + } +spin_unlock_irqrestore (&iext_info->iext_ext_lock, flag); + +return len; + } +#endif +if (!strcmp (a->attr.name,"ckpt_thread_ioprio" )) {struct ckpt_req_control *cprc = &sbi->cprc_info;int class =IOPRIO_PRIO_CLASS (cprc->ckpt_thread_ioprio);
@@ -535,6 +567,48 @@ static ssize_t __sbi_store(struct f2fs_attr *a,return ret ? ret : count; } +#ifdef CONFIG_F2FS_INLINE_EXTENT +if (!strcmp (a->attr.name,"inline_extent_extension_list" )) { +const char *name =strim ((char *)buf); +bool set = true; +unsigned int capacity =0 ; +char ext_name[F2FS_EXTENSION_LEN ]; +const char *sep; + +if (*name =='!' ) { + name++; + set = false; + } + +if (!strlen (name) ||strlen (name) >=F2FS_EXTENSION_LEN ) +return -EINVAL ; + +/* Parse optional capacity: "ext:capacity" format. */ + sep =strchr (name,':' ); +if (sep) { +int name_len = sep - name; + +if (name_len <=0 || name_len >=F2FS_EXTENSION_LEN ) +return -EINVAL ; +memcpy (ext_name, name, name_len); + ext_name[name_len] ='\0' ; +if (set) { + ret =kstrtouint (sep +1 ,10 , &capacity); +if (ret) +return ret; +if (!capacity) +return -EINVAL ; + } + name = ext_name; + } + + ret =f2fs_iext_update_extension_list (sbi, name, set, + capacity); + +return ret ? ret : count; + } +#endif +if (!strcmp (a->attr.name,"ckpt_thread_ioprio" )) {const char *name =strim ((char *)buf);struct ckpt_req_control *cprc = &sbi->cprc_info;
@@ -604,6 +678,14 @@ static ssize_t __sbi_store(struct f2fs_attr *a,return count; } +#ifdef CONFIG_F2FS_INLINE_EXTENT +if (!strcmp (a->attr.name,"inline_extent_enable" )) { +if (t >1 ) +return -EINVAL ; +f2fs_iext_set_enable (sbi, !!t); +return count; + } +#endif if (!strcmp (a->attr.name,"discard_io_aware_gran" )) {if (t >MAX_PLIST_NUM )return -EINVAL ;
@@ -1257,6 +1339,11 @@ NM_INFO_GENERAL_RW_ATTR(dirty_nats_ratio);/* F2FS_SBI ATTR */ F2FS_RW_ATTR (F2FS_SBI , f2fs_super_block, extension_list, extension_list); +#ifdef CONFIG_F2FS_INLINE_EXTENT +F2FS_RW_ATTR (INLINE_EXTENT , f2fs_iext_info, inline_extent_extension_list, + extensions); +F2FS_RW_ATTR (INLINE_EXTENT , f2fs_iext_info, inline_extent_enable, iext_enable); +#endif F2FS_SBI_RW_ATTR (gc_idle, gc_mode);F2FS_SBI_RW_ATTR (gc_urgent, gc_mode);F2FS_SBI_RW_ATTR (cp_interval, interval_time[CP_TIME ]);
@@ -1457,6 +1544,10 @@ static struct attribute *f2fs_attrs[] = {ATTR_LIST (max_io_bytes),ATTR_LIST (gc_pin_file_thresh),ATTR_LIST (extension_list), +#ifdef CONFIG_F2FS_INLINE_EXTENT +ATTR_LIST (inline_extent_extension_list), +ATTR_LIST (inline_extent_enable), +#endif #ifdef CONFIG_F2FS_FAULT_INJECTIONATTR_LIST (inject_rate), ATTR_LIST(inject_type),
Signature · 8 lines
2.43.0 _______________________________________________ Linux-f2fs-devel mailing list [email protected] https://lists.sourceforge.net/lists/listinfo/linux-f2fs-devel
RFC PATCH v4 3/3 f2fs: introduce tracepoints for inline extent lookup and update
In reply to Yongpeng YangFrom: Yongpeng Yang <[email protected]>
Add tracepoints to aid performance analysis and debugging of the inline extent mechanism:
- trace_f2fs_iext_lookup_blkaddr_start: fired at the beginning of an inline extent lookup, recording the inode and logical block offset.
- trace_f2fs_iext_lookup_blkaddr_end: fired on successful lookup, recording the inode, logical offset, resolved physical block address, and extent length.
- trace_f2fs_iext_update_data_blkaddr: fired when updating a block mapping in the inline extent area, recording the inode, logical offset, and new physical block address.
These tracepoints can be used with ftrace/perf to measure inline extent cache hit rates and identify hot files benefiting from the feature.
--- fs/f2fs/iextent.c | 7 ++++ include/trace/events/f2fs.h | 79 +++++++++++++++++++++++++++++++++++++ 2 files changed, 86 insertions(+)
fs/f2fs/iextent.c +7 -0
@@ -9,6 +9,7 @@#include "f2fs.h" #include "iextent.h" +#include <trace/events/f2fs.h> /* * ASSERT - debug assertion for inline extent code.
@@ -256,6 +257,7 @@ int f2fs_iext_update_data_blkaddr(struct inode *inode, struct folio *ifolio,block_t start, end;unsigned int len; +trace_f2fs_iext_update_data_blkaddr (inode, fofs, blkaddr);/* NEW_ADDR blocks are never cached. Treat it as a delete. */ if (blkaddr ==NEW_ADDR ) blkaddr =NULL_ADDR ;
@@ -345,6 +347,8 @@ int f2fs_iext_lookup_blkaddr(struct inode *inode, struct folio *ifolio,int index, hit;block_t blk_start, fofs_start; +trace_f2fs_iext_lookup_blkaddr_start (inode, fofs); +if (EXT_ENTRY_COUNT (eh) ==0 ||F2FS_EXT_LOGICAL_END (last_ext) < fofs)return -ENOENT ;
@@ -361,6 +365,9 @@ int f2fs_iext_lookup_blkaddr(struct inode *inode, struct folio *ifolio,if (len) *len =F2FS_EXT_LEN (ext) - (fofs - fofs_start); +trace_f2fs_iext_lookup_blkaddr_end (inode, fofs, + *blkaddr, len ? *len :1 ); +return 0 ; }
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
Quoted 130 lines · Yongpeng Yang
From: Yongpeng Yang <[email protected]>
Changes since v3:
- Do not cacheNEW_ADDRin the inline extent area. ANEW_ADDRwrite is now handled exactly likeNULL_ADDR: it only unmaps the block.
- Simplify the insert path. A single-block overwrite is now expressed as four small steps:
1) reserve room for a possible split.
2) unmap the old mapping of the block.
3) insert the new mapping.
4) try to merge the inserted mapping with its left and right.
- Remove the inline-extent code-coverage statistics.v3: https://lore.kernel.org/all/[email protected]/
Changes since v2:
- Inline extent no longer covers direct block mappings. The inline extent area is now placed after structf2fs_inode->i_extra_end, inside thei_extra_isizeregion. This removes the need for format conversion and for f2fs-tools to understand/modify the inline extent on-disk format.
- Split structf2fs_inode->i_compr_blocks(was__le64) into__le32i_compr_blocks+__le32i_inline_ext_capacity, wherei_inline_ext_capacityrecords the per-inode inline extent capacity.
- Dropped [RFC PATCH v2 1/5] "replace raw dnode pointer arithmetic withf2fs_data_blkaddr()":f2fs_truncate_data_blocks_rangeno longer needs changes to accommodate the redesigned inline extent.
- Dropped [RFC PATCH v2 3/5] "support setting inline extent flag via ioctl": format conversion between inline extent and the direct block address array is no longer needed.
- Re-ran the performance tests (see updated numbers below).v2: https://lore.kernel.org/all/[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.v1: https://lore.kernel.org/all/[email protected]/
This patchset introduces an inline extent mapping mechanism for f2fs. Instead of storing individual block addresses for indirect-node blocks, this feature packs contiguous block ranges into compact extent entries stored directly in the inode, reducing indirect/double-indirect node page reads and enabling O(log n) block address lookup via binary search.
Design overview:
- The inline extent area is placed immediately afteri_extra_endin the on-disk inode, within thei_extra_isizeregion. Its size (number of extent entries) is determined by the new fieldi_inline_ext_capacity.
- On-disk layout:[i_extra_isize .. i_extra_end] [f2fs_iext_header | f2fs_extent[cap]] |<------------------ i_extra_isize (in bytes) ------------------->|- Inline extent only caches mappings for indirect blocks (fofs >=
ADDRS_PER_INODE). Direct block mappings continue to use i_addr[], so no format conversion is required.
- Per-inode capacity is decided at file creation time based on the configured file-extension matching rules (see sysfs below).
- Mutually exclusive with compression.Patch 1: Core implementation -- data structures, extent operations
(lookup, insert, merge, split, truncate), and integration with the f2fs data/node/inode/recovery paths.
Patch 2: sysfs interface -- runtime enable/disable toggle and the file
extension list (with optional per-extension capacity) for automatic inline extent activation.
Patch 3: Tracepoints for inline extent lookup and update operations.Test setup (Xiaomi smartphone, UFS 4.0 storage):
echo 1 > /sys/fs/f2fs/<dev>/inline_extent_enable echo 'mp4:256' > /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 | 31.6 | 32.4 | +2.5% | | 8K | 55.4 | 58.5 | +5.6% | | 32K | 155.3 | 166.8 | +7.4% | | 64K | 229.8 | 255.3 | +11.1% | | 128K | 337.8 | 388 | +14.9% | +---------------------------------------------------+The improvement comes from eliminating indirect/double-indirect node page reads during block address lookup -- indirect-block mappings are stored directly in the inode page and found via binary search.
Yongpeng Yang (3):
f2fs: introduce inline extent mapping for inode data blocks
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 | 146 +++++++++- fs/f2fs/dir.c | 1 + fs/f2fs/f2fs.h | 44 ++- fs/f2fs/file.c | 1 + fs/f2fs/iextent.c | 535 ++++++++++++++++++++++++++++++++++++ fs/f2fs/iextent.h | 136 +++++++++ fs/f2fs/inline.c | 1 + fs/f2fs/inode.c | 41 ++- fs/f2fs/namei.c | 67 +++++ fs/f2fs/node.c | 38 ++- fs/f2fs/node.h | 4 +
Quoted 9 lines
fs/f2fs/recovery.c | 15 + fs/f2fs/super.c | 29 ++ fs/f2fs/sysfs.c | 91 ++++++ include/linux/f2fs_fs.h | 3 +- include/trace/events/f2fs.h | 79 ++++++ 18 files changed, 1229 insertions(+), 21 deletions(-) create mode 100644 fs/f2fs/iextent.c create mode 100644 fs/f2fs/iextent.h
ping
Thanks,
Yongpeng
_______________________________________________
Linux-f2fs-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/linux-f2fs-devel