erofs: allow sharing page cache with the same aops only
PATCH 1/1 erofs: allow sharing page cache with the same aops only
Inode with identical data but different @aops cannot be mixed because the page cache is managed by different subsystems (e.g., @aops for compressed on-disk inodes cannot handle plain on-disk inodes).
In this patch, we never allow inodes to share the page cache among plain, compressed, and fileio cases. When a shared inode is created, we initialize @aops that is the same as the initial real inode, and subsequent inodes cannot share the page cache if the inferred @aops differ from the corresponding shared inode.
This is reasonable as a first step because, in typical use cases, if an inode is compressible, it will fall into compressed inodes across different filesystem images unless users use plain filesystems. However, in that cases, users will use plain filesystems all the time.
--- fs/erofs/inode.c | 3 ++- fs/erofs/internal.h | 20 +++++++++----------- fs/erofs/ishare.c | 14 +++++++++----- 3 files changed, 20 insertions(+), 17 deletions(-)
fs/erofs/inode.c +2 -1
@@ -254,7 +254,8 @@ static int erofs_fill_inode(struct inode *inode) }mapping_set_large_folios (inode->i_mapping); -return erofs_inode_set_aops (inode, inode, false); + inode->i_mapping->a_ops =erofs_get_aops (inode, false); +return IS_ERR (inode->i_mapping->a_ops) ?PTR_ERR (inode->i_mapping->a_ops) :0 ; }/*
fs/erofs/internal.h +9 -11
@@ -471,26 +471,24 @@ static inline void *erofs_vm_map_ram(struct page **pages, unsigned int count)return NULL ; } -static inline int erofs_inode_set_aops (struct inode *inode, -struct inode *realinode,bool no_fscache) +static inline const struct address_space_operations * +erofs_get_aops (struct inode *realinode,bool no_fscache) {if (erofs_inode_is_data_compressed (EROFS_I (realinode)->datalayout)) {if (!IS_ENABLED (CONFIG_EROFS_FS_ZIP )) -return -EOPNOTSUPP ; +return ERR_PTR (-EOPNOTSUPP );DO_ONCE_LITE_IF (realinode->i_blkbits !=PAGE_SHIFT , erofs_info, realinode->i_sb,"EXPERIMENTAL EROFS subpage compressed block support in use. Use at your own risk!" ); - inode->i_mapping->a_ops = &z_erofs_aops; -return 0 ; +return &z_erofs_aops; } - inode->i_mapping->a_ops = &erofs_aops; -if (IS_ENABLED (CONFIG_EROFS_FS_ONDEMAND ) && !no_fscache && -erofs_is_fscache_mode (realinode->i_sb)) - inode->i_mapping->a_ops = &erofs_fscache_access_aops;if (IS_ENABLED (CONFIG_EROFS_FS_BACKED_BY_FILE ) &&erofs_is_fileio_mode (EROFS_SB (realinode->i_sb))) - inode->i_mapping->a_ops = &erofs_fileio_aops; -return 0 ; +return &erofs_fileio_aops; +if (IS_ENABLED (CONFIG_EROFS_FS_ONDEMAND ) && !no_fscache && +erofs_is_fscache_mode (realinode->i_sb)) +return &erofs_fscache_access_aops; +return &erofs_aops; }int erofs_register_sysfs (struct super_block *sb);
fs/erofs/ishare.c +9 -5
@@ -40,10 +40,14 @@ bool erofs_ishare_fill_inode(struct inode *inode) {struct erofs_sb_info *sbi =EROFS_SB (inode->i_sb);struct erofs_inode *vi =EROFS_I (inode); +const struct address_space_operations *aops;struct erofs_inode_fingerprint fp;struct inode *sharedinode;unsigned long hash; + aops =erofs_get_aops (inode, true); +if (IS_ERR (aops)) +return false;if (erofs_xattr_fill_inode_fingerprint (&fp, inode, sbi->domain_id))return false; hash =xxh32 (fp.opaque, fp.size,0 );
@@ -56,15 +60,15 @@ bool erofs_ishare_fill_inode(struct inode *inode) }if (inode_state_read_once (sharedinode) &I_NEW ) { -if (erofs_inode_set_aops (sharedinode, inode, true)) { -iget_failed (sharedinode); -kfree (fp.opaque); -return false; - } + sharedinode->i_mapping->a_ops = aops; sharedinode->i_size = vi->vfs_inode.i_size;unlock_new_inode (sharedinode); }else {kfree (fp.opaque); +if (aops != sharedinode->i_mapping->a_ops) { +iput (sharedinode); +return false; + }if (sharedinode->i_size != vi->vfs_inode.i_size) { _erofs_printk(inode->i_sb, KERN_WARNING "size(%lld:%lld) not matches for the same fingerprint\n",
Signature · 1 line
2.22.0
Gao Xiang
maintainerHi Hongbo,
Quoted 30 lines · Hongbo Li
Inode with identical data but different @aops cannot be mixed because the page cache is managed by different subsystems (e.g., @aops for compressed on-disk inodes cannot handle plain on-disk inodes).
In this patch, we never allow inodes to share the page cache among plain, compressed, and fileio cases. When a shared inode is created, we initialize @aops that is the same as the initial real inode, and subsequent inodes cannot share the page cache if the inferred @aops differ from the corresponding shared inode.
This is reasonable as a first step because, in typical use cases, if an inode is compressible, it will fall into compressed inodes across different filesystem images unless users use plain filesystems. However, in that cases, users will use plain filesystems all the time.
Fixes 5ef3208e3be5 ("erofs: introduce the page cache share feature")Signed-off-by Hongbo Li <[email protected]>--- fs/erofs/inode.c | 3 ++- fs/erofs/internal.h | 20 +++++++++----------- fs/erofs/ishare.c | 14 +++++++++----- 3 files changed, 20 insertions(+), 17 deletions(-)fs/erofs/inode.c +0
-0
fs/erofs/inode.c static int erofs_fill_inode(struct inode *inode) · line 258
Quoted 6 lines
fs/erofs/inode.c +2
-1@@ -254,7 +254,8 @@ static int erofs_fill_inode(struct inode *inode) }mapping_set_large_folios (inode->i_mapping); -return erofs_inode_set_aops (inode, inode, false); + inode->i_mapping->a_ops =erofs_get_aops (inode, false); +return IS_ERR (inode->i_mapping->a_ops) ?PTR_ERR (inode->i_mapping->a_ops) :0 ;
I hope there is an aops variable instead of assigning inode->i_mapping->a_ops directly.
Quoted 29 lines
fs/erofs/inode.c +0
-0}/* fs/erofs/internal.h +4
-7@@ -471,26 +471,24 @@ static inline void *erofs_vm_map_ram(struct page **pages, unsigned int count)return NULL ; } -static inline int erofs_inode_set_aops (struct inode *inode, -struct inode *realinode,bool no_fscache) +static inline const struct address_space_operations * +erofs_get_aops (struct inode *realinode,bool no_fscache) {if (erofs_inode_is_data_compressed (EROFS_I (realinode)->datalayout)) {if (!IS_ENABLED (CONFIG_EROFS_FS_ZIP )) -return -EOPNOTSUPP ; +return ERR_PTR (-EOPNOTSUPP );DO_ONCE_LITE_IF (realinode->i_blkbits !=PAGE_SHIFT , erofs_info, realinode->i_sb,"EXPERIMENTAL EROFS subpage compressed block support in use. Use at your own risk!" ); - inode->i_mapping->a_ops = &z_erofs_aops; -return 0 ; +return &z_erofs_aops; } - inode->i_mapping->a_ops = &erofs_aops; - if (IS_ENABLED(CONFIG_EROFS_FS_ONDEMAND) && !no_fscache &&
fs/erofs/internal.h static inline void *erofs_vm_map_ram(struct page **pages, unsigned int count) · line 490
Quoted 10 lines
fs/erofs/internal.h +4
-4- erofs_is_fscache_mode(realinode->i_sb)) - inode->i_mapping->a_ops = &erofs_fscache_access_aops;if (IS_ENABLED (CONFIG_EROFS_FS_BACKED_BY_FILE ) &&erofs_is_fileio_mode (EROFS_SB (realinode->i_sb))) - inode->i_mapping->a_ops = &erofs_fileio_aops; -return 0 ; +return &erofs_fileio_aops; +if (IS_ENABLED (CONFIG_EROFS_FS_ONDEMAND ) && !no_fscache && +erofs_is_fscache_mode (realinode->i_sb)) +return &erofs_fscache_access_aops;
Can you rearrange it as
if (IS_ENABLED(CONFIG_EROFS_FS_ONDEMAND) && !no_fscache && erofs_is_fscache_mode(realinode->i_sb)) return &erofs_fscache_access_aops; if (IS_ENABLED(CONFIG_EROFS_FS_BACKED_BY_FILE) && erofs_is_fileio_mode(EROFS_SB(realinode->i_sb))) inode->i_mapping->a_ops = &erofs_fileio_aops; return &erofs_aops;
?
Thanks,
Gao Xiang
Quoted 8 lines · Gao Xiang
Hi Hongbo,
Quoted 5 lines · Hongbo Li
Inode with identical data but different @aops cannot be mixed because the page cache is managed by different subsystems (e.g., @aops for compressed on-disk inodes cannot handle plain on-disk inodes).
...
Quoted 8 lines
Quoted 8 lines
fs/erofs/inode.c +0
-0@@ -254,7 +254,8 @@ static int erofs_fill_inode(struct inode *inode) }
Quoted 8 lines
fs/erofs/inode.c static int erofs_fill_inode(struct inode *inode) · line 258
Quoted 4 lines
fs/erofs/inode.c +2
-1mapping_set_large_folios (inode->i_mapping); -return erofs_inode_set_aops (inode, inode, false); + inode->i_mapping->a_ops =erofs_get_aops (inode, false); +return IS_ERR (inode->i_mapping->a_ops) ?PTR_ERR (inode->i_mapping->a_ops) :0 ;I hope there is an aops variable instead of assigning
inode->i_mapping->a_opsdirectly.
Ok, thank you.
Quoted 41 lines
Quoted 29 lines
fs/erofs/inode.c +0
-0}/* fs/erofs/internal.h +4
-7@@ -471,26 +471,24 @@ static inline void *erofs_vm_map_ram(struct page **pages, unsigned int count)return NULL ; } -static inline int erofs_inode_set_aops (struct inode *inode, -struct inode *realinode,bool no_fscache) +static inline const struct address_space_operations * +erofs_get_aops (struct inode *realinode,bool no_fscache) {if (erofs_inode_is_data_compressed (EROFS_I (realinode)->datalayout)) {if (!IS_ENABLED (CONFIG_EROFS_FS_ZIP )) -return -EOPNOTSUPP ; +return ERR_PTR (-EOPNOTSUPP );DO_ONCE_LITE_IF (realinode->i_blkbits !=PAGE_SHIFT , erofs_info, realinode->i_sb,"EXPERIMENTAL EROFS subpage compressed block support in use. Use at your own risk!" ); - inode->i_mapping->a_ops = &z_erofs_aops; -return 0 ; +return &z_erofs_aops; } - inode->i_mapping->a_ops = &erofs_aops; - if (IS_ENABLED(CONFIG_EROFS_FS_ONDEMAND) && !no_fscache &&fs/erofs/internal.h static inline void *erofs_vm_map_ram(struct page **pages, unsigned int count) · line 490
Quoted 10 lines
fs/erofs/internal.h +4
-4- erofs_is_fscache_mode(realinode->i_sb)) - inode->i_mapping->a_ops = &erofs_fscache_access_aops;if (IS_ENABLED (CONFIG_EROFS_FS_BACKED_BY_FILE ) &&erofs_is_fileio_mode (EROFS_SB (realinode->i_sb))) - inode->i_mapping->a_ops = &erofs_fileio_aops; -return 0 ; +return &erofs_fileio_aops; +if (IS_ENABLED (CONFIG_EROFS_FS_ONDEMAND ) && !no_fscache && +erofs_is_fscache_mode (realinode->i_sb)) +return &erofs_fscache_access_aops;Can you rearrange it as
Quoted 8 lines
if (IS_ENABLED(CONFIG_EROFS_FS_ONDEMAND) && !no_fscache && erofs_is_fscache_mode(realinode->i_sb)) return &erofs_fscache_access_aops; if (IS_ENABLED(CONFIG_EROFS_FS_BACKED_BY_FILE) && erofs_is_fileio_mode(EROFS_SB(realinode->i_sb))) inode->i_mapping->a_ops = &erofs_fileio_aops; return &erofs_aops;
Ok, they are equal. Since the EROFS in fscache mode can be fileio mode. And I will rearrange it in next version.
Thanks,
Hongbo
Quoted 5 lines
?
Thanks,
Gao Xiang