erofs-utils: optimize write_uncompressed_file_from_fd()
PATCH 1/1 erofs-utils: optimize write_uncompressed_file_from_fd()
Utilize copy offloading to speed up copying data from the source filesystem to the target EROFS filesystem.
This method improves build speed by approximately 9% (tested with Linux 5.4.140 source code dataset).
--- configure.ac | 2 ++ include/erofs/io.h | 4 ++++ lib/inode.c | 23 +++++++---------------- lib/io.c | 45 +++++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 58 insertions(+), 16 deletions(-)
configure.ac +2 -0
@@ -204,6 +204,7 @@ AC_CHECK_HEADERS(m4_flatten([ sys/ioctl.h sys/mman.h sys/random.h + sys/sendfile.h sys/stat.h sys/statfs.h sys/sysmacros.h
@@ -267,6 +268,7 @@ AC_CHECK_FUNCS(m4_flatten([ pwrite64 posix_fadvise fstatfs + sendfile strdup strerror strrchr
include/erofs/io.h +4 -0
@@ -33,6 +33,8 @@ struct erofs_vfops {ssize_t (*read)(struct erofs_vfile *vf,void *buf,size_t len);off_t (*lseek)(struct erofs_vfile *vf,u64 offset,int whence);int (*fstat)(struct erofs_vfile *vf,struct stat *buf); +int (*xcopy)(struct erofs_vfile *vout,off_t pos, +struct erofs_vfile *vin,int len); };struct erofs_vfile {
@@ -52,6 +54,8 @@ off_t erofs_io_lseek(struct erofs_vfile *vf, u64 offset, int whence);ssize_t erofs_copy_file_range (int fd_in,u64 *off_in,int fd_out,u64 *off_out,size_t length); +int erofs_io_xcopy (struct erofs_vfile *vout,off_t pos, +struct erofs_vfile *vin,int len); #ifdef __cplusplus }
lib/inode.c +7 -16
@@ -514,30 +514,21 @@ static bool erofs_file_is_compressible(struct erofs_inode *inode)static int write_uncompressed_file_from_fd (struct erofs_inode *inode,int fd) {int ret; -unsigned int nblocks, i; +unsigned int nblocks;struct erofs_sb_info *sbi = inode->sbi; inode->datalayout =EROFS_INODE_FLAT_INLINE ; - nblocks = inode->i_size /erofs_blksiz (sbi); + nblocks = inode->i_size >> sbi->blkszbits; ret =__allocate_inode_bh_data (inode, nblocks,DATA );if (ret)return ret; -for (i =0 ; i < nblocks; ++i) { -char buf[EROFS_MAX_BLOCK_SIZE ]; - - ret =read (fd, buf,erofs_blksiz (sbi)); -if (ret !=erofs_blksiz (sbi)) { -if (ret <0 ) -return -errno; -return -EAGAIN ; - } - - ret =erofs_blk_write (sbi, buf, inode->u.i_blkaddr + i,1 ); -if (ret) -return ret; - } + ret =erofs_io_xcopy (&sbi->bdev,erofs_pos (sbi, inode->u.i_blkaddr), + &((struct erofs_vfile ){ .fd = fd }), +erofs_pos (sbi, nblocks)); +if (ret) +return ret;/* read the tail-end data */ inode->idata_size = inode->i_size %erofs_blksiz (sbi);
lib/io.c +45 -0
54 lines not on this page · raw message
Signature · 1 line
2.39.3
PATCH v2 1/1 erofs-utils: optimize write_uncompressed_file_from_fd()
Utilize copy offloading to speed up copying data from the source filesystem to the target EROFS filesystem.
This method improves build speed by approximately 9% (tested with Linux 5.4.140 source code dataset).
---
changes since v1:
- Fix macos build error:
https://github.com/erofs/erofsnightly/actions/runs/9607090927 - Fix unexpected lseek related to diskbuf: https://github.com/erofs/erofsnightly/actions/runs/9607047368
configure.ac | 2 ++ include/erofs/io.h | 4 ++++ lib/inode.c | 23 +++++++---------------- lib/io.c | 45 +++++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 58 insertions(+), 16 deletions(-)
configure.ac +2 -0
@@ -204,6 +204,7 @@ AC_CHECK_HEADERS(m4_flatten([ sys/ioctl.h sys/mman.h sys/random.h + sys/sendfile.h sys/stat.h sys/statfs.h sys/sysmacros.h
@@ -267,6 +268,7 @@ AC_CHECK_FUNCS(m4_flatten([ pwrite64 posix_fadvise fstatfs + sendfile strdup strerror strrchr
include/erofs/io.h +4 -0
@@ -33,6 +33,8 @@ struct erofs_vfops {ssize_t (*read)(struct erofs_vfile *vf,void *buf,size_t len);off_t (*lseek)(struct erofs_vfile *vf,u64 offset,int whence);int (*fstat)(struct erofs_vfile *vf,struct stat *buf); +int (*xcopy)(struct erofs_vfile *vout,off_t pos, +struct erofs_vfile *vin,int len); };struct erofs_vfile {
@@ -52,6 +54,8 @@ off_t erofs_io_lseek(struct erofs_vfile *vf, u64 offset, int whence);ssize_t erofs_copy_file_range (int fd_in,u64 *off_in,int fd_out,u64 *off_out,size_t length); +int erofs_io_xcopy (struct erofs_vfile *vout,off_t pos, +struct erofs_vfile *vin,int len); #ifdef __cplusplus }
lib/inode.c +7 -16
@@ -514,30 +514,21 @@ static bool erofs_file_is_compressible(struct erofs_inode *inode)static int write_uncompressed_file_from_fd (struct erofs_inode *inode,int fd) {int ret; -unsigned int nblocks, i; +unsigned int nblocks;struct erofs_sb_info *sbi = inode->sbi; inode->datalayout =EROFS_INODE_FLAT_INLINE ; - nblocks = inode->i_size /erofs_blksiz (sbi); + nblocks = inode->i_size >> sbi->blkszbits; ret =__allocate_inode_bh_data (inode, nblocks,DATA );if (ret)return ret; -for (i =0 ; i < nblocks; ++i) { -char buf[EROFS_MAX_BLOCK_SIZE ]; - - ret =read (fd, buf,erofs_blksiz (sbi)); -if (ret !=erofs_blksiz (sbi)) { -if (ret <0 ) -return -errno; -return -EAGAIN ; - } - - ret =erofs_blk_write (sbi, buf, inode->u.i_blkaddr + i,1 ); -if (ret) -return ret; - } + ret =erofs_io_xcopy (&sbi->bdev,erofs_pos (sbi, inode->u.i_blkaddr), + &((struct erofs_vfile ){ .fd = fd }), +erofs_pos (sbi, nblocks)); +if (ret) +return ret;/* read the tail-end data */ inode->idata_size = inode->i_size %erofs_blksiz (sbi);
lib/io.c +45 -0
54 lines not on this page · raw message
Signature · 1 line
2.39.3
PATCH v3 1/1 erofs-utils: optimize write_uncompressed_file_from_fd()
Utilize copy offloading to speed up copying data from the source filesystem to the target EROFS filesystem.
This method improves build speed by approximately 9% (tested with Linux 5.4.140 source code dataset).
---
changes since v2:
- avoid seeking diskbuf but try to use copy_file_range() instead.
configure.ac | 2 ++ include/erofs/io.h | 4 ++++ lib/inode.c | 24 ++++++++-------------- lib/io.c | 50 ++++++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 64 insertions(+), 16 deletions(-)
configure.ac +2 -0
@@ -204,6 +204,7 @@ AC_CHECK_HEADERS(m4_flatten([ sys/ioctl.h sys/mman.h sys/random.h + sys/sendfile.h sys/stat.h sys/statfs.h sys/sysmacros.h
@@ -267,6 +268,7 @@ AC_CHECK_FUNCS(m4_flatten([ pwrite64 posix_fadvise fstatfs + sendfile strdup strerror strrchr
include/erofs/io.h +4 -0
@@ -33,6 +33,8 @@ struct erofs_vfops {ssize_t (*read)(struct erofs_vfile *vf,void *buf,size_t len);off_t (*lseek)(struct erofs_vfile *vf,u64 offset,int whence);int (*fstat)(struct erofs_vfile *vf,struct stat *buf); +int (*xcopy)(struct erofs_vfile *vout,off_t pos, +struct erofs_vfile *vin,int len,bool noseek); };struct erofs_vfile {
@@ -52,6 +54,8 @@ off_t erofs_io_lseek(struct erofs_vfile *vf, u64 offset, int whence);ssize_t erofs_copy_file_range (int fd_in,u64 *off_in,int fd_out,u64 *off_out,size_t length); +int erofs_io_xcopy (struct erofs_vfile *vout,off_t pos, +struct erofs_vfile *vin,int len,bool noseek); #ifdef __cplusplus }
lib/inode.c +8 -16
@@ -514,30 +514,22 @@ static bool erofs_file_is_compressible(struct erofs_inode *inode)static int write_uncompressed_file_from_fd (struct erofs_inode *inode,int fd) {int ret; -unsigned int nblocks, i; +unsigned int nblocks;struct erofs_sb_info *sbi = inode->sbi; inode->datalayout =EROFS_INODE_FLAT_INLINE ; - nblocks = inode->i_size /erofs_blksiz (sbi); + nblocks = inode->i_size >> sbi->blkszbits; ret =__allocate_inode_bh_data (inode, nblocks,DATA );if (ret)return ret; -for (i =0 ; i < nblocks; ++i) { -char buf[EROFS_MAX_BLOCK_SIZE ]; - - ret =read (fd, buf,erofs_blksiz (sbi)); -if (ret !=erofs_blksiz (sbi)) { -if (ret <0 ) -return -errno; -return -EAGAIN ; - } - - ret =erofs_blk_write (sbi, buf, inode->u.i_blkaddr + i,1 ); -if (ret) -return ret; - } + ret =erofs_io_xcopy (&sbi->bdev,erofs_pos (sbi, inode->u.i_blkaddr), + &((struct erofs_vfile ){ .fd = fd }), +erofs_pos (sbi, nblocks), + inode->datasource ==EROFS_INODE_DATA_SOURCE_DISKBUF ); +if (ret) +return ret;/* read the tail-end data */ inode->idata_size = inode->i_size %erofs_blksiz (sbi);
lib/io.c +50 -0
59 lines not on this page · raw message
Signature · 1 line
2.39.3