erofs: add erofs_sb_free() helper
PATCH 1/4 erofs: add erofs_sb_free() helper
Unify the common parts of erofs_fc_free() and erofs_kill_sb() as erofs_sb_free().
Thus, fput() in erofs_fc_get_tree() is no longer needed, too.
--- fs/erofs/super.c | 36 +++++++++++++++++++----------------- 1 file changed, 19 insertions(+), 17 deletions(-)
fs/erofs/super.c +19 -17
@@ -703,16 +703,19 @@ static int erofs_fc_get_tree(struct fs_context *fc) GET_TREE_BDEV_QUIET_LOOKUP : 0);#ifdef CONFIG_EROFS_FS_BACKED_BY_FILE if (ret == -ENOTBLK ) { +struct file *file; +if (!fc->source)return invalf (fc,"No source specified" ); - sbi->fdev =filp_open (fc->source,O_RDONLY |O_LARGEFILE ,0 ); -if (IS_ERR (sbi->fdev)) -return PTR_ERR (sbi->fdev); + + file =filp_open (fc->source,O_RDONLY |O_LARGEFILE ,0 ); +if (IS_ERR (file)) +return PTR_ERR (file); + sbi->fdev = file;if (S_ISREG (file_inode (sbi->fdev)->i_mode) && sbi->fdev->f_mapping->a_ops->read_folio)return get_tree_nodev (fc, erofs_fc_fill_super); -fput (sbi->fdev); }#endif return ret;
@@ -763,19 +766,24 @@ static void erofs_free_dev_context(struct erofs_dev_context *devs)kfree (devs); } -static void erofs_fc_free (struct fs_context *fc) +static void erofs_sb_free (struct erofs_sb_info *sbi) { -struct erofs_sb_info *sbi = fc->s_fs_info; - -if (!sbi) -return ; -erofs_free_dev_context (sbi->devs);kfree (sbi->fsid);kfree (sbi->domain_id); +if (sbi->fdev) +fput (sbi->fdev);kfree (sbi); } +static void erofs_fc_free (struct fs_context *fc) +{ +struct erofs_sb_info *sbi = fc->s_fs_info; + +if (sbi)/* free here if an error occurs before transferring to sb */ +erofs_sb_free (sbi); +} +static const struct fs_context_operations erofs_context_ops = { .parse_param = erofs_fc_parse_param, .get_tree = erofs_fc_get_tree,
@@ -813,15 +821,9 @@ static void erofs_kill_sb(struct super_block *sb)kill_anon_super (sb); elsekill_block_super (sb ); - -erofs_free_dev_context (sbi->devs);fs_put_dax (sbi->dax_dev,NULL );erofs_fscache_unregister_fs (sb); -kfree (sbi->fsid); -kfree (sbi->domain_id); -if (sbi->fdev) -fput (sbi->fdev); -kfree (sbi); +erofs_sb_free (sbi); sb->s_fs_info =NULL ; }
Signature · 1 line
2.43.5
PATCH 2/4 erofs: use `struct erofs_device_info` for the primary device
Instead of just listing each one directly in struct erofs_sb_info except that we still use sb->s_bdev for the primary block device.
--- fs/erofs/data.c | 10 +++------- fs/erofs/internal.h | 7 ++----- fs/erofs/super.c | 27 +++++++++++++-------------- 3 files changed, 18 insertions(+), 26 deletions(-)
fs/erofs/data.c +3 -7
@@ -56,7 +56,7 @@ void erofs_init_metabuf(struct erofs_buf *buf, struct super_block *sb) buf->file =NULL ;if (erofs_is_fileio_mode (sbi)) { - buf->file = sbi->fdev;/* some fs like FUSE needs it */ + buf->file = sbi->dif0.file;/* some fs like FUSE needs it */ buf->mapping = buf->file->f_mapping; }else if (erofs_is_fscache_mode (sb)) buf->mapping = sbi->s_fscache->inode->i_mapping;
@@ -201,12 +201,8 @@ int erofs_map_dev(struct super_block *sb, struct erofs_map_dev *map)erofs_off_t startoff, length;int id; - map->m_bdev = sb->s_bdev; - map->m_daxdev =EROFS_SB (sb)->dax_dev; - map->m_dax_part_off =EROFS_SB (sb)->dax_part_off; - map->m_fscache =EROFS_SB (sb)->s_fscache; - map->m_fp =EROFS_SB (sb)->fdev; - +erofs_fill_from_devinfo (map, &EROFS_SB (sb)->dif0); + map->m_bdev = sb->s_bdev;/* use s_bdev for the primary device */ if (map->m_deviceid) {down_read (&devs->rwsem); dif =idr_find (&devs->tree, map->m_deviceid -1 );
fs/erofs/internal.h +2 -5
@@ -107,6 +107,7 @@ struct erofs_xattr_prefix_item { };struct erofs_sb_info { +struct erofs_device_info dif0;struct erofs_mount_opts opt;/* options */ #ifdef CONFIG_EROFS_FS_ZIP /* list for all registered superblocks, mainly for shrinker */
@@ -124,13 +125,9 @@ struct erofs_sb_info {struct erofs_sb_lz4_info lz4;#endif /* CONFIG_EROFS_FS_ZIP */ -struct file *fdev;struct inode *packed_inode;struct erofs_dev_context *devs; -struct dax_device *dax_dev; -u64 dax_part_off;u64 total_blocks; -u32 primarydevice_blocks;u32 meta_blkaddr;#ifdef CONFIG_EROFS_FS_XATTR
@@ -187,7 +184,7 @@ struct erofs_sb_info {static inline bool erofs_is_fileio_mode (struct erofs_sb_info *sbi) { -return IS_ENABLED (CONFIG_EROFS_FS_BACKED_BY_FILE ) && sbi->fdev; +return IS_ENABLED (CONFIG_EROFS_FS_BACKED_BY_FILE ) && sbi->dif0.file; }static inline bool erofs_is_fscache_mode (struct super_block *sb)
fs/erofs/super.c +13 -14
@@ -203,7 +203,7 @@ static int erofs_scan_devices(struct super_block *sb,struct erofs_device_info *dif;int id, err =0 ; - sbi->total_blocks = sbi->primarydevice_blocks; + sbi->total_blocks = sbi->dif0.blocks;if (!erofs_sb_has_device_table (sbi)) ondisk_extradevs =0 ;else
@@ -307,7 +307,7 @@ static int erofs_read_superblock(struct super_block *sb) sbi->sb_size); goto out; } - sbi->primarydevice_blocks =le32_to_cpu (dsb->blocks); + sbi->dif0.blocks =le32_to_cpu (dsb->blocks); sbi->meta_blkaddr =le32_to_cpu (dsb->meta_blkaddr);#ifdef CONFIG_EROFS_FS_XATTR sbi->xattr_blkaddr =le32_to_cpu (dsb->xattr_blkaddr);
@@ -602,9 +602,8 @@ static int erofs_fc_fill_super(struct super_block *sb, struct fs_context *fc)return -EINVAL ; } - sbi->dax_dev =fs_dax_get_by_bdev (sb->s_bdev, - &sbi->dax_part_off, -NULL ,NULL ); + sbi->dif0.dax_dev =fs_dax_get_by_bdev (sb->s_bdev, + &sbi->dif0.dax_part_off,NULL ,NULL ); } err =erofs_read_superblock (sb);
@@ -627,7 +626,7 @@ static int erofs_fc_fill_super(struct super_block *sb, struct fs_context *fc) }if (test_opt (&sbi->opt,DAX_ALWAYS )) { -if (!sbi->dax_dev) { +if (!sbi->dif0.dax_dev) {errorfc (fc,"DAX unsupported by block device. Turning off DAX." );clear_opt (&sbi->opt,DAX_ALWAYS ); }else if (sbi->blkszbits !=PAGE_SHIFT ) {
@@ -707,14 +706,13 @@ static int erofs_fc_get_tree(struct fs_context *fc)if (!fc->source)return invalf (fc,"No source specified" ); - file =filp_open (fc->source,O_RDONLY |O_LARGEFILE ,0 );if (IS_ERR (file))return PTR_ERR (file); - sbi->fdev = file; + sbi->dif0.file = file; -if (S_ISREG (file_inode (sbi->fdev)->i_mode) && - sbi->fdev->f_mapping->a_ops->read_folio) +if (S_ISREG (file_inode (sbi->dif0.file)->i_mode) && + sbi->dif0.file->f_mapping->a_ops->read_folio) return get_tree_nodev(fc, erofs_fc_fill_super); }#endif
@@ -771,8 +769,8 @@ static void erofs_sb_free(struct erofs_sb_info *sbi)erofs_free_dev_context (sbi->devs);kfree (sbi->fsid);kfree (sbi->domain_id); -if (sbi->fdev) -fput (sbi->fdev); +if (sbi->dif0.file) +fput (sbi->dif0.file);kfree (sbi); }
@@ -817,11 +815,12 @@ static void erofs_kill_sb(struct super_block *sb) {struct erofs_sb_info *sbi =EROFS_SB (sb); -if ((IS_ENABLED (CONFIG_EROFS_FS_ONDEMAND ) && sbi->fsid) || sbi->fdev) +if ((IS_ENABLED (CONFIG_EROFS_FS_ONDEMAND ) && sbi->fsid) || + sbi->dif0.file)kill_anon_super (sb);else kill_block_super (sb); -fs_put_dax (sbi->dax_dev,NULL ); +fs_put_dax (sbi->dif0.dax_dev,NULL );erofs_fscache_unregister_fs (sb);erofs_sb_free (sbi); sb->s_fs_info =NULL ;
Signature · 1 line
2.43.5
Re: [PATCH 2/4] erofs: use `struct erofs_device_info` for the primary device
Quoted 4 lines · Gao Xiang
Instead of just listing each one directly in
struct erofs_sb_infoexcept that we still usesb->s_bdevfor the primary block device.Signed-off-by Gao Xiang <[email protected]>
Thanks,
PATCH 3/4 erofs: reference `struct erofs_device_info` for erofs_map_dev
In reply to Gao XiangRecord m_sb and m_dif to replace m_fscache, m_daxdev, m_fp and m_dax_part_off in order to simplify the codebase.
Note that m_bdev is still left since it can be assigned from sb->s_bdev directly.
--- fs/erofs/data.c | 26 ++++++++++---------------- fs/erofs/fileio.c | 2 +- fs/erofs/internal.h | 6 ++---- 3 files changed, 13 insertions(+), 21 deletions(-)
fs/erofs/data.c +10 -16
@@ -179,19 +179,13 @@ int erofs_map_blocks(struct inode *inode, struct erofs_map_blocks *map) }static void erofs_fill_from_devinfo (struct erofs_map_dev *map, -struct erofs_device_info *dif) +struct super_block *sb,struct erofs_device_info *dif) { + map->m_sb = sb; + map->m_dif = dif; map->m_bdev =NULL ; - map->m_fp =NULL ; -if (dif->file) { -if (S_ISBLK (file_inode (dif->file)->i_mode)) - map->m_bdev =file_bdev (dif->file); -else - map->m_fp = dif->file; - } - map->m_daxdev = dif->dax_dev; - map->m_dax_part_off = dif->dax_part_off; - map->m_fscache = dif->fscache; +if (dif->file &&S_ISBLK (file_inode (dif->file)->i_mode)) + map->m_bdev =file_bdev (dif->file); }int erofs_map_dev (struct super_block *sb,struct erofs_map_dev *map)
@@ -201,7 +195,7 @@ int erofs_map_dev(struct super_block *sb, struct erofs_map_dev *map)erofs_off_t startoff, length;int id; -erofs_fill_from_devinfo (map, &EROFS_SB (sb)->dif0); +erofs_fill_from_devinfo (map, sb, &EROFS_SB (sb)->dif0); map->m_bdev = sb->s_bdev;/* use s_bdev for the primary device */ if (map->m_deviceid) {down_read (&devs->rwsem);
@@ -215,7 +209,7 @@ int erofs_map_dev(struct super_block *sb, struct erofs_map_dev *map)up_read (&devs->rwsem);return 0 ; } -erofs_fill_from_devinfo (map, dif); +erofs_fill_from_devinfo (map, sb, dif);up_read (&devs->rwsem); }else if (devs->extra_devices && !devs->flatdev) {down_read (&devs->rwsem);
@@ -228,7 +222,7 @@ int erofs_map_dev(struct super_block *sb, struct erofs_map_dev *map)if (map->m_pa >= startoff && map->m_pa < startoff + length) { map->m_pa -= startoff; -erofs_fill_from_devinfo (map, dif); +erofs_fill_from_devinfo (map, sb, dif);break ; } }
@@ -298,7 +292,7 @@ static int erofs_iomap_begin(struct inode *inode, loff_t offset, loff_t length, iomap->offset = map.m_la;if (flags &IOMAP_DAX ) - iomap->dax_dev = mdev.m_daxdev; + iomap->dax_dev = mdev.m_dif->dax_dev;else iomap->bdev = mdev.m_bdev; iomap->length = map.m_llen;
@@ -327,7 +321,7 @@ static int erofs_iomap_begin(struct inode *inode, loff_t offset, loff_t length, iomap->type =IOMAP_MAPPED ; iomap->addr = mdev.m_pa;if (flags &IOMAP_DAX ) - iomap->addr += mdev.m_dax_part_off; + iomap->addr += mdev.m_dif->dax_part_off; }return 0 ; }
fs/erofs/fileio.c +1 -1
@@ -67,7 +67,7 @@ static struct erofs_fileio_rq *erofs_fileio_rq_alloc(struct erofs_map_dev *mdev) GFP_KERNEL | __GFP_NOFAIL);bio_init (&rq->bio,NULL , rq->bvecs,BIO_MAX_VECS ,REQ_OP_READ ); - rq->iocb.ki_filp = mdev->m_fp; + rq->iocb.ki_filp = mdev->m_dif->file;return rq; }
fs/erofs/internal.h +2 -4
@@ -354,11 +354,9 @@ enum { };struct erofs_map_dev { -struct erofs_fscache *m_fscache; +struct super_block *m_sb; +struct erofs_device_info *m_dif;struct block_device *m_bdev; -struct dax_device *m_daxdev; -struct file *m_fp; -u64 m_dax_part_off;erofs_off_t m_pa;unsigned int m_deviceid;
Signature · 1 line
2.43.5
Re: [PATCH 3/4] erofs: reference `struct erofs_device_info` for erofs_map_dev
Quoted 7 lines · Gao Xiang
Record
m_sbandm_difto replacem_fscache,m_daxdev,m_fpandm_dax_part_offin order to simplify the codebase.Note that
m_bdevis still left since it can be assigned fromsb->s_bdevdirectly.Signed-off-by Gao Xiang <[email protected]>
Thanks,
PATCH v2 3/4 erofs: reference `struct erofs_device_info` for erofs_map_dev
In reply to Gao XiangRecord m_sb and m_dif to replace m_fscache, m_daxdev, m_fp and m_dax_part_off in order to simplify the codebase.
Note that m_bdev is still left since it can be assigned from sb->s_bdev directly.
---
v1: https://lore.kernel.org/r/[email protected]
changes since v1:
- fix fscache build.
fs/erofs/data.c | 26 ++++++++++---------------- fs/erofs/fileio.c | 2 +- fs/erofs/fscache.c | 4 ++-- fs/erofs/internal.h | 6 ++---- 4 files changed, 15 insertions(+), 23 deletions(-)
fs/erofs/data.c +10 -16
@@ -179,19 +179,13 @@ int erofs_map_blocks(struct inode *inode, struct erofs_map_blocks *map) }static void erofs_fill_from_devinfo (struct erofs_map_dev *map, -struct erofs_device_info *dif) +struct super_block *sb,struct erofs_device_info *dif) { + map->m_sb = sb; + map->m_dif = dif; map->m_bdev =NULL ; - map->m_fp =NULL ; -if (dif->file) { -if (S_ISBLK (file_inode (dif->file)->i_mode)) - map->m_bdev =file_bdev (dif->file); -else - map->m_fp = dif->file; - } - map->m_daxdev = dif->dax_dev; - map->m_dax_part_off = dif->dax_part_off; - map->m_fscache = dif->fscache; +if (dif->file &&S_ISBLK (file_inode (dif->file)->i_mode)) + map->m_bdev =file_bdev (dif->file); }int erofs_map_dev (struct super_block *sb,struct erofs_map_dev *map)
@@ -201,7 +195,7 @@ int erofs_map_dev(struct super_block *sb, struct erofs_map_dev *map)erofs_off_t startoff, length;int id; -erofs_fill_from_devinfo (map, &EROFS_SB (sb)->dif0); +erofs_fill_from_devinfo (map, sb, &EROFS_SB (sb)->dif0); map->m_bdev = sb->s_bdev;/* use s_bdev for the primary device */ if (map->m_deviceid) {down_read (&devs->rwsem);
@@ -215,7 +209,7 @@ int erofs_map_dev(struct super_block *sb, struct erofs_map_dev *map)up_read (&devs->rwsem);return 0 ; } -erofs_fill_from_devinfo (map, dif); +erofs_fill_from_devinfo (map, sb, dif);up_read (&devs->rwsem); }else if (devs->extra_devices && !devs->flatdev) {down_read (&devs->rwsem);
@@ -228,7 +222,7 @@ int erofs_map_dev(struct super_block *sb, struct erofs_map_dev *map)if (map->m_pa >= startoff && map->m_pa < startoff + length) { map->m_pa -= startoff; -erofs_fill_from_devinfo (map, dif); +erofs_fill_from_devinfo (map, sb, dif);break ; } }
@@ -298,7 +292,7 @@ static int erofs_iomap_begin(struct inode *inode, loff_t offset, loff_t length, iomap->offset = map.m_la;if (flags &IOMAP_DAX ) - iomap->dax_dev = mdev.m_daxdev; + iomap->dax_dev = mdev.m_dif->dax_dev;else iomap->bdev = mdev.m_bdev; iomap->length = map.m_llen;
@@ -327,7 +321,7 @@ static int erofs_iomap_begin(struct inode *inode, loff_t offset, loff_t length, iomap->type =IOMAP_MAPPED ; iomap->addr = mdev.m_pa;if (flags &IOMAP_DAX ) - iomap->addr += mdev.m_dax_part_off; + iomap->addr += mdev.m_dif->dax_part_off; }return 0 ; }
fs/erofs/fileio.c +1 -1
@@ -67,7 +67,7 @@ static struct erofs_fileio_rq *erofs_fileio_rq_alloc(struct erofs_map_dev *mdev) GFP_KERNEL | __GFP_NOFAIL);bio_init (&rq->bio,NULL , rq->bvecs,BIO_MAX_VECS ,REQ_OP_READ ); - rq->iocb.ki_filp = mdev->m_fp; + rq->iocb.ki_filp = mdev->m_dif->file;return rq; }
fs/erofs/fscache.c +2 -2
@@ -198,7 +198,7 @@ struct bio *erofs_fscache_bio_alloc(struct erofs_map_dev *mdev) io =kmalloc (sizeof (*io),GFP_KERNEL | __GFP_NOFAIL);bio_init (&io->bio,NULL , io->bvecs,BIO_MAX_VECS ,REQ_OP_READ ); - io->io.private = mdev->m_fscache->cookie; + io->io.private = mdev->m_dif->fscache->cookie; io->io.end_io = erofs_fscache_bio_endio;refcount_set (&io->io.ref,1 );return &io->bio;
@@ -316,7 +316,7 @@ static int erofs_fscache_data_read_slice(struct erofs_fscache_rq *req)if (!io)return -ENOMEM ;iov_iter_xarray (&io->iter,ITER_DEST , &mapping->i_pages, pos, count); - ret =erofs_fscache_read_io_async (mdev.m_fscache->cookie, + ret =erofs_fscache_read_io_async (mdev.m_dif->fscache->cookie, mdev.m_pa + (pos - map.m_la), io);erofs_fscache_req_io_put (io);
fs/erofs/internal.h +2 -4
@@ -354,11 +354,9 @@ enum { };struct erofs_map_dev { -struct erofs_fscache *m_fscache; +struct super_block *m_sb; +struct erofs_device_info *m_dif;struct block_device *m_bdev; -struct dax_device *m_daxdev; -struct file *m_fp; -u64 m_dax_part_off;erofs_off_t m_pa;unsigned int m_deviceid;
Signature · 1 line
2.43.5
kernel test robot
build botRe: [PATCH 3/4] erofs: reference `struct erofs_device_info` for erofs_map_dev
In reply to Gao Xiangkernel test robot noticed the following build errors:
Hi Gao,
kernel test robot noticed the following build errors:
[auto build test ERROR on xiang-erofs/dev]
[also build test ERROR on linus/master v6.13-rc2 next-20241213] [cannot apply to xiang-erofs/dev-test xiang-erofs/fixes]
[If your patch is applied to the wrong git tree, kindly drop us a note. And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch#_base_tree_information]
url: https://github.com/intel-lab-lkp/linux/commits/Gao-Xiang/erofs-use-struct-erofs_device_info-for-the-primary-device/20241213-115709 base: https://git.kernel.org/pub/scm/linux/kernel/git/xiang/erofs.git dev patch link: https://lore.kernel.org/r/20241212133504.2047178-3-hsiangkao%40linux.alibaba.com patch subject: [PATCH 3/4] erofs: reference `struct erofs_device_info` for erofs_map_dev config: riscv-randconfig-001-20241214 (https://download.01.org/0day-ci/archive/20241214/[email protected]/config) compiler: clang version 20.0.0git (https://github.com/llvm/llvm-project 2dc22615fd46ab2566d0f26d5ba234ab12dc4bf8) reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20241214/[email protected]/reproduce)
If you fix the issue in a separate patch/commit (i.e. not just a new version of the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <[email protected]>
| Closes: https://lore.kernel.org/oe-kbuild-all/[email protected]/
All errors (new ones prefixed by >>):
In file included from include/linux/fs_context.h:14:
In file included from include/linux/security.h:35:
In file included from include/linux/bpf.h:31:
In file included from include/linux/memcontrol.h:13:
In file included from include/linux/cgroup.h:26:
In file included from include/linux/kernel_stat.h:8:
In file included from include/linux/interrupt.h:11:
In file included from include/linux/hardirq.h:11:
In file included from ./arch/riscv/include/generated/asm/hardirq.h:1:
In file included from include/asm-generic/hardirq.h:17:
In file included from include/linux/irq.h:20:
In file included from include/linux/io.h:14:
In file included from arch/riscv/include/asm/io.h:136:
include/asm-generic/io.h:760:2: warning: performing pointer arithmetic on a null pointer has undefined behavior [-Wnull-pointer-arithmetic]
760 | insl(addr, buffer, count);
| ^~~~~~~~~~~~~~~~~~~~~~~~~
arch/riscv/include/asm/io.h:106:53: note: expanded from macro 'insl'
106 | #define insl(addr, buffer, count) __insl(PCI_IOBASE + (addr), buffer, count)
| ~~~~~~~~~~ ^
In file included from fs/erofs/fscache.c:6:
In file included from include/linux/pseudo_fs.h:4:
In file included from include/linux/fs_context.h:14:
In file included from include/linux/security.h:35:
In file included from include/linux/bpf.h:31:
In file included from include/linux/memcontrol.h:13:
In file included from include/linux/cgroup.h:26:
In file included from include/linux/kernel_stat.h:8:
In file included from include/linux/interrupt.h:11:
In file included from include/linux/hardirq.h:11:
In file included from ./arch/riscv/include/generated/asm/hardirq.h:1:
In file included from include/asm-generic/hardirq.h:17:
In file included from include/linux/irq.h:20:
In file included from include/linux/io.h:14:
In file included from arch/riscv/include/asm/io.h:136:
include/asm-generic/io.h:769:2: warning: performing pointer arithmetic on a null pointer has undefined behavior [-Wnull-pointer-arithmetic]
769 | outsb(addr, buffer, count);
| ^~~~~~~~~~~~~~~~~~~~~~~~~~
arch/riscv/include/asm/io.h:118:55: note: expanded from macro 'outsb'
118 | #define outsb(addr, buffer, count) __outsb(PCI_IOBASE + (addr), buffer, count)
| ~~~~~~~~~~ ^
In file included from fs/erofs/fscache.c:6:
In file included from include/linux/pseudo_fs.h:4:
In file included from include/linux/fs_context.h:14:
In file included from include/linux/security.h:35:
In file included from include/linux/bpf.h:31:
In file included from include/linux/memcontrol.h:13:
In file included from include/linux/cgroup.h:26:
In file included from include/linux/kernel_stat.h:8:
In file included from include/linux/interrupt.h:11:
In file included from include/linux/hardirq.h:11:
In file included from ./arch/riscv/include/generated/asm/hardirq.h:1:
In file included from include/asm-generic/hardirq.h:17:
In file included from include/linux/irq.h:20:
In file included from include/linux/io.h:14:
In file included from arch/riscv/include/asm/io.h:136:
include/asm-generic/io.h:778:2: warning: performing pointer arithmetic on a null pointer has undefined behavior [-Wnull-pointer-arithmetic]
778 | outsw(addr, buffer, count);
| ^~~~~~~~~~~~~~~~~~~~~~~~~~
arch/riscv/include/asm/io.h:119:55: note: expanded from macro 'outsw'
119 | #define outsw(addr, buffer, count) __outsw(PCI_IOBASE + (addr), buffer, count)
| ~~~~~~~~~~ ^
In file included from fs/erofs/fscache.c:6:
In file included from include/linux/pseudo_fs.h:4:
In file included from include/linux/fs_context.h:14:
In file included from include/linux/security.h:35:
In file included from include/linux/bpf.h:31:
In file included from include/linux/memcontrol.h:13:
In file included from include/linux/cgroup.h:26:
In file included from include/linux/kernel_stat.h:8:
In file included from include/linux/interrupt.h:11:
In file included from include/linux/hardirq.h:11:
In file included from ./arch/riscv/include/generated/asm/hardirq.h:1:
In file included from include/asm-generic/hardirq.h:17:
In file included from include/linux/irq.h:20:
In file included from include/linux/io.h:14:
In file included from arch/riscv/include/asm/io.h:136:
include/asm-generic/io.h:787:2: warning: performing pointer arithmetic on a null pointer has undefined behavior [-Wnull-pointer-arithmetic]
787 | outsl(addr, buffer, count);
| ^~~~~~~~~~~~~~~~~~~~~~~~~~
arch/riscv/include/asm/io.h:120:55: note: expanded from macro 'outsl'
120 | #define outsl(addr, buffer, count) __outsl(PCI_IOBASE + (addr), buffer, count)
| ~~~~~~~~~~ ^
In file included from fs/erofs/fscache.c:6:
In file included from include/linux/pseudo_fs.h:4:
In file included from include/linux/fs_context.h:14:
In file included from include/linux/security.h:35:
In file included from include/linux/bpf.h:31:
In file included from include/linux/memcontrol.h:13:
In file included from include/linux/cgroup.h:26:
In file included from include/linux/kernel_stat.h:8:
In file included from include/linux/interrupt.h:11:
In file included from include/linux/hardirq.h:11:
In file included from ./arch/riscv/include/generated/asm/hardirq.h:1:
In file included from include/asm-generic/hardirq.h:17:
In file included from include/linux/irq.h:20:
In file included from include/linux/io.h:14:
In file included from arch/riscv/include/asm/io.h:136:
include/asm-generic/io.h:1115:55: warning: performing pointer arithmetic on a null pointer has undefined behavior [-Wnull-pointer-arithmetic]
1115 | return (port > MMIO_UPPER_LIMIT) ? NULL : PCI_IOBASE + port;
| ~~~~~~~~~~ ^
>> fs/erofs/fscache.c:201:25: error: no member named 'm_fscache' in 'struct erofs_map_dev' 201 | io->io.private = mdev->m_fscache->cookie;
| ~~~~ ^
fs/erofs/fscache.c:319:41: error: no member named 'm_fscache' in 'struct erofs_map_dev'
319 | ret = erofs_fscache_read_io_async(mdev.m_fscache->cookie,
| ~~~~ ^
14 warnings and 2 errors generated.
vim +201 fs/erofs/fscache.c
a1bafc3109d713 Jingbo Xu 2024-03-08 194
a1bafc3109d713 Jingbo Xu 2024-03-08 195 struct bio *erofs_fscache_bio_alloc(struct erofs_map_dev *mdev)
a1bafc3109d713 Jingbo Xu 2024-03-08 196 {
a1bafc3109d713 Jingbo Xu 2024-03-08 197 struct erofs_fscache_bio *io;
a1bafc3109d713 Jingbo Xu 2024-03-08 198
a1bafc3109d713 Jingbo Xu 2024-03-08 199 io = kmalloc(sizeof(*io), GFP_KERNEL | __GFP_NOFAIL);
a1bafc3109d713 Jingbo Xu 2024-03-08 200 bio_init(&io->bio, NULL, io->bvecs, BIO_MAX_VECS, REQ_OP_READ);
a1bafc3109d713 Jingbo Xu 2024-03-08 @201 io->io.private = mdev->m_fscache->cookie;
a1bafc3109d713 Jingbo Xu 2024-03-08 202 io->io.end_io = erofs_fscache_bio_endio;
a1bafc3109d713 Jingbo Xu 2024-03-08 203 refcount_set(&io->io.ref, 1);
a1bafc3109d713 Jingbo Xu 2024-03-08 204 return &io->bio;
a1bafc3109d713 Jingbo Xu 2024-03-08 205 }a1bafc3109d713 Jingbo Xu 2024-03-08 206
Signature · 2 lines
0-DAY CI Kernel Test Service https://github.com/intel/lkp-tests/wiki
PATCH 4/4 erofs: use buffered I/O for file-backed mounts by default
In reply to Gao XiangFor many use cases (e.g. container images are just fetched from remote), performance will be impacted if underlay page cache is up-to-date but direct i/o will flush dirty pages first.
Instead, let's use buffered I/O by default and add a (re)mount option to explicitly enable direct I/O if underlay files are supported too.
The startup time for containerd is improved as below:
unpack 1st run non-1st runs EROFS snapshotter buffered I/O file 4.586404265s 0.308s 0.198s EROFS snapshotter direct I/O file 4.581742849s 2.238s 0.222s EROFS snapshotter loop 4.596023152s 0.346s 0.201s Overlayfs snapshotter 5.382851037s 0.206s 0.214s
--- fs/erofs/fileio.c | 7 +++++-- fs/erofs/internal.h | 1 + fs/erofs/super.c | 21 +++++++++++++-------- 3 files changed, 19 insertions(+), 10 deletions(-)
fs/erofs/fileio.c +5 -2
@@ -9,6 +9,7 @@ struct erofs_fileio_rq {struct bio_vec bvecs[BIO_MAX_VECS ];struct bio bio;struct kiocb iocb; +struct super_block *sb; };struct erofs_fileio {
@@ -52,8 +53,9 @@ static void erofs_fileio_rq_submit(struct erofs_fileio_rq *rq) rq->iocb.ki_pos = rq->bio.bi_iter.bi_sector <<SECTOR_SHIFT ; rq->iocb.ki_ioprio =get_current_ioprio (); rq->iocb.ki_complete = erofs_fileio_ki_complete; - rq->iocb.ki_flags = (rq->iocb.ki_filp->f_mode &FMODE_CAN_ODIRECT ) ? -IOCB_DIRECT :0 ; +if (test_opt (&EROFS_SB (rq->sb)->opt,DIRECT_IO ) && + rq->iocb.ki_filp->f_mode &FMODE_CAN_ODIRECT ) + rq->iocb.ki_flags =IOCB_DIRECT ;iov_iter_bvec (&iter,ITER_DEST , rq->bvecs, rq->bio.bi_vcnt, rq->bio.bi_iter.bi_size); ret =vfs_iocb_iter_read (rq->iocb.ki_filp, &rq->iocb, &iter);
@@ -68,6 +70,7 @@ static struct erofs_fileio_rq *erofs_fileio_rq_alloc(struct erofs_map_dev *mdev)bio_init (&rq->bio,NULL , rq->bvecs,BIO_MAX_VECS ,REQ_OP_READ ); rq->iocb.ki_filp = mdev->m_dif->file; + rq->sb = mdev->m_sb;return rq; }
fs/erofs/internal.h +1 -0
@@ -177,6 +177,7 @@ struct erofs_sb_info {#define EROFS_MOUNT_POSIX_ACL 0x00000020#define EROFS_MOUNT_DAX_ALWAYS 0x00000040#define EROFS_MOUNT_DAX_NEVER 0x00000080 +#define EROFS_MOUNT_DIRECT_IO 0x00000100#define clear_opt (opt, option) ((opt)->mount_opt &= ~EROFS_MOUNT_##option)#define set_opt (opt, option) ((opt)->mount_opt |= EROFS_MOUNT_##option)
fs/erofs/super.c +13 -8
@@ -364,14 +364,8 @@ static void erofs_default_options(struct erofs_sb_info *sbi) }enum { - Opt_user_xattr, - Opt_acl, - Opt_cache_strategy, - Opt_dax, - Opt_dax_enum, - Opt_device, - Opt_fsid, - Opt_domain_id, + Opt_user_xattr, Opt_acl, Opt_cache_strategy, Opt_dax, Opt_dax_enum, + Opt_device, Opt_fsid, Opt_domain_id, Opt_directio, Opt_err };
@@ -398,6 +392,7 @@ static const struct fs_parameter_spec erofs_fs_parameters[] = {fsparam_string ("device" , Opt_device),fsparam_string ("fsid" , Opt_fsid),fsparam_string ("domain_id" , Opt_domain_id), + fsparam_flag_no("directio", Opt_directio), {} };
@@ -511,6 +506,16 @@ static int erofs_fc_parse_param(struct fs_context *fc,errorfc (fc,"%s option not supported" , erofs_fs_parameters[opt].name);break ;#endif +case Opt_directio: +#ifdef CONFIG_EROFS_FS_BACKED_BY_FILE +if (result.boolean) +set_opt (&sbi->opt,DIRECT_IO ); +else +clear_opt (&sbi->opt,DIRECT_IO ); +#else +errorfc (fc,"%s option not supported" , erofs_fs_parameters[opt].name); +#endif +break ;default :return -ENOPARAM ; }
Signature · 1 line
2.43.5
PATCH v2 4/4 erofs: use buffered I/O for file-backed mounts by default
For many use cases (e.g. container images are just fetched from remote), performance will be impacted if underlay page cache is up-to-date but direct i/o flushes dirty pages first.
Instead, let's use buffered I/O by default to keep in sync with loop devices and add a (re)mount option to explicitly enable direct I/O if supported by the underlying files.
The container startup time is improved as below:
unpack 1st run non-1st runs EROFS snapshotter buffered I/O file 4.586404265s 0.308s 0.198s EROFS snapshotter direct I/O file 4.581742849s 2.238s 0.222s EROFS snapshotter loop 4.596023152s 0.346s 0.201s Overlayfs snapshotter 5.382851037s 0.206s 0.214s
---
v1: https://lore.kernel.org/r/[email protected]
changes since v1 (obsoleted version by mistake):
- refine commit message;
- add directio in erofs_show_options() too.
fs/erofs/fileio.c | 7 +++++-- fs/erofs/internal.h | 1 + fs/erofs/super.c | 23 +++++++++++++++-------- 3 files changed, 21 insertions(+), 10 deletions(-)
fs/erofs/fileio.c +5 -2
@@ -9,6 +9,7 @@ struct erofs_fileio_rq {struct bio_vec bvecs[BIO_MAX_VECS ];struct bio bio;struct kiocb iocb; +struct super_block *sb; };struct erofs_fileio {
@@ -52,8 +53,9 @@ static void erofs_fileio_rq_submit(struct erofs_fileio_rq *rq) rq->iocb.ki_pos = rq->bio.bi_iter.bi_sector <<SECTOR_SHIFT ; rq->iocb.ki_ioprio =get_current_ioprio (); rq->iocb.ki_complete = erofs_fileio_ki_complete; - rq->iocb.ki_flags = (rq->iocb.ki_filp->f_mode &FMODE_CAN_ODIRECT ) ? -IOCB_DIRECT :0 ; +if (test_opt (&EROFS_SB (rq->sb)->opt,DIRECT_IO ) && + rq->iocb.ki_filp->f_mode &FMODE_CAN_ODIRECT ) + rq->iocb.ki_flags =IOCB_DIRECT ;iov_iter_bvec (&iter,ITER_DEST , rq->bvecs, rq->bio.bi_vcnt, rq->bio.bi_iter.bi_size); ret =vfs_iocb_iter_read (rq->iocb.ki_filp, &rq->iocb, &iter);
@@ -68,6 +70,7 @@ static struct erofs_fileio_rq *erofs_fileio_rq_alloc(struct erofs_map_dev *mdev)bio_init (&rq->bio,NULL , rq->bvecs,BIO_MAX_VECS ,REQ_OP_READ ); rq->iocb.ki_filp = mdev->m_dif->file; + rq->sb = mdev->m_sb;return rq; }
fs/erofs/internal.h +1 -0
@@ -177,6 +177,7 @@ struct erofs_sb_info {#define EROFS_MOUNT_POSIX_ACL 0x00000020#define EROFS_MOUNT_DAX_ALWAYS 0x00000040#define EROFS_MOUNT_DAX_NEVER 0x00000080 +#define EROFS_MOUNT_DIRECT_IO 0x00000100#define clear_opt (opt, option) ((opt)->mount_opt &= ~EROFS_MOUNT_##option)#define set_opt (opt, option) ((opt)->mount_opt |= EROFS_MOUNT_##option)
fs/erofs/super.c +15 -8
@@ -364,14 +364,8 @@ static void erofs_default_options(struct erofs_sb_info *sbi) }enum { - Opt_user_xattr, - Opt_acl, - Opt_cache_strategy, - Opt_dax, - Opt_dax_enum, - Opt_device, - Opt_fsid, - Opt_domain_id, + Opt_user_xattr, Opt_acl, Opt_cache_strategy, Opt_dax, Opt_dax_enum, + Opt_device, Opt_fsid, Opt_domain_id, Opt_directio, Opt_err };
@@ -398,6 +392,7 @@ static const struct fs_parameter_spec erofs_fs_parameters[] = {fsparam_string ("device" , Opt_device),fsparam_string ("fsid" , Opt_fsid),fsparam_string ("domain_id" , Opt_domain_id), + fsparam_flag_no("directio", Opt_directio), {} };
@@ -511,6 +506,16 @@ static int erofs_fc_parse_param(struct fs_context *fc,errorfc (fc,"%s option not supported" , erofs_fs_parameters[opt].name);break ;#endif +case Opt_directio: +#ifdef CONFIG_EROFS_FS_BACKED_BY_FILE +if (result.boolean) +set_opt (&sbi->opt,DIRECT_IO ); +else +clear_opt (&sbi->opt,DIRECT_IO ); +#else +errorfc (fc,"%s option not supported" , erofs_fs_parameters[opt].name); +#endif +break ;default :return -ENOPARAM ; }
@@ -948,6 +953,8 @@ static int erofs_show_options(struct seq_file *seq, struct dentry *root)seq_puts (seq,",dax=always" );if (test_opt (opt,DAX_NEVER ))seq_puts (seq,",dax=never" ); +if (erofs_is_fileio_mode (sbi) &&test_opt (opt,DIRECT_IO )) +seq_puts (seq,",directio" );#ifdef CONFIG_EROFS_FS_ONDEMAND if (sbi->fsid)seq_printf (seq,",fsid=%s" , sbi->fsid);
Signature · 1 line
2.43.5
Re: [PATCH v2 4/4] erofs: use buffered I/O for file-backed mounts by default
Quoted 10 lines · Gao Xiang
For many use cases (e.g. container images are just fetched from remote), performance will be impacted if underlay page cache is up-to-date but direct i/o flushes dirty pages first.
Instead, let's use buffered I/O by default to keep in sync with loop devices and add a (re)mount option to explicitly enable direct I/O if supported by the underlying files.
The container startup time is improved as below:
unpack 1st run non-1st runs
Quoted 8 lines
EROFS snapshotter buffered I/O file 4.586404265s 0.308s 0.198s EROFS snapshotter direct I/O file 4.581742849s 2.238s 0.222s EROFS snapshotter loop 4.596023152s 0.346s 0.201s Overlayfs snapshotter 5.382851037s 0.206s 0.214sFixes fb176750266a ("erofs: add file-backed mount support")Cc Derek McGowan <[email protected]>Signed-off-by Gao Xiang <[email protected]>
Thanks,
Quoted 6 lines · Gao Xiang
Unify the common parts of
erofs_fc_free()anderofs_kill_sb()aserofs_sb_free().Thus,
fput()inerofs_fc_get_tree()is no longer needed, too.Signed-off-by Gao Xiang <[email protected]>
Thanks,