Add threading support to e2fsprogs
cover Add threading support to e2fsprogs
This patch set adds the infrastructure to support threading to libext2fs. It makes the unix_io I/O Manager thread-aware. Wang's parallel bitmap code has been adapted to use the new threading infrastructure.
The code has been tested with TSAN and ASAN built into gcc 10.2:
configure 'CFLAGS=-g -fsanitize=thread' 'LDFLAGS=-fsanitize=thread' make clean ; make -j16 ; make -j16 check
configure 'CFLAGS=-g -fsanitize=address' 'LDFLAGS=-fsanitize=address' make clean ; make -j16 ; make -j16 check
As I(tytso) needed to excerpt out some of the changes to generated patches in "Add configure and build support for the pthreads", the full patch series can be found in git:
git fetch https://git.kernel.org/pub/scm/fs/ext2/e2fsprogs.git pthreads
Changes with V1:
Fix review remarks for "ext2fs: parallel bitmap loading".
Tested stat_mutex performance on instance with 60 CPUs and fragmented 3TB Local SSD. No noticable contention seem for the stat_mutex.
Theodore Ts'o (4):
Add configure and build support for the pthreads library
libext2fs: add threading support to the I/O manager abstraction
libext2fs: allow the unix_io manager's cache to be disabled and
re-enabled
Enable threaded support for e2fsprogs' applications.
Wang Shilong (1):
ext2fs: parallel bitmap loading
MCONFIG.in | 12 +- aclocal.m4 | 560 ++++++++++++++++++++++++++-------------- configure | 213 ++++++++++++--- configure.ac | 24 ++ debugfs/debugfs.c | 6 +- e2fsck/unix.c | 2 +- lib/config.h.in | 83 +++++- lib/ext2fs/ext2_io.h | 3 + lib/ext2fs/ext2fs.h | 9 + lib/ext2fs/openfs.c | 2 + lib/ext2fs/rw_bitmaps.c | 332 ++++++++++++++++++++---- lib/ext2fs/test_io.c | 6 +- lib/ext2fs/undo_io.c | 2 + lib/ext2fs/unix_io.c | 156 +++++++++-- misc/dumpe2fs.c | 2 +- misc/e2freefrag.c | 2 +- misc/e2fuzz.c | 4 +- misc/e2image.c | 3 +- misc/fuse2fs.c | 3 +- misc/tune2fs.c | 3 +- resize/main.c | 2 +- 21 files changed, 1093 insertions(+), 336 deletions(-)
Signature · 1 line
2.30.0.284.gd98b1dd5eaa7-goog
RFC PATCH 1/5 Add configure and build support for the pthreads library
From: Theodore Ts'o <[email protected]>
Support for pthreads can be forcibly disabled by passing "--without-pthread" to the configure script.
The actual changes in this commit are in configure.ac and MCONFIG.in; the other files were generated as a result of running aclocal, autoconf, and autoheader on a Debian testing system.
Note: the autoconf-archive package must now be installed before rerunning aclocal, to supply the AX_PTHREAD macro.
--- MCONFIG.in | 12 +- aclocal.m4 | 560 +++++++++++++++++++++++++++++++----------------- configure | 213 ++++++++++++++---- configure.ac | 24 +++ lib/config.h.in | 83 +++++-- 5 files changed, 636 insertions(+), 256 deletions(-)
MCONFIG.in +7 -5
@@ -86,15 +86,17 @@ SYSTEMD_SYSTEM_UNIT_DIR = @systemd_system_unit_dir@ SANITIZER_CFLAGS = @lto_cflags@ @ubsan_cflags@ @addrsan_cflags@ @threadsan_cflags@ SANITIZER_LDFLAGS = @lto_ldflags@ @ubsan_ldflags@ @addrsan_ldflags@ @threadsan_ldflags@ -CC = @CC@ +CC = @PTHREAD_CC@ BUILD_CC = @BUILD_CC@ +PTHREAD_CFLAGS = @PTHREAD_CFLAGS@ +PTHREAD_LIBS = @PTHREAD_LIBS@ CFLAGS = @CFLAGS@ CFLAGS_SHLIB = @CFLAGS_SHLIB@ CFLAGS_STLIB = @CFLAGS_STLIB@ CPPFLAGS = @INCLUDES@ -ALL_CFLAGS = $(CPPFLAGS) $(SANITIZER_CFLAGS) $(CFLAGS) $(CFLAGS_WARN) @DEFS@ $(LOCAL_CFLAGS) -ALL_CFLAGS_SHLIB = $(CPPFLAGS) $(SANITIZER_CFLAGS) $(CFLAGS_SHLIB) $(CFLAGS_WARN) @DEFS@ $(LOCAL_CFLAGS) -ALL_CFLAGS_STLIB = $(CPPFLAGS) $(SANITIZER_CFLAGS) $(CFLAGS_STLIB) $(CFLAGS_WARN) @DEFS@ $(LOCAL_CFLAGS) +ALL_CFLAGS = $(CPPFLAGS) $(SANITIZER_CFLAGS) $(CFLAGS) $(PTHREAD_CFLAGS) $(CFLAGS_WARN) @DEFS@ $(LOCAL_CFLAGS) +ALL_CFLAGS_SHLIB = $(CPPFLAGS) $(SANITIZER_CFLAGS) $(CFLAGS_SHLIB) $(PTHREAD_CFLAGS) $(CFLAGS_WARN) @DEFS@ $(LOCAL_CFLAGS) +ALL_CFLAGS_STLIB = $(CPPFLAGS) $(SANITIZER_CFLAGS) $(CFLAGS_STLIB) $(PTHREAD_CFLAGS) $(CFLAGS_WARN) @DEFS@ $(LOCAL_CFLAGS) LDFLAGS = $(SANITIZER_LDFLAGS) @LDFLAGS@ LDFLAGS_SHLIB = $(SANITIZER_LDFLAGS) @LDFLAGS_SHLIB@ ALL_LDFLAGS = $(LDFLAGS) @LDFLAG_DYNAMIC@
@@ -139,7 +141,7 @@ LIBFUSE = @FUSE_LIB@ LIBSUPPORT = $(LIBINTL) $(LIB)/libsupport@STATIC_LIB_EXT@ LIBBLKID = @LIBBLKID@ @PRIVATE_LIBS_CMT@ $(LIBUUID) LIBINTL = @LIBINTL@ -SYSLIBS = @LIBS@ +SYSLIBS = @LIBS@ @PTHREAD_LIBS@ DEPLIBSS = $(LIB)/libss@LIB_EXT@ DEPLIBCOM_ERR = $(LIB)/libcom_err@LIB_EXT@ DEPLIBUUID = @DEPLIBUUID@
aclocal.m4 +363 -197
1,090 lines not on this page · raw message
configure +171 -42
453 lines not on this page · raw message
configure.ac +24 -0
@@ -773,6 +773,30 @@ fi dnl dnl dnl +AC_ARG_WITH([pthread], +[ --without-pthread disable use of pthread support], +[if test "$withval" = "no" +then + try_pthread="" + AC_MSG_RESULT([Disabling pthread support]) +else + try_pthread="yes" + AC_MSG_RESULT([Testing for pthread support]) +fi] +, +try_pthread="yes" +AC_MSG_RESULT([Try testing for pthread support by default]) +) +if test "$try_pthread" = "yes" +then +AX_PTHREAD +else +test -n "$PTHREAD_CC" || PTHREAD_CC="$CC" +AC_SUBST([PTHREAD_CC]) +fi +dnl +dnl +dnl AH_TEMPLATE([USE_UUIDD], [Define to 1 to build uuidd]) AC_ARG_ENABLE([uuidd], [ --disable-uuidd disable building the uuid daemon],
lib/config.h.in +71 -12
132 lines not on this page · raw message
Signature · 1 line
2.30.0.284.gd98b1dd5eaa7-goog
RFC PATCH 2/5 libext2fs: add threading support to the I/O manager abstraction
In reply to Saranya MuruganandamFrom: Theodore Ts'o <[email protected]>
Add initial implementation support for the unix_io manager. Applications which want to use threading should pass in IO_FLAG_THREADS when opening the channel. Channels which support threading (which as of this commit is unix_io and test_io if the backing io_manager supports threading) will set the CHANNEL_FLAGS_THREADS bit in io->flags. Library code or applications can test if threading is enabled by checking this flag.
Applications using libext2fs can pass in EXT2_FLAG_THREADS to ext2fs_open() or ext2fs_open2() to request threading support.
--- lib/ext2fs/ext2_io.h | 2 + lib/ext2fs/ext2fs.h | 1 + lib/ext2fs/openfs.c | 2 + lib/ext2fs/test_io.c | 6 +- lib/ext2fs/undo_io.c | 2 + lib/ext2fs/unix_io.c | 137 ++++++++++++++++++++++++++++++++++++++----- 6 files changed, 133 insertions(+), 17 deletions(-)
lib/ext2fs/ext2_io.h +2 -0
@@ -33,6 +33,7 @@ typedef struct struct_io_stats *io_stats;#define CHANNEL_FLAGS_WRITETHROUGH 0x01#define CHANNEL_FLAGS_DISCARD_ZEROES 0x02#define CHANNEL_FLAGS_BLOCK_DEVICE 0x04 +#define CHANNEL_FLAGS_THREADS 0x08#define io_channel_discard_zeroes_data (i) (i->flags & CHANNEL_FLAGS_DISCARD_ZEROES)
@@ -104,6 +105,7 @@ struct struct_io_manager {#define IO_FLAG_EXCLUSIVE 0x0002#define IO_FLAG_DIRECT_IO 0x0004#define IO_FLAG_FORCE_BOUNCE 0x0008 +#define IO_FLAG_THREADS 0x0010/* * Convenience functions....
lib/ext2fs/ext2fs.h +1 -0
@@ -206,6 +206,7 @@ typedef struct ext2_file *ext2_file_t;#define EXT2_FLAG_IGNORE_SB_ERRORS 0x800000#define EXT2_FLAG_BBITMAP_TAIL_PROBLEM 0x1000000#define EXT2_FLAG_IBITMAP_TAIL_PROBLEM 0x2000000 +#define EXT2_FLAG_THREADS 0x4000000/* * Special flag in the ext2 inode i_flag field that means that this is
lib/ext2fs/openfs.c +2 -0
@@ -170,6 +170,8 @@ errcode_t ext2fs_open2(const char *name, const char *io_options, io_flags |=IO_FLAG_EXCLUSIVE ;if (flags &EXT2_FLAG_DIRECT_IO ) io_flags |=IO_FLAG_DIRECT_IO ; +if (flags &EXT2_FLAG_THREADS ) + io_flags |=IO_FLAG_THREADS ; retval = manager->open (fs->device_name, io_flags, &fs->io);if (retval) goto cleanup;
lib/ext2fs/test_io.c +5 -1
@@ -197,6 +197,7 @@ static errcode_t test_open(const char *name, int flags, io_channel *channel) io->read_error =0 ; io->write_error =0 ; io->refcount =1 ; + io->flags =0 ;memset (data,0 ,sizeof (struct test_private_data )); data->magic =EXT2_ET_MAGIC_TEST_IO_CHANNEL ;
@@ -237,8 +238,11 @@ static errcode_t test_open(const char *name, int flags, io_channel *channel)if ((value =safe_getenv ("TEST_IO_WRITE_ABORT" )) !=NULL ) data->write_abort_count =strtoul (value,NULL ,0 ); -if (data->real) +if (data->real) { io->align = data->real->align; +if (data->real->flags &CHANNEL_FLAGS_THREADS ) + io->flags |=CHANNEL_FLAGS_THREADS ; + } *channel = io;return 0 ;
lib/ext2fs/undo_io.c +2 -0
@@ -698,6 +698,8 @@ static errcode_t undo_open(const char *name, int flags, io_channel *channel)int undo_fd =-1 ;errcode_t retval; +/* We don't support multi-threading, at least for now */ + flags &= ~IO_FLAG_THREADS ;if (name ==0 )return EXT2_ET_BAD_DEVICE_NAME ; retval =ext2fs_get_mem (sizeof (struct struct_io_channel ), &io);
lib/ext2fs/unix_io.c +121 -16
326 lines not on this page · raw message
Signature · 1 line
2.30.0.284.gd98b1dd5eaa7-goog
RFC PATCH 3/5 libext2fs: allow the unix_io manager's cache to be disabled and re-enabled
In reply to Saranya MuruganandamFrom: Theodore Ts'o <[email protected]>
--- lib/ext2fs/ext2_io.h | 1 + lib/ext2fs/unix_io.c | 19 +++++++++++++++++++ 2 files changed, 20 insertions(+)
lib/ext2fs/ext2_io.h +1 -0
@@ -106,6 +106,7 @@ struct struct_io_manager {#define IO_FLAG_DIRECT_IO 0x0004#define IO_FLAG_FORCE_BOUNCE 0x0008#define IO_FLAG_THREADS 0x0010 +#define IO_FLAG_NOCACHE 0x0020/* * Convenience functions....
lib/ext2fs/unix_io.c +19 -0
@@ -942,6 +942,8 @@ static errcode_t unix_read_blk64(io_channel channel, unsigned long long block,#ifdef NO_IO_CACHE return raw_read_blk (channel, data, block, count, buf);#else +if (data->flags &IO_FLAG_NOCACHE ) +return raw_read_blk (channel, data, block, count, buf);/* * If we're doing an odd-sized read or a very large read, * flush out the cache and then do a direct read.
@@ -1032,6 +1034,8 @@ static errcode_t unix_write_blk64(io_channel channel, unsigned long long block,#ifdef NO_IO_CACHE return raw_write_blk (channel, data, block, count, buf);#else +if (data->flags &IO_FLAG_NOCACHE ) +return raw_write_blk (channel, data, block, count, buf);/* * If we're doing an odd-sized write or a very large write, * flush out the cache completely and then do a direct write.
@@ -1161,6 +1165,7 @@ static errcode_t unix_set_option(io_channel channel, const char *option, {struct unix_private_data *data;unsigned long long tmp; +errcode_t retval;char *end;EXT2_CHECK_MAGIC (channel,EXT2_ET_MAGIC_IO_CHANNEL );
@@ -1179,6 +1184,20 @@ static errcode_t unix_set_option(io_channel channel, const char *option,return EXT2_ET_INVALID_ARGUMENT ;return 0 ; } +if (!strcmp (option,"cache" )) { +if (!arg) +return EXT2_ET_INVALID_ARGUMENT ; +if (!strcmp (arg,"on" )) { + data->flags &= ~IO_FLAG_NOCACHE ; +return 0 ; + } +if (!strcmp (arg,"off" )) { + retval =flush_cached_blocks (channel, data,0 ); + data->flags |=IO_FLAG_NOCACHE ; +return retval; + } +return EXT2_ET_INVALID_ARGUMENT ; + }return EXT2_ET_INVALID_ARGUMENT ; }
Signature · 1 line
2.30.0.284.gd98b1dd5eaa7-goog
RFC PATCH 4/5 ext2fs: parallel bitmap loading
In reply to Saranya MuruganandamFrom: Wang Shilong <[email protected]>
In our benchmarking for PiB size filesystem, pass5 takes 10446s to finish and 99.5% of time takes on reading bitmaps.
It makes sense to reading bitmaps using multiple threads, a quickly benchmark show 10446s to 626s with 64 threads.
[ This has all of many bug fixes for rw_bitmaps.c from the original
luster patch set collapsed into a single commit. In addition it has
the new ext2fs_rw_bitmaps() api proposed by Ted. ]
--- lib/ext2fs/ext2fs.h | 8 + lib/ext2fs/rw_bitmaps.c | 332 +++++++++++++++++++++++++++++++++------- 2 files changed, 288 insertions(+), 52 deletions(-)
lib/ext2fs/ext2fs.h +8 -0
@@ -688,6 +688,14 @@ struct ext2_xattr_handle;#define XATTR_ABORT 1#define XATTR_CHANGED 2 +/* +* flags for ext2fs_rw_bitmaps() +*/ +#define EXT2FS_BITMAPS_WRITE 0x0001 +#define EXT2FS_BITMAPS_BLOCK 0x0002 +#define EXT2FS_BITMAPS_INODE 0x0004 +#define EXT2FS_BITMAPS_VALID_FLAGS 0x0007 +/* * function prototypes */
lib/ext2fs/rw_bitmaps.c +280 -52
445 lines not on this page · raw message
Signature · 1 line
2.30.0.284.gd98b1dd5eaa7-goog
RFC PATCH 5/5 Enable threaded support for e2fsprogs' applications.
In reply to Saranya MuruganandamFrom: Theodore Ts'o <[email protected]>
--- debugfs/debugfs.c | 6 ++++-- e2fsck/unix.c | 2 +- misc/dumpe2fs.c | 2 +- misc/e2freefrag.c | 2 +- misc/e2fuzz.c | 4 ++-- misc/e2image.c | 3 ++- misc/fuse2fs.c | 3 ++- misc/tune2fs.c | 3 ++- resize/main.c | 2 +- 9 files changed, 16 insertions(+), 11 deletions(-)
debugfs/debugfs.c +4 -2
@@ -231,7 +231,8 @@ void do_open_filesys(int argc, char **argv, int sci_idx EXT2FS_ATTR((unused)),int catastrophic =0 ;blk64_t superblock =0 ;blk64_t blocksize =0 ; -int open_flags =EXT2_FLAG_SOFTSUPP_FEATURES |EXT2_FLAG_64BITS ; +int open_flags =EXT2_FLAG_SOFTSUPP_FEATURES |EXT2_FLAG_64BITS | +EXT2_FLAG_THREADS ;char *data_filename =0 ;char *undo_file =NULL ;
@@ -2532,7 +2533,8 @@ int main(int argc, char **argv)#endif "[-c]] [device]" ;int c; -int open_flags =EXT2_FLAG_SOFTSUPP_FEATURES |EXT2_FLAG_64BITS ; +int open_flags =EXT2_FLAG_SOFTSUPP_FEATURES | +EXT2_FLAG_64BITS |EXT2_FLAG_THREADS ;char *request =0 ;int exit_status =0 ;char *cmd_file =0 ;
e2fsck/unix.c +1 -1
@@ -1474,7 +1474,7 @@ int main (int argc, char *argv[]) } ctx->superblock = ctx->use_superblock; - flags =EXT2_FLAG_SKIP_MMP ; + flags =EXT2_FLAG_SKIP_MMP |EXT2_FLAG_THREADS ; restart:#ifdef CONFIG_TESTIO_DEBUG if (getenv ("TEST_IO_FLAGS" ) ||getenv ("TEST_IO_BLOCK" )) {
misc/dumpe2fs.c +1 -1
@@ -665,7 +665,7 @@ int main (int argc, char ** argv) device_name = argv[optind++]; flags =EXT2_FLAG_JOURNAL_DEV_OK |EXT2_FLAG_SOFTSUPP_FEATURES | -EXT2_FLAG_64BITS ; +EXT2_FLAG_64BITS |EXT2_FLAG_THREADS ;if (force) flags |=EXT2_FLAG_FORCE ;if (image_dump)
misc/e2freefrag.c +1 -1
@@ -363,7 +363,7 @@ static void collect_info(ext2_filsys fs, struct chunk_info *chunk_info, FILE *f)static void open_device (char *device_name,ext2_filsys *fs) {int retval; -int flag =EXT2_FLAG_FORCE |EXT2_FLAG_64BITS ; +int flag =EXT2_FLAG_FORCE |EXT2_FLAG_64BITS |EXT2_FLAG_THREADS ; retval =ext2fs_open (device_name, flag,0 ,0 , unix_io_manager, fs);if (retval) {
misc/e2fuzz.c +2 -2
@@ -201,8 +201,8 @@ static int process_fs(const char *fsname) }/* Ensure the fs is clean and does not have errors */ - ret =ext2fs_open (fsname,EXT2_FLAG_64BITS ,0 ,0 , unix_io_manager, - &fs); + ret =ext2fs_open (fsname,EXT2_FLAG_64BITS |EXT2_FLAG_THREADS , +0 ,0 , unix_io_manager, &fs);if (ret) {fprintf (stderr,"%s: failed to open filesystem.\n" , fsname);
misc/e2image.c +2 -1
@@ -1482,7 +1482,8 @@ int main (int argc, char ** argv)ext2_filsys fs;char *image_fn, offset_opt[64 ];struct ext2_qcow2_hdr *header =NULL ; -int open_flag =EXT2_FLAG_64BITS |EXT2_FLAG_IGNORE_CSUM_ERRORS ; +int open_flag =EXT2_FLAG_64BITS |EXT2_FLAG_THREADS | +EXT2_FLAG_IGNORE_CSUM_ERRORS ;int img_type =0 ;int flags =0 ;int mount_flags =0 ;
misc/fuse2fs.c +2 -1
@@ -3727,7 +3727,8 @@ int main(int argc, char *argv[])errcode_t err;char *logfile;char extra_args[BUFSIZ ]; -int ret =0 , flags =EXT2_FLAG_64BITS |EXT2_FLAG_EXCLUSIVE ; +int ret =0 ; +int flags =EXT2_FLAG_64BITS |EXT2_FLAG_THREADS |EXT2_FLAG_EXCLUSIVE ;memset (&fctx,0 ,sizeof (fctx)); fctx.magic =FUSE2FS_MAGIC ;
misc/tune2fs.c +2 -1
@@ -2950,7 +2950,8 @@ retry_open:if ((open_flag &EXT2_FLAG_RW ) ==0 || f_flag) open_flag |=EXT2_FLAG_SKIP_MMP ; - open_flag |=EXT2_FLAG_64BITS |EXT2_FLAG_JOURNAL_DEV_OK ; + open_flag |=EXT2_FLAG_64BITS |EXT2_FLAG_THREADS | +EXT2_FLAG_JOURNAL_DEV_OK ;/* keep the filesystem struct around to dump MMP data */ open_flag |=EXT2_FLAG_NOFREE_ON_ERROR ;
resize/main.c +1 -1
@@ -402,7 +402,7 @@ int main (int argc, char ** argv)if (!(mount_flags &EXT2_MF_MOUNTED )) io_flags =EXT2_FLAG_RW |EXT2_FLAG_EXCLUSIVE ; - io_flags |=EXT2_FLAG_64BITS ; + io_flags |=EXT2_FLAG_64BITS |EXT2_FLAG_THREADS ;if (undo_file) { retval =resize2fs_setup_tdb (device_name, undo_file, &io_ptr);if (retval)
Signature · 1 line
2.30.0.284.gd98b1dd5eaa7-goog
Quoted 12 lines · Saranya Muruganandam
This patch set adds the infrastructure to support threading to libext2fs. It makes the
unix_ioI/O Manager thread-aware. Wang's parallel bitmap code has been adapted to use the new threading infrastructure.The code has been tested with TSAN and ASAN built into gcc 10.2:
configure 'CFLAGS=-g -fsanitize=thread' 'LDFLAGS=-fsanitize=thread' make clean ; make -j16 ; make -j16 check
configure 'CFLAGS=-g -fsanitize=address' 'LDFLAGS=-fsanitize=address' make clean ; make -j16 ; make -j16 check
Quoted 5 lines
As I(tytso) needed to excerpt out some of the changes to generated patches in "Add configure and build support for the pthreads", the full patch series can be found in git:
git fetch https://git.kernel.org/pub/scm/fs/ext2/e2fsprogs.git pthreads
Thanks, I've applied this patch series. (There were some slight merge conflicts due to some other changes from the maint branch so I had to regenerate the aclocal.m4 and configure files.)
- Ted