f2fs: another way to set large folio by remembering inode number
Subsystems (5)
Jaegeuk Kim
maintainerPATCH 1/1 f2fs: another way to set large folio by remembering inode number
enum {
F2FS_XATTR_FADV_LARGEFOLIO,
};
unsigned int value = BIT(F2FS_XATTR_FADV_LARGEFOLIO);
1. setxattr(file, "user.fadvise", &value, sizeof(unsigned int), 0) -> register the inode number for large folio
2. chmod(0400, file)
-> make Read-Only
3. open()
-> f2fs_iget() with large folio
4. open(WRITE), mkwrite on mmap, chmod(WRITE)
-> return error
5. iput() and open()
-> goto #3
6. unlink
-> deregister the inode number
--- fs/f2fs/checkpoint.c | 2 +- fs/f2fs/data.c | 2 +- fs/f2fs/f2fs.h | 1 + fs/f2fs/file.c | 11 +++++++++-- fs/f2fs/inode.c | 19 ++++++++++++++++--- fs/f2fs/super.c | 7 +++++++ fs/f2fs/xattr.c | 35 ++++++++++++++++++++++++++++++++++- fs/f2fs/xattr.h | 6 ++++++ 8 files changed, 75 insertions(+), 8 deletions(-)
fs/f2fs/checkpoint.c +1 -1
@@ -778,7 +778,7 @@ void f2fs_remove_ino_entry(struct f2fs_sb_info *sbi, nid_t ino, int type)__remove_ino_entry (sbi, ino, type); } -/* mode should be APPEND_INO, UPDATE_INO or TRANS_DIR_INO */ +/* mode should be APPEND_INO, UPDATE_INO, LARGE_FOLIO_IO, or TRANS_DIR_INO */ bool f2fs_exist_written_data (struct f2fs_sb_info *sbi,nid_t ino,int mode) {struct inode_management *im = &sbi->im[mode];
fs/f2fs/data.c +1 -1
@@ -2494,7 +2494,7 @@ static int f2fs_read_data_large_folio(struct inode *inode,int ret =0 ;bool folio_in_bio; -if (!IS_IMMUTABLE (inode) ||f2fs_compressed_file (inode)) { +if (f2fs_compressed_file (inode)) {if (folio)folio_unlock (folio);return -EOPNOTSUPP ;
fs/f2fs/f2fs.h +1 -0
@@ -381,6 +381,7 @@ enum {/* for the list of ino */ enum {ORPHAN_INO ,/* for orphan ino list */ +LARGE_FOLIO_INO ,/* for large folio case */ APPEND_INO ,/* for append ino list */ UPDATE_INO ,/* for update ino list */ TRANS_DIR_INO ,/* for transactions dir ino list */
fs/f2fs/file.c +9 -2
@@ -2068,9 +2068,16 @@ static long f2fs_fallocate(struct file *file, int mode,static int f2fs_release_file (struct inode *inode,struct file *filp) { -if (atomic_dec_and_test (&F2FS_I (inode)->open_count)) +if (atomic_dec_and_test (&F2FS_I (inode)->open_count)) {f2fs_remove_donate_inode (inode); - +/* +* In order to get large folio as soon as possible, let's drop +* inode cache asap. See also f2fs_drop_inode. +*/ +if (f2fs_exist_written_data (F2FS_I_SB (inode), + inode->i_ino,LARGE_FOLIO_INO )) +d_drop (filp->f_path.dentry); + }/* * f2fs_release_file is called at every close calls. So we should * not drop any inmemory pages by close called by other process.
fs/f2fs/inode.c +16 -3
@@ -565,6 +565,20 @@ static bool is_meta_ino(struct f2fs_sb_info *sbi, unsigned int ino) ino ==F2FS_COMPRESS_INO (sbi); } +static void f2fs_mapping_set_large_folio (struct inode *inode) +{ +struct f2fs_sb_info *sbi =F2FS_I_SB (inode); + +if (f2fs_compressed_file (inode)) +return ; +if (f2fs_quota_file (sbi, inode->i_ino)) +return ; +if (IS_IMMUTABLE (inode) || + (f2fs_exist_written_data (sbi, inode->i_ino,LARGE_FOLIO_INO ) && + !(inode->i_mode &S_IWUGO ))) +mapping_set_folio_min_order (inode->i_mapping,0 ); +} +struct inode *f2fs_iget (struct super_block *sb,unsigned long ino) {struct f2fs_sb_info *sbi =F2FS_SB (sb);
@@ -620,9 +634,7 @@ struct inode *f2fs_iget(struct super_block *sb, unsigned long ino) inode->i_op = &f2fs_file_inode_operations; inode->i_fop = &f2fs_file_operations; inode->i_mapping->a_ops = &f2fs_dblock_aops; -if (IS_IMMUTABLE (inode) && !f2fs_compressed_file (inode) && - !f2fs_quota_file (sbi, inode->i_ino)) -mapping_set_folio_min_order (inode->i_mapping,0 ); +f2fs_mapping_set_large_folio (inode); }else if (S_ISDIR (inode->i_mode)) { inode->i_op = &f2fs_dir_inode_operations; inode->i_fop = &f2fs_dir_operations;
@@ -895,6 +907,7 @@ void f2fs_evict_inode(struct inode *inode)f2fs_remove_ino_entry (sbi, inode->i_ino,APPEND_INO );f2fs_remove_ino_entry (sbi, inode->i_ino,UPDATE_INO );f2fs_remove_ino_entry (sbi, inode->i_ino,FLUSH_INO ); +f2fs_remove_ino_entry (sbi, inode->i_ino,LARGE_FOLIO_INO );if (!is_sbi_flag_set (sbi,SBI_IS_FREEZING )) {sb_start_intwrite (inode->i_sb);
fs/f2fs/super.c +7 -0
@@ -1844,6 +1844,13 @@ static int f2fs_drop_inode(struct inode *inode)return 1 ; } } +/* +* In order to get large folio as soon as possible, let's drop +* inode cache asap. See also f2fs_release_file. +*/ +if (f2fs_exist_written_data (F2FS_I_SB (inode), + inode->i_ino,LARGE_FOLIO_INO )) +return 1 ;/* * This is to avoid a deadlock condition like below.
fs/f2fs/xattr.c +34 -1
@@ -44,6 +44,16 @@ static void xattr_free(struct f2fs_sb_info *sbi, void *xattr_addr,kfree (xattr_addr); } +static int f2fs_xattr_fadvise_get (struct inode *inode,void *buffer) +{ +if (!buffer) + goto out; +if (mapping_large_folio_support (inode->i_mapping)) + *((unsigned int *)buffer) |=BIT (F2FS_XATTR_FADV_LARGEFOLIO ); +out: +return sizeof (unsigned int ); +} +static int f2fs_xattr_generic_get (const struct xattr_handler *handler,struct dentry *unused,struct inode *inode,const char *name,void *buffer,size_t size)
@@ -61,10 +71,29 @@ static int f2fs_xattr_generic_get(const struct xattr_handler *handler,default :return -EINVAL ; } +if (handler->flags ==F2FS_XATTR_INDEX_USER && + !strcmp (name,"fadvise" )) +return f2fs_xattr_fadvise_get (inode, buffer); +return f2fs_getxattr (inode, handler->flags, name, buffer, size,NULL ); } +static int f2fs_xattr_fadvise_set (struct inode *inode,const void *value) +{ +unsigned int new_fadvise; + + new_fadvise = *(unsigned int *)value; + +if (new_fadvise &BIT (F2FS_XATTR_FADV_LARGEFOLIO )) +f2fs_add_ino_entry (F2FS_I_SB (inode), + inode->i_ino,LARGE_FOLIO_INO ); +else +f2fs_remove_ino_entry (F2FS_I_SB (inode), + inode->i_ino,LARGE_FOLIO_INO ); +return 0 ; +} + static int f2fs_xattr_generic_set(const struct xattr_handler *handler, struct mnt_idmap *idmap, struct dentry *unused, struct inode *inode,
@@ -84,6 +113,10 @@ static int f2fs_xattr_generic_set(const struct xattr_handler *handler,default :return -EINVAL ; } +if (handler->flags ==F2FS_XATTR_INDEX_USER && + !strcmp (name,"fadvise" )) +return f2fs_xattr_fadvise_set (inode, value); +return f2fs_setxattr (inode, handler->flags, name, value, size,NULL , flags); }
@@ -842,4 +875,4 @@ int __init f2fs_init_xattr_cache(void)void f2fs_destroy_xattr_cache (void ) {kmem_cache_destroy (inline_xattr_slab); -} +}
fs/f2fs/xattr.h +6 -0
@@ -24,6 +24,7 @@#define F2FS_XATTR_REFCOUNT_MAX 1024/* Name indexes */ +#define F2FS_USER_FADVISE_NAME "user.fadvise"#define F2FS_SYSTEM_ADVISE_NAME "system.advise"#define F2FS_XATTR_INDEX_USER 1#define F2FS_XATTR_INDEX_POSIX_ACL_ACCESS 2
@@ -39,6 +40,11 @@#define F2FS_XATTR_NAME_ENCRYPTION_CONTEXT "c"#define F2FS_XATTR_NAME_VERITY "v" +/* used for F2FS_USER_FADVISE_NAME */ +enum { +F2FS_XATTR_FADV_LARGEFOLIO , +}; +struct f2fs_xattr_header {__le32 h_magic;/* magic number for identification */ __le32 h_refcount;/* reference count */
Signature · 1 line
2.53.0.1213.gd9a14994de-goog
Jaegeuk Kim
maintainerenum {
F2FS_XATTR_FADV_LARGEFOLIO,
};
unsigned int value = BIT(F2FS_XATTR_FADV_LARGEFOLIO);
1. setxattr(file, "user.fadvise", &value, sizeof(unsigned int), 0) -> register the inode number for large folio
2. chmod(0400, file)
-> make Read-Only
3. fsync() && close() && open(READ)
-> f2fs_iget() with large folio
4. open(WRITE), mkwrite on mmap, chmod(WRITE)
-> return error
5. close() and open()
-> goto #3
6. unlink
-> deregister the inode number
---
Log from v1:
- add a condition in f2fs_drop_inode
- add Doc
Documentation/filesystems/f2fs.rst | 41 ++++++++++++++++++++++++++---- fs/f2fs/checkpoint.c | 2 +- fs/f2fs/data.c | 2 +- fs/f2fs/f2fs.h | 1 + fs/f2fs/file.c | 11 ++++++-- fs/f2fs/inode.c | 19 +++++++++++--- fs/f2fs/super.c | 7 +++++ fs/f2fs/xattr.c | 35 ++++++++++++++++++++++++- fs/f2fs/xattr.h | 6 +++++ 9 files changed, 111 insertions(+), 13 deletions(-)
Documentation/filesystems/f2fs.rst +36 -5
@@ -1044,11 +1044,14 @@ page allocation for significant performance gains. To minimize code complexity, this support is currently excluded from the write path, which requires handling complex optimizations such as compression and block allocation modes. -This optional feature is triggered only when a file's immutable bit is set. -Consequently, F2FS will return EOPNOTSUPP if a user attempts to open a cached -file with write permissions, even immediately after clearing the bit. Write -access is only restored once the cached inode is dropped. The usage flow is -demonstrated below: +This optional feature is triggered by two mechanisms: the file's immutable bit +or a specific xattr flag. In both cases, F2FS ensures data integrity by +restricting the file to a read-only state while large folios are active. + +1. Immutable Bit Approach: +Triggered when the FS_IMMUTABLE_FL is set. This is a strict enforcement +where the file cannot be modified at all until the bit is cleared and +the cached inode is dropped. .. code-block::
@@ -1078,3 +1081,31 @@ demonstrated below: Written 4096 bytes with pattern = zero, total_time = 29 us, max_latency = 28 us # rm /data/testfile_read_seq + +2. XATTR fadvise Approach: +A more flexible registration via extended attributes. + +.. code-block:: + + enum { + F2FS_XATTR_FADV_LARGEFOLIO, + }; + unsigned int value = BIT(F2FS_XATTR_FADV_LARGEFOLIO); + + /* Registers the inode number for large folio support in the subsystem.*/ + # setxattr(file, "user.fadvise", &value, sizeof(unsigned int), 0) + + /* The file must be made Read-Only to transition into the large folio path. */ + # fchmod(0400, fd) + + /* clean up dirty inode state. */ + # fsync(fd) + + /* Drop the inode cache. + # close(fd) + + /* f2fs_iget() instantiates the inode with large folio support.*/ + # open() + + /* Returns -EOPNOTSUPP or error to protect the large folio cache.*/ + # open(WRITE), mkwrite on mmap, or chmod(WRITE)
fs/f2fs/checkpoint.c +1 -1
@@ -778,7 +778,7 @@ void f2fs_remove_ino_entry(struct f2fs_sb_info *sbi, nid_t ino, int type)__remove_ino_entry (sbi, ino, type); } -/* mode should be APPEND_INO, UPDATE_INO or TRANS_DIR_INO */ +/* mode should be APPEND_INO, UPDATE_INO, LARGE_FOLIO_IO, or TRANS_DIR_INO */ bool f2fs_exist_written_data (struct f2fs_sb_info *sbi,nid_t ino,int mode) {struct inode_management *im = &sbi->im[mode];
fs/f2fs/data.c +1 -1
@@ -2494,7 +2494,7 @@ static int f2fs_read_data_large_folio(struct inode *inode,int ret =0 ;bool folio_in_bio; -if (!IS_IMMUTABLE (inode) ||f2fs_compressed_file (inode)) { +if (f2fs_compressed_file (inode)) {if (folio)folio_unlock (folio);return -EOPNOTSUPP ;
fs/f2fs/f2fs.h +1 -0
@@ -381,6 +381,7 @@ enum {/* for the list of ino */ enum {ORPHAN_INO ,/* for orphan ino list */ +LARGE_FOLIO_INO ,/* for large folio case */ APPEND_INO ,/* for append ino list */ UPDATE_INO ,/* for update ino list */ TRANS_DIR_INO ,/* for transactions dir ino list */
fs/f2fs/file.c +9 -2
@@ -2068,9 +2068,16 @@ static long f2fs_fallocate(struct file *file, int mode,static int f2fs_release_file (struct inode *inode,struct file *filp) { -if (atomic_dec_and_test (&F2FS_I (inode)->open_count)) +if (atomic_dec_and_test (&F2FS_I (inode)->open_count)) {f2fs_remove_donate_inode (inode); - +/* +* In order to get large folio as soon as possible, let's drop +* inode cache asap. See also f2fs_drop_inode. +*/ +if (f2fs_exist_written_data (F2FS_I_SB (inode), + inode->i_ino,LARGE_FOLIO_INO )) +d_drop (filp->f_path.dentry); + }/* * f2fs_release_file is called at every close calls. So we should * not drop any inmemory pages by close called by other process.
fs/f2fs/inode.c +16 -3
@@ -565,6 +565,20 @@ static bool is_meta_ino(struct f2fs_sb_info *sbi, unsigned int ino) ino ==F2FS_COMPRESS_INO (sbi); } +static void f2fs_mapping_set_large_folio (struct inode *inode) +{ +struct f2fs_sb_info *sbi =F2FS_I_SB (inode); + +if (f2fs_compressed_file (inode)) +return ; +if (f2fs_quota_file (sbi, inode->i_ino)) +return ; +if (IS_IMMUTABLE (inode) || + (f2fs_exist_written_data (sbi, inode->i_ino,LARGE_FOLIO_INO ) && + !(inode->i_mode &S_IWUGO ))) +mapping_set_folio_min_order (inode->i_mapping,0 ); +} +struct inode *f2fs_iget (struct super_block *sb,unsigned long ino) {struct f2fs_sb_info *sbi =F2FS_SB (sb);
@@ -620,9 +634,7 @@ struct inode *f2fs_iget(struct super_block *sb, unsigned long ino) inode->i_op = &f2fs_file_inode_operations; inode->i_fop = &f2fs_file_operations; inode->i_mapping->a_ops = &f2fs_dblock_aops; -if (IS_IMMUTABLE (inode) && !f2fs_compressed_file (inode) && - !f2fs_quota_file (sbi, inode->i_ino)) -mapping_set_folio_min_order (inode->i_mapping,0 ); +f2fs_mapping_set_large_folio (inode); }else if (S_ISDIR (inode->i_mode)) { inode->i_op = &f2fs_dir_inode_operations; inode->i_fop = &f2fs_dir_operations;
@@ -895,6 +907,7 @@ void f2fs_evict_inode(struct inode *inode)f2fs_remove_ino_entry (sbi, inode->i_ino,APPEND_INO );f2fs_remove_ino_entry (sbi, inode->i_ino,UPDATE_INO );f2fs_remove_ino_entry (sbi, inode->i_ino,FLUSH_INO ); +f2fs_remove_ino_entry (sbi, inode->i_ino,LARGE_FOLIO_INO );if (!is_sbi_flag_set (sbi,SBI_IS_FREEZING )) {sb_start_intwrite (inode->i_sb);
fs/f2fs/super.c +7 -0
@@ -1844,6 +1844,13 @@ static int f2fs_drop_inode(struct inode *inode)return 1 ; } } +/* +* In order to get large folio as soon as possible, let's drop +* inode cache asap. See also f2fs_release_file. +*/ +if (f2fs_exist_written_data (sbi, inode->i_ino,LARGE_FOLIO_INO ) && + !is_inode_flag_set (inode,FI_DIRTY_INODE )) +return 1 ;/* * This is to avoid a deadlock condition like below.
fs/f2fs/xattr.c +34 -1
@@ -44,6 +44,16 @@ static void xattr_free(struct f2fs_sb_info *sbi, void *xattr_addr,kfree (xattr_addr); } +static int f2fs_xattr_fadvise_get (struct inode *inode,void *buffer) +{ +if (!buffer) + goto out; +if (mapping_large_folio_support (inode->i_mapping)) + *((unsigned int *)buffer) |=BIT (F2FS_XATTR_FADV_LARGEFOLIO ); +out: +return sizeof (unsigned int ); +} +static int f2fs_xattr_generic_get (const struct xattr_handler *handler,struct dentry *unused,struct inode *inode,const char *name,void *buffer,size_t size)
@@ -61,10 +71,29 @@ static int f2fs_xattr_generic_get(const struct xattr_handler *handler,default :return -EINVAL ; } +if (handler->flags ==F2FS_XATTR_INDEX_USER && + !strcmp (name,"fadvise" )) +return f2fs_xattr_fadvise_get (inode, buffer); +return f2fs_getxattr (inode, handler->flags, name, buffer, size,NULL ); } +static int f2fs_xattr_fadvise_set (struct inode *inode,const void *value) +{ +unsigned int new_fadvise; + + new_fadvise = *(unsigned int *)value; + +if (new_fadvise &BIT (F2FS_XATTR_FADV_LARGEFOLIO )) +f2fs_add_ino_entry (F2FS_I_SB (inode), + inode->i_ino,LARGE_FOLIO_INO ); +else +f2fs_remove_ino_entry (F2FS_I_SB (inode), + inode->i_ino,LARGE_FOLIO_INO ); +return 0 ; +} + static int f2fs_xattr_generic_set(const struct xattr_handler *handler, struct mnt_idmap *idmap, struct dentry *unused, struct inode *inode,
@@ -84,6 +113,10 @@ static int f2fs_xattr_generic_set(const struct xattr_handler *handler,default :return -EINVAL ; } +if (handler->flags ==F2FS_XATTR_INDEX_USER && + !strcmp (name,"fadvise" )) +return f2fs_xattr_fadvise_set (inode, value); +return f2fs_setxattr (inode, handler->flags, name, value, size,NULL , flags); }
@@ -842,4 +875,4 @@ int __init f2fs_init_xattr_cache(void)void f2fs_destroy_xattr_cache (void ) {kmem_cache_destroy (inline_xattr_slab); -} +}
fs/f2fs/xattr.h +6 -0
@@ -24,6 +24,7 @@#define F2FS_XATTR_REFCOUNT_MAX 1024/* Name indexes */ +#define F2FS_USER_FADVISE_NAME "user.fadvise"#define F2FS_SYSTEM_ADVISE_NAME "system.advise"#define F2FS_XATTR_INDEX_USER 1#define F2FS_XATTR_INDEX_POSIX_ACL_ACCESS 2
@@ -39,6 +40,11 @@#define F2FS_XATTR_NAME_ENCRYPTION_CONTEXT "c"#define F2FS_XATTR_NAME_VERITY "v" +/* used for F2FS_USER_FADVISE_NAME */ +enum { +F2FS_XATTR_FADV_LARGEFOLIO , +}; +struct f2fs_xattr_header {__le32 h_magic;/* magic number for identification */ __le32 h_refcount;/* reference count */
Signature · 1 line
2.53.0.1213.gd9a14994de-goog
Please add the relevant mailing lists when adding new user interfaces.
And I'm not sure hacks working around the proper large folio implementation are something that should be merged upstream.
Quoted 314 lines · Jaegeuk Kim
enum {
F2FS_XATTR_FADV_LARGEFOLIO,
};unsigned int value =
BIT(F2FS_XATTR_FADV_LARGEFOLIO);1.
setxattr(file, "user.fadvise", &value, sizeof(unsigned int), 0)-> register the inode number for large folio
2.chmod(0400, file)
-> make Read-Only
3.fsync()&&close()&& open(READ)
->f2fs_iget()with large folio
4. open(WRITE), mkwrite on mmap, chmod(WRITE)
-> return error
5.close()andopen()
-> goto #3
6. unlink
-> deregister the inode numberSuggested-by Akilesh Kailash <[email protected]>Signed-off-by Jaegeuk Kim <[email protected]>---
Log from v1:
- add a condition inf2fs_drop_inode
- add DocDocumentation/filesystems/f2fs.rst | 41 ++++++++++++++++++++++++++---- fs/f2fs/checkpoint.c | 2 +- fs/f2fs/data.c | 2 +- fs/f2fs/f2fs.h | 1 + fs/f2fs/file.c | 11 ++++++-- fs/f2fs/inode.c | 19 +++++++++++--- fs/f2fs/super.c | 7 +++++ fs/f2fs/xattr.c | 35 ++++++++++++++++++++++++- fs/f2fs/xattr.h | 6 +++++ 9 files changed, 111 insertions(+), 13 deletions(-)Documentation/filesystems/f2fs.rst +36
-5@@ -1044,11 +1044,14 @@ page allocation for significant performance gains. To minimize code complexity, this support is currently excluded from the write path, which requires handling complex optimizations such as compression and block allocation modes. -This optional feature is triggered only when a file's immutable bit is set. -Consequently, F2FS will return EOPNOTSUPP if a user attempts to open a cached -file with write permissions, even immediately after clearing the bit. Write -access is only restored once the cached inode is dropped. The usage flow is -demonstrated below: +This optional feature is triggered by two mechanisms: the file's immutable bit +or a specific xattr flag. In both cases, F2FS ensures data integrity by +restricting the file to a read-only state while large folios are active. + +1. Immutable Bit Approach: +Triggered when the FS_IMMUTABLE_FL is set. This is a strict enforcement +where the file cannot be modified at all until the bit is cleared and +the cached inode is dropped. .. code-block::@@ -1078,3 +1081,31 @@ demonstrated below: Written 4096 bytes with pattern = zero, total_time = 29 us, max_latency = 28 us # rm /data/testfile_read_seq + +2. XATTR fadvise Approach: +A more flexible registration via extended attributes. + +.. code-block:: + + enum { + F2FS_XATTR_FADV_LARGEFOLIO, + }; + unsigned int value = BIT(F2FS_XATTR_FADV_LARGEFOLIO); + + /* Registers the inode number for large folio support in the subsystem.*/ + # setxattr(file, "user.fadvise", &value, sizeof(unsigned int), 0) + + /* The file must be made Read-Only to transition into the large folio path. */ + # fchmod(0400, fd) + + /* clean up dirty inode state. */ + # fsync(fd) + + /* Drop the inode cache. + # close(fd) + + /* f2fs_iget() instantiates the inode with large folio support.*/ + # open() + + /* Returns -EOPNOTSUPP or error to protect the large folio cache.*/ + # open(WRITE), mkwrite on mmap, or chmod(WRITE)fs/f2fs/checkpoint.c +1
-1@@ -778,7 +778,7 @@ void f2fs_remove_ino_entry(struct f2fs_sb_info *sbi, nid_t ino, int type)__remove_ino_entry (sbi, ino, type); } -/* mode should be APPEND_INO, UPDATE_INO or TRANS_DIR_INO */ +/* mode should be APPEND_INO, UPDATE_INO, LARGE_FOLIO_IO, or TRANS_DIR_INO */ bool f2fs_exist_written_data (struct f2fs_sb_info *sbi,nid_t ino,int mode) {struct inode_management *im = &sbi->im[mode];fs/f2fs/data.c +1
-1@@ -2494,7 +2494,7 @@ static int f2fs_read_data_large_folio(struct inode *inode,int ret =0 ;bool folio_in_bio; -if (!IS_IMMUTABLE (inode) ||f2fs_compressed_file (inode)) { +if (f2fs_compressed_file (inode)) {if (folio)folio_unlock (folio);return -EOPNOTSUPP ;fs/f2fs/f2fs.h +1
-0@@ -381,6 +381,7 @@ enum {/* for the list of ino */ enum {ORPHAN_INO ,/* for orphan ino list */ +LARGE_FOLIO_INO ,/* for large folio case */ APPEND_INO ,/* for append ino list */ UPDATE_INO ,/* for update ino list */ TRANS_DIR_INO ,/* for transactions dir ino list */ fs/f2fs/file.c +9
-2@@ -2068,9 +2068,16 @@ static long f2fs_fallocate(struct file *file, int mode,static int f2fs_release_file (struct inode *inode,struct file *filp) { -if (atomic_dec_and_test (&F2FS_I (inode)->open_count)) +if (atomic_dec_and_test (&F2FS_I (inode)->open_count)) {f2fs_remove_donate_inode (inode); - +/* +* In order to get large folio as soon as possible, let's drop +* inode cache asap. See also f2fs_drop_inode. +*/ +if (f2fs_exist_written_data (F2FS_I_SB (inode), + inode->i_ino,LARGE_FOLIO_INO )) +d_drop (filp->f_path.dentry); + }/* * f2fs_release_file is called at every close calls. So we should * not drop any inmemory pages by close called by other process. fs/f2fs/inode.c +16
-3@@ -565,6 +565,20 @@ static bool is_meta_ino(struct f2fs_sb_info *sbi, unsigned int ino) ino ==F2FS_COMPRESS_INO (sbi); } +static void f2fs_mapping_set_large_folio (struct inode *inode) +{ +struct f2fs_sb_info *sbi =F2FS_I_SB (inode); + +if (f2fs_compressed_file (inode)) +return ; +if (f2fs_quota_file (sbi, inode->i_ino)) +return ; +if (IS_IMMUTABLE (inode) || + (f2fs_exist_written_data (sbi, inode->i_ino,LARGE_FOLIO_INO ) && + !(inode->i_mode &S_IWUGO ))) +mapping_set_folio_min_order (inode->i_mapping,0 ); +} +struct inode *f2fs_iget (struct super_block *sb,unsigned long ino) {struct f2fs_sb_info *sbi =F2FS_SB (sb);@@ -620,9 +634,7 @@ struct inode *f2fs_iget(struct super_block *sb, unsigned long ino) inode->i_op = &f2fs_file_inode_operations; inode->i_fop = &f2fs_file_operations; inode->i_mapping->a_ops = &f2fs_dblock_aops; -if (IS_IMMUTABLE (inode) && !f2fs_compressed_file (inode) && - !f2fs_quota_file (sbi, inode->i_ino)) -mapping_set_folio_min_order (inode->i_mapping,0 ); +f2fs_mapping_set_large_folio (inode); }else if (S_ISDIR (inode->i_mode)) { inode->i_op = &f2fs_dir_inode_operations; inode->i_fop = &f2fs_dir_operations;@@ -895,6 +907,7 @@ void f2fs_evict_inode(struct inode *inode)f2fs_remove_ino_entry (sbi, inode->i_ino,APPEND_INO );f2fs_remove_ino_entry (sbi, inode->i_ino,UPDATE_INO );f2fs_remove_ino_entry (sbi, inode->i_ino,FLUSH_INO ); +f2fs_remove_ino_entry (sbi, inode->i_ino,LARGE_FOLIO_INO );if (!is_sbi_flag_set (sbi,SBI_IS_FREEZING )) {sb_start_intwrite (inode->i_sb);fs/f2fs/super.c +7
-0@@ -1844,6 +1844,13 @@ static int f2fs_drop_inode(struct inode *inode)return 1 ; } } +/* +* In order to get large folio as soon as possible, let's drop +* inode cache asap. See also f2fs_release_file. +*/ +if (f2fs_exist_written_data (sbi, inode->i_ino,LARGE_FOLIO_INO ) && + !is_inode_flag_set (inode,FI_DIRTY_INODE )) +return 1 ;/* * This is to avoid a deadlock condition like below. fs/f2fs/xattr.c +34
-1@@ -44,6 +44,16 @@ static void xattr_free(struct f2fs_sb_info *sbi, void *xattr_addr,kfree (xattr_addr); } +static int f2fs_xattr_fadvise_get (struct inode *inode,void *buffer) +{ +if (!buffer) + goto out; +if (mapping_large_folio_support (inode->i_mapping)) + *((unsigned int *)buffer) |=BIT (F2FS_XATTR_FADV_LARGEFOLIO ); +out: +return sizeof (unsigned int ); +} +static int f2fs_xattr_generic_get (const struct xattr_handler *handler,struct dentry *unused,struct inode *inode,const char *name,void *buffer,size_t size)@@ -61,10 +71,29 @@ static int f2fs_xattr_generic_get(const struct xattr_handler *handler,default :return -EINVAL ; } +if (handler->flags ==F2FS_XATTR_INDEX_USER && + !strcmp (name,"fadvise" )) +return f2fs_xattr_fadvise_get (inode, buffer); +return f2fs_getxattr (inode, handler->flags, name, buffer, size,NULL ); } +static int f2fs_xattr_fadvise_set (struct inode *inode,const void *value) +{ +unsigned int new_fadvise; + + new_fadvise = *(unsigned int *)value; + +if (new_fadvise &BIT (F2FS_XATTR_FADV_LARGEFOLIO )) +f2fs_add_ino_entry (F2FS_I_SB (inode), + inode->i_ino,LARGE_FOLIO_INO ); +else +f2fs_remove_ino_entry (F2FS_I_SB (inode), + inode->i_ino,LARGE_FOLIO_INO ); +return 0 ; +} + static int f2fs_xattr_generic_set(const struct xattr_handler *handler, struct mnt_idmap *idmap, struct dentry *unused, struct inode *inode,@@ -84,6 +113,10 @@ static int f2fs_xattr_generic_set(const struct xattr_handler *handler,default :return -EINVAL ; } +if (handler->flags ==F2FS_XATTR_INDEX_USER && + !strcmp (name,"fadvise" )) +return f2fs_xattr_fadvise_set (inode, value); +return f2fs_setxattr (inode, handler->flags, name, value, size,NULL , flags); }@@ -842,4 +875,4 @@ int __init f2fs_init_xattr_cache(void)void f2fs_destroy_xattr_cache (void ) {kmem_cache_destroy (inline_xattr_slab); -} +}fs/f2fs/xattr.h +6
-0@@ -24,6 +24,7 @@#define F2FS_XATTR_REFCOUNT_MAX 1024/* Name indexes */ +#define F2FS_USER_FADVISE_NAME "user.fadvise"#define F2FS_SYSTEM_ADVISE_NAME "system.advise"#define F2FS_XATTR_INDEX_USER 1#define F2FS_XATTR_INDEX_POSIX_ACL_ACCESS 2@@ -39,6 +40,11 @@#define F2FS_XATTR_NAME_ENCRYPTION_CONTEXT "c"#define F2FS_XATTR_NAME_VERITY "v" +/* used for F2FS_USER_FADVISE_NAME */ +enum { +F2FS_XATTR_FADV_LARGEFOLIO , +}; +struct f2fs_xattr_header {__le32 h_magic;/* magic number for identification */ __le32 h_refcount;/* reference count */ Signature · 1 line
2.53.0.1213.gd9a14994de-goog
---end quoted text---
Jaegeuk Kim
maintainerQuoted 4 lines · Christoph Hellwig
Please add the relevant mailing lists when adding new user interfaces.
And I'm not sure hacks working around the proper large folio implementation are something that should be merged upstream.
Cc'ed linux-api and linux-fsdevel onto the patch thread with a proposal that I'm not sure it's acceptable or not.
Quoted 317 lines · Jaegeuk Kim
Quoted 314 lines
enum {
F2FS_XATTR_FADV_LARGEFOLIO,
};unsigned int value =
BIT(F2FS_XATTR_FADV_LARGEFOLIO);1.
setxattr(file, "user.fadvise", &value, sizeof(unsigned int), 0)-> register the inode number for large folio
2.chmod(0400, file)
-> make Read-Only
3.fsync()&&close()&& open(READ)
->f2fs_iget()with large folio
4. open(WRITE), mkwrite on mmap, chmod(WRITE)
-> return error
5.close()andopen()
-> goto #3
6. unlink
-> deregister the inode numberSuggested-by Akilesh Kailash <[email protected]>Signed-off-by Jaegeuk Kim <[email protected]>---
Log from v1:
- add a condition inf2fs_drop_inode
- add DocDocumentation/filesystems/f2fs.rst | 41 ++++++++++++++++++++++++++---- fs/f2fs/checkpoint.c | 2 +- fs/f2fs/data.c | 2 +- fs/f2fs/f2fs.h | 1 + fs/f2fs/file.c | 11 ++++++-- fs/f2fs/inode.c | 19 +++++++++++--- fs/f2fs/super.c | 7 +++++ fs/f2fs/xattr.c | 35 ++++++++++++++++++++++++- fs/f2fs/xattr.h | 6 +++++ 9 files changed, 111 insertions(+), 13 deletions(-)Documentation/filesystems/f2fs.rst +36
-5@@ -1044,11 +1044,14 @@ page allocation for significant performance gains. To minimize code complexity, this support is currently excluded from the write path, which requires handling complex optimizations such as compression and block allocation modes. -This optional feature is triggered only when a file's immutable bit is set. -Consequently, F2FS will return EOPNOTSUPP if a user attempts to open a cached -file with write permissions, even immediately after clearing the bit. Write -access is only restored once the cached inode is dropped. The usage flow is -demonstrated below: +This optional feature is triggered by two mechanisms: the file's immutable bit +or a specific xattr flag. In both cases, F2FS ensures data integrity by +restricting the file to a read-only state while large folios are active. + +1. Immutable Bit Approach: +Triggered when the FS_IMMUTABLE_FL is set. This is a strict enforcement +where the file cannot be modified at all until the bit is cleared and +the cached inode is dropped. .. code-block::@@ -1078,3 +1081,31 @@ demonstrated below: Written 4096 bytes with pattern = zero, total_time = 29 us, max_latency = 28 us # rm /data/testfile_read_seq + +2. XATTR fadvise Approach: +A more flexible registration via extended attributes. + +.. code-block:: + + enum { + F2FS_XATTR_FADV_LARGEFOLIO, + }; + unsigned int value = BIT(F2FS_XATTR_FADV_LARGEFOLIO); + + /* Registers the inode number for large folio support in the subsystem.*/ + # setxattr(file, "user.fadvise", &value, sizeof(unsigned int), 0) + + /* The file must be made Read-Only to transition into the large folio path. */ + # fchmod(0400, fd) + + /* clean up dirty inode state. */ + # fsync(fd) + + /* Drop the inode cache. + # close(fd) + + /* f2fs_iget() instantiates the inode with large folio support.*/ + # open() + + /* Returns -EOPNOTSUPP or error to protect the large folio cache.*/ + # open(WRITE), mkwrite on mmap, or chmod(WRITE)fs/f2fs/checkpoint.c +1
-1@@ -778,7 +778,7 @@ void f2fs_remove_ino_entry(struct f2fs_sb_info *sbi, nid_t ino, int type)__remove_ino_entry (sbi, ino, type); } -/* mode should be APPEND_INO, UPDATE_INO or TRANS_DIR_INO */ +/* mode should be APPEND_INO, UPDATE_INO, LARGE_FOLIO_IO, or TRANS_DIR_INO */ bool f2fs_exist_written_data (struct f2fs_sb_info *sbi,nid_t ino,int mode) {struct inode_management *im = &sbi->im[mode];fs/f2fs/data.c +1
-1@@ -2494,7 +2494,7 @@ static int f2fs_read_data_large_folio(struct inode *inode,int ret =0 ;bool folio_in_bio; -if (!IS_IMMUTABLE (inode) ||f2fs_compressed_file (inode)) { +if (f2fs_compressed_file (inode)) {if (folio)folio_unlock (folio);return -EOPNOTSUPP ;fs/f2fs/f2fs.h +1
-0@@ -381,6 +381,7 @@ enum {/* for the list of ino */ enum {ORPHAN_INO ,/* for orphan ino list */ +LARGE_FOLIO_INO ,/* for large folio case */ APPEND_INO ,/* for append ino list */ UPDATE_INO ,/* for update ino list */ TRANS_DIR_INO ,/* for transactions dir ino list */ fs/f2fs/file.c +9
-2@@ -2068,9 +2068,16 @@ static long f2fs_fallocate(struct file *file, int mode,static int f2fs_release_file (struct inode *inode,struct file *filp) { -if (atomic_dec_and_test (&F2FS_I (inode)->open_count)) +if (atomic_dec_and_test (&F2FS_I (inode)->open_count)) {f2fs_remove_donate_inode (inode); - +/* +* In order to get large folio as soon as possible, let's drop +* inode cache asap. See also f2fs_drop_inode. +*/ +if (f2fs_exist_written_data (F2FS_I_SB (inode), + inode->i_ino,LARGE_FOLIO_INO )) +d_drop (filp->f_path.dentry); + }/* * f2fs_release_file is called at every close calls. So we should * not drop any inmemory pages by close called by other process. fs/f2fs/inode.c +16
-3@@ -565,6 +565,20 @@ static bool is_meta_ino(struct f2fs_sb_info *sbi, unsigned int ino) ino ==F2FS_COMPRESS_INO (sbi); } +static void f2fs_mapping_set_large_folio (struct inode *inode) +{ +struct f2fs_sb_info *sbi =F2FS_I_SB (inode); + +if (f2fs_compressed_file (inode)) +return ; +if (f2fs_quota_file (sbi, inode->i_ino)) +return ; +if (IS_IMMUTABLE (inode) || + (f2fs_exist_written_data (sbi, inode->i_ino,LARGE_FOLIO_INO ) && + !(inode->i_mode &S_IWUGO ))) +mapping_set_folio_min_order (inode->i_mapping,0 ); +} +struct inode *f2fs_iget (struct super_block *sb,unsigned long ino) {struct f2fs_sb_info *sbi =F2FS_SB (sb);@@ -620,9 +634,7 @@ struct inode *f2fs_iget(struct super_block *sb, unsigned long ino) inode->i_op = &f2fs_file_inode_operations; inode->i_fop = &f2fs_file_operations; inode->i_mapping->a_ops = &f2fs_dblock_aops; -if (IS_IMMUTABLE (inode) && !f2fs_compressed_file (inode) && - !f2fs_quota_file (sbi, inode->i_ino)) -mapping_set_folio_min_order (inode->i_mapping,0 ); +f2fs_mapping_set_large_folio (inode); }else if (S_ISDIR (inode->i_mode)) { inode->i_op = &f2fs_dir_inode_operations; inode->i_fop = &f2fs_dir_operations;@@ -895,6 +907,7 @@ void f2fs_evict_inode(struct inode *inode)f2fs_remove_ino_entry (sbi, inode->i_ino,APPEND_INO );f2fs_remove_ino_entry (sbi, inode->i_ino,UPDATE_INO );f2fs_remove_ino_entry (sbi, inode->i_ino,FLUSH_INO ); +f2fs_remove_ino_entry (sbi, inode->i_ino,LARGE_FOLIO_INO );if (!is_sbi_flag_set (sbi,SBI_IS_FREEZING )) {sb_start_intwrite (inode->i_sb);fs/f2fs/super.c +7
-0@@ -1844,6 +1844,13 @@ static int f2fs_drop_inode(struct inode *inode)return 1 ; } } +/* +* In order to get large folio as soon as possible, let's drop +* inode cache asap. See also f2fs_release_file. +*/ +if (f2fs_exist_written_data (sbi, inode->i_ino,LARGE_FOLIO_INO ) && + !is_inode_flag_set (inode,FI_DIRTY_INODE )) +return 1 ;/* * This is to avoid a deadlock condition like below. fs/f2fs/xattr.c +34
-1@@ -44,6 +44,16 @@ static void xattr_free(struct f2fs_sb_info *sbi, void *xattr_addr,kfree (xattr_addr); } +static int f2fs_xattr_fadvise_get (struct inode *inode,void *buffer) +{ +if (!buffer) + goto out; +if (mapping_large_folio_support (inode->i_mapping)) + *((unsigned int *)buffer) |=BIT (F2FS_XATTR_FADV_LARGEFOLIO ); +out: +return sizeof (unsigned int ); +} +static int f2fs_xattr_generic_get (const struct xattr_handler *handler,struct dentry *unused,struct inode *inode,const char *name,void *buffer,size_t size)@@ -61,10 +71,29 @@ static int f2fs_xattr_generic_get(const struct xattr_handler *handler,default :return -EINVAL ; } +if (handler->flags ==F2FS_XATTR_INDEX_USER && + !strcmp (name,"fadvise" )) +return f2fs_xattr_fadvise_get (inode, buffer); +return f2fs_getxattr (inode, handler->flags, name, buffer, size,NULL ); } +static int f2fs_xattr_fadvise_set (struct inode *inode,const void *value) +{ +unsigned int new_fadvise; + + new_fadvise = *(unsigned int *)value; + +if (new_fadvise &BIT (F2FS_XATTR_FADV_LARGEFOLIO )) +f2fs_add_ino_entry (F2FS_I_SB (inode), + inode->i_ino,LARGE_FOLIO_INO ); +else +f2fs_remove_ino_entry (F2FS_I_SB (inode), + inode->i_ino,LARGE_FOLIO_INO ); +return 0 ; +} + static int f2fs_xattr_generic_set(const struct xattr_handler *handler, struct mnt_idmap *idmap, struct dentry *unused, struct inode *inode,@@ -84,6 +113,10 @@ static int f2fs_xattr_generic_set(const struct xattr_handler *handler,default :return -EINVAL ; } +if (handler->flags ==F2FS_XATTR_INDEX_USER && + !strcmp (name,"fadvise" )) +return f2fs_xattr_fadvise_set (inode, value); +return f2fs_setxattr (inode, handler->flags, name, value, size,NULL , flags); }@@ -842,4 +875,4 @@ int __init f2fs_init_xattr_cache(void)void f2fs_destroy_xattr_cache (void ) {kmem_cache_destroy (inline_xattr_slab); -} +}fs/f2fs/xattr.h +6
-0@@ -24,6 +24,7 @@#define F2FS_XATTR_REFCOUNT_MAX 1024/* Name indexes */ +#define F2FS_USER_FADVISE_NAME "user.fadvise"#define F2FS_SYSTEM_ADVISE_NAME "system.advise"#define F2FS_XATTR_INDEX_USER 1#define F2FS_XATTR_INDEX_POSIX_ACL_ACCESS 2@@ -39,6 +40,11 @@#define F2FS_XATTR_NAME_ENCRYPTION_CONTEXT "c"#define F2FS_XATTR_NAME_VERITY "v" +/* used for F2FS_USER_FADVISE_NAME */ +enum { +F2FS_XATTR_FADV_LARGEFOLIO , +}; +struct f2fs_xattr_header {__le32 h_magic;/* magic number for identification */ __le32 h_refcount;/* reference count */ Signature · 1 line
2.53.0.1213.gd9a14994de-goog---end quoted text---
Quoted 8 lines · Jaegeuk Kim
Quoted 4 lines · Christoph Hellwig
Please add the relevant mailing lists when adding new user interfaces.
And I'm not sure hacks working around the proper large folio implementation are something that should be merged upstream.
Cc'ed linux-api and linux-fsdevel onto the patch thread with a proposal that I'm not sure it's acceptable or not.
You haven't sent a proposal. This is a reply to a reply to a reply of a patch. There's no justification for why f2fs is so special that it needs this. What the hell is going on? You know this is not the way to get code merged into Linux.
Jaegeuk Kim
maintainerQuoted 7 lines · Matthew Wilcox
Quoted 6 lines · Jaegeuk Kim
Quoted 4 lines · Christoph Hellwig
Please add the relevant mailing lists when adding new user interfaces.
And I'm not sure hacks working around the proper large folio implementation are something that should be merged upstream.
Quoted 7 lines
Quoted 2 lines
Cc'ed linux-api and linux-fsdevel onto the patch thread with a proposal that I'm not sure it's acceptable or not.
You haven't sent a proposal. This is a reply to a reply to a reply of a patch. There's no justification for why f2fs is so special that it needs this. What the hell is going on? You know this is not the way to get code merged into Linux.
I added two ideas in that email. Have you even tried to understand?
Quoted 11 lines · Jaegeuk Kim
Quoted 10 lines · Matthew Wilcox
Quoted 8 lines · Jaegeuk Kim
Quoted 4 lines · Christoph Hellwig
Please add the relevant mailing lists when adding new user interfaces.
And I'm not sure hacks working around the proper large folio implementation are something that should be merged upstream.
Cc'ed linux-api and linux-fsdevel onto the patch thread with a proposal that I'm not sure it's acceptable or not.
Quoted 6 lines
Quoted 4 lines
You haven't sent a proposal. This is a reply to a reply to a reply of a patch. There's no justification for why f2fs is so special that it needs this. What the hell is going on? You know this is not the way to get code merged into Linux.
I added two ideas in that email. Have you even tried to understand?
You want to establish "user.fadvise" as an extended attribute containing a bitmask. The sole bit defined in that attribute means "use large folios", but you also have to change the file mode and set the IMMUTABLE bit for it to actually do anything.
Meanwhile, you can't actually persist any of the fadvise(2) advice flags, so the xattr name doesn't even make sense. Maybe you meant to call it "user.madvise" since the closest thing I can think of is MADV_HUGEPAGE?
I've understood enough. YUCK.
--D
Jaegeuk Kim
maintainerQuoted 17 lines · Darrick J. Wong
Quoted 16 lines · Jaegeuk Kim
Quoted 14 lines · Matthew Wilcox
Quoted 8 lines · Jaegeuk Kim
Quoted 4 lines · Christoph Hellwig
Please add the relevant mailing lists when adding new user interfaces.
And I'm not sure hacks working around the proper large folio implementation are something that should be merged upstream.
Cc'ed linux-api and linux-fsdevel onto the patch thread with a proposal that I'm not sure it's acceptable or not.
You haven't sent a proposal. This is a reply to a reply to a reply of a patch. There's no justification for why f2fs is so special that it needs this. What the hell is going on? You know this is not the way to get code merged into Linux.
Quoted 6 lines
Quoted 1 line
I added two ideas in that email. Have you even tried to understand?
You want to establish "user.fadvise" as an extended attribute containing a bitmask. The sole bit defined in that attribute means "use large folios", but you also have to change the file mode and set the IMMUTABLE bit for it to actually do anything.
Partly yes. This path has nothing to do with IMMUTABLE bit, since I used to activate the large folio with that bit, but hit a big pain which requires clearing the bit whenever just deleting the file.
So, this gives a new way to activate the large folio by chmod(0400) and setxattr("user.fadvise") only while providing quick inode eviction in order to set mapping by iget, and allowing file deletion easily.
I feel the arguable points would be 1) the path to evict inode by calling d_drop in release_file and returning 1 in drop_inode, 2) how to give the hint between fadvise(FADV_LARGE_FOLIO) or setxattr(user.fadvise) by individual file system.
Quoted 7 lines
Meanwhile, you can't actually persist any of the fadvise(2) advice flags, so the xattr name doesn't even make sense. Maybe you meant to call it "user.madvise" since the closest thing I can think of is
MADV_HUGEPAGE?I've understood enough. YUCK.
Thank you for taking the time to take a look.
Quoted 2 lines
--D
Quoted 7 lines · Matthew Wilcox
Quoted 6 lines · Jaegeuk Kim
Quoted 4 lines · Christoph Hellwig
Please add the relevant mailing lists when adding new user interfaces.
And I'm not sure hacks working around the proper large folio implementation are something that should be merged upstream.
Quoted 7 lines
Quoted 2 lines
Cc'ed linux-api and linux-fsdevel onto the patch thread with a proposal that I'm not sure it's acceptable or not.
You haven't sent a proposal. This is a reply to a reply to a reply of a patch. There's no justification for why f2fs is so special that it needs this. What the hell is going on? You know this is not the way to get code merged into Linux.
None of this got properly answers, and this broken interface now landed in linux-next. IT is offloading a user.* xattr which is free-form user data with semantics that are weird to say it very nicely.
All this was done against the advice in the mailing list discussion.
I think at some point we just need to stop taking f2fs updates likes this.
Quoted 10 lines · Christoph Hellwig
Quoted 4 lines
You haven't sent a proposal. This is a reply to a reply to a reply of a patch. There's no justification for why f2fs is so special that it needs this. What the hell is going on? You know this is not the way to get code merged into Linux.
None of this got properly answers, and this broken interface now landed in linux-next. IT is offloading a user.* xattr which is free-form user data with semantics that are weird to say it very nicely.
All this was done against the advice in the mailing list discussion.
So let me get this straight. This is a magic xattr interface which is not even persisted in the file system, but instead sets a 32-bit bitmask in the struct inode which disappears once the inode gets flushed from the inode stack. And it uses a generic xattr name, "user.fadvise".
There's no way in *hell* any other file system is likely to adopt such a broken interface, so why didn't you just use an ioctl to set this magic f2fs-specific flag?
Quoted 2 lines
I think at some point we just need to stop taking f2fs updates likes this.
Well, that's ultiamtely up to Linus. I'll say that if I were Linus (and I'm glad I'm not :-), and I saw this in a pull request, I'd reject it out of hand. But whether it's worth making a huge fuss and asking escalating this mess to Linus, we probably should get a bit more community consensus before taking such a drastic step.
Christian, since you're one of the VFS maintaienrs, what's your opinion about escalating this to Linus?
- Ted
Quoted 9 lines · Theodore Tso
So let me get this straight. This is a magic xattr interface which is not even persisted in the file system, but instead sets a 32-bit bitmask in the struct inode which disappears once the inode gets flushed from the inode stack. And it uses a generic xattr name, "user.fadvise".
There's no way in *hell* any other file system is likely to adopt such a broken interface, so why didn't you just use an ioctl to set this magic f2fs-specific flag?
I mean, yes, this API is horrendous. But it's just another example of f2fs thinking it's somehow special and not just enabling large folios like other filesystems do. This hurts everyone, not just people who use f2fs.
Jaegeuk Kim
maintainerQuoted 7 lines · Matthew Wilcox
Quoted 6 lines · Theodore Tso
So let me get this straight. This is a magic xattr interface which is not even persisted in the file system, but instead sets a 32-bit bitmask in the struct inode which disappears once the inode gets flushed from the inode stack. And it uses a generic xattr name, "user.fadvise".
Quoted 8 lines
Quoted 3 lines
There's no way in *hell* any other file system is likely to adopt such a broken interface, so why didn't you just use an ioctl to set this magic f2fs-specific flag?
I mean, yes, this API is horrendous. But it's just another example of f2fs thinking it's somehow special and not just enabling large folios like other filesystems do. This hurts everyone, not just people who use f2fs.
From the production viewpoint, I raised a concern on setting large folio by default, since that exhausts lots of high-order pages, which were needed for essential system services and critical apps.
Quoted 12 lines · Jaegeuk Kim
Quoted 11 lines · Matthew Wilcox
Quoted 9 lines · Theodore Tso
So let me get this straight. This is a magic xattr interface which is not even persisted in the file system, but instead sets a 32-bit bitmask in the struct inode which disappears once the inode gets flushed from the inode stack. And it uses a generic xattr name, "user.fadvise".
There's no way in *hell* any other file system is likely to adopt such a broken interface, so why didn't you just use an ioctl to set this magic f2fs-specific flag?
Quoted 8 lines
Quoted 6 lines
I mean, yes, this API is horrendous. But it's just another example of f2fs thinking it's somehow special and not just enabling large folios like other filesystems do. This hurts everyone, not just people who use f2fs.
From the production viewpoint, I raised a concern on setting large folio by
default, since that exhausts lots of high-order pages, which were needed for essential system services and critical apps.
Random fears or actual data?
Jaegeuk Kim
maintainerQuoted 18 lines · Matthew Wilcox
Quoted 17 lines · Jaegeuk Kim
Quoted 15 lines · Matthew Wilcox
Quoted 9 lines · Theodore Tso
So let me get this straight. This is a magic xattr interface which is not even persisted in the file system, but instead sets a 32-bit bitmask in the struct inode which disappears once the inode gets flushed from the inode stack. And it uses a generic xattr name, "user.fadvise".
There's no way in *hell* any other file system is likely to adopt such a broken interface, so why didn't you just use an ioctl to set this magic f2fs-specific flag?
I mean, yes, this API is horrendous. But it's just another example of f2fs thinking it's somehow special and not just enabling large folios like other filesystems do. This hurts everyone, not just people who use f2fs.
Quoted 5 lines
Quoted 3 lines
Quoted 1 line
From the production viewpoint, I raised a concern on setting large folio by
default, since that exhausts lots of high-order pages, which were needed for essential system services and critical apps.
Random fears or actual data?
This was a quick buddyinfo right after booting the device.
Before:
Node 0, zone Normal 22684 42284 28704 16901 9515 4566 1854 673 181 36 758
After disabling EROFS large folio:
Node 0, zone Normal 8486 4732 2175 1161 697 272 82 19 3 1 856
Quoted 6 lines
_______________________________________________
Linux-f2fs-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/linux-f2fs-devel
Quoted 7 lines · Jaegeuk Kim
This was a quick buddyinfo right after booting the device.
Before:
Node 0, zone Normal 22684 42284 28704 16901 9515 4566 1854 673 181 36 758After disabling EROFS large folio:
Node 0, zone Normal 8486 4732 2175 1161 697 272 82 19 3 1 856
And what are you trying to say us with that?
Jaegeuk Kim
maintainerQuoted 10 lines · Christoph Hellwig
Quoted 7 lines · Jaegeuk Kim
This was a quick buddyinfo right after booting the device.
Before:
Node 0, zone Normal 22684 42284 28704 16901 9515 4566 1854 673 181 36 758After disabling EROFS large folio:
Node 0, zone Normal 8486 4732 2175 1161 697 272 82 19 3 1 856And what are you trying to say us with that?
This means, high-order pages were used up by EROFS which sets large folio by default. So, I wanted to say the concern was based on actual data which was what Mattew asked.
Quoted 7 lines
_______________________________________________
Linux-f2fs-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/linux-f2fs-devel
Quoted 7 lines · Jaegeuk Kim
Quoted 6 lines · Christoph Hellwig
Quoted 5 lines · Jaegeuk Kim
This was a quick buddyinfo right after booting the device.
Before:
Node 0, zone Normal 22684 42284 28704 16901 9515 4566 1854 673 181 36 758
Quoted 8 lines
Quoted 4 lines
Quoted 2 lines
After disabling EROFS large folio:
Node 0, zone Normal 8486 4732 2175 1161 697 272 82 19 3 1 856And what are you trying to say us with that?
This means, high-order pages were used up by EROFS which sets large folio by default. So, I wanted to say the concern was based on actual data which was what Mattew asked.
This isn't that though. What you actually need is to show that high order allocations are _failing_. The MM is far more complicated than you seem to understand. There isn't a fixed number of large folios available; when we try to allocate memory, we do reclaim. And if there's large folios on the LRU list, you'll get them.
If what you want is large folios readily available, then what you want is large folios used _everywhere_ because then they're easy to get! If there's small folios in use, you need to reclaim a lot of memory in order to reassemble large folios (it's the birthday paradox, similar to the hash collision problem).
Jaegeuk Kim
maintainerQuoted 23 lines · Matthew Wilcox
Quoted 7 lines · Jaegeuk Kim
Quoted 6 lines · Christoph Hellwig
Quoted 5 lines · Jaegeuk Kim
This was a quick buddyinfo right after booting the device.
Before:
Node 0, zone Normal 22684 42284 28704 16901 9515 4566 1854 673 181 36 758Quoted 8 lines
Quoted 4 lines
Quoted 2 lines
After disabling EROFS large folio:
Node 0, zone Normal 8486 4732 2175 1161 697 272 82 19 3 1 856And what are you trying to say us with that?
This means, high-order pages were used up by EROFS which sets large folio by default. So, I wanted to say the concern was based on actual data which was what Mattew asked.
This isn't that though. What you actually need is to show that high order allocations are _failing_. The MM is far more complicated than you seem to understand. There isn't a fixed number of large folios available; when we try to allocate memory, we do reclaim. And if there's large folios on the LRU list, you'll get them.
Quoted 5 lines
If what you want is large folios readily available, then what you want is large folios used _everywhere_ because then they're easy to get! If there's small folios in use, you need to reclaim a lot of memory in order to reassemble large folios (it's the birthday paradox, similar to the hash collision problem).
Thanks for the feedback. Actually, I tried to do compact_memory before doing read() for AI loading, but I got complaints where it took hundreds milliseconds to run that compact_memory. Is there a good way to secure high-order pages before that read()? It was quite hard to project when it will happen.
Quoted 6 lines
_______________________________________________
Linux-f2fs-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/linux-f2fs-devel
Quoted 4 lines · Jaegeuk Kim
Thanks for the feedback. Actually, I tried to do
compact_memorybefore doingread()for AI loading, but I got complaints where it took hundreds milliseconds to run thatcompact_memory. Is there a good way to secure high-order pages before thatread()? It was quite hard to project when it will happen.
Make sure that all files use large folios as much as possible so that
you have a lot of clean pagecache to reclaim.. Same for any other
easily reclaimable memory through shrinkers.
Quoted 8 lines · Matthew Wilcox
Quoted 5 lines
Quoted 1 line
And what are you trying to say us with that?
This means, high-order pages were used up by EROFS which sets large folio by default. So, I wanted to say the concern was based on actual data which was what Mattew asked.
This isn't that though. What you actually need is to show that high order allocations are _failing_.
Exactly.
Quoted 2 lines
If what you want is large folios readily available, then what you want is large folios used _everywhere_ because then they're easy to get!
Yes.
Quoted 3 lines
If there's small folios in use, you need to reclaim a lot of memory in order to reassemble large folios (it's the birthday paradox, similar to the hash collision problem).
Yeah. Although it seems we have an issue with > order costly folios at the moment, but we should fix this.
And f2fs really needs to up the game and support large folios fully so that we can run that kind of analysis there as well, without this all this is just piling hacks on top of other hacks.
Jaegeuk Kim
maintainerQuoted 21 lines · Christoph Hellwig
Quoted 8 lines · Matthew Wilcox
Quoted 5 lines
Quoted 1 line
And what are you trying to say us with that?
This means, high-order pages were used up by EROFS which sets large folio by default. So, I wanted to say the concern was based on actual data which was what Mattew asked.
This isn't that though. What you actually need is to show that high order allocations are _failing_.
Exactly.
Quoted 2 lines
If what you want is large folios readily available, then what you want is large folios used _everywhere_ because then they're easy to get!
Yes.
Quoted 3 lines
If there's small folios in use, you need to reclaim a lot of memory in order to reassemble large folios (it's the birthday paradox, similar to the hash collision problem).
Quoted 6 lines
Yeah. Although it seems we have an issue with > order costly folios at the moment, but we should fix this.
And f2fs really needs to up the game and support large folios fully so that we can run that kind of analysis there as well, without this all this is just piling hacks on top of other hacks.
Ok, I'll revisit the large folio support in f2fs, and try to revisit the problem afterwards.
Thanks,
Quoted 6 lines
_______________________________________________
Linux-f2fs-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/linux-f2fs-devel
Quoted 7 lines · Matthew Wilcox
Quoted 6 lines · Theodore Tso
So let me get this straight. This is a magic xattr interface which is not even persisted in the file system, but instead sets a 32-bit bitmask in the struct inode which disappears once the inode gets flushed from the inode stack. And it uses a generic xattr name, "user.fadvise".
Quoted 8 lines
Quoted 3 lines
There's no way in *hell* any other file system is likely to adopt such a broken interface, so why didn't you just use an ioctl to set this magic f2fs-specific flag?
I mean, yes, this API is horrendous. But it's just another example of f2fs thinking it's somehow special and not just enabling large folios like other filesystems do. This hurts everyone, not just people who use f2fs.
Yes. And assuming we'd have a legit use to unconditionally use smaller folios for given files we'd really need to control it in the MM. Even if it ends up being a Android-only hack.
Jaegeuk Kim
maintainerQuoted 18 lines · Theodore Tso
Quoted 10 lines · Christoph Hellwig
Quoted 4 lines
You haven't sent a proposal. This is a reply to a reply to a reply of a patch. There's no justification for why f2fs is so special that it needs this. What the hell is going on? You know this is not the way to get code merged into Linux.
None of this got properly answers, and this broken interface now landed in linux-next. IT is offloading a user.* xattr which is free-form user data with semantics that are weird to say it very nicely.
All this was done against the advice in the mailing list discussion.
So let me get this straight. This is a magic xattr interface which is not even persisted in the file system, but instead sets a 32-bit bitmask in the struct inode which disappears once the inode gets flushed from the inode stack. And it uses a generic xattr name, "user.fadvise".
Quoted 3 lines
There's no way in *hell* any other file system is likely to adopt such a broken interface, so why didn't you just use an ioctl to set this magic f2fs-specific flag?
I went this route because Android heavily restricts ioctl() permissions and we needed broader access for this to work within the framework. It’s definitely a pragmatic choice just to get it running in production.
If ioctl() is a right way for upstream, I'm happy to change this patch. By the way, I really don't understand why all the messages are so offensive, even without trying to understand the problem or guiding right directions.
Quoted 9 lines
Quoted 3 lines
I think at some point we just need to stop taking f2fs updates likes this.
Well, that's ultiamtely up to Linus. I'll say that if I were Linus (and I'm glad I'm not :-), and I saw this in a pull request, I'd reject it out of hand. But whether it's worth making a huge fuss and asking escalating this mess to Linus, we probably should get a bit more community consensus before taking such a drastic step.
Could I also raise a quick concern regarding the phrasing/wording used in the communications?
Quoted 11 lines
Christian, since you're one of the VFS maintaienrs, what's your opinion about escalating this to Linus?
- Ted
_______________________________________________
Linux-f2fs-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/linux-f2fs-devel
Quoted 19 lines · Jaegeuk Kim
Quoted 18 lines · Theodore Tso
Quoted 10 lines · Christoph Hellwig
Quoted 4 lines
You haven't sent a proposal. This is a reply to a reply to a reply of a patch. There's no justification for why f2fs is so special that it needs this. What the hell is going on? You know this is not the way to get code merged into Linux.
None of this got properly answers, and this broken interface now landed in linux-next. IT is offloading a user.* xattr which is free-form user data with semantics that are weird to say it very nicely.
All this was done against the advice in the mailing list discussion.
So let me get this straight. This is a magic xattr interface which is not even persisted in the file system, but instead sets a 32-bit bitmask in the struct inode which disappears once the inode gets flushed from the inode stack. And it uses a generic xattr name, "user.fadvise".
Quoted 6 lines
Quoted 3 lines
There's no way in *hell* any other file system is likely to adopt such a broken interface, so why didn't you just use an ioctl to set this magic f2fs-specific flag?
I went this route because Android heavily restricts
ioctl()permissions and we needed broader access for this to work within the framework.
It's straightforward (2 lines I think) to update Android's SELinux policy to allow an ioctl in all domains. So that doesn't seem like a reason to not use an ioctl. In fact this is actually a reason *to* use an ioctl, as it shows that ioctls can be allowed/denied independently as needed, whereas xattrs just use the file write permission.
- Eric
Jaegeuk Kim
maintainerQuoted 24 lines · On 05/21, Eric Biggers via Linux-f2fs-devel wrote:
Quoted 23 lines · Jaegeuk Kim
Quoted 21 lines · Theodore Tso
Quoted 10 lines · Christoph Hellwig
Quoted 4 lines
You haven't sent a proposal. This is a reply to a reply to a reply of a patch. There's no justification for why f2fs is so special that it needs this. What the hell is going on? You know this is not the way to get code merged into Linux.
None of this got properly answers, and this broken interface now landed in linux-next. IT is offloading a user.* xattr which is free-form user data with semantics that are weird to say it very nicely.
All this was done against the advice in the mailing list discussion.
So let me get this straight. This is a magic xattr interface which is not even persisted in the file system, but instead sets a 32-bit bitmask in the struct inode which disappears once the inode gets flushed from the inode stack. And it uses a generic xattr name, "user.fadvise".
There's no way in *hell* any other file system is likely to adopt such a broken interface, so why didn't you just use an ioctl to set this magic f2fs-specific flag?
Quoted 8 lines
Quoted 2 lines
I went this route because Android heavily restricts
ioctl()permissions and we needed broader access for this to work within the framework.It's straightforward (2 lines I think) to update Android's SELinux policy to allow an ioctl in all domains. So that doesn't seem like a reason to not use an ioctl. In fact this is actually a reason *to* use an ioctl, as it shows that ioctls can be allowed/denied independently as needed, whereas xattrs just use the file write permission.
Ok, that's also great news to me.
Quoted 8 lines
- Eric
_______________________________________________
Linux-f2fs-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/linux-f2fs-devel
Christian Brauner
maintainerQuoted 24 lines · Eric Biggers
Quoted 23 lines · Jaegeuk Kim
Quoted 21 lines · Theodore Tso
Quoted 10 lines · Christoph Hellwig
Quoted 4 lines
You haven't sent a proposal. This is a reply to a reply to a reply of a patch. There's no justification for why f2fs is so special that it needs this. What the hell is going on? You know this is not the way to get code merged into Linux.
None of this got properly answers, and this broken interface now landed in linux-next. IT is offloading a user.* xattr which is free-form user data with semantics that are weird to say it very nicely.
All this was done against the advice in the mailing list discussion.
So let me get this straight. This is a magic xattr interface which is not even persisted in the file system, but instead sets a 32-bit bitmask in the struct inode which disappears once the inode gets flushed from the inode stack. And it uses a generic xattr name, "user.fadvise".
There's no way in *hell* any other file system is likely to adopt such a broken interface, so why didn't you just use an ioctl to set this magic f2fs-specific flag?
Quoted 8 lines
Quoted 2 lines
I went this route because Android heavily restricts
ioctl()permissions and we needed broader access for this to work within the framework.It's straightforward (2 lines I think) to update Android's SELinux policy to allow an ioctl in all domains. So that doesn't seem like a reason to not use an ioctl. In fact this is actually a reason *to* use an ioctl, as it shows that ioctls can be allowed/denied independently as needed, whereas xattrs just use the file write permission.
Thank you, I very much agree.
Quoted 7 lines · Jaegeuk Kim
I went this route because Android heavily restricts
ioctl()permissions and we needed broader access for this to work within the framework. It’s definitely a pragmatic choice just to get it running in production.If
ioctl()is a right way for upstream, I'm happy to change this patch. By the way, I really don't understand why all the messages are so offensive, even without trying to understand the problem or guiding right directions.
The reason why some people were getting annoyed was because as a Linux file system maintainer, there was an assumption that you would understand that extended attributes --- especially in the user.* namespace --- have an intended use case of storing a user-chosen small piece of metadata that would be stored in the file system.
Hijacking user.fadvise such that it no longer persistent stores an extended attribute for one specific file system --- such that if a hypothetical user application might decide to store a piece of application data in the extended attribute named "fadvise" would do something completely different on a single mainline file system is in such poor taste that I would have *hoped* that any Linux file system maintainer would know that this a Really Bad Thing, such that if someone in your development community suggested such an idea, you would reject it.
And then, when people complained that it was a bad idea, and you decided to put in the f2fs branch, such that it would show up in linux-next, and there was no way for other file system developers to object (short of appealing to Linus) --- well, that's basically you taking advantage of your file system maintainer privileges. And this is why I started proposing whether we needed to appeal this to Linus so he could make the call to reject something that the community had already told you was in terrible, terrible taste.
As far as trying to understand why you were doing this --- I have to turn that question around. Why didn't *you* explain why you needed to do this thing? I went through the e-mail history, and I couldn't find an explanation of why you decided to do this thing.
Perhaps we need to add an explanation the Documentation directory explaining what the intended use of the extended attribute case, and perhaps referencing past cases were people tried to use this to bypass the linux-api review process (f2fs's user.fadvise is not the first time someone has tried to do this) thing), so that automated review bots like Sashiko can explain why it's in such terrible taste to patch authors, perhaps we need to do this. Up until now, I think the assumption is that file system maintainers would know something this self-evident, and if not, if it was pointed out, they wouldn't try to force such an ill-advised interface to Linus.
- Ted
P.S. As an exmaple of how I hanlded a somewhat similar scenario in the past, my employer's cluster file system needed FALLOC_FL_NO_HIDE_STALE to save $$$$ in TCO storage costs. But the concern was this would be an attractive nuisance for enterprise distro users, who would see the massive performance increase, not realize that this would leak stale data, which could result in user PII being exposed, thus making life hard for Enterprise Linux's reputation. (This wasn't an issue at $WORK because we enrypt all data at rest, and the cluster file system daemon was a privileged server who (a) knew what it was doing, and (b) only it would have access to set FALLOC_FL_NO_HIDE_STALE.)
I disclosed *why* $WORK needed such a thing (it made a huge difference to storage TCO costss for Google's Cluster Filesystem), and after discussion and negotiation, we came to a compromise which involved my keeping the (very small) patch out of tree, but reserving the code point upstream to avoid future bitfield collisions. They key here was that I *knew* it was controversial, and I understood what problems it might cause in the rest of the ecosystem. That's part of the job of a maintainer, and it's also why a company might want to hire a maintainer. They can represent the needs of multiple stakeholders --- the upstream community, upstream users and the greater Linux ecosystem, as well as their employer.
Jaegeuk Kim
maintainerQuoted 15 lines · Theodore Tso
Quoted 7 lines · Jaegeuk Kim
I went this route because Android heavily restricts
ioctl()permissions and we needed broader access for this to work within the framework. It’s definitely a pragmatic choice just to get it running in production.If
ioctl()is a right way for upstream, I'm happy to change this patch. By the way, I really don't understand why all the messages are so offensive, even without trying to understand the problem or guiding right directions.The reason why some people were getting annoyed was because as a Linux file system maintainer, there was an assumption that you would understand that extended attributes --- especially in the user.* namespace --- have an intended use case of storing a user-chosen small piece of metadata that would be stored in the file system.
Quoted 9 lines
Hijacking user.fadvise such that it no longer persistent stores an extended attribute for one specific file system --- such that if a hypothetical user application might decide to store a piece of application data in the extended attribute named "fadvise" would do something completely different on a single mainline file system is in such poor taste that I would have *hoped* that any Linux file system maintainer would know that this a Really Bad Thing, such that if someone in your development community suggested such an idea, you would reject it.
Thank you for the explanation. It seems I made a wrong assumption on the usage of "user." prefix where each filesystem can support in different ways.
Quoted 9 lines
And then, when people complained that it was a bad idea, and you decided to put in the f2fs branch, such that it would show up in linux-next, and there was no way for other file system developers to object (short of appealing to Linus) --- well, that's basically you taking advantage of your file system maintainer privileges. And this is why I started proposing whether we needed to appeal this to Linus so he could make the call to reject something that the community had already told you was in terrible, terrible taste.
To be fair, I hadn't queued it in linux-next for weeks since the first post, and was waiting for more feedbacks. If I was able to hear "user." is a generic prefix used for all filesystems and use ioctl from the beginning, I'd just drop and be able to start arguing with security folks back. Since my employer is funding for production mainly, not much upstream work, I couldn't sit and wait for the response for months. :(
Quoted 5 lines
As far as trying to understand why you were doing this --- I have to turn that question around. Why didn't *you* explain why you needed to do this thing? I went through the e-mail history, and I couldn't find an explanation of why you decided to do this thing.
I shared some motivation when replying to Darrick's feedback [1], but yes, it was not enough for all heads-up. The problem started that some speicific application needs as many high-order pages as possible mostly for reads. So, I thought we can turn on large folio on the specific files per hints. One way for the hints was using immutable bit, but it turned out it's very hard to manage disabling the bit whenever deleting the files. Along with limited ioctl() and requiring inode eviction to manage large folio activation, I had to implement this path.
[1] https://lore.kernel.org/lkml/[email protected]/
Quoted 11 lines
Perhaps we need to add an explanation the Documentation directory explaining what the intended use of the extended attribute case, and perhaps referencing past cases were people tried to use this to bypass the linux-api review process (f2fs's user.fadvise is not the first time someone has tried to do this) thing), so that automated review bots like Sashiko can explain why it's in such terrible taste to patch authors, perhaps we need to do this. Up until now, I think the assumption is that file system maintainers would know something this self-evident, and if not, if it was pointed out, they wouldn't try to force such an ill-advised interface to Linus.
I believe this helps a lot to all newbies like me.
I really appreciate your feedback.
Quoted 32 lines
- Ted
P.S. As an exmaple of how I hanlded a somewhat similar scenario in the past, my employer's cluster file system neededFALLOC_FL_NO_HIDE_STALEto save $$$$ in TCO storage costs. But the concern was this would be an attractive nuisance for enterprise distro users, who would see the massive performance increase, not realize that this would leak stale data, which could result in user PII being exposed, thus making life hard for Enterprise Linux's reputation. (This wasn't an issue at $WORK because we enrypt all data at rest, and the cluster file system daemon was a privileged server who (a) knew what it was doing, and (b) only it would have access to setFALLOC_FL_NO_HIDE_STALE.)I disclosed *why* $WORK needed such a thing (it made a huge difference to storage TCO costss for Google's Cluster Filesystem), and after discussion and negotiation, we came to a compromise which involved my keeping the (very small) patch out of tree, but reserving the code point upstream to avoid future bitfield collisions. They key here was that I *knew* it was controversial, and I understood what problems it might cause in the rest of the ecosystem. That's part of the job of a maintainer, and it's also why a company might want to hire a maintainer. They can represent the needs of multiple stakeholders --- the upstream community, upstream users and the greater Linux ecosystem, as well as their employer.
_______________________________________________
Linux-f2fs-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/linux-f2fs-devel
Quoted 4 lines · Jaegeuk Kim
Thank you for the explanation. It seems I made a wrong assumption on the usage of "user." prefix where each filesystem can support in different ways.
The "user." prefix is used by all userspace applications that wish to store extended attributes. For example, user.mime_type, user.xdg.origin_url, user.charset, user.appache_handler, etc
For more information, see:
https://www.freedesktop.org/wiki/CommonExtendedAttribute
https://wiki.archlinux.org/title/Extended_attributes
I certainly assumed this was common knowledge across all file system maintainers, but this was apparently not true in your case. I don't know how this could be the case given that f2fs implements extended attributes, and I would have thought you would have known that when testing that feature.
Quoted 10 lines
I shared some motivation when replying to Darrick's feedback [1], but yes, it was not enough for all heads-up. The problem started that some speicific application needs as many high-order pages as possible mostly for reads. So, I thought we can turn on large folio on the specific files per hints. One way for the hints was using immutable bit, but it turned out it's very hard to manage disabling the bit whenever deleting the files. Along with limited
ioctl()and requiring inode eviction to manage large folio activation, I had to implement this path.
Actually, you still haven't explained your use case, at least, not well enough for me to understand what you are trying to do.
So an application wants a particular file to use as many high-order pages as possible. Why? What sort of guarantees do you need to provide? What happens if they can't be provided? What happens if a possibly malicious, or at least gready, application uses this interface to grab a lot of high-order pages?
From your patch:
1. setxattr(file, "user.fadvise", &value, sizeof(unsigned int), 0) -> register the inode number for large folio
2. chmod(0400, file)
-> make Read-Only
3. open()
-> f2fs_iget() with large folio
4. open(WRITE), mkwrite on mmap, chmod(WRITE)
-> return error
5. iput() and open()
-> goto #3
6. unlink
-> deregister the inode number
Why should making the file read-only matter? And when you say "derigster the inode number", why should this be related to deleting the inode?
This is an interface which seems to be very specific to your use case. What if those requirements change over time? What if you want pull in a file without making it be read-only? And what if you want to release the large-order pages without deleting the file?
- Ted
Jaegeuk Kim
maintainerQuoted 56 lines · Theodore Tso
Quoted 4 lines · Jaegeuk Kim
Thank you for the explanation. It seems I made a wrong assumption on the usage of "user." prefix where each filesystem can support in different ways.
The "user." prefix is used by all userspace applications that wish to store extended attributes. For example, user.mime_type, user.xdg.origin_url, user.charset, user.appache_handler, etc
For more information, see:
https://www.freedesktop.org/wiki/CommonExtendedAttribute
https://wiki.archlinux.org/title/Extended_attributesI certainly assumed this was common knowledge across all file system maintainers, but this was apparently not true in your case. I don't know how this could be the case given that f2fs implements extended attributes, and I would have thought you would have known that when testing that feature.
Quoted 10 lines
I shared some motivation when replying to Darrick's feedback [1], but yes, it was not enough for all heads-up. The problem started that some speicific application needs as many high-order pages as possible mostly for reads. So, I thought we can turn on large folio on the specific files per hints. One way for the hints was using immutable bit, but it turned out it's very hard to manage disabling the bit whenever deleting the files. Along with limited
ioctl()and requiring inode eviction to manage large folio activation, I had to implement this path.Actually, you still haven't explained your use case, at least, not well enough for me to understand what you are trying to do.
So an application wants a particular file to use as many high-order pages as possible. Why? What sort of guarantees do you need to provide? What happens if they can't be provided? What happens if a possibly malicious, or at least gready, application uses this interface to grab a lot of high-order pages?
Quoted 1 line
From your patch:
1.
setxattr(file, "user.fadvise", &value, sizeof(unsigned int), 0)-> register the inode number for large folio
2.chmod(0400, file)
-> make Read-Only
3.open()
->f2fs_iget()with large folio
4. open(WRITE), mkwrite on mmap, chmod(WRITE)
-> return error
5.iput()andopen()
-> goto #3
6. unlink
-> deregister the inode number
Quoted 8 lines
Why should making the file read-only matter? And when you say "derigster the inode number", why should this be related to deleting the inode?
This is an interface which seems to be very specific to your use case. What if those requirements change over time? What if you want pull in a file without making it be read-only? And what if you want to release the large-order pages without deleting the file?
Let me try to write more details, helped with Gemini.
Background
----------
The primary use case is accelerating AI model loading, which demands exceptionally high sequential read speeds. In our benchmarks on embedded systems:
- Using high-order page allocations allows the system to saturate the Universal Flash Storage (UFS) bandwidth, reaching 4 GB/s even at medium-to-low CPU frequencies.
- In contrast, standard small folios cap performance at 2 GB/s.
The performance doubling stems directly from reducing CPU cycle overhead during memory allocation.
Problem Statement
-----------------
High-order pages become heavily fragmented and scarce shortly after device boot. We cannot afford to deplete these limited resources on default filesystem operations using large folios. Instead, we need a mechanism to strictly prioritize and reserve high-order allocations for specific, critical payloads—specifically, large AI model files.
Design Principles
-----------------
- Best-Effort Allocation: The system guarantees no fixed number of high-order pages. Allocation falls back gracefully from Order-10 down to Order-0 based on current memory availability.
- Standard Page Cache Lifecycle: No custom or rigid memory management is introduced. These folios remain fully under the control of the Memory Management (MM) subsystem and can be reclaimed via the Least Recently Used (LRU) mechanism at any time.
- Read-Only Optimization: To minimize code complexity (e.g., handling writeback, compression, and concurrency), this high-order allocation mechanism is strictly restricted to read-only files. The vast majority of performance gains are derived from read operations.
Questions
---------
Q: Why does an application require a specific file to utilize as many high-order pages as possible?
A: It significantly boosts sequential read bandwidth in resource-constrained
embedded systems by reducing the CPU overhead associated with page allocation during high-throughput I/O.
Q: What sort of guarantees does this mechanism need to provide?
A: No hard guarantees are provided. The filesystem provides a best-effort
mechanism to attempt high-order page allocations for flagged inodes while the filesystem is mounted.
Q: What is the fallback behavior if high-order pages cannot be allocated?
A: The system treats the configuration as a performance hint. If high-order
pages are unavailable, it seamlessly falls back to standard small folios. Functional behavior remains entirely unchanged.
Q: Why is restricting the implementation to read-only files necessary?
A: Limiting the scope to read-only files bypasses the architectural complexities
of managing writes, dirtying pages, and compression in large folios, while still capturing the core performance benefits of high-speed sequential reads.
Q: What mitigations prevent a malicious or greedy application from abusing this
interface to monopolize high-order pages?
A: The interface acts purely as a hint to the allocation path. Because it falls
back to small folios when memory is tight, it poses no greater systemic risk than existing large-folio implementations used by other filesystems. Standard MM eviction and LRU paths remain fully active.
Q: Why is deregistering the inode number linked to inode deletion?
A: We need the high-order allocation hint to persist even if the inode is
temporarily evicted from the VFS cache. To achieve this, we maintain a tracking list of hinted inode numbers. When a file is permanently deleted, its hint becomes obsolete, requiring us to deregister it from the list to prevent memory leaks or identifier reuse conflicts.
Q: How can an application release these large-order pages without deleting the
file?
A: Pages allocated via this mechanism receive no special status in the page
cache. They are managed by standard LRU logic and can be explicitly released by the user at any time using existing system calls, such as posix_fadvise(..., POSIX_FADV_DONTNEED).
Q: This interface seems highly tailored to a specific use case. What happens if
these requirements evolve over time?
A: Massive AI model loading is a long-term architectural paradigm. Providing a
targeted VFS/filesystem hint to optimize read bandwidth for specific large datasets is a highly practical, repeatable pattern that addresses a systemic bottleneck in embedded AI deployments.
Quoted 2 lines
- Ted
Quoted 1 line · Jaegeuk Kim
Let me try to write more details, helped with Gemini.
This is garbage, and frankly disrespectful. I'm not going to argue with your AI bot.
Jaegeuk Kim
maintainerQuoted 5 lines · Matthew Wilcox
Quoted 1 line · Jaegeuk Kim
Let me try to write more details, helped with Gemini.
This is garbage, and frankly disrespectful. I'm not going to argue with your AI bot.
I wrote down all and they rephrased it a bit. Which points are you feeling like that?
Quoted 6 lines
_______________________________________________
Linux-f2fs-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/linux-f2fs-devel
Randy Dunlap
reviewerQuoted 61 lines · Jaegeuk Kim
Quoted 60 lines · Theodore Tso
Quoted 4 lines · Jaegeuk Kim
Thank you for the explanation. It seems I made a wrong assumption on the usage of "user." prefix where each filesystem can support in different ways.
The "user." prefix is used by all userspace applications that wish to store extended attributes. For example, user.mime_type, user.xdg.origin_url, user.charset, user.appache_handler, etc
For more information, see:
https://www.freedesktop.org/wiki/CommonExtendedAttribute
https://wiki.archlinux.org/title/Extended_attributesI certainly assumed this was common knowledge across all file system maintainers, but this was apparently not true in your case. I don't know how this could be the case given that f2fs implements extended attributes, and I would have thought you would have known that when testing that feature.
Quoted 10 lines
I shared some motivation when replying to Darrick's feedback [1], but yes, it was not enough for all heads-up. The problem started that some speicific application needs as many high-order pages as possible mostly for reads. So, I thought we can turn on large folio on the specific files per hints. One way for the hints was using immutable bit, but it turned out it's very hard to manage disabling the bit whenever deleting the files. Along with limited
ioctl()and requiring inode eviction to manage large folio activation, I had to implement this path.Actually, you still haven't explained your use case, at least, not well enough for me to understand what you are trying to do.
So an application wants a particular file to use as many high-order pages as possible. Why? What sort of guarantees do you need to provide? What happens if they can't be provided? What happens if a possibly malicious, or at least gready, application uses this interface to grab a lot of high-order pages?
Quoted 1 line
From your patch:
1.
setxattr(file, "user.fadvise", &value, sizeof(unsigned int), 0)-> register the inode number for large folio
2.chmod(0400, file)
-> make Read-Only
3.open()
->f2fs_iget()with large folio
4. open(WRITE), mkwrite on mmap, chmod(WRITE)
-> return error
5.iput()andopen()
-> goto #3
6. unlink
-> deregister the inode numberWhy should making the file read-only matter? And when you say "derigster the inode number", why should this be related to deleting the inode?
Quoted 6 lines
Quoted 4 lines
This is an interface which seems to be very specific to your use case. What if those requirements change over time? What if you want pull in a file without making it be read-only? And what if you want to release the large-order pages without deleting the file?
Let me try to write more details, helped with Gemini.
[as an interested reader:]
If this idea is so good, why shouldn't it be done in the VFS/MM so that other filesystems could do the same thing instead of just in f2fs?
Signature · 1 line
~Randy
Jaegeuk Kim
maintainerQuoted 69 lines · Randy Dunlap
Quoted 66 lines · Jaegeuk Kim
Quoted 64 lines · Theodore Tso
Quoted 4 lines · Jaegeuk Kim
Thank you for the explanation. It seems I made a wrong assumption on the usage of "user." prefix where each filesystem can support in different ways.
The "user." prefix is used by all userspace applications that wish to store extended attributes. For example, user.mime_type, user.xdg.origin_url, user.charset, user.appache_handler, etc
For more information, see:
https://www.freedesktop.org/wiki/CommonExtendedAttribute
https://wiki.archlinux.org/title/Extended_attributesI certainly assumed this was common knowledge across all file system maintainers, but this was apparently not true in your case. I don't know how this could be the case given that f2fs implements extended attributes, and I would have thought you would have known that when testing that feature.
Quoted 10 lines
I shared some motivation when replying to Darrick's feedback [1], but yes, it was not enough for all heads-up. The problem started that some speicific application needs as many high-order pages as possible mostly for reads. So, I thought we can turn on large folio on the specific files per hints. One way for the hints was using immutable bit, but it turned out it's very hard to manage disabling the bit whenever deleting the files. Along with limited
ioctl()and requiring inode eviction to manage large folio activation, I had to implement this path.Actually, you still haven't explained your use case, at least, not well enough for me to understand what you are trying to do.
So an application wants a particular file to use as many high-order pages as possible. Why? What sort of guarantees do you need to provide? What happens if they can't be provided? What happens if a possibly malicious, or at least gready, application uses this interface to grab a lot of high-order pages?
Quoted 1 line
From your patch:
1.
setxattr(file, "user.fadvise", &value, sizeof(unsigned int), 0)-> register the inode number for large folio
2.chmod(0400, file)
-> make Read-Only
3.open()
->f2fs_iget()with large folio
4. open(WRITE), mkwrite on mmap, chmod(WRITE)
-> return error
5.iput()andopen()
-> goto #3
6. unlink
-> deregister the inode numberWhy should making the file read-only matter? And when you say "derigster the inode number", why should this be related to deleting the inode?
This is an interface which seems to be very specific to your use case. What if those requirements change over time? What if you want pull in a file without making it be read-only? And what if you want to release the large-order pages without deleting the file?
Quoted 6 lines
Quoted 1 line
Let me try to write more details, helped with Gemini.
[as an interested reader:]
If this idea is so good, why shouldn't it be done in the VFS/MM so that other filesystems could do the same thing instead of just in f2fs?
Thanks for the feedback. I'm really open, but just trying to understand it's good or not. If it's so bad at all, I'd be really ready to drop it even the ioctl approach, even though I already prepared its implementation.
Quoted 5 lines
Signature · 2 lines
-- ~Randy
Quoted 9 lines · Jaegeuk Kim
Background
----------
The primary use case is accelerating AI model loading, which demands exceptionally high sequential read speeds. In our benchmarks on embedded systems:
- Using high-order page allocations allows the system to saturate the Universal Flash Storage (UFS) bandwidth, reaching 4 GB/s even at medium-to-low CPU frequencies.
- In contrast, standard small folios cap performance at 2 GB/s.
So you're interested in optimizing the I/O speeds. And apparenty, on your hardware, the UFS controller has limits on scatter-gather entries --- UFS seems to call this Physical Region Description (PRD) table entries. Per Gemini:
1. PRD Segment & Length Limits
Maximum PRD Entries: Hardware limits typically cap the number
of PRD entries (or segments) to 255 or 256 per transfer request.
Maximum Transfer Length: Each individual PRD entry typically
allows a maximum transfer size of (65,535 bytes) per segment.
2. Host Controller Hardware Limits (UFSHCI)
Transfer Queue Depth: A UFS controller supports a predefined
number of outstanding task request entries. This is often hard-capped at 32 concurrent transfer requests (slots) by the doorbell register array.
Descriptor Pre-fetch: Some UFS host controllers are
pre-configured to pre-fetch multiple PRD entries sequentially before requiring main memory reads.
Is this an accurate description of the limits that you are trying to work with? How much data are you trying to read? Looking at Gemma 4 models, E2B is about 10GB or 3GB for the 4-bit quantized version. E4B is 15GB, or 5GB for the 4-bit quantized version. Is that about right?
It seems... surprising that the additional I/O operations are actually throttloing UFS device bandwidth by 2x (4GB/s vs 2GB/s). Have you dug into why this is happening, and whether there is anything that can be optimized below the file system?
Quoted 7 lines
Problem Statement
-----------------
High-order pages become heavily fragmented and scarce shortly after device boot. We cannot afford to deplete these limited resources on default filesystem operations using large folios. Instead, we need a mechanism to strictly prioritize and reserve high-order allocations for specific, critical payloads—specifically, large AI model files.
There's a fundamental assumption here, which is that the only use of high order pages is the page cache. This doesn't take into account anonymous pages used by programs that isn't backed by files. Nor does it take into account kernel memory allocations.
But that being said, you seem to be assuming that you can reduce the pressure on high order pages by only using large folios for these AI model files.
But the problem with using small folios is that if you want to actually *use* the memory, unless you want to segment out the memory so it can't be used for anything other than the AI models (e.g., by using somthing like hugetlbfs) it's just going to break up the memory into smaller folios. So that's not actually going to *help* in actual real life use cases. It might help for your artificial benchmarks / experiments, but in the real life case where Android applications are running and fragmenting all of the device memory, the large folios won't be available *anyway*.
Quoted 7 lines
Q: Why is deregistering the inode number linked to inode deletion?
A: We need the high-order allocation hint to persist even if the inode is
temporarily evicted from the VFS cache. To achieve this, we maintain a tracking list of hinted inode numbers. When a file is permanently deleted, its hint becomes obsolete, requiring us to deregister it from the list to prevent memory leaks or identifier reuse conflicts.
Assuming that the high-order allocation hint is a good thing, why not just make it persistent? e.g., just a *real* extended attribute (which is more wateful of space), or grab a flag in the on-disk f2fs inode? Then you don't need to have an in-memory list of hinted inodes; instead, you can just have the Android package manager set that flag indicating that you want that special treatment. This is all assuming that we need an explicit hint, though....
Quoted 5 lines
Massive AI model loading is a long-term architectural paradigm. Providing a targeted VFS/filesystem hint to optimize read bandwidth for specific large datasets is a highly practical, repeatable pattern that addresses a systemic bottleneck in embedded AI deployments.
It's really too bad you didn't propose this as a LSF/MM topic, and presented this at a session at Zagreb two weeks ago. That would have been a much more upstream-friendly way of collaborating, and it might have allowed the mm experts to give you some more dynamic, real-time feedback.
Cheers,
- Ted
Quoted 4 lines · Theodore Tso
It seems... surprising that the additional I/O operations are actually throttloing UFS device bandwidth by 2x (4GB/s vs 2GB/s). Have you dug into why this is happening, and whether there is anything that can be optimized below the file system?
The layers below the filesystem (block, SCSI, UFS) is what I'm responsible for in the Pixel team and I can assure you that these are highly optimized.
Since the transfer size used in Jaegeuk's tests is much larger than 4 KiB, how many CPU cycles are used per IO by the layers below the filesystem is not limiting the transfer bandwidth.
Bart.
Quoted 5 lines · Bart Van Assche
Quoted 4 lines · Theodore Tso
It seems... surprising that the additional I/O operations are actually throttloing UFS device bandwidth by 2x (4GB/s vs 2GB/s). Have you dug into why this is happening, and whether there is anything that can be optimized below the file system?
Quoted 7 lines
The layers below the filesystem (block, SCSI, UFS) is what I'm responsible for in the Pixel team and I can assure you that these are highly optimized.
Since the transfer size used in Jaegeuk's tests is much larger than 4 KiB, how many CPU cycles are used per IO by the layers below the filesystem is not limiting the transfer bandwidth.
I'm honestly not sure what discussion we have here. Larger I/O is pretty much always more efficient. If you submit smaller I/O you need more merging to build it back up larger, and more I/Os.
Which is exaxtly why we need large folio support everywhere, as it makes a huge difference in I/O performance.
Jaegeuk Kim
maintainerQuoted 10 lines · Christoph Hellwig
Quoted 9 lines · Bart Van Assche
Quoted 4 lines · Theodore Tso
It seems... surprising that the additional I/O operations are actually throttloing UFS device bandwidth by 2x (4GB/s vs 2GB/s). Have you dug into why this is happening, and whether there is anything that can be optimized below the file system?
The layers below the filesystem (block, SCSI, UFS) is what I'm responsible for in the Pixel team and I can assure you that these are highly optimized.
Quoted 7 lines
Quoted 3 lines
Since the transfer size used in Jaegeuk's tests is much larger than 4 KiB, how many CPU cycles are used per IO by the layers below the filesystem is not limiting the transfer bandwidth.
I'm honestly not sure what discussion we have here. Larger I/O is pretty much always more efficient. If you submit smaller I/O you need more merging to build it back up larger, and more I/Os.
F2FS merges bios before submit_bio, regardless of small or large folios, since the block addresses are consecutive. So, I think IO subsystem was working in full speed.
Quoted 10 lines
Which is exaxtly why we need large folio support everywhere, as it makes a huge difference in I/O performance.
_______________________________________________
Linux-f2fs-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/linux-f2fs-devel
Quoted 3 lines · Jaegeuk Kim
F2FS merges bios before
submit_bio, regardless of small or large folios, since the block addresses are consecutive. So, I think IO subsystem was working in full speed.
As does every other remotely modern file system. But that merging is surprisingly expensive, which is why using folios gets really major performance improvements.
For one doing these checks to merge touch quite a few cache lines. Second, devices are often a lot more efficient if they see fewer SGL entries. I.e. having a 1MB bio a single SGL tends to work better than having 256 of them.
The same is true in the kernel code itself, both in the submission path (dma mapping and co), and even more so in the page cache handling both before submitting and in the completion path.
See Bart's patch about how long the walk of the bio_vecs in the f2fs completion path can take. We had similar issues in XFS even in the workqueue completion path due to lack of rescheduling, and these simply go away when you do the folio manipulation in larger chunks (LAZY_PREEMPT would avoid the need to explicit rescheduling these days, but that just papers over the symptoms in this case).
Jaegeuk Kim
maintainerQuoted 17 lines · Christoph Hellwig
Quoted 3 lines · Jaegeuk Kim
F2FS merges bios before
submit_bio, regardless of small or large folios, since the block addresses are consecutive. So, I think IO subsystem was working in full speed.As does every other remotely modern file system. But that merging is surprisingly expensive, which is why using folios gets really major performance improvements.
For one doing these checks to merge touch quite a few cache lines. Second, devices are often a lot more efficient if they see fewer SGL entries. I.e. having a 1MB bio a single SGL tends to work better than having 256 of them.
The same is true in the kernel code itself, both in the submission path (dma mapping and co), and even more so in the page cache handling both before submitting and in the completion path.
Quoted 7 lines
See Bart's patch about how long the walk of the
bio_vecsin the f2fs completion path can take. We had similar issues in XFS even in the workqueue completion path due to lack of rescheduling, and these simply go away when you do the folio manipulation in larger chunks (LAZY_PREEMPTwould avoid the need to explicit rescheduling these days, but that just papers over the symptoms in this case).
I see. That's also super helpful. Let me kick off the large folio support asap. Thanks.
Quoted 27 lines · Jaegeuk Kim
Quoted 17 lines · Christoph Hellwig
Quoted 3 lines · Jaegeuk Kim
F2FS merges bios before
submit_bio, regardless of small or large folios, since the block addresses are consecutive. So, I think IO subsystem was working in full speed.As does every other remotely modern file system. But that merging is surprisingly expensive, which is why using folios gets really major performance improvements.
For one doing these checks to merge touch quite a few cache lines. Second, devices are often a lot more efficient if they see fewer SGL entries. I.e. having a 1MB bio a single SGL tends to work better than having 256 of them.
The same is true in the kernel code itself, both in the submission path (dma mapping and co), and even more so in the page cache handling both before submitting and in the completion path.Quoted 7 lines
See Bart's patch about how long the walk of the
bio_vecsin the f2fs completion path can take. We had similar issues in XFS even in the workqueue completion path due to lack of rescheduling, and these simply go away when you do the folio manipulation in larger chunks (LAZY_PREEMPTwould avoid the need to explicit rescheduling these days, but that just papers over the symptoms in this case).
Quoted 2 lines
I see. That's also super helpful. Let me kick off the large folio support asap. Thanks.
Hi Jaegeuk,
Nanzhe has put significant effort into this work at Xiaomi over the past several months. Large folios can now be supported on non-immutable files.
He has conducted extensive testing on the Pixel 6 and fixed a number of hangs discovered during development. He is still benchmarking performance, but the implementation appears to be reasonably stable at this point. We can run Android Monkey for many hours without observing any hangs.
If you would like to see an RFC, I can ask Nanzhe to send one as soon as possible after some cleanup and polishing.
Best regards,
Barry
Jaegeuk Kim
maintainerQuoted 28 lines · On 05/31, Barry Song via Linux-f2fs-devel wrote:
Quoted 27 lines · Jaegeuk Kim
Quoted 24 lines · Christoph Hellwig
Quoted 3 lines · Jaegeuk Kim
F2FS merges bios before
submit_bio, regardless of small or large folios, since the block addresses are consecutive. So, I think IO subsystem was working in full speed.As does every other remotely modern file system. But that merging is surprisingly expensive, which is why using folios gets really major performance improvements.
For one doing these checks to merge touch quite a few cache lines. Second, devices are often a lot more efficient if they see fewer SGL entries. I.e. having a 1MB bio a single SGL tends to work better than having 256 of them.
The same is true in the kernel code itself, both in the submission path (dma mapping and co), and even more so in the page cache handling both before submitting and in the completion path.See Bart's patch about how long the walk of the
bio_vecsin the f2fs completion path can take. We had similar issues in XFS even in the workqueue completion path due to lack of rescheduling, and these simply go away when you do the folio manipulation in larger chunks (LAZY_PREEMPTwould avoid the need to explicit rescheduling these days, but that just papers over the symptoms in this case).
Quoted 4 lines
Quoted 2 lines
I see. That's also super helpful. Let me kick off the large folio support asap. Thanks.
Hi Jaegeuk,
Hi Barry,
Quoted 5 lines
Nanzhe has put significant effort into this work at Xiaomi over the past several months. Large folios can now be supported on non-immutable files.
Quoted 8 lines
He has conducted extensive testing on the Pixel 6 and fixed a number of hangs discovered during development. He is still benchmarking performance, but the implementation appears to be reasonably stable at this point. We can run Android Monkey for many hours without observing any hangs.
If you would like to see an RFC, I can ask Nanzhe to send one as soon as possible after some cleanup and polishing.
Yeah, I was about to reach out to you. Let's do some discussion offline.
Thanks,
Quoted 9 lines
Best regards,
Barry_______________________________________________
Linux-f2fs-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/linux-f2fs-devel
Jaegeuk Kim
maintainerQuoted 41 lines · Theodore Tso
Quoted 9 lines · Jaegeuk Kim
Background
----------
The primary use case is accelerating AI model loading, which demands exceptionally high sequential read speeds. In our benchmarks on embedded systems:
- Using high-order page allocations allows the system to saturate the Universal Flash Storage (UFS) bandwidth, reaching 4 GB/s even at medium-to-low CPU frequencies.
- In contrast, standard small folios cap performance at 2 GB/s.So you're interested in optimizing the I/O speeds. And apparenty, on your hardware, the UFS controller has limits on scatter-gather entries --- UFS seems to call this Physical Region Description (PRD) table entries. Per Gemini:
1. PRD Segment & Length Limits
Maximum PRD Entries: Hardware limits typically cap the number
of PRD entries (or segments) to 255 or 256 per transfer request.Maximum Transfer Length: Each individual PRD entry typically
allows a maximum transfer size of (65,535 bytes) per segment.2. Host Controller Hardware Limits (UFSHCI)
Transfer Queue Depth: A UFS controller supports a predefined
number of outstanding task request entries. This is often hard-capped at 32 concurrent transfer requests (slots) by the doorbell register array.Descriptor Pre-fetch: Some UFS host controllers are
pre-configured to pre-fetch multiple PRD entries sequentially before requiring main memory reads.Is this an accurate description of the limits that you are trying to work with? How much data are you trying to read? Looking at Gemma 4 models, E2B is about 10GB or 3GB for the 4-bit quantized version. E4B is 15GB, or 5GB for the 4-bit quantized version. Is that about right?
Quoted 4 lines
It seems... surprising that the additional I/O operations are actually throttloing UFS device bandwidth by 2x (4GB/s vs 2GB/s). Have you dug into why this is happening, and whether there is anything that can be optimized below the file system?
I can't tell the exact size tho, roughly it's between 1GB and 4GB. And, per lots of test results with various tunings, it turned out memory allocation speed was the culprit. If we use 4KB page, we couldn't get the full bandwidth unless we set the biggest core running the highest frequency. Unfortunately, however, we can't use the core like that due to performance drop of other system service and power drain.
Quoted 18 lines
Quoted 8 lines
Problem Statement
-----------------
High-order pages become heavily fragmented and scarce shortly after device boot. We cannot afford to deplete these limited resources on default filesystem operations using large folios. Instead, we need a mechanism to strictly prioritize and reserve high-order allocations for specific, critical payloads—specifically, large AI model files.There's a fundamental assumption here, which is that the only use of high order pages is the page cache. This doesn't take into account anonymous pages used by programs that isn't backed by files. Nor does it take into account kernel memory allocations.
But that being said, you seem to be assuming that you can reduce the pressure on high order pages by only using large folios for these AI model files.
Quoted 9 lines
But the problem with using small folios is that if you want to actually *use* the memory, unless you want to segment out the memory so it can't be used for anything other than the AI models (e.g., by using somthing like hugetlbfs) it's just going to break up the memory into smaller folios. So that's not actually going to *help* in actual real life use cases. It might help for your artificial benchmarks / experiments, but in the real life case where Android applications are running and fragmenting all of the device memory, the large folios won't be available *anyway*.
Agreed it's hard to get this done perfectly tho, as the best effort on this particular AI model case, I focused on two timings when loading the models:
1) right after device boot, 2) dynamic loading when required. To secure high order pages, for 1), I disabled the large folio consumed by EROFS, while for 2), I tried to call compact_memory before loading the model. Both of cases, I could observe we could get fair amount of large folios. Yes, not 100% tho.
Quoted 9 lines
Quoted 8 lines
Q: Why is deregistering the inode number linked to inode deletion?
A: We need the high-order allocation hint to persist even if the inode is
temporarily evicted from the VFS cache. To achieve this, we maintain a tracking list of hinted inode numbers. When a file is permanently deleted, its hint becomes obsolete, requiring us to deregister it from the list to prevent memory leaks or identifier reuse conflicts.
Quoted 7 lines
Assuming that the high-order allocation hint is a good thing, why not just make it persistent? e.g., just a *real* extended attribute (which is more wateful of space), or grab a flag in the on-disk f2fs inode? Then you don't need to have an in-memory list of hinted inodes; instead, you can just have the Android package manager set that flag indicating that you want that special treatment. This is all assuming that we need an explicit hint, though....
I think that's doable, yes, if the explict hint is acceptable.
Quoted 7 lines
Quoted 6 lines
Massive AI model loading is a long-term architectural paradigm. Providing a targeted VFS/filesystem hint to optimize read bandwidth for specific large datasets is a highly practical, repeatable pattern that addresses a systemic bottleneck in embedded AI deployments.
Quoted 5 lines
It's really too bad you didn't propose this as a LSF/MM topic, and presented this at a session at Zagreb two weeks ago. That would have been a much more upstream-friendly way of collaborating, and it might have allowed the mm experts to give you some more dynamic, real-time feedback.
Indeed, I was off from LSF/MM for years due to various product issues, not related F2FS tho. Let me make some effort to attend upcoming ones like LPC, if I can get the budget from company.
Quoted 10 lines
Cheers,
- Ted
_______________________________________________
Linux-f2fs-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/linux-f2fs-devel
Quoted 10 lines · Jaegeuk Kim
Quoted 4 lines
It seems... surprising that the additional I/O operations are actually throttloing UFS device bandwidth by 2x (4GB/s vs 2GB/s). Have you dug into why this is happening, and whether there is anything that can be optimized below the file system?
I can't tell the exact size tho, roughly it's between 1GB and 4GB. And, per lots of test results with various tunings, it turned out memory allocation speed was the culprit. If we use 4KB page, we couldn't get the full bandwidth unless we set the biggest core running the highest frequency.
OK, if we assume that the model file that you want to load is is 2GB then the number of 4k pages that you need is a bit over half a million (524288). So if it take 1 second with large folios (2 GB/s as you stated above), and half-second without (4 GB/s), then you're basically saying that it was costing you half-second to allocate 524288 singleton pages. And the whole point of this exercise is to save that half second?
And I assume that these timing was using a performance cores, and part of the goal here is to be able to use an efficiency core instead.
Did I get that right?
Quoted 10 lines
Quoted 9 lines
But the problem with using small folios is that if you want to actually *use* the memory, unless you want to segment out the memory so it can't be used for anything other than the AI models (e.g., by using somthing like hugetlbfs) it's just going to break up the memory into smaller folios. So that's not actually going to *help* in actual real life use cases. It might help for your artificial benchmarks / experiments, but in the real life case where Android applications are running and fragmenting all of the device memory, the large folios won't be available *anyway*.
Quoted 6 lines
Agreed it's hard to get this done perfectly tho, as the best effort on this particular AI model case, I focused on two timings when loading the models:
1) right after device boot, 2) dynamic loading when required. To secure high order pages, for 1), I disabled the large folio consumed by EROFS, while for 2), I tried to callcompact_memorybefore loading the model. Both of cases, I could observe we could get fair amount of large folios. Yes, not 100% tho.
If (1) is a common case in real life, the thing to do would be grab 2GB of large folios early in the startup sequence, and then letting erofs do its thing --- and then at the end of the startup, right before you load the model, you can release the 2GB worth of large folios.
(That being said, I'm guessing #1 is actually not that interesting, since as a percentage of the time that it takes for an Android device to startup, is adding an extra half-second *really* going to be noticeable by the user?)
But for case #2, that's the much more challenging case. If you don't call compact_memory() you're going to burn half a second to allocate the 4k pages, since the large folios won't be available. But if you *do* call compact_memory() in a production ROM, depending fragmented the memory is and how much memory have, calling compat_memory() could take **minutes**. So what's the point?
The bottom line is if it's right after device boot, there are simple techniques that don't require hacking up the f2fs. But in the demand-loaded case, calling compact_memory() is the last thing you'll want to do. You're better either asking the mm to allocate the 4k pages, or do whatever compaction it can do to just free up 2GB worth of folios. (Calling compact_memory() is overkill, and only makes sense in the context of benchmark / proof of concept demo.)
Either way, trying to get file systems to avoid using large folios in the hopes that this will speed up large AI model loading.... doesn't seem to make sense.
If the problem is fundamentally about making 2GB worth of large folios available in a way that takes significantly less time that just allocating the model using half-million 4k pages, that's the question that we should be asking Matthew and the mm folks. Which is why it was too bad we didn't raise this issue at LSF/MM earlier this month.
Quoted 3 lines
Indeed, I was off from LSF/MM for years due to various product issues, not related F2FS tho. Let me make some effort to attend upcoming ones like LPC, if I can get the budget from company.
Next time, as a suggestion, feel free to raise the issue when the LSF/MM CFP goes out, even if you don't think it's likely you will get an invite. Indeed, with a sufficiently interesting topic, that's the way to *get* an invitation. It will require breaking down the technical requires as you and I have done for the last few messages on this thread.
Even if you can't attend LSF/MM due to time or budget reasons, there are a number of your colleagues who are attending, who could raise the question on your behalf. I've been known to do that once or twice on behalf of other Google teams. But it does require that you approach the usual LSF/MM suspects a good 2-3 months before the conference so we can help you craft the an appropriate response to the CFP.
Cheers,
- Ted
Jaegeuk Kim
maintainerQuoted 20 lines · Theodore Tso
Quoted 10 lines · Jaegeuk Kim
Quoted 4 lines
It seems... surprising that the additional I/O operations are actually throttloing UFS device bandwidth by 2x (4GB/s vs 2GB/s). Have you dug into why this is happening, and whether there is anything that can be optimized below the file system?
I can't tell the exact size tho, roughly it's between 1GB and 4GB. And, per lots of test results with various tunings, it turned out memory allocation speed was the culprit. If we use 4KB page, we couldn't get the full bandwidth unless we set the biggest core running the highest frequency.
OK, if we assume that the model file that you want to load is is 2GB then the number of 4k pages that you need is a bit over half a million (524288). So if it take 1 second with large folios (2 GB/s as you stated above), and half-second without (4 GB/s), then you're basically saying that it was costing you half-second to allocate 524288 singleton pages. And the whole point of this exercise is to save that half second?
Quoted 4 lines
And I assume that these timing was using a performance cores, and part of the goal here is to be able to use an efficiency core instead.
Did I get that right?
Yes, right.
Quoted 47 lines
Quoted 11 lines
Quoted 10 lines
But the problem with using small folios is that if you want to actually *use* the memory, unless you want to segment out the memory so it can't be used for anything other than the AI models (e.g., by using somthing like hugetlbfs) it's just going to break up the memory into smaller folios. So that's not actually going to *help* in actual real life use cases. It might help for your artificial benchmarks / experiments, but in the real life case where Android applications are running and fragmenting all of the device memory, the large folios won't be available *anyway*.
Quoted 6 lines
Agreed it's hard to get this done perfectly tho, as the best effort on this particular AI model case, I focused on two timings when loading the models:
1) right after device boot, 2) dynamic loading when required. To secure high order pages, for 1), I disabled the large folio consumed by EROFS, while for 2), I tried to callcompact_memorybefore loading the model. Both of cases, I could observe we could get fair amount of large folios. Yes, not 100% tho.If (1) is a common case in real life, the thing to do would be grab 2GB of large folios early in the startup sequence, and then letting erofs do its thing --- and then at the end of the startup, right before you load the model, you can release the 2GB worth of large folios.
(That being said, I'm guessing #1 is actually not that interesting, since as a percentage of the time that it takes for an Android device to startup, is adding an extra half-second *really* going to be noticeable by the user?)
But for case #2, that's the much more challenging case. If you don't call
compact_memory()you're going to burn half a second to allocate the 4k pages, since the large folios won't be available. But if you *do* callcompact_memory()in a production ROM, depending fragmented the memory is and how much memory have, callingcompat_memory()could take **minutes**. So what's the point?The bottom line is if it's right after device boot, there are simple techniques that don't require hacking up the f2fs. But in the demand-loaded case, calling
compact_memory()is the last thing you'll want to do. You're better either asking the mm to allocate the 4k pages, or do whatever compaction it can do to just free up 2GB worth of folios. (Callingcompact_memory()is overkill, and only makes sense in the context of benchmark / proof of concept demo.)Either way, trying to get file systems to avoid using large folios in the hopes that this will speed up large AI model loading.... doesn't seem to make sense.
Quoted 5 lines
If the problem is fundamentally about making 2GB worth of large folios available in a way that takes significantly less time that just allocating the model using half-million 4k pages, that's the question that we should be asking Matthew and the mm folks. Which is why it was too bad we didn't raise this issue at LSF/MM earlier this month.
Thanks for the context. To clarify a piece I missed earlier: the model pages are also utilized for inference. Our data shows that larger chunks yield higher inference speeds. Consequently, I required high-order pages to optimize both read throughput and inference latency. I will halt my current efforts and wait for alternative suggestions.
Quoted 12 lines
Quoted 4 lines
Indeed, I was off from LSF/MM for years due to various product issues, not related F2FS tho. Let me make some effort to attend upcoming ones like LPC, if I can get the budget from company.
Next time, as a suggestion, feel free to raise the issue when the LSF/MM CFP goes out, even if you don't think it's likely you will get an invite. Indeed, with a sufficiently interesting topic, that's the way to *get* an invitation. It will require breaking down the technical requires as you and I have done for the last few messages on this thread.
Quoted 6 lines
Even if you can't attend LSF/MM due to time or budget reasons, there are a number of your colleagues who are attending, who could raise the question on your behalf. I've been known to do that once or twice on behalf of other Google teams. But it does require that you approach the usual LSF/MM suspects a good 2-3 months before the conference so we can help you craft the an appropriate response to the CFP.
Thanks for the suggestion. Will definitely do.
Quoted 10 lines
Cheers,
- Ted
_______________________________________________
Linux-f2fs-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/linux-f2fs-devel
Quoted 5 lines · Jaegeuk Kim
Thanks for the context. To clarify a piece I missed earlier: the model pages are also utilized for inference. Our data shows that larger chunks yield higher inference speeds. Consequently, I required high-order pages to optimize both read throughput and inference latency. I will halt my current efforts and wait for alternative suggestions.
I think your efforts would be best directed towards general support for large folios in f2fs. There's still 40+ places in f2fs that use a struct page, and converting them all to folios would be a great help.
Jaegeuk Kim
maintainerQuoted 10 lines · Matthew Wilcox
Quoted 5 lines · Jaegeuk Kim
Thanks for the context. To clarify a piece I missed earlier: the model pages are also utilized for inference. Our data shows that larger chunks yield higher inference speeds. Consequently, I required high-order pages to optimize both read throughput and inference latency. I will halt my current efforts and wait for alternative suggestions.
I think your efforts would be best directed towards general support for large folios in f2fs. There's still 40+ places in f2fs that use a struct page, and converting them all to folios would be a great help.
Ok, I'll dive into it in priority, but it'll take some time since I think we'd better to refactor some major data structures.
Quoted 6 lines
_______________________________________________
Linux-f2fs-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/linux-f2fs-devel
Quoted 7 lines · Theodore Tso
The bottom line is if it's right after device boot, there are simple techniques that don't require hacking up the f2fs. But in the demand-loaded case, calling
compact_memory()is the last thing you'll want to do. You're better either asking the mm to allocate the 4k pages, or do whatever compaction it can do to just free up 2GB worth of folios. (Callingcompact_memory()is overkill, and only makes sense in the context of benchmark / proof of concept demo.)
Or have a lot of clean pagecache using higher order folios that can you can instantly reclaim?
Quoted 6 lines · Theodore Tso
2. Host Controller Hardware Limits (UFSHCI)
Transfer Queue Depth: A UFS controller supports a predefined
number of outstanding task request entries. This is often hard-capped at 32 concurrent transfer requests (slots) by the doorbell register array.
The above information comes from the UFSHCI 3 standard. Jaegeuk's test setup has an UFSHCI 4.0 controller that supports one submission queue per CPU and also one completion queue per CPU. This is an architecture that is very similar but not identical to NVMe. Jaegeuk, please correct me if I got anything wrong.
Bart.
Quoted 10 lines · Jaegeuk Kim
Background
----------
The primary use case is accelerating AI model loading, which demands exceptionally high sequential read speeds. In our benchmarks on embedded systems:
- Using high-order page allocations allows the system to saturate the Universal Flash Storage (UFS) bandwidth, reaching 4 GB/s even at medium-to-low CPU frequencies.
- In contrast, standard small folios cap performance at 2 GB/s.
Quoted 2 lines
The performance doubling stems directly from reducing CPU cycle overhead during memory allocation.
When you say "AI model loading", are you mmap()ing the file of weights, or are you calling read() to load the file into anonymous memory?
This matters because for the first operation, you need to allocate folios of PMD size in order to make best use of TLB entries. For the second operation, it's more important to iterate through the file quickly, freeing folios behind you after you access them so they're available for the next batch.
Jaegeuk Kim
maintainerQuoted 14 lines · Matthew Wilcox
Quoted 10 lines · Jaegeuk Kim
Background
----------
The primary use case is accelerating AI model loading, which demands exceptionally high sequential read speeds. In our benchmarks on embedded systems:
- Using high-order page allocations allows the system to saturate the Universal Flash Storage (UFS) bandwidth, reaching 4 GB/s even at medium-to-low CPU frequencies.
- In contrast, standard small folios cap performance at 2 GB/s.Quoted 2 lines
The performance doubling stems directly from reducing CPU cycle overhead during memory allocation.
Quoted 8 lines
When you say "AI model loading", are you mmap()ing the file of weights, or are you calling
read()to load the file into anonymous memory?This matters because for the first operation, you need to allocate folios of PMD size in order to make best use of TLB entries. For the second operation, it's more important to iterate through the file quickly, freeing folios behind you after you access them so they're available for the next batch.
We deal with multiple options tho, what I'm looking at is mostly a preloading models by mmap(MAP_POPULATE) which takes the readahead path bumping up the order by 2. Previously I also looked at fadvise(WILLNEED), but gave up due to the broken interface. OTOH, we use RWF_DONTCACHE for read() case, but I don't think it's ideal for the best loading performance.
Quoted 6 lines
_______________________________________________
Linux-f2fs-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/linux-f2fs-devel
Quoted 3 lines · Jaegeuk Kim
I went this route because Android heavily restricts
ioctl()permissions and we needed broader access for this to work within the framework. It’s definitely a pragmatic choice just to get it running in production.
That is not a good reason.
Quoted 3 lines
If
ioctl()is a right way for upstream, I'm happy to change this patch. By the way, I really don't understand why all the messages are so offensive, even without trying to understand the problem or guiding right directions.
The right way is to:
1) Talk to the relevant subsystems (MM and fsdevel), and if it affects userspace that linux-api list and actually explain your use case.
2) And then actually listen to feedback. f2fs just keeps piling these ABI hacks on without any review, and it is causing real problems.
Christian Brauner
maintainerQuoted 25 lines · Theodore Tso
Quoted 10 lines · Christoph Hellwig
Quoted 4 lines
You haven't sent a proposal. This is a reply to a reply to a reply of a patch. There's no justification for why f2fs is so special that it needs this. What the hell is going on? You know this is not the way to get code merged into Linux.
None of this got properly answers, and this broken interface now landed in linux-next. IT is offloading a user.* xattr which is free-form user data with semantics that are weird to say it very nicely.
All this was done against the advice in the mailing list discussion.
So let me get this straight. This is a magic xattr interface which is not even persisted in the file system, but instead sets a 32-bit bitmask in the struct inode which disappears once the inode gets flushed from the inode stack. And it uses a generic xattr name, "user.fadvise".
There's no way in *hell* any other file system is likely to adopt such a broken interface, so why didn't you just use an ioctl to set this magic f2fs-specific flag?
Quoted 2 lines
I think at some point we just need to stop taking f2fs updates likes this.
Quoted 8 lines
Well, that's ultiamtely up to Linus. I'll say that if I were Linus (and I'm glad I'm not :-), and I saw this in a pull request, I'd reject it out of hand. But whether it's worth making a huge fuss and asking escalating this mess to Linus, we probably should get a bit more community consensus before taking such a drastic step.
Christian, since you're one of the VFS maintaienrs, what's your opinion about escalating this to Linus?
I think we don't need to involve Linus.
The interface as is is broken. Using xattrs for this makes no sense whatsoever.
Jaegeuk Kim
maintainerBy the way, is it worth to add some generic apis such as
1) reclaim a specifc inode object when closing the last file
2) add another fadvise hint for large folio
Quoted 313 lines · Jaegeuk Kim
enum {
F2FS_XATTR_FADV_LARGEFOLIO,
};unsigned int value =
BIT(F2FS_XATTR_FADV_LARGEFOLIO);1.
setxattr(file, "user.fadvise", &value, sizeof(unsigned int), 0)-> register the inode number for large folio
2.chmod(0400, file)
-> make Read-Only
3.fsync()&&close()&& open(READ)
->f2fs_iget()with large folio
4. open(WRITE), mkwrite on mmap, chmod(WRITE)
-> return error
5.close()andopen()
-> goto #3
6. unlink
-> deregister the inode numberSuggested-by Akilesh Kailash <[email protected]>Signed-off-by Jaegeuk Kim <[email protected]>---
Log from v1:
- add a condition inf2fs_drop_inode
- add DocDocumentation/filesystems/f2fs.rst | 41 ++++++++++++++++++++++++++---- fs/f2fs/checkpoint.c | 2 +- fs/f2fs/data.c | 2 +- fs/f2fs/f2fs.h | 1 + fs/f2fs/file.c | 11 ++++++-- fs/f2fs/inode.c | 19 +++++++++++--- fs/f2fs/super.c | 7 +++++ fs/f2fs/xattr.c | 35 ++++++++++++++++++++++++- fs/f2fs/xattr.h | 6 +++++ 9 files changed, 111 insertions(+), 13 deletions(-)Documentation/filesystems/f2fs.rst +36
-5@@ -1044,11 +1044,14 @@ page allocation for significant performance gains. To minimize code complexity, this support is currently excluded from the write path, which requires handling complex optimizations such as compression and block allocation modes. -This optional feature is triggered only when a file's immutable bit is set. -Consequently, F2FS will return EOPNOTSUPP if a user attempts to open a cached -file with write permissions, even immediately after clearing the bit. Write -access is only restored once the cached inode is dropped. The usage flow is -demonstrated below: +This optional feature is triggered by two mechanisms: the file's immutable bit +or a specific xattr flag. In both cases, F2FS ensures data integrity by +restricting the file to a read-only state while large folios are active. + +1. Immutable Bit Approach: +Triggered when the FS_IMMUTABLE_FL is set. This is a strict enforcement +where the file cannot be modified at all until the bit is cleared and +the cached inode is dropped. .. code-block::@@ -1078,3 +1081,31 @@ demonstrated below: Written 4096 bytes with pattern = zero, total_time = 29 us, max_latency = 28 us # rm /data/testfile_read_seq + +2. XATTR fadvise Approach: +A more flexible registration via extended attributes. + +.. code-block:: + + enum { + F2FS_XATTR_FADV_LARGEFOLIO, + }; + unsigned int value = BIT(F2FS_XATTR_FADV_LARGEFOLIO); + + /* Registers the inode number for large folio support in the subsystem.*/ + # setxattr(file, "user.fadvise", &value, sizeof(unsigned int), 0) + + /* The file must be made Read-Only to transition into the large folio path. */ + # fchmod(0400, fd) + + /* clean up dirty inode state. */ + # fsync(fd) + + /* Drop the inode cache. + # close(fd) + + /* f2fs_iget() instantiates the inode with large folio support.*/ + # open() + + /* Returns -EOPNOTSUPP or error to protect the large folio cache.*/ + # open(WRITE), mkwrite on mmap, or chmod(WRITE)fs/f2fs/checkpoint.c +1
-1@@ -778,7 +778,7 @@ void f2fs_remove_ino_entry(struct f2fs_sb_info *sbi, nid_t ino, int type)__remove_ino_entry (sbi, ino, type); } -/* mode should be APPEND_INO, UPDATE_INO or TRANS_DIR_INO */ +/* mode should be APPEND_INO, UPDATE_INO, LARGE_FOLIO_IO, or TRANS_DIR_INO */ bool f2fs_exist_written_data (struct f2fs_sb_info *sbi,nid_t ino,int mode) {struct inode_management *im = &sbi->im[mode];fs/f2fs/data.c +1
-1@@ -2494,7 +2494,7 @@ static int f2fs_read_data_large_folio(struct inode *inode,int ret =0 ;bool folio_in_bio; -if (!IS_IMMUTABLE (inode) ||f2fs_compressed_file (inode)) { +if (f2fs_compressed_file (inode)) {if (folio)folio_unlock (folio);return -EOPNOTSUPP ;fs/f2fs/f2fs.h +1
-0@@ -381,6 +381,7 @@ enum {/* for the list of ino */ enum {ORPHAN_INO ,/* for orphan ino list */ +LARGE_FOLIO_INO ,/* for large folio case */ APPEND_INO ,/* for append ino list */ UPDATE_INO ,/* for update ino list */ TRANS_DIR_INO ,/* for transactions dir ino list */ fs/f2fs/file.c +9
-2@@ -2068,9 +2068,16 @@ static long f2fs_fallocate(struct file *file, int mode,static int f2fs_release_file (struct inode *inode,struct file *filp) { -if (atomic_dec_and_test (&F2FS_I (inode)->open_count)) +if (atomic_dec_and_test (&F2FS_I (inode)->open_count)) {f2fs_remove_donate_inode (inode); - +/* +* In order to get large folio as soon as possible, let's drop +* inode cache asap. See also f2fs_drop_inode. +*/ +if (f2fs_exist_written_data (F2FS_I_SB (inode), + inode->i_ino,LARGE_FOLIO_INO )) +d_drop (filp->f_path.dentry); + }/* * f2fs_release_file is called at every close calls. So we should * not drop any inmemory pages by close called by other process. fs/f2fs/inode.c +16
-3@@ -565,6 +565,20 @@ static bool is_meta_ino(struct f2fs_sb_info *sbi, unsigned int ino) ino ==F2FS_COMPRESS_INO (sbi); } +static void f2fs_mapping_set_large_folio (struct inode *inode) +{ +struct f2fs_sb_info *sbi =F2FS_I_SB (inode); + +if (f2fs_compressed_file (inode)) +return ; +if (f2fs_quota_file (sbi, inode->i_ino)) +return ; +if (IS_IMMUTABLE (inode) || + (f2fs_exist_written_data (sbi, inode->i_ino,LARGE_FOLIO_INO ) && + !(inode->i_mode &S_IWUGO ))) +mapping_set_folio_min_order (inode->i_mapping,0 ); +} +struct inode *f2fs_iget (struct super_block *sb,unsigned long ino) {struct f2fs_sb_info *sbi =F2FS_SB (sb);@@ -620,9 +634,7 @@ struct inode *f2fs_iget(struct super_block *sb, unsigned long ino) inode->i_op = &f2fs_file_inode_operations; inode->i_fop = &f2fs_file_operations; inode->i_mapping->a_ops = &f2fs_dblock_aops; -if (IS_IMMUTABLE (inode) && !f2fs_compressed_file (inode) && - !f2fs_quota_file (sbi, inode->i_ino)) -mapping_set_folio_min_order (inode->i_mapping,0 ); +f2fs_mapping_set_large_folio (inode); }else if (S_ISDIR (inode->i_mode)) { inode->i_op = &f2fs_dir_inode_operations; inode->i_fop = &f2fs_dir_operations;@@ -895,6 +907,7 @@ void f2fs_evict_inode(struct inode *inode)f2fs_remove_ino_entry (sbi, inode->i_ino,APPEND_INO );f2fs_remove_ino_entry (sbi, inode->i_ino,UPDATE_INO );f2fs_remove_ino_entry (sbi, inode->i_ino,FLUSH_INO ); +f2fs_remove_ino_entry (sbi, inode->i_ino,LARGE_FOLIO_INO );if (!is_sbi_flag_set (sbi,SBI_IS_FREEZING )) {sb_start_intwrite (inode->i_sb);fs/f2fs/super.c +7
-0@@ -1844,6 +1844,13 @@ static int f2fs_drop_inode(struct inode *inode)return 1 ; } } +/* +* In order to get large folio as soon as possible, let's drop +* inode cache asap. See also f2fs_release_file. +*/ +if (f2fs_exist_written_data (sbi, inode->i_ino,LARGE_FOLIO_INO ) && + !is_inode_flag_set (inode,FI_DIRTY_INODE )) +return 1 ;/* * This is to avoid a deadlock condition like below. fs/f2fs/xattr.c +34
-1@@ -44,6 +44,16 @@ static void xattr_free(struct f2fs_sb_info *sbi, void *xattr_addr,kfree (xattr_addr); } +static int f2fs_xattr_fadvise_get (struct inode *inode,void *buffer) +{ +if (!buffer) + goto out; +if (mapping_large_folio_support (inode->i_mapping)) + *((unsigned int *)buffer) |=BIT (F2FS_XATTR_FADV_LARGEFOLIO ); +out: +return sizeof (unsigned int ); +} +static int f2fs_xattr_generic_get (const struct xattr_handler *handler,struct dentry *unused,struct inode *inode,const char *name,void *buffer,size_t size)@@ -61,10 +71,29 @@ static int f2fs_xattr_generic_get(const struct xattr_handler *handler,default :return -EINVAL ; } +if (handler->flags ==F2FS_XATTR_INDEX_USER && + !strcmp (name,"fadvise" )) +return f2fs_xattr_fadvise_get (inode, buffer); +return f2fs_getxattr (inode, handler->flags, name, buffer, size,NULL ); } +static int f2fs_xattr_fadvise_set (struct inode *inode,const void *value) +{ +unsigned int new_fadvise; + + new_fadvise = *(unsigned int *)value; + +if (new_fadvise &BIT (F2FS_XATTR_FADV_LARGEFOLIO )) +f2fs_add_ino_entry (F2FS_I_SB (inode), + inode->i_ino,LARGE_FOLIO_INO ); +else +f2fs_remove_ino_entry (F2FS_I_SB (inode), + inode->i_ino,LARGE_FOLIO_INO ); +return 0 ; +} + static int f2fs_xattr_generic_set(const struct xattr_handler *handler, struct mnt_idmap *idmap, struct dentry *unused, struct inode *inode,@@ -84,6 +113,10 @@ static int f2fs_xattr_generic_set(const struct xattr_handler *handler,default :return -EINVAL ; } +if (handler->flags ==F2FS_XATTR_INDEX_USER && + !strcmp (name,"fadvise" )) +return f2fs_xattr_fadvise_set (inode, value); +return f2fs_setxattr (inode, handler->flags, name, value, size,NULL , flags); }@@ -842,4 +875,4 @@ int __init f2fs_init_xattr_cache(void)void f2fs_destroy_xattr_cache (void ) {kmem_cache_destroy (inline_xattr_slab); -} +}fs/f2fs/xattr.h +6
-0@@ -24,6 +24,7 @@#define F2FS_XATTR_REFCOUNT_MAX 1024/* Name indexes */ +#define F2FS_USER_FADVISE_NAME "user.fadvise"#define F2FS_SYSTEM_ADVISE_NAME "system.advise"#define F2FS_XATTR_INDEX_USER 1#define F2FS_XATTR_INDEX_POSIX_ACL_ACCESS 2@@ -39,6 +40,11 @@#define F2FS_XATTR_NAME_ENCRYPTION_CONTEXT "c"#define F2FS_XATTR_NAME_VERITY "v" +/* used for F2FS_USER_FADVISE_NAME */ +enum { +F2FS_XATTR_FADV_LARGEFOLIO , +}; +struct f2fs_xattr_header {__le32 h_magic;/* magic number for identification */ __le32 h_refcount;/* reference count */ Signature · 1 line
2.53.0.1213.gd9a14994de-goog
Chao Yu
maintainerQuoted 78 lines · On 4/10/2026 9:16 AM, Jaegeuk Kim via Linux-f2fs-devel wrote:
enum {
F2FS_XATTR_FADV_LARGEFOLIO,
};unsigned int value =
BIT(F2FS_XATTR_FADV_LARGEFOLIO);1.
setxattr(file, "user.fadvise", &value, sizeof(unsigned int), 0)-> register the inode number for large folio
2.chmod(0400, file)
-> make Read-Only
3.fsync()&&close()&& open(READ)
->f2fs_iget()with large folio
4. open(WRITE), mkwrite on mmap, chmod(WRITE)
-> return error
5.close()andopen()
-> goto #3
6. unlink
-> deregister the inode numberSuggested-by Akilesh Kailash <[email protected]>Signed-off-by Jaegeuk Kim <[email protected]>---
Log from v1:
- add a condition inf2fs_drop_inode
- add DocDocumentation/filesystems/f2fs.rst | 41 ++++++++++++++++++++++++++---- fs/f2fs/checkpoint.c | 2 +- fs/f2fs/data.c | 2 +- fs/f2fs/f2fs.h | 1 + fs/f2fs/file.c | 11 ++++++-- fs/f2fs/inode.c | 19 +++++++++++--- fs/f2fs/super.c | 7 +++++ fs/f2fs/xattr.c | 35 ++++++++++++++++++++++++- fs/f2fs/xattr.h | 6 +++++ 9 files changed, 111 insertions(+), 13 deletions(-)Documentation/filesystems/f2fs.rst +20
-5@@ -1044,11 +1044,14 @@ page allocation for significant performance gains. To minimize code complexity, this support is currently excluded from the write path, which requires handling complex optimizations such as compression and block allocation modes. -This optional feature is triggered only when a file's immutable bit is set. -Consequently, F2FS will return EOPNOTSUPP if a user attempts to open a cached -file with write permissions, even immediately after clearing the bit. Write -access is only restored once the cached inode is dropped. The usage flow is -demonstrated below: +This optional feature is triggered by two mechanisms: the file's immutable bit +or a specific xattr flag. In both cases, F2FS ensures data integrity by +restricting the file to a read-only state while large folios are active. + +1. Immutable Bit Approach: +Triggered when the FS_IMMUTABLE_FL is set. This is a strict enforcement +where the file cannot be modified at all until the bit is cleared and +the cached inode is dropped. .. code-block::@@ -1078,3 +1081,31 @@ demonstrated below: Written 4096 bytes with pattern = zero, total_time = 29 us, max_latency = 28 us # rm /data/testfile_read_seq + +2. XATTR fadvise Approach: +A more flexible registration via extended attributes. + +.. code-block:: + + enum { + F2FS_XATTR_FADV_LARGEFOLIO, + }; + unsigned int value = BIT(F2FS_XATTR_FADV_LARGEFOLIO); + + /* Registers the inode number for large folio support in the subsystem.*/
Documentation/filesystems/f2fs.rst demonstrated below: · line 1105
Quoted 10 lines
Documentation/filesystems/f2fs.rst +10
-0+ # setxattr(file, "user.fadvise", &value, sizeof(unsigned int), 0) + + /* The file must be made Read-Only to transition into the large folio path. */ + # fchmod(0400, fd) + + /* clean up dirty inode state. */ + # fsync(fd) + + /* Drop the inode cache. + # close(fd)
If drop_cache or memory reclaim was called here, then LARGE_FOLIO_INO will be dropped in f2fs_evict_inode(), do we need to keep LARGE_FOLIO_INO if inode->i_nlink is valid in f2fs_evict_inode()?
Thanks,
Quoted 222 lines
Documentation/filesystems/f2fs.rst +6
-0+ + /* f2fs_iget() instantiates the inode with large folio support.*/ + # open() + + /* Returns -EOPNOTSUPP or error to protect the large folio cache.*/ + # open(WRITE), mkwrite on mmap, or chmod(WRITE)fs/f2fs/checkpoint.c +1
-1@@ -778,7 +778,7 @@ void f2fs_remove_ino_entry(struct f2fs_sb_info *sbi, nid_t ino, int type)__remove_ino_entry (sbi, ino, type); } -/* mode should be APPEND_INO, UPDATE_INO or TRANS_DIR_INO */ +/* mode should be APPEND_INO, UPDATE_INO, LARGE_FOLIO_IO, or TRANS_DIR_INO */ bool f2fs_exist_written_data (struct f2fs_sb_info *sbi,nid_t ino,int mode) {struct inode_management *im = &sbi->im[mode];fs/f2fs/data.c +1
-1@@ -2494,7 +2494,7 @@ static int f2fs_read_data_large_folio(struct inode *inode,int ret =0 ;bool folio_in_bio; -if (!IS_IMMUTABLE (inode) ||f2fs_compressed_file (inode)) { +if (f2fs_compressed_file (inode)) {if (folio)folio_unlock (folio);return -EOPNOTSUPP ;fs/f2fs/f2fs.h +1
-0@@ -381,6 +381,7 @@ enum {/* for the list of ino */ enum {ORPHAN_INO ,/* for orphan ino list */ +LARGE_FOLIO_INO ,/* for large folio case */ APPEND_INO ,/* for append ino list */ UPDATE_INO ,/* for update ino list */ TRANS_DIR_INO ,/* for transactions dir ino list */ fs/f2fs/file.c +9
-2@@ -2068,9 +2068,16 @@ static long f2fs_fallocate(struct file *file, int mode,static int f2fs_release_file (struct inode *inode,struct file *filp) { -if (atomic_dec_and_test (&F2FS_I (inode)->open_count)) +if (atomic_dec_and_test (&F2FS_I (inode)->open_count)) {f2fs_remove_donate_inode (inode); - +/* +* In order to get large folio as soon as possible, let's drop +* inode cache asap. See also f2fs_drop_inode. +*/ +if (f2fs_exist_written_data (F2FS_I_SB (inode), + inode->i_ino,LARGE_FOLIO_INO )) +d_drop (filp->f_path.dentry); + }/* * f2fs_release_file is called at every close calls. So we should * not drop any inmemory pages by close called by other process. fs/f2fs/inode.c +16
-3@@ -565,6 +565,20 @@ static bool is_meta_ino(struct f2fs_sb_info *sbi, unsigned int ino) ino ==F2FS_COMPRESS_INO (sbi); } +static void f2fs_mapping_set_large_folio (struct inode *inode) +{ +struct f2fs_sb_info *sbi =F2FS_I_SB (inode); + +if (f2fs_compressed_file (inode)) +return ; +if (f2fs_quota_file (sbi, inode->i_ino)) +return ; +if (IS_IMMUTABLE (inode) || + (f2fs_exist_written_data (sbi, inode->i_ino,LARGE_FOLIO_INO ) && + !(inode->i_mode &S_IWUGO ))) +mapping_set_folio_min_order (inode->i_mapping,0 ); +} +struct inode *f2fs_iget (struct super_block *sb,unsigned long ino) {struct f2fs_sb_info *sbi =F2FS_SB (sb);@@ -620,9 +634,7 @@ struct inode *f2fs_iget(struct super_block *sb, unsigned long ino) inode->i_op = &f2fs_file_inode_operations; inode->i_fop = &f2fs_file_operations; inode->i_mapping->a_ops = &f2fs_dblock_aops; -if (IS_IMMUTABLE (inode) && !f2fs_compressed_file (inode) && - !f2fs_quota_file (sbi, inode->i_ino)) -mapping_set_folio_min_order (inode->i_mapping,0 ); +f2fs_mapping_set_large_folio (inode); }else if (S_ISDIR (inode->i_mode)) { inode->i_op = &f2fs_dir_inode_operations; inode->i_fop = &f2fs_dir_operations;@@ -895,6 +907,7 @@ void f2fs_evict_inode(struct inode *inode)f2fs_remove_ino_entry (sbi, inode->i_ino,APPEND_INO );f2fs_remove_ino_entry (sbi, inode->i_ino,UPDATE_INO );f2fs_remove_ino_entry (sbi, inode->i_ino,FLUSH_INO ); +f2fs_remove_ino_entry (sbi, inode->i_ino,LARGE_FOLIO_INO );if (!is_sbi_flag_set (sbi,SBI_IS_FREEZING )) {sb_start_intwrite (inode->i_sb);fs/f2fs/super.c +7
-0@@ -1844,6 +1844,13 @@ static int f2fs_drop_inode(struct inode *inode)return 1 ; } } +/* +* In order to get large folio as soon as possible, let's drop +* inode cache asap. See also f2fs_release_file. +*/ +if (f2fs_exist_written_data (sbi, inode->i_ino,LARGE_FOLIO_INO ) && + !is_inode_flag_set (inode,FI_DIRTY_INODE )) +return 1 ;/* * This is to avoid a deadlock condition like below. fs/f2fs/xattr.c +34
-1@@ -44,6 +44,16 @@ static void xattr_free(struct f2fs_sb_info *sbi, void *xattr_addr,kfree (xattr_addr); } +static int f2fs_xattr_fadvise_get (struct inode *inode,void *buffer) +{ +if (!buffer) + goto out; +if (mapping_large_folio_support (inode->i_mapping)) + *((unsigned int *)buffer) |=BIT (F2FS_XATTR_FADV_LARGEFOLIO ); +out: +return sizeof (unsigned int ); +} +static int f2fs_xattr_generic_get (const struct xattr_handler *handler,struct dentry *unused,struct inode *inode,const char *name,void *buffer,size_t size)@@ -61,10 +71,29 @@ static int f2fs_xattr_generic_get(const struct xattr_handler *handler,default :return -EINVAL ; } +if (handler->flags ==F2FS_XATTR_INDEX_USER && + !strcmp (name,"fadvise" )) +return f2fs_xattr_fadvise_get (inode, buffer); +return f2fs_getxattr (inode, handler->flags, name, buffer, size,NULL ); } +static int f2fs_xattr_fadvise_set (struct inode *inode,const void *value) +{ +unsigned int new_fadvise; + + new_fadvise = *(unsigned int *)value; + +if (new_fadvise &BIT (F2FS_XATTR_FADV_LARGEFOLIO )) +f2fs_add_ino_entry (F2FS_I_SB (inode), + inode->i_ino,LARGE_FOLIO_INO ); +else +f2fs_remove_ino_entry (F2FS_I_SB (inode), + inode->i_ino,LARGE_FOLIO_INO ); +return 0 ; +} + static int f2fs_xattr_generic_set(const struct xattr_handler *handler, struct mnt_idmap *idmap, struct dentry *unused, struct inode *inode,@@ -84,6 +113,10 @@ static int f2fs_xattr_generic_set(const struct xattr_handler *handler,default :return -EINVAL ; } +if (handler->flags ==F2FS_XATTR_INDEX_USER && + !strcmp (name,"fadvise" )) +return f2fs_xattr_fadvise_set (inode, value); +return f2fs_setxattr (inode, handler->flags, name, value, size,NULL , flags); }@@ -842,4 +875,4 @@ int __init f2fs_init_xattr_cache(void)void f2fs_destroy_xattr_cache (void ) {kmem_cache_destroy (inline_xattr_slab); -} +}fs/f2fs/xattr.h +6
-0@@ -24,6 +24,7 @@#define F2FS_XATTR_REFCOUNT_MAX 1024/* Name indexes */ +#define F2FS_USER_FADVISE_NAME "user.fadvise"#define F2FS_SYSTEM_ADVISE_NAME "system.advise"#define F2FS_XATTR_INDEX_USER 1#define F2FS_XATTR_INDEX_POSIX_ACL_ACCESS 2@@ -39,6 +40,11 @@#define F2FS_XATTR_NAME_ENCRYPTION_CONTEXT "c"#define F2FS_XATTR_NAME_VERITY "v" +/* used for F2FS_USER_FADVISE_NAME */ +enum { +F2FS_XATTR_FADV_LARGEFOLIO , +}; +struct f2fs_xattr_header {__le32 h_magic;/* magic number for identification */ __le32 h_refcount;/* reference count */
Jaegeuk Kim
maintainerQuoted 80 lines · Chao Yu
Quoted 79 lines · On 4/10/2026 9:16 AM, Jaegeuk Kim via Linux-f2fs-devel wrote:
enum {
F2FS_XATTR_FADV_LARGEFOLIO,
};unsigned int value =
BIT(F2FS_XATTR_FADV_LARGEFOLIO);1.
setxattr(file, "user.fadvise", &value, sizeof(unsigned int), 0)-> register the inode number for large folio
2.chmod(0400, file)
-> make Read-Only
3.fsync()&&close()&& open(READ)
->f2fs_iget()with large folio
4. open(WRITE), mkwrite on mmap, chmod(WRITE)
-> return error
5.close()andopen()
-> goto #3
6. unlink
-> deregister the inode numberSuggested-by Akilesh Kailash <[email protected]>Signed-off-by Jaegeuk Kim <[email protected]>---
Log from v1:
- add a condition inf2fs_drop_inode
- add DocDocumentation/filesystems/f2fs.rst | 41 ++++++++++++++++++++++++++---- fs/f2fs/checkpoint.c | 2 +- fs/f2fs/data.c | 2 +- fs/f2fs/f2fs.h | 1 + fs/f2fs/file.c | 11 ++++++-- fs/f2fs/inode.c | 19 +++++++++++--- fs/f2fs/super.c | 7 +++++ fs/f2fs/xattr.c | 35 ++++++++++++++++++++++++- fs/f2fs/xattr.h | 6 +++++ 9 files changed, 111 insertions(+), 13 deletions(-)Documentation/filesystems/f2fs.rst +26
-5@@ -1044,11 +1044,14 @@ page allocation for significant performance gains. To minimize code complexity, this support is currently excluded from the write path, which requires handling complex optimizations such as compression and block allocation modes. -This optional feature is triggered only when a file's immutable bit is set. -Consequently, F2FS will return EOPNOTSUPP if a user attempts to open a cached -file with write permissions, even immediately after clearing the bit. Write -access is only restored once the cached inode is dropped. The usage flow is -demonstrated below: +This optional feature is triggered by two mechanisms: the file's immutable bit +or a specific xattr flag. In both cases, F2FS ensures data integrity by +restricting the file to a read-only state while large folios are active. + +1. Immutable Bit Approach: +Triggered when the FS_IMMUTABLE_FL is set. This is a strict enforcement +where the file cannot be modified at all until the bit is cleared and +the cached inode is dropped. .. code-block::@@ -1078,3 +1081,31 @@ demonstrated below: Written 4096 bytes with pattern = zero, total_time = 29 us, max_latency = 28 us # rm /data/testfile_read_seq + +2. XATTR fadvise Approach: +A more flexible registration via extended attributes. + +.. code-block:: + + enum { + F2FS_XATTR_FADV_LARGEFOLIO, + }; + unsigned int value = BIT(F2FS_XATTR_FADV_LARGEFOLIO); + + /* Registers the inode number for large folio support in the subsystem.*/ + # setxattr(file, "user.fadvise", &value, sizeof(unsigned int), 0) + + /* The file must be made Read-Only to transition into the large folio path. */ + # fchmod(0400, fd) + + /* clean up dirty inode state. */
Quoted 8 lines
Documentation/filesystems/f2fs.rst demonstrated below: · line 1105
Quoted 4 lines
Documentation/filesystems/f2fs.rst +4
-0+ # fsync(fd) + + /* Drop the inode cache. + # close(fd)If
drop_cacheor memory reclaim was called here, thenLARGE_FOLIO_INOwill be dropped inf2fs_evict_inode(), do we need to keepLARGE_FOLIO_INOifinode->i_nlinkis valid inf2fs_evict_inode()?
We remove it only when we delete the file?
Quoted 215 lines
Thanks,
Quoted 212 lines
Documentation/filesystems/f2fs.rst +6
-0+ + /* f2fs_iget() instantiates the inode with large folio support.*/ + # open() + + /* Returns -EOPNOTSUPP or error to protect the large folio cache.*/ + # open(WRITE), mkwrite on mmap, or chmod(WRITE)fs/f2fs/checkpoint.c +1
-1@@ -778,7 +778,7 @@ void f2fs_remove_ino_entry(struct f2fs_sb_info *sbi, nid_t ino, int type)__remove_ino_entry (sbi, ino, type); } -/* mode should be APPEND_INO, UPDATE_INO or TRANS_DIR_INO */ +/* mode should be APPEND_INO, UPDATE_INO, LARGE_FOLIO_IO, or TRANS_DIR_INO */ bool f2fs_exist_written_data (struct f2fs_sb_info *sbi,nid_t ino,int mode) {struct inode_management *im = &sbi->im[mode];fs/f2fs/data.c +1
-1@@ -2494,7 +2494,7 @@ static int f2fs_read_data_large_folio(struct inode *inode,int ret =0 ;bool folio_in_bio; -if (!IS_IMMUTABLE (inode) ||f2fs_compressed_file (inode)) { +if (f2fs_compressed_file (inode)) {if (folio)folio_unlock (folio);return -EOPNOTSUPP ;fs/f2fs/f2fs.h +1
-0@@ -381,6 +381,7 @@ enum {/* for the list of ino */ enum {ORPHAN_INO ,/* for orphan ino list */ +LARGE_FOLIO_INO ,/* for large folio case */ APPEND_INO ,/* for append ino list */ UPDATE_INO ,/* for update ino list */ TRANS_DIR_INO ,/* for transactions dir ino list */ fs/f2fs/file.c +9
-2@@ -2068,9 +2068,16 @@ static long f2fs_fallocate(struct file *file, int mode,static int f2fs_release_file (struct inode *inode,struct file *filp) { -if (atomic_dec_and_test (&F2FS_I (inode)->open_count)) +if (atomic_dec_and_test (&F2FS_I (inode)->open_count)) {f2fs_remove_donate_inode (inode); - +/* +* In order to get large folio as soon as possible, let's drop +* inode cache asap. See also f2fs_drop_inode. +*/ +if (f2fs_exist_written_data (F2FS_I_SB (inode), + inode->i_ino,LARGE_FOLIO_INO )) +d_drop (filp->f_path.dentry); + }/* * f2fs_release_file is called at every close calls. So we should * not drop any inmemory pages by close called by other process. fs/f2fs/inode.c +16
-3@@ -565,6 +565,20 @@ static bool is_meta_ino(struct f2fs_sb_info *sbi, unsigned int ino) ino ==F2FS_COMPRESS_INO (sbi); } +static void f2fs_mapping_set_large_folio (struct inode *inode) +{ +struct f2fs_sb_info *sbi =F2FS_I_SB (inode); + +if (f2fs_compressed_file (inode)) +return ; +if (f2fs_quota_file (sbi, inode->i_ino)) +return ; +if (IS_IMMUTABLE (inode) || + (f2fs_exist_written_data (sbi, inode->i_ino,LARGE_FOLIO_INO ) && + !(inode->i_mode &S_IWUGO ))) +mapping_set_folio_min_order (inode->i_mapping,0 ); +} +struct inode *f2fs_iget (struct super_block *sb,unsigned long ino) {struct f2fs_sb_info *sbi =F2FS_SB (sb);@@ -620,9 +634,7 @@ struct inode *f2fs_iget(struct super_block *sb, unsigned long ino) inode->i_op = &f2fs_file_inode_operations; inode->i_fop = &f2fs_file_operations; inode->i_mapping->a_ops = &f2fs_dblock_aops; -if (IS_IMMUTABLE (inode) && !f2fs_compressed_file (inode) && - !f2fs_quota_file (sbi, inode->i_ino)) -mapping_set_folio_min_order (inode->i_mapping,0 ); +f2fs_mapping_set_large_folio (inode); }else if (S_ISDIR (inode->i_mode)) { inode->i_op = &f2fs_dir_inode_operations; inode->i_fop = &f2fs_dir_operations;@@ -895,6 +907,7 @@ void f2fs_evict_inode(struct inode *inode)f2fs_remove_ino_entry (sbi, inode->i_ino,APPEND_INO );f2fs_remove_ino_entry (sbi, inode->i_ino,UPDATE_INO );f2fs_remove_ino_entry (sbi, inode->i_ino,FLUSH_INO ); +f2fs_remove_ino_entry (sbi, inode->i_ino,LARGE_FOLIO_INO );if (!is_sbi_flag_set (sbi,SBI_IS_FREEZING )) {sb_start_intwrite (inode->i_sb);fs/f2fs/super.c +7
-0@@ -1844,6 +1844,13 @@ static int f2fs_drop_inode(struct inode *inode)return 1 ; } } +/* +* In order to get large folio as soon as possible, let's drop +* inode cache asap. See also f2fs_release_file. +*/ +if (f2fs_exist_written_data (sbi, inode->i_ino,LARGE_FOLIO_INO ) && + !is_inode_flag_set (inode,FI_DIRTY_INODE )) +return 1 ;/* * This is to avoid a deadlock condition like below. fs/f2fs/xattr.c +34
-1@@ -44,6 +44,16 @@ static void xattr_free(struct f2fs_sb_info *sbi, void *xattr_addr,kfree (xattr_addr); } +static int f2fs_xattr_fadvise_get (struct inode *inode,void *buffer) +{ +if (!buffer) + goto out; +if (mapping_large_folio_support (inode->i_mapping)) + *((unsigned int *)buffer) |=BIT (F2FS_XATTR_FADV_LARGEFOLIO ); +out: +return sizeof (unsigned int ); +} +static int f2fs_xattr_generic_get (const struct xattr_handler *handler,struct dentry *unused,struct inode *inode,const char *name,void *buffer,size_t size)@@ -61,10 +71,29 @@ static int f2fs_xattr_generic_get(const struct xattr_handler *handler,default :return -EINVAL ; } +if (handler->flags ==F2FS_XATTR_INDEX_USER && + !strcmp (name,"fadvise" )) +return f2fs_xattr_fadvise_get (inode, buffer); +return f2fs_getxattr (inode, handler->flags, name, buffer, size,NULL ); } +static int f2fs_xattr_fadvise_set (struct inode *inode,const void *value) +{ +unsigned int new_fadvise; + + new_fadvise = *(unsigned int *)value; + +if (new_fadvise &BIT (F2FS_XATTR_FADV_LARGEFOLIO )) +f2fs_add_ino_entry (F2FS_I_SB (inode), + inode->i_ino,LARGE_FOLIO_INO ); +else +f2fs_remove_ino_entry (F2FS_I_SB (inode), + inode->i_ino,LARGE_FOLIO_INO ); +return 0 ; +} + static int f2fs_xattr_generic_set(const struct xattr_handler *handler, struct mnt_idmap *idmap, struct dentry *unused, struct inode *inode,@@ -84,6 +113,10 @@ static int f2fs_xattr_generic_set(const struct xattr_handler *handler,default :return -EINVAL ; } +if (handler->flags ==F2FS_XATTR_INDEX_USER && + !strcmp (name,"fadvise" )) +return f2fs_xattr_fadvise_set (inode, value); +return f2fs_setxattr (inode, handler->flags, name, value, size,NULL , flags); }@@ -842,4 +875,4 @@ int __init f2fs_init_xattr_cache(void)void f2fs_destroy_xattr_cache (void ) {kmem_cache_destroy (inline_xattr_slab); -} +}fs/f2fs/xattr.h +6
-0@@ -24,6 +24,7 @@#define F2FS_XATTR_REFCOUNT_MAX 1024/* Name indexes */ +#define F2FS_USER_FADVISE_NAME "user.fadvise"#define F2FS_SYSTEM_ADVISE_NAME "system.advise"#define F2FS_XATTR_INDEX_USER 1#define F2FS_XATTR_INDEX_POSIX_ACL_ACCESS 2@@ -39,6 +40,11 @@#define F2FS_XATTR_NAME_ENCRYPTION_CONTEXT "c"#define F2FS_XATTR_NAME_VERITY "v" +/* used for F2FS_USER_FADVISE_NAME */ +enum { +F2FS_XATTR_FADV_LARGEFOLIO , +}; +struct f2fs_xattr_header {__le32 h_magic;/* magic number for identification */ __le32 h_refcount;/* reference count */
Chao Yu
maintainerQuoted 90 lines · Jaegeuk Kim
Quoted 80 lines · Chao Yu
Quoted 79 lines · On 4/10/2026 9:16 AM, Jaegeuk Kim via Linux-f2fs-devel wrote:
enum {
F2FS_XATTR_FADV_LARGEFOLIO,
};unsigned int value =
BIT(F2FS_XATTR_FADV_LARGEFOLIO);1.
setxattr(file, "user.fadvise", &value, sizeof(unsigned int), 0)-> register the inode number for large folio
2.chmod(0400, file)
-> make Read-Only
3.fsync()&&close()&& open(READ)
->f2fs_iget()with large folio
4. open(WRITE), mkwrite on mmap, chmod(WRITE)
-> return error
5.close()andopen()
-> goto #3
6. unlink
-> deregister the inode numberSuggested-by Akilesh Kailash <[email protected]>Signed-off-by Jaegeuk Kim <[email protected]>---
Log from v1:
- add a condition inf2fs_drop_inode
- add DocDocumentation/filesystems/f2fs.rst | 41 ++++++++++++++++++++++++++---- fs/f2fs/checkpoint.c | 2 +- fs/f2fs/data.c | 2 +- fs/f2fs/f2fs.h | 1 + fs/f2fs/file.c | 11 ++++++-- fs/f2fs/inode.c | 19 +++++++++++--- fs/f2fs/super.c | 7 +++++ fs/f2fs/xattr.c | 35 ++++++++++++++++++++++++- fs/f2fs/xattr.h | 6 +++++ 9 files changed, 111 insertions(+), 13 deletions(-)Documentation/filesystems/f2fs.rst +26
-5@@ -1044,11 +1044,14 @@ page allocation for significant performance gains. To minimize code complexity, this support is currently excluded from the write path, which requires handling complex optimizations such as compression and block allocation modes. -This optional feature is triggered only when a file's immutable bit is set. -Consequently, F2FS will return EOPNOTSUPP if a user attempts to open a cached -file with write permissions, even immediately after clearing the bit. Write -access is only restored once the cached inode is dropped. The usage flow is -demonstrated below: +This optional feature is triggered by two mechanisms: the file's immutable bit +or a specific xattr flag. In both cases, F2FS ensures data integrity by +restricting the file to a read-only state while large folios are active. + +1. Immutable Bit Approach: +Triggered when the FS_IMMUTABLE_FL is set. This is a strict enforcement +where the file cannot be modified at all until the bit is cleared and +the cached inode is dropped. .. code-block::@@ -1078,3 +1081,31 @@ demonstrated below: Written 4096 bytes with pattern = zero, total_time = 29 us, max_latency = 28 us # rm /data/testfile_read_seq + +2. XATTR fadvise Approach: +A more flexible registration via extended attributes. + +.. code-block:: + + enum { + F2FS_XATTR_FADV_LARGEFOLIO, + }; + unsigned int value = BIT(F2FS_XATTR_FADV_LARGEFOLIO); + + /* Registers the inode number for large folio support in the subsystem.*/ + # setxattr(file, "user.fadvise", &value, sizeof(unsigned int), 0) + + /* The file must be made Read-Only to transition into the large folio path. */ + # fchmod(0400, fd) + + /* clean up dirty inode state. */Quoted 8 lines
Documentation/filesystems/f2fs.rst demonstrated below: · line 1105
Quoted 4 lines
Documentation/filesystems/f2fs.rst +4
-0+ # fsync(fd) + + /* Drop the inode cache. + # close(fd)If
drop_cacheor memory reclaim was called here, thenLARGE_FOLIO_INOwill be dropped inf2fs_evict_inode(), do we need to keepLARGE_FOLIO_INOifinode->i_nlinkis valid inf2fs_evict_inode()?
Quoted 1 line
We remove it only when we delete the file?
Oh, right, we only remove the ino entry if nlink is zero. I missed that.
Thanks,
Quoted 216 lines
Quoted 216 lines
Thanks,
Quoted 212 lines
Documentation/filesystems/f2fs.rst +6
-0+ + /* f2fs_iget() instantiates the inode with large folio support.*/ + # open() + + /* Returns -EOPNOTSUPP or error to protect the large folio cache.*/ + # open(WRITE), mkwrite on mmap, or chmod(WRITE)fs/f2fs/checkpoint.c +1
-1@@ -778,7 +778,7 @@ void f2fs_remove_ino_entry(struct f2fs_sb_info *sbi, nid_t ino, int type)__remove_ino_entry (sbi, ino, type); } -/* mode should be APPEND_INO, UPDATE_INO or TRANS_DIR_INO */ +/* mode should be APPEND_INO, UPDATE_INO, LARGE_FOLIO_IO, or TRANS_DIR_INO */ bool f2fs_exist_written_data (struct f2fs_sb_info *sbi,nid_t ino,int mode) {struct inode_management *im = &sbi->im[mode];fs/f2fs/data.c +1
-1@@ -2494,7 +2494,7 @@ static int f2fs_read_data_large_folio(struct inode *inode,int ret =0 ;bool folio_in_bio; -if (!IS_IMMUTABLE (inode) ||f2fs_compressed_file (inode)) { +if (f2fs_compressed_file (inode)) {if (folio)folio_unlock (folio);return -EOPNOTSUPP ;fs/f2fs/f2fs.h +1
-0@@ -381,6 +381,7 @@ enum {/* for the list of ino */ enum {ORPHAN_INO ,/* for orphan ino list */ +LARGE_FOLIO_INO ,/* for large folio case */ APPEND_INO ,/* for append ino list */ UPDATE_INO ,/* for update ino list */ TRANS_DIR_INO ,/* for transactions dir ino list */ fs/f2fs/file.c +9
-2@@ -2068,9 +2068,16 @@ static long f2fs_fallocate(struct file *file, int mode,static int f2fs_release_file (struct inode *inode,struct file *filp) { -if (atomic_dec_and_test (&F2FS_I (inode)->open_count)) +if (atomic_dec_and_test (&F2FS_I (inode)->open_count)) {f2fs_remove_donate_inode (inode); - +/* +* In order to get large folio as soon as possible, let's drop +* inode cache asap. See also f2fs_drop_inode. +*/ +if (f2fs_exist_written_data (F2FS_I_SB (inode), + inode->i_ino,LARGE_FOLIO_INO )) +d_drop (filp->f_path.dentry); + }/* * f2fs_release_file is called at every close calls. So we should * not drop any inmemory pages by close called by other process. fs/f2fs/inode.c +16
-3@@ -565,6 +565,20 @@ static bool is_meta_ino(struct f2fs_sb_info *sbi, unsigned int ino) ino ==F2FS_COMPRESS_INO (sbi); } +static void f2fs_mapping_set_large_folio (struct inode *inode) +{ +struct f2fs_sb_info *sbi =F2FS_I_SB (inode); + +if (f2fs_compressed_file (inode)) +return ; +if (f2fs_quota_file (sbi, inode->i_ino)) +return ; +if (IS_IMMUTABLE (inode) || + (f2fs_exist_written_data (sbi, inode->i_ino,LARGE_FOLIO_INO ) && + !(inode->i_mode &S_IWUGO ))) +mapping_set_folio_min_order (inode->i_mapping,0 ); +} +struct inode *f2fs_iget (struct super_block *sb,unsigned long ino) {struct f2fs_sb_info *sbi =F2FS_SB (sb);@@ -620,9 +634,7 @@ struct inode *f2fs_iget(struct super_block *sb, unsigned long ino) inode->i_op = &f2fs_file_inode_operations; inode->i_fop = &f2fs_file_operations; inode->i_mapping->a_ops = &f2fs_dblock_aops; -if (IS_IMMUTABLE (inode) && !f2fs_compressed_file (inode) && - !f2fs_quota_file (sbi, inode->i_ino)) -mapping_set_folio_min_order (inode->i_mapping,0 ); +f2fs_mapping_set_large_folio (inode); }else if (S_ISDIR (inode->i_mode)) { inode->i_op = &f2fs_dir_inode_operations; inode->i_fop = &f2fs_dir_operations;@@ -895,6 +907,7 @@ void f2fs_evict_inode(struct inode *inode)f2fs_remove_ino_entry (sbi, inode->i_ino,APPEND_INO );f2fs_remove_ino_entry (sbi, inode->i_ino,UPDATE_INO );f2fs_remove_ino_entry (sbi, inode->i_ino,FLUSH_INO ); +f2fs_remove_ino_entry (sbi, inode->i_ino,LARGE_FOLIO_INO );if (!is_sbi_flag_set (sbi,SBI_IS_FREEZING )) {sb_start_intwrite (inode->i_sb);fs/f2fs/super.c +7
-0@@ -1844,6 +1844,13 @@ static int f2fs_drop_inode(struct inode *inode)return 1 ; } } +/* +* In order to get large folio as soon as possible, let's drop +* inode cache asap. See also f2fs_release_file. +*/ +if (f2fs_exist_written_data (sbi, inode->i_ino,LARGE_FOLIO_INO ) && + !is_inode_flag_set (inode,FI_DIRTY_INODE )) +return 1 ;/* * This is to avoid a deadlock condition like below. fs/f2fs/xattr.c +34
-1@@ -44,6 +44,16 @@ static void xattr_free(struct f2fs_sb_info *sbi, void *xattr_addr,kfree (xattr_addr); } +static int f2fs_xattr_fadvise_get (struct inode *inode,void *buffer) +{ +if (!buffer) + goto out; +if (mapping_large_folio_support (inode->i_mapping)) + *((unsigned int *)buffer) |=BIT (F2FS_XATTR_FADV_LARGEFOLIO ); +out: +return sizeof (unsigned int ); +} +static int f2fs_xattr_generic_get (const struct xattr_handler *handler,struct dentry *unused,struct inode *inode,const char *name,void *buffer,size_t size)@@ -61,10 +71,29 @@ static int f2fs_xattr_generic_get(const struct xattr_handler *handler,default :return -EINVAL ; } +if (handler->flags ==F2FS_XATTR_INDEX_USER && + !strcmp (name,"fadvise" )) +return f2fs_xattr_fadvise_get (inode, buffer); +return f2fs_getxattr (inode, handler->flags, name, buffer, size,NULL ); } +static int f2fs_xattr_fadvise_set (struct inode *inode,const void *value) +{ +unsigned int new_fadvise; + + new_fadvise = *(unsigned int *)value; + +if (new_fadvise &BIT (F2FS_XATTR_FADV_LARGEFOLIO )) +f2fs_add_ino_entry (F2FS_I_SB (inode), + inode->i_ino,LARGE_FOLIO_INO ); +else +f2fs_remove_ino_entry (F2FS_I_SB (inode), + inode->i_ino,LARGE_FOLIO_INO ); +return 0 ; +} + static int f2fs_xattr_generic_set(const struct xattr_handler *handler, struct mnt_idmap *idmap, struct dentry *unused, struct inode *inode,@@ -84,6 +113,10 @@ static int f2fs_xattr_generic_set(const struct xattr_handler *handler,default :return -EINVAL ; } +if (handler->flags ==F2FS_XATTR_INDEX_USER && + !strcmp (name,"fadvise" )) +return f2fs_xattr_fadvise_set (inode, value); +return f2fs_setxattr (inode, handler->flags, name, value, size,NULL , flags); }@@ -842,4 +875,4 @@ int __init f2fs_init_xattr_cache(void)void f2fs_destroy_xattr_cache (void ) {kmem_cache_destroy (inline_xattr_slab); -} +}fs/f2fs/xattr.h +6
-0@@ -24,6 +24,7 @@#define F2FS_XATTR_REFCOUNT_MAX 1024/* Name indexes */ +#define F2FS_USER_FADVISE_NAME "user.fadvise"#define F2FS_SYSTEM_ADVISE_NAME "system.advise"#define F2FS_XATTR_INDEX_USER 1#define F2FS_XATTR_INDEX_POSIX_ACL_ACCESS 2@@ -39,6 +40,11 @@#define F2FS_XATTR_NAME_ENCRYPTION_CONTEXT "c"#define F2FS_XATTR_NAME_VERITY "v" +/* used for F2FS_USER_FADVISE_NAME */ +enum { +F2FS_XATTR_FADV_LARGEFOLIO , +}; +struct f2fs_xattr_header {__le32 h_magic;/* magic number for identification */ __le32 h_refcount;/* reference count */
Quoted 19 lines · On 4/10/2026 9:16 AM, Jaegeuk Kim via Linux-f2fs-devel wrote:
enum {
F2FS_XATTR_FADV_LARGEFOLIO,
};unsigned int value =
BIT(F2FS_XATTR_FADV_LARGEFOLIO);1.
setxattr(file, "user.fadvise", &value, sizeof(unsigned int), 0)-> register the inode number for large folio
2.chmod(0400, file)
-> make Read-Only
3.fsync()&&close()&& open(READ)
->f2fs_iget()with large folio
4. open(WRITE), mkwrite on mmap, chmod(WRITE)
-> return error
5.close()andopen()
-> goto #3
6. unlink
-> deregister the inode number
Quoted 2 lines
Suggested-by Akilesh Kailash <[email protected]>Signed-off-by Jaegeuk Kim <[email protected]>
Thanks,