resize2fs: Add support for lazy itable initialization
PATCH 1/2 resize2fs: Add support for lazy itable initialization
Lazy inode table initialization speeds up file system resize operation because we can let the inode tables uninitialized. For some time now the mke2fs has similar option and now, when we have in-kernel lazyinit implementation we can add this feature to the resize2fs as well.
This commit adds extended options '-E' to the resize2fs code along with the first extended option lazy_itable_init=n. With lazy_itable_init extended option one can instruct resize2fs to skip inode table initialization to significantly speed-up file system resize. If the option is omitted and the file system supports lazy inode table initialization it defaults to 1.
--- resize/main.c | 68 +++++++++++++++++++++++++++++++- resize/online.c | 2 +- resize/resize2fs.8.in | 20 +++++++++ resize/resize2fs.c | 105 +++++++++++++++++++++++++++--------------------- resize/resize2fs.h | 3 +- 5 files changed, 148 insertions(+), 50 deletions(-)
resize/main.c +66 -2
@@ -40,7 +40,8 @@ char *program_name, *device_name, *io_options;static void usage (char *prog) {fprintf (stderr,_ ("Usage: %s [-d debug_flags] [-f] [-F] [-M] [-P] " -"[-p] device [new_size]\n\n" ), prog); +"[-p] [-E extended_options] device [new_size]\n\n" ), + prog);exit (1 ); }
@@ -146,6 +147,59 @@ static void determine_fs_stride(ext2_filsys fs)#endif } +static void parse_extended_opts (int *flags,const char *opts) +{ +char *buf, *token, *next, *p, *arg, *badopt =0 ; +int len; +int r_usage =0 ; + + len =strlen (opts); + buf =malloc (len+1 ); +if (!buf) { +fprintf (stderr, +_ ("Couldn't allocate memory to parse options!\n" )); +exit (1 ); + } +strcpy (buf, opts); +for (token = buf; token && *token; token = next) { + p =strchr (token,',' ); + next =0 ; +if (p) { + *p =0 ; + next = p+1 ; + } + arg =strchr (token,'=' ); +if (arg) { + *arg =0 ; + arg++; + } +if (!strcmp (token,"lazy_itable_init" )) { +int lazy; +if (arg) + lazy =strtoul (arg, &p,0 ); +else + lazy =1 ; +if (lazy) + *flags |=RESIZE_LAZY_ITABLE_INIT ; + }else { + r_usage++; + badopt = token; + } + } +if (r_usage) { +fprintf (stderr,_ ("\nBad option(s) specified: %s\n\n" +"Extended options are separated by commas, " +"and may take an argument which\n" +"\tis set off by an equals ('=') sign.\n\n" +"Valid extended options are:\n" +"\tlazy_itable_init=<0 to disable, 1 to enable>\n\n" ), + badopt ? badopt :"" ); +free (buf); +exit (1 ); + } +free (buf); +} +int main (int argc,char ** argv) {errcode_t retval;
@@ -174,6 +228,7 @@ int main (int argc, char ** argv)long sysval;int len, mount_flags;char *mtpt; +char * extended_opts =NULL ;#ifdef ENABLE_NLS setlocale (LC_MESSAGES ,"" );
@@ -189,7 +244,7 @@ int main (int argc, char ** argv)if (argc && *argv) program_name = *argv; -while ((c =getopt (argc, argv,"d:fFhMPpS:" )) !=EOF ) { +while ((c =getopt (argc, argv,"d:fFhMPpS:E:" )) !=EOF ) {switch (c) {case 'h' :usage (program_name);
@@ -215,6 +270,9 @@ int main (int argc, char ** argv)case 'S' : use_stride =atoi (optarg);break ; +case 'E' : + extended_opts = optarg; +break ;default :usage (program_name); }
@@ -232,6 +290,12 @@ int main (int argc, char ** argv)if (io_options) *io_options++ =0 ; +if (access ("/sys/fs/ext4/features/lazy_itable_init" ,R_OK ) ==0 ) + flags |=RESIZE_LAZY_ITABLE_INIT ; + +if (extended_opts) +parse_extended_opts (&flags, extended_opts); +/* * Figure out whether or not the device is mounted, and if it is * where it is mounted.
resize/online.c +1 -1
@@ -104,7 +104,7 @@ errcode_t online_resize_fs(ext2_filsys fs, const char *mtpt,* but at least it allows on-line resizing to function. */ new_fs->super->s_feature_incompat &= ~EXT4_FEATURE_INCOMPAT_FLEX_BG ; - retval =adjust_fs_info (new_fs, fs,0 , *new_size); + retval =adjust_fs_info (new_fs, fs,0 , *new_size,0 );if (retval)return retval;
resize/resize2fs.8.in +20 -0
@@ -18,6 +18,10 @@ resize2fs \- ext2/ext3/ext4 file system resizer .B \-S .I RAID-stride ] +[ +.B \-E +.I extended-options +] .I device [ .I size
@@ -128,6 +132,22 @@ The program will heuristically determine the RAID stride that was specified when the filesystem was created. This option allows the user to explicitly specify a RAID stride setting to be used by resize2fs instead. +.TP +.B \-E \fIextended-options +Set extended options for the filesystem. Extended options are comma +separated, and may take an argument using the equals ('=') sign. +The following extended options are supported: +.RS 1.2i +.TP +.B lazy_itable_init\fR[\fB= \fI<0 to disable, 1 to enable>\fR] +If enabled and the uninit_bg feature is enabled, the inode table will +not be fully initialized by +.BR resize2fs . +This speeds up filesystem +resize noticeably, but it requires the kernel to finish +initializing the filesystem in the background when the filesystem is +mounted. If the option value is omitted, it defaults to 1 to +enable lazy inode table initialization. .SH KNOWN BUGS The minimum size of the filesystem as estimated by resize2fs may be incorrect, especially for filesystems with 1k and 2k blocksizes.
resize/resize2fs.c +59 -46
154 lines not on this page · raw message
resize/resize2fs.h +2 -1
@@ -79,6 +79,7 @@ typedef struct ext2_sim_progress *ext2_sim_progmeter;#define RESIZE_PERCENT_COMPLETE 0x0100#define RESIZE_VERBOSE 0x0200 +#define RESIZE_LAZY_ITABLE_INIT 0x0400/* Do not initialize inode tables*/ /* * The core state structure for the ext2 resizer
@@ -129,7 +130,7 @@ extern errcode_t resize_fs(ext2_filsys fs, blk64_t *new_size, int flags,extern errcode_t adjust_fs_info (ext2_filsys fs,ext2_filsys old_fs,ext2fs_block_bitmap reserve_blocks, -blk64_t new_size); +blk64_t new_size,int flags);extern blk64_t calculate_minimum_resize_size (ext2_filsys fs);
Signature · 1 line
1.7.2.3
PATCH 2/2 resize2fs: Add discard support
This commit adds two new extended options - discard and nodiscard. When '-E discard' is specified, resize2fs will attempt to discard the portion of the device which will be used to extend the file system.
As a side-effect, if the discard also zeroes data (every subsequent read form discarded block will return zeros) resize2fs will skip inode table initialization, but still set the EXT2_BG_INODE_ZEROED flag. The default is 'nodiscard'.
--- resize/main.c | 11 ++++++- resize/resize2fs.8.in | 14 +++++++++ resize/resize2fs.c | 74 ++++++++++++++++++++++++++++++++++++++++++++++++- resize/resize2fs.h | 3 ++ 4 files changed, 100 insertions(+), 2 deletions(-)
resize/main.c +10 -1
@@ -61,6 +61,9 @@ static errcode_t resize_progress_func(ext2_resize_t rfs, int pass,ext2fs_progress_close (progress); progress =0 ;switch (pass) { +case E2_RSZ_DISCARD_DEVICE : + label =_ ("Discarding device" ); +break ;case E2_RSZ_EXTEND_ITABLE_PASS : label =_ ("Extending the inode table" );break ;
@@ -181,6 +184,10 @@ static void parse_extended_opts(int *flags, const char *opts) lazy =1 ;if (lazy) *flags |=RESIZE_LAZY_ITABLE_INIT ; + }else if (!strcmp (token,"discard" )) { + *flags |=RESIZE_DISCARD ; + }else if (!strcmp (token,"nodiscard" )) { + *flags &= ~RESIZE_DISCARD ; }else { r_usage++; badopt = token;
@@ -192,7 +199,9 @@ static void parse_extended_opts(int *flags, const char *opts)"and may take an argument which\n" "\tis set off by an equals ('=') sign.\n\n" "Valid extended options are:\n" - "\tlazy_itable_init=<0 to disable, 1 to enable>\n\n"), +"\tlazy_itable_init=<0 to disable, 1 to enable>\n" +"\tdiscard\n" + "\tnodiscard\n\n"), badopt ? badopt : "");free (buf);exit (1 );
resize/resize2fs.8.in +14 -0
@@ -148,6 +148,20 @@ resize noticeably, but it requires the kernel to finish initializing the filesystem in the background when the filesystem is mounted. If the option value is omitted, it defaults to 1 to enable lazy inode table initialization. +TP +.BI discard +Attempt to discard blocks +.BR resize2fs +is going to use to extend the filesystem (discarding blocks is useful on solid +state devices and sparse / thin-provisioned storage) before the resize. If the +device advertises that discard also zeroes data (any subsequent read after the +discard and before write returns zero), then mark all not-yet-zeroed inode +tables as zeroed. This significantly speed up filesystem resize if +.BR lazy_itable_init +is not specified. +.TP +.BI nodiscard +Do not attempt to discard blocks before resize. This is the default. .SH KNOWN BUGS The minimum size of the filesystem as estimated by resize2fs may be incorrect, especially for filesystems with 1k and 2k blocksizes.
resize/resize2fs.c +73 -1
98 lines not on this page · raw message
resize/resize2fs.h +3 -0
@@ -80,6 +80,8 @@ typedef struct ext2_sim_progress *ext2_sim_progmeter;#define RESIZE_PERCENT_COMPLETE 0x0100#define RESIZE_VERBOSE 0x0200#define RESIZE_LAZY_ITABLE_INIT 0x0400/* Do not initialize inode tables*/ +#define RESIZE_DISCARD 0x0800/* Discard space before attempt to resize */ +#define RESIZE_DISCARD_ZEROES 0x1000/* Discard zeroes data */ /* * The core state structure for the ext2 resizer
@@ -115,6 +117,7 @@ struct ext2_resize_struct {/* * Progress pass numbers... */ +#define E2_RSZ_DISCARD_DEVICE 0#define E2_RSZ_EXTEND_ITABLE_PASS 1#define E2_RSZ_BLOCK_RELOC_PASS 2#define E2_RSZ_INODE_SCAN_PASS 3
Signature · 1 line
1.7.2.3
Quoted 2 lines · Lukas Czerner
This commit adds extended options '-E' to the resize2fs code along with the first extended option lazy_itable_init=n.
Here it says the option is "=n", is it also possible to force this with "=y"?
resize/main.c static void determine_fs_stride(ext2_filsys fs) · line 183
Quoted 10 lines
resize/main.c +10
-0+static void parse_extended_opts (int *flags,const char *opts) +{ +if (!strcmp (token,"lazy_itable_init" )) { +int lazy; +if (arg) + lazy =strtoul (arg, &p,0 ); +else + lazy =1 ; +if (lazy) + *flags |=RESIZE_LAZY_ITABLE_INIT ;
Here it parses the option as "=0" or "=1", not "=n" or "=y". It looks like "=n" will accidentally return 0 from strtoul(), so that works as expected, but the "=y" option would fail (it would also return 0).
resize/main.c static void determine_fs_stride(ext2_filsys fs) · line 195
Quoted 3 lines
resize/main.c +3
-0+if (r_usage) { + fprintf(stderr, _("\nBad option(s) specified: %s\n\n" + "\tlazy_itable_init=<0 to disable, 1 to enable>\n\n"),
It looks a bit confusing "=<0 to disable", I thought initially that meant any value <= 0 would disable it, though I later see that there is a closing '>'. I think it is more standard to use "{}" braces for "one of these options must be given".
resize/main.c int main (int argc, char ** argv) · line 294
Quoted 6 lines
resize/main.c +5
-0@@ -232,6 +290,12 @@ int main (int argc, char ** argv) +if (access ("/sys/fs/ext4/features/lazy_itable_init" ,R_OK ) ==0 ) + flags |=RESIZE_LAZY_ITABLE_INIT ; + +if (extended_opts) +parse_extended_opts (&flags, extended_opts);
Good that the command-line options override the default value.
resize/resize2fs.8.in The · line 142
Quoted 1 line
resize/resize2fs.8.in +1
-0+.B lazy_itable_init\fR[\fB= \fI<0 to disable, 1 to enable>\fR]
Similarly, this should use "{}" around the options instead of "<>".
resize/resize2fs.8.in The · line 144
Quoted 2 lines
resize/resize2fs.8.in +2
-0+If enabled and the uninit_bg feature is enabled, the inode table will +not be fully initialized by
I would write "not be zeroed out on disk", since it is otherwise unclear if "not fully initialized" means that there will be less inodes available or some other issues if the inode table is not "fully" initialized.
Cheers, Andreas
Quoted 5 lines · Andreas Dilger
Quoted 2 lines · Lukas Czerner
This commit adds extended options '-E' to the resize2fs code along with the first extended option lazy_itable_init=n.
Here it says the option is "=n", is it also possible to force this with "=y"?
Oh, no not really. It should be just =0 or =1, it is the same as we have in mke2fs.
Quoted 13 lines
resize/main.c static void determine_fs_stride(ext2_filsys fs) · line 183
Quoted 11 lines
resize/main.c +10
-0+static void parse_extended_opts (int *flags,const char *opts) +{ +if (!strcmp (token,"lazy_itable_init" )) { +int lazy; +if (arg) + lazy =strtoul (arg, &p,0 ); +else + lazy =1 ; +if (lazy) + *flags |=RESIZE_LAZY_ITABLE_INIT ;Here it parses the option as "=0" or "=1", not "=n" or "=y". It looks like "=n" will accidentally return 0 from
strtoul(), so that works as expected, but the "=y" option would fail (it would also return 0).
As I mentioned it is not supposed to work with =y or =n, but only with =0 or =1. So I think it is expected, isn't it ?
Quoted 6 lines
resize/main.c static void determine_fs_stride(ext2_filsys fs) · line 195
Quoted 4 lines
resize/main.c +3
-0+if (r_usage) { + fprintf(stderr, _("\nBad option(s) specified: %s\n\n" + "\tlazy_itable_init=<0 to disable, 1 to enable>\n\n"),It looks a bit confusing "=<0 to disable", I thought initially that meant any value <= 0 would disable it, though I later see that there is a closing '>'. I think it is more standard to use "{}" braces for "one of these options must be given".
:) I did not noticed that before, but you're right, I'll change that to use "{}".
Quoted 9 lines
resize/main.c int main (int argc, char ** argv) · line 294
Quoted 7 lines
resize/main.c +5
-0@@ -232,6 +290,12 @@ int main (int argc, char ** argv) +if (access ("/sys/fs/ext4/features/lazy_itable_init" ,R_OK ) ==0 ) + flags |=RESIZE_LAZY_ITABLE_INIT ; + +if (extended_opts) +parse_extended_opts (&flags, extended_opts);Good that the command-line options override the default value.
Yes, it suppose to be that way.
Quoted 11 lines
resize/resize2fs.8.in The · line 142
Quoted 2 lines
resize/resize2fs.8.in +1
-0+.B lazy_itable_init\fR[\fB= \fI<0 to disable, 1 to enable>\fR]Similarly, this should use "{}" around the options instead of "<>".
resize/resize2fs.8.in The · line 144
Quoted 2 lines
resize/resize2fs.8.in +2
-0+If enabled and the uninit_bg feature is enabled, the inode table will +not be fully initialized byI would write "not be zeroed out on disk", since it is otherwise unclear if "not fully initialized" means that there will be less inodes available or some other issues if the inode table is not "fully" initialized.
Right.
Quoted 3 lines
Cheers, Andreas
Thanks!
-Lukas
PATCH v2 1/2 resize2fs: Add support for lazy itable initialization
Lazy inode table initialization speeds up file system resize operation because we can let the inode tables uninitialized. For some time now the mke2fs has similar option and now, when we have in-kernel lazyinit implementation we can add this feature to the resize2fs as well.
This commit adds extended options '-E' to the resize2fs code along with the first extended option lazy_itable_init=n, where n is a 0 or 1, though the '=n' argument can be omitted. With lazy_itable_init extended option one can instruct resize2fs to skip inode table initialization to significantly speed-up file system resize. If the option is omitted and the file system supports lazy inode table initialization it defaults to 1.
--- resize/main.c | 68 +++++++++++++++++++++++++++++++- resize/online.c | 2 +- resize/resize2fs.8.in | 20 +++++++++ resize/resize2fs.c | 105 +++++++++++++++++++++++++++--------------------- resize/resize2fs.h | 3 +- 5 files changed, 148 insertions(+), 50 deletions(-)
resize/main.c +66 -2
@@ -40,7 +40,8 @@ char *program_name, *device_name, *io_options;static void usage (char *prog) {fprintf (stderr,_ ("Usage: %s [-d debug_flags] [-f] [-F] [-M] [-P] " -"[-p] device [new_size]\n\n" ), prog); +"[-p] [-E extended_options] device [new_size]\n\n" ), + prog);exit (1 ); }
@@ -146,6 +147,59 @@ static void determine_fs_stride(ext2_filsys fs)#endif } +static void parse_extended_opts (int *flags,const char *opts) +{ +char *buf, *token, *next, *p, *arg, *badopt =0 ; +int len; +int r_usage =0 ; + + len =strlen (opts); + buf =malloc (len+1 ); +if (!buf) { +fprintf (stderr, +_ ("Couldn't allocate memory to parse options!\n" )); +exit (1 ); + } +strcpy (buf, opts); +for (token = buf; token && *token; token = next) { + p =strchr (token,',' ); + next =0 ; +if (p) { + *p =0 ; + next = p+1 ; + } + arg =strchr (token,'=' ); +if (arg) { + *arg =0 ; + arg++; + } +if (!strcmp (token,"lazy_itable_init" )) { +int lazy; +if (arg) + lazy =strtoul (arg, &p,0 ); +else + lazy =1 ; +if (lazy ==1 ) + *flags |=RESIZE_LAZY_ITABLE_INIT ; + }else { + r_usage++; + badopt = token; + } + } +if (r_usage) { +fprintf (stderr,_ ("\nBad option(s) specified: %s\n\n" +"Extended options are separated by commas, " +"and may take an argument which\n" +"\tis set off by an equals ('=') sign.\n\n" +"Valid extended options are:\n" +"\tlazy_itable_init[={0 to disable, 1 to enable}]\n\n" ), + badopt ? badopt :"" ); +free (buf); +exit (1 ); + } +free (buf); +} +int main (int argc,char ** argv) {errcode_t retval;
@@ -174,6 +228,7 @@ int main (int argc, char ** argv)long sysval;int len, mount_flags;char *mtpt; +char * extended_opts =NULL ;#ifdef ENABLE_NLS setlocale (LC_MESSAGES ,"" );
@@ -189,7 +244,7 @@ int main (int argc, char ** argv)if (argc && *argv) program_name = *argv; -while ((c =getopt (argc, argv,"d:fFhMPpS:" )) !=EOF ) { +while ((c =getopt (argc, argv,"d:fFhMPpS:E:" )) !=EOF ) {switch (c) {case 'h' :usage (program_name);
@@ -215,6 +270,9 @@ int main (int argc, char ** argv)case 'S' : use_stride =atoi (optarg);break ; +case 'E' : + extended_opts = optarg; +break ;default :usage (program_name); }
@@ -232,6 +290,12 @@ int main (int argc, char ** argv)if (io_options) *io_options++ =0 ; +if (access ("/sys/fs/ext4/features/lazy_itable_init" ,R_OK ) ==0 ) + flags |=RESIZE_LAZY_ITABLE_INIT ; + +if (extended_opts) +parse_extended_opts (&flags, extended_opts); +/* * Figure out whether or not the device is mounted, and if it is * where it is mounted.
resize/online.c +1 -1
@@ -104,7 +104,7 @@ errcode_t online_resize_fs(ext2_filsys fs, const char *mtpt,* but at least it allows on-line resizing to function. */ new_fs->super->s_feature_incompat &= ~EXT4_FEATURE_INCOMPAT_FLEX_BG ; - retval =adjust_fs_info (new_fs, fs,0 , *new_size); + retval =adjust_fs_info (new_fs, fs,0 , *new_size,0 );if (retval)return retval;
resize/resize2fs.8.in +20 -0
@@ -18,6 +18,10 @@ resize2fs \- ext2/ext3/ext4 file system resizer .B \-S .I RAID-stride ] +[ +.B \-E +.I extended-options +] .I device [ .I size
@@ -128,6 +132,22 @@ The program will heuristically determine the RAID stride that was specified when the filesystem was created. This option allows the user to explicitly specify a RAID stride setting to be used by resize2fs instead. +.TP +.B \-E \fIextended-options +Set extended options for the filesystem. Extended options are comma +separated, and may take an argument using the equals ('=') sign. +The following extended options are supported: +.RS 1.2i +.TP +.B lazy_itable_init\fR[\fB= \fI{0 to disable, 1 to enable}\fR] +If enabled and the uninit_bg feature is enabled, the inode table will +not be zeroed out on disk by +.BR resize2fs . +This speeds up filesystem +resize noticeably, but it requires the kernel to finish +initializing the filesystem in the background when the filesystem is +mounted. If the option value is omitted, it defaults to 1 to +enable lazy inode table initialization. .SH KNOWN BUGS The minimum size of the filesystem as estimated by resize2fs may be incorrect, especially for filesystems with 1k and 2k blocksizes.
resize/resize2fs.c +59 -46
154 lines not on this page · raw message
resize/resize2fs.h +2 -1
@@ -79,6 +79,7 @@ typedef struct ext2_sim_progress *ext2_sim_progmeter;#define RESIZE_PERCENT_COMPLETE 0x0100#define RESIZE_VERBOSE 0x0200 +#define RESIZE_LAZY_ITABLE_INIT 0x0400/* Do not initialize inode tables*/ /* * The core state structure for the ext2 resizer
@@ -129,7 +130,7 @@ extern errcode_t resize_fs(ext2_filsys fs, blk64_t *new_size, int flags,extern errcode_t adjust_fs_info (ext2_filsys fs,ext2_filsys old_fs,ext2fs_block_bitmap reserve_blocks, -blk64_t new_size); +blk64_t new_size,int flags);extern blk64_t calculate_minimum_resize_size (ext2_filsys fs);
Signature · 1 line
1.7.2.3
PATCH 1/1 mke2fs: Add support for lazy journal initialization
This patch adds the ability to skip zeroing the journal on disk. This can significantly speed up mke2fs with large journals. At worst the uninitialized journal is only a very short-term risk (if at all), because the journal will be overwritten on any new filesystem as soon as any significant amount of data is written to disk, unlike lazy_itable_init which can leave uninitialized itable blocks indefinitely (in the absence of the kernel init thread).
Cheers, Andreas
From a7f156b9078e2b121c4c7d509b55476804ae3f92 Mon Sep 17 00:00:00 2001
From: Andreas Dilger <[email protected]>
Date: Thu, 3 Feb 2011 13:04:15 -0700
Subject: [PATCH] mke2fs: Add lazy journal initialization option
This patch adds the ability to skip zeroing the journal on disk. This can significantly speed up mke2fs with large journals. At worst the uninitialized journal is only a very short-term risk (if at all), because the journal will be overwritten on any new filesystem as soon as any significant amount of data is written to disk, unlike lazy_itable_init which can leave uninitialized itable blocks indefinitely (in the absence of the kernel init thread).
--- lib/ext2fs/ext2fs.h | 5 ++--- lib/ext2fs/mkjournal.c | 22 ++++++++++++++++++---- lib/ext2fs/unix_io.c | 2 ++ misc/mke2fs.8.in | 10 +++++++++- misc/mke2fs.c | 19 +++++++++++++++++-- 5 files changed, 48 insertions(+), 10 deletions(-)
lib/ext2fs/ext2fs.h +2 -3
@@ -193,10 +193,9 @@ typedef struct ext2_file *ext2_file_t;/* * Flags for mkjournal -* -* EXT2_MKJOURNAL_V1_SUPER Make a (deprecated) V1 journal superblock */ -#define EXT2_MKJOURNAL_V1_SUPER 0x0000001 +#define EXT2_MKJOURNAL_V1_SUPER 0x0000001/* create V1 superblock (deprecated) */ +#define EXT2_MKJOURNAL_LAZYINIT 0x0000002/* don't zero journal inode before use*/ struct opaque_ext2_group_desc ;
lib/ext2fs/mkjournal.c +18 -4
@@ -103,7 +103,7 @@ static errcode_t write_journal_file(ext2_filsys fs, char *filename,/* Open the device or journal file */ if ((fd =open (filename,O_WRONLY )) <0 ) { retval = errno; - goto errout; + goto errfree; }/* Write the superblock out */
@@ -117,6 +117,9 @@ static errcode_t write_journal_file(ext2_filsys fs, char *filename, goto errout;memset (buf,0 , fs->blocksize); +if (flags &EXT2_MKJOURNAL_LAZYINIT ) + goto success; +for (i =1 ; i < size; i++) { ret_size =write (fd, buf, fs->blocksize);if (ret_size <0 ) {
@@ -126,10 +129,12 @@ static errcode_t write_journal_file(ext2_filsys fs, char *filename,if (ret_size != (int ) fs->blocksize) goto errout; } -close (fd); +success: retval =0 ; errout: +close (fd); +errfree:ext2fs_free_mem (&buf);return retval; }
@@ -213,6 +218,7 @@ struct mkjournal_struct {blk64_t goal;blk64_t blk_to_zero;int zero_count; +int flags;char *buf;errcode_t err; };
@@ -242,9 +248,9 @@ static int mkjournal_proc(ext2_filsys fs, es->newblocks++; retval =0 ; -if (blockcnt <=0 ) +if (blockcnt <=0 ) { retval =io_channel_write_blk64 (fs->io, new_blk,1 , es->buf); -else { + }else if (!(es->flags &EXT2_MKJOURNAL_LAZYINIT )) {if (es->zero_count) {if ((es->blk_to_zero + es->zero_count == new_blk) && (es->zero_count <1024 ))
@@ -308,6 +314,7 @@ static errcode_t write_journal_inode(ext2_filsys fs, ext2_ino_t journal_ino, es.newblocks =0 ; es.buf = buf; es.err =0 ; + es.flags = flags; es.zero_count =0 ;if (fs->super->s_feature_incompat &EXT3_FEATURE_INCOMPAT_EXTENTS ) {
@@ -504,6 +511,13 @@ errcode_t ext2fs_add_journal_inode(ext2_filsys fs, blk_t size, int flags)if ((fd =open (jfile,O_CREAT |O_WRONLY ,0600 )) <0 )return errno; +/* Note that we can't do lazy journal initialization for mounted +* filesystems, since the zero writing is also allocating the +* journal blocks. We could use fallocate, but not all kernels +* support that, and creating a journal on a mounted ext2 +* filesystems is extremely rare these days... Skip it for now. */ + flags &= ~EXT2_MKJOURNAL_LAZYINIT ; +if ((retval =write_journal_file (fs, jfile, size, flags))) goto errout;
lib/ext2fs/unix_io.c +2 -0
@@ -472,8 +472,10 @@ static errcode_t unix_open(const char *name, int flags, io_channel *channel) open_flags = (flags &IO_FLAG_RW ) ?O_RDWR :O_RDONLY ;if (flags &IO_FLAG_EXCLUSIVE ) open_flags |=O_EXCL ; +#ifdef O_DIRECT if (flags &IO_FLAG_DIRECT_IO ) open_flags |=O_DIRECT ; +#endif data->flags = flags;#ifdef HAVE_OPEN64
misc/mke2fs.8.in +9 -1
@@ -232,7 +232,15 @@ This speeds up filesystem initialization noticeably, but it requires the kernel to finish initializing the filesystem in the background when the filesystem is first mounted. If the option value is omitted, it defaults to 1 to -enable lazy inode table initialization. +enable lazy inode table zeroing. +.TP +.B lazy_journal_init\fR[\fB= \fI{0 to disable, 1 to enable}\fR] +If enabled, the journal inode will not be fully zeroed out by +.BR mke2fs . +This speeds up filesystem initialization noticeably, but carries some +small risk if the system crashes before the journal has been overwritten +entirely one time. If the option value is omitted, it defaults to 1 to +enable lazy journal inode zeroing. .TP .B test_fs Set a flag in the filesystem superblock indicating that it may be
misc/mke2fs.c +17 -2
@@ -501,6 +501,10 @@ static void create_journal_dev(ext2_filsys fs) _("while initializing journal superblock"));exit (1 ); } + +if (journal_flags &EXT2_MKJOURNAL_LAZYINIT ) + goto write_superblock; +ext2fs_numeric_progress_init (fs, &progress,_ ("Zeroing journal device: " ),ext2fs_blocks_count (fs->super));
@@ -525,6 +529,8 @@ static void create_journal_dev(ext2_filsys fs) }ext2fs_zero_blocks2 (0 ,0 ,0 ,0 ,0 ); +ext2fs_numeric_progress_close (fs, &progress,NULL ); +write_superblock: retval =io_channel_write_blk64 (fs->io, fs->super->s_first_data_block+1 ,1 , buf);
@@ -533,7 +539,6 @@ static void create_journal_dev(ext2_filsys fs) _("while writing journal superblock"));exit (1 ); } -ext2fs_numeric_progress_close (fs, &progress,NULL ); }static void show_stats (ext2_filsys fs)
@@ -744,6 +749,12 @@ static void parse_extended_opts(struct ext2_super_block *param, } }else if (!strcmp (token,"test_fs" )) { param->s_flags |=EXT2_FLAGS_TEST_FILESYS ; + }else if (!strcmp (token,"lazy_journal_init" )) { +if (arg) + journal_flags |=strtoul (arg, &p,0 ) ? +EXT2_MKJOURNAL_LAZYINIT :0 ; +else + journal_flags |=EXT2_MKJOURNAL_LAZYINIT ; }else if (!strcmp (token,"lazy_itable_init" )) {if (arg) lazy_itable_init =strtoul (arg, &p,0 );
@@ -767,7 +778,8 @@ static void parse_extended_opts(struct ext2_super_block *param,"\tstride=<RAID per-disk data chunk in blocks>\n" "\tstripe-width=<RAID stride * data disks in blocks>\n" "\tresize=<resize maximum size in blocks>\n" -"\tlazy_itable_init=<0 to disable, 1 to enable>\n" +"\tlazy_itable_init={0 to disable, 1 to enable}\n" +"\tlazy_journal_init={0 to disable, 1 to enable}\n" "\ttest_fs\n" "\tdiscard\n" "\tnodiscard\n\n"),
@@ -1756,6 +1768,9 @@ profile_error: lazy_itable_init =get_bool_from_profile (fs_types,"lazy_itable_init" , lazy_itable_init); + journal_flags |=get_bool_from_profile (fs_types, +"lazy_journal_init" ,0 ) ? +EXT2_MKJOURNAL_LAZYINIT :0 ; discard =get_bool_from_profile (fs_types,"discard" , discard);/* Get options from profile */
Signature · 1 line
1.7.2
Re: [PATCH] mke2fs: Add support for lazy journal initialization
Quoted 9 lines · Andreas Dilger
This patch adds the ability to skip zeroing the journal on disk. This can significantly speed up mke2fs with large journals. At worst the uninitialized journal is only a very short-term risk (if at all), because the journal will be overwritten on any new filesystem as soon as any significant amount of data is written to disk, unlike
lazy_itable_initwhich can leave uninitialized itable blocks indefinitely (in the absence of the kernel init thread).Cheers, Andreas
Hi Andreas,
I think that we can skip the journal zeroing if the underlying device, or the journal device supports discard, and advertise that discard zeroes data. It is the same behavior as in the case of inode tables and it would be nice to have the same thing for journal. Are you planning to implement this as well ?
Thanks!
-Lukas
Re: [PATCH] mke2fs: Add support for lazy journal initialization
Quoted 8 lines · Lukas Czerner
Quoted 6 lines · Andreas Dilger
This patch adds the ability to skip zeroing the journal on disk. This can significantly speed up mke2fs with large journals. At worst the uninitialized journal is only a very short-term risk (if at all), because the journal will be overwritten on any new filesystem as soon as any significant amount of data is written to disk, unlike
lazy_itable_initwhich can leave uninitialized itable blocks indefinitely (in the absence of the kernel init thread).
Quoted 5 lines
I think that we can skip the journal zeroing if the underlying device, or the journal device supports discard, and advertise that discard zeroes data. It is the same behavior as in the case of inode tables and it would be nice to have the same thing for journal. Are you planning to implement this as well ?
That detection didn't exist when I originally wrote that patch. It definitely makes sense to default to not zeroing the journal if discard has been done.
Cheers, Andreas
Quoted 11 lines · Lukas Czerner
Lazy inode table initialization speeds up file system resize operation because we can let the inode tables uninitialized. For some time now the mke2fs has similar option and now, when we have in-kernel lazyinit implementation we can add this feature to the resize2fs as well.
This commit adds extended options '-E' to the resize2fs code along with the first extended option lazy_itable_init=n, where n is a 0 or 1, though the '=n' argument can be omitted. With
lazy_itable_initextended option one can instruct resize2fs to skip inode table initialization to significantly speed-up file system resize. If the option is omitted and the file system supports lazy inode table initialization it defaults to 1.
Hi Ted,
those two patches are lying long enough. Any chance merging them ? Or would I need to rebase and repost ?
Thanks!
-Lukas
Quoted 362 lines
Signed-off-by Lukas Czerner <[email protected]>--- resize/main.c | 68 +++++++++++++++++++++++++++++++- resize/online.c | 2 +- resize/resize2fs.8.in | 20 +++++++++ resize/resize2fs.c | 105 +++++++++++++++++++++++++++--------------------- resize/resize2fs.h | 3 +- 5 files changed, 148 insertions(+), 50 deletions(-)resize/main.c +66
-2@@ -40,7 +40,8 @@ char *program_name, *device_name, *io_options;static void usage (char *prog) {fprintf (stderr,_ ("Usage: %s [-d debug_flags] [-f] [-F] [-M] [-P] " -"[-p] device [new_size]\n\n" ), prog); +"[-p] [-E extended_options] device [new_size]\n\n" ), + prog);exit (1 ); }@@ -146,6 +147,59 @@ static void determine_fs_stride(ext2_filsys fs)#endif } +static void parse_extended_opts (int *flags,const char *opts) +{ +char *buf, *token, *next, *p, *arg, *badopt =0 ; +int len; +int r_usage =0 ; + + len =strlen (opts); + buf =malloc (len+1 ); +if (!buf) { +fprintf (stderr, +_ ("Couldn't allocate memory to parse options!\n" )); +exit (1 ); + } +strcpy (buf, opts); +for (token = buf; token && *token; token = next) { + p =strchr (token,',' ); + next =0 ; +if (p) { + *p =0 ; + next = p+1 ; + } + arg =strchr (token,'=' ); +if (arg) { + *arg =0 ; + arg++; + } +if (!strcmp (token,"lazy_itable_init" )) { +int lazy; +if (arg) + lazy =strtoul (arg, &p,0 ); +else + lazy =1 ; +if (lazy ==1 ) + *flags |=RESIZE_LAZY_ITABLE_INIT ; + }else { + r_usage++; + badopt = token; + } + } +if (r_usage) { +fprintf (stderr,_ ("\nBad option(s) specified: %s\n\n" +"Extended options are separated by commas, " +"and may take an argument which\n" +"\tis set off by an equals ('=') sign.\n\n" +"Valid extended options are:\n" +"\tlazy_itable_init[={0 to disable, 1 to enable}]\n\n" ), + badopt ? badopt :"" ); +free (buf); +exit (1 ); + } +free (buf); +} +int main (int argc,char ** argv) {errcode_t retval;@@ -174,6 +228,7 @@ int main (int argc, char ** argv)long sysval;int len, mount_flags;char *mtpt; +char * extended_opts =NULL ;#ifdef ENABLE_NLS setlocale (LC_MESSAGES ,"" );@@ -189,7 +244,7 @@ int main (int argc, char ** argv)if (argc && *argv) program_name = *argv; -while ((c =getopt (argc, argv,"d:fFhMPpS:" )) !=EOF ) { +while ((c =getopt (argc, argv,"d:fFhMPpS:E:" )) !=EOF ) {switch (c) {case 'h' :usage (program_name);@@ -215,6 +270,9 @@ int main (int argc, char ** argv)case 'S' : use_stride =atoi (optarg);break ; +case 'E' : + extended_opts = optarg; +break ;default :usage (program_name); }@@ -232,6 +290,12 @@ int main (int argc, char ** argv)if (io_options) *io_options++ =0 ; +if (access ("/sys/fs/ext4/features/lazy_itable_init" ,R_OK ) ==0 ) + flags |=RESIZE_LAZY_ITABLE_INIT ; + +if (extended_opts) +parse_extended_opts (&flags, extended_opts); +/* * Figure out whether or not the device is mounted, and if it is * where it is mounted. resize/online.c +1
-1@@ -104,7 +104,7 @@ errcode_t online_resize_fs(ext2_filsys fs, const char *mtpt,* but at least it allows on-line resizing to function. */ new_fs->super->s_feature_incompat &= ~EXT4_FEATURE_INCOMPAT_FLEX_BG ; - retval =adjust_fs_info (new_fs, fs,0 , *new_size); + retval =adjust_fs_info (new_fs, fs,0 , *new_size,0 );if (retval)return retval;resize/resize2fs.8.in +20
-0@@ -18,6 +18,10 @@ resize2fs \- ext2/ext3/ext4 file system resizer .B \-S .I RAID-stride ] +[ +.B \-E +.I extended-options +] .I device [ .I size@@ -128,6 +132,22 @@ The program will heuristically determine the RAID stride that was specified when the filesystem was created. This option allows the user to explicitly specify a RAID stride setting to be used by resize2fs instead. +.TP +.B \-E \fIextended-options +Set extended options for the filesystem. Extended options are comma +separated, and may take an argument using the equals ('=') sign. +The following extended options are supported: +.RS 1.2i +.TP +.B lazy_itable_init\fR[\fB= \fI{0 to disable, 1 to enable}\fR] +If enabled and the uninit_bg feature is enabled, the inode table will +not be zeroed out on disk by +.BR resize2fs . +This speeds up filesystem +resize noticeably, but it requires the kernel to finish +initializing the filesystem in the background when the filesystem is +mounted. If the option value is omitted, it defaults to 1 to +enable lazy inode table initialization. .SH KNOWN BUGS The minimum size of the filesystem as estimated by resize2fs may be incorrect, especially for filesystems with 1k and 2k blocksizes.resize/resize2fs.c +59
-46@@ -41,7 +41,8 @@#endif static void fix_uninit_block_bitmaps (ext2_filsys fs); -static errcode_t adjust_superblock (ext2_resize_t rfs,blk64_t new_size); +static errcode_t adjust_superblock (ext2_resize_t rfs,blk64_t new_size, +int flags);static errcode_t blocks_to_move (ext2_resize_t rfs);static errcode_t block_mover (ext2_resize_t rfs);static errcode_t inode_scan_and_fix (ext2_resize_t rfs);@@ -102,7 +103,7 @@ errcode_t resize_fs(ext2_filsys fs, blk64_t *new_size, int flags,if (retval) goto errout; - retval =adjust_superblock (rfs, *new_size); + retval =adjust_superblock (rfs, *new_size, flags);if (retval) goto errout;@@ -288,7 +289,8 @@ static void free_gdp_blocks(ext2_filsys fs,* filesystem. */ errcode_t adjust_fs_info (ext2_filsys fs,ext2_filsys old_fs, -ext2fs_block_bitmap reserve_blocks,blk64_t new_size) +ext2fs_block_bitmap reserve_blocks,blk64_t new_size, +int flags) {errcode_t retval;blk64_t overhead =0 ;@@ -497,8 +499,12 @@ retry: adjblocks =0 ;ext2fs_bg_flags_zap (fs, i); -if (csum_flag) +if (csum_flag && (flags &RESIZE_LAZY_ITABLE_INIT )) +ext2fs_bg_flags_set (fs, i,EXT2_BG_INODE_UNINIT ); +else if (csum_flag)ext2fs_bg_flags_set (fs, i,EXT2_BG_INODE_UNINIT |EXT2_BG_INODE_ZEROED ); +else + flags &= ~RESIZE_LAZY_ITABLE_INIT ;if (i == fs->group_desc_count-1 ) { numblocks = (ext2fs_blocks_count (fs->super) - fs->super->s_first_data_block) %@@ -562,18 +568,57 @@ errout:return (retval); } +static errcode_t write_inode_tables (ext2_resize_t rfs,ext2_filsys fs) +{ +unsigned long i, max_group; +errcode_t retval; +int adj =0 ; + +memset (rfs->itable_buf,0 , fs->blocksize * fs->inode_blocks_per_group); + adj = rfs->old_fs->group_desc_count; + max_group = fs->group_desc_count - adj; +if (rfs->progress) { + retval = rfs->progress (rfs,E2_RSZ_EXTEND_ITABLE_PASS , +0 , max_group); +if (retval) + goto out; + } + +for (i = rfs->old_fs->group_desc_count; + i < fs->group_desc_count; i++) { +/* +* Write out the new inode table +*/ + retval =io_channel_write_blk64 (fs->io, +ext2fs_inode_table_loc (fs, i), + fs->inode_blocks_per_group, + rfs->itable_buf); +if (retval) +break ; + +io_channel_flush (fs->io); +if (rfs->progress) { + retval = rfs->progress (rfs,E2_RSZ_EXTEND_ITABLE_PASS , + i - adj +1 , max_group); +if (retval) +break ; + } + } +io_channel_flush (fs->io); +out: +return retval; +} + +/* * This routine adjusts the superblock and other data structures, both * in disk as well as in memory... */ -static errcode_t adjust_superblock (ext2_resize_t rfs,blk64_t new_size) +static errcode_t adjust_superblock (ext2_resize_t rfs,blk64_t new_size, +int flags) { -ext2_filsys fs; -int adj =0 ; +ext2_filsys fs;errcode_t retval; -blk64_t group_block; -unsigned long i; -unsigned long max_group; fs = rfs->new_fs;ext2fs_mark_super_dirty (fs);@@ -585,7 +630,8 @@ static errcode_t adjust_superblock(ext2_resize_t rfs, blk64_t new_size)if (retval)return retval; - retval =adjust_fs_info (fs, rfs->old_fs, rfs->reserve_blocks, new_size); + retval =adjust_fs_info (fs, rfs->old_fs, rfs->reserve_blocks, new_size, + flags);if (retval) goto errout;@@ -626,41 +672,8 @@ static errcode_t adjust_superblock(ext2_resize_t rfs, blk64_t new_size)if (retval) goto errout; -memset (rfs->itable_buf,0 , fs->blocksize * fs->inode_blocks_per_group); - group_block = fs->super->s_first_data_block + - rfs->old_fs->group_desc_count * fs->super->s_blocks_per_group; - - adj = rfs->old_fs->group_desc_count; - max_group = fs->group_desc_count - adj; -if (rfs->progress) { - retval = rfs->progress (rfs,E2_RSZ_EXTEND_ITABLE_PASS , -0 , max_group); -if (retval) - goto errout; - } -for (i = rfs->old_fs->group_desc_count; - i < fs->group_desc_count; i++) { -/* -* Write out the new inode table -*/ - retval =io_channel_write_blk64 (fs->io, -ext2fs_inode_table_loc (fs, i), - fs->inode_blocks_per_group, - rfs->itable_buf); -if (retval) goto errout; - -io_channel_flush (fs->io); -if (rfs->progress) { - retval = rfs->progress (rfs,E2_RSZ_EXTEND_ITABLE_PASS , - i - adj +1 , max_group); -if (retval) - goto errout; - } - group_block += fs->super->s_blocks_per_group; - } -io_channel_flush (fs->io); - retval =0 ; - +if (!(flags &RESIZE_LAZY_ITABLE_INIT )) + retval =write_inode_tables (rfs, fs); errout:return retval; }resize/resize2fs.h +2
-1@@ -79,6 +79,7 @@ typedef struct ext2_sim_progress *ext2_sim_progmeter;#define RESIZE_PERCENT_COMPLETE 0x0100#define RESIZE_VERBOSE 0x0200 +#define RESIZE_LAZY_ITABLE_INIT 0x0400/* Do not initialize inode tables*/ /* * The core state structure for the ext2 resizer @@ -129,7 +130,7 @@ extern errcode_t resize_fs(ext2_filsys fs, blk64_t *new_size, int flags,extern errcode_t adjust_fs_info (ext2_filsys fs,ext2_filsys old_fs,ext2fs_block_bitmap reserve_blocks, -blk64_t new_size); +blk64_t new_size,int flags);extern blk64_t calculate_minimum_resize_size (ext2_filsys fs);
Quoted 11 lines · Lukas Czerner
Lazy inode table initialization speeds up file system resize operation because we can let the inode tables uninitialized. For some time now the mke2fs has similar option and now, when we have in-kernel lazyinit implementation we can add this feature to the resize2fs as well.
This commit adds extended options '-E' to the resize2fs code along with the first extended option lazy_itable_init=n. With
lazy_itable_initextended option one can instruct resize2fs to skip inode table initialization to significantly speed-up file system resize. If the option is omitted and the file system supports lazy inode table initialization it defaults to 1.
ping
Quoted 362 lines
Signed-off-by Lukas Czerner <[email protected]>--- resize/main.c | 68 +++++++++++++++++++++++++++++++- resize/online.c | 2 +- resize/resize2fs.8.in | 20 +++++++++ resize/resize2fs.c | 105 +++++++++++++++++++++++++++--------------------- resize/resize2fs.h | 3 +- 5 files changed, 148 insertions(+), 50 deletions(-)resize/main.c +66
-2@@ -40,7 +40,8 @@ char *program_name, *device_name, *io_options;static void usage (char *prog) {fprintf (stderr,_ ("Usage: %s [-d debug_flags] [-f] [-F] [-M] [-P] " -"[-p] device [new_size]\n\n" ), prog); +"[-p] [-E extended_options] device [new_size]\n\n" ), + prog);exit (1 ); }@@ -146,6 +147,59 @@ static void determine_fs_stride(ext2_filsys fs)#endif } +static void parse_extended_opts (int *flags,const char *opts) +{ +char *buf, *token, *next, *p, *arg, *badopt =0 ; +int len; +int r_usage =0 ; + + len =strlen (opts); + buf =malloc (len+1 ); +if (!buf) { +fprintf (stderr, +_ ("Couldn't allocate memory to parse options!\n" )); +exit (1 ); + } +strcpy (buf, opts); +for (token = buf; token && *token; token = next) { + p =strchr (token,',' ); + next =0 ; +if (p) { + *p =0 ; + next = p+1 ; + } + arg =strchr (token,'=' ); +if (arg) { + *arg =0 ; + arg++; + } +if (!strcmp (token,"lazy_itable_init" )) { +int lazy; +if (arg) + lazy =strtoul (arg, &p,0 ); +else + lazy =1 ; +if (lazy) + *flags |=RESIZE_LAZY_ITABLE_INIT ; + }else { + r_usage++; + badopt = token; + } + } +if (r_usage) { +fprintf (stderr,_ ("\nBad option(s) specified: %s\n\n" +"Extended options are separated by commas, " +"and may take an argument which\n" +"\tis set off by an equals ('=') sign.\n\n" +"Valid extended options are:\n" +"\tlazy_itable_init=<0 to disable, 1 to enable>\n\n" ), + badopt ? badopt :"" ); +free (buf); +exit (1 ); + } +free (buf); +} +int main (int argc,char ** argv) {errcode_t retval;@@ -174,6 +228,7 @@ int main (int argc, char ** argv)long sysval;int len, mount_flags;char *mtpt; +char * extended_opts =NULL ;#ifdef ENABLE_NLS setlocale (LC_MESSAGES ,"" );@@ -189,7 +244,7 @@ int main (int argc, char ** argv)if (argc && *argv) program_name = *argv; -while ((c =getopt (argc, argv,"d:fFhMPpS:" )) !=EOF ) { +while ((c =getopt (argc, argv,"d:fFhMPpS:E:" )) !=EOF ) {switch (c) {case 'h' :usage (program_name);@@ -215,6 +270,9 @@ int main (int argc, char ** argv)case 'S' : use_stride =atoi (optarg);break ; +case 'E' : + extended_opts = optarg; +break ;default :usage (program_name); }@@ -232,6 +290,12 @@ int main (int argc, char ** argv)if (io_options) *io_options++ =0 ; +if (access ("/sys/fs/ext4/features/lazy_itable_init" ,R_OK ) ==0 ) + flags |=RESIZE_LAZY_ITABLE_INIT ; + +if (extended_opts) +parse_extended_opts (&flags, extended_opts); +/* * Figure out whether or not the device is mounted, and if it is * where it is mounted. resize/online.c +1
-1@@ -104,7 +104,7 @@ errcode_t online_resize_fs(ext2_filsys fs, const char *mtpt,* but at least it allows on-line resizing to function. */ new_fs->super->s_feature_incompat &= ~EXT4_FEATURE_INCOMPAT_FLEX_BG ; - retval =adjust_fs_info (new_fs, fs,0 , *new_size); + retval =adjust_fs_info (new_fs, fs,0 , *new_size,0 );if (retval)return retval;resize/resize2fs.8.in +20
-0@@ -18,6 +18,10 @@ resize2fs \- ext2/ext3/ext4 file system resizer .B \-S .I RAID-stride ] +[ +.B \-E +.I extended-options +] .I device [ .I size@@ -128,6 +132,22 @@ The program will heuristically determine the RAID stride that was specified when the filesystem was created. This option allows the user to explicitly specify a RAID stride setting to be used by resize2fs instead. +.TP +.B \-E \fIextended-options +Set extended options for the filesystem. Extended options are comma +separated, and may take an argument using the equals ('=') sign. +The following extended options are supported: +.RS 1.2i +.TP +.B lazy_itable_init\fR[\fB= \fI<0 to disable, 1 to enable>\fR] +If enabled and the uninit_bg feature is enabled, the inode table will +not be fully initialized by +.BR resize2fs . +This speeds up filesystem +resize noticeably, but it requires the kernel to finish +initializing the filesystem in the background when the filesystem is +mounted. If the option value is omitted, it defaults to 1 to +enable lazy inode table initialization. .SH KNOWN BUGS The minimum size of the filesystem as estimated by resize2fs may be incorrect, especially for filesystems with 1k and 2k blocksizes.resize/resize2fs.c +59
-46@@ -41,7 +41,8 @@#endif static void fix_uninit_block_bitmaps (ext2_filsys fs); -static errcode_t adjust_superblock (ext2_resize_t rfs,blk64_t new_size); +static errcode_t adjust_superblock (ext2_resize_t rfs,blk64_t new_size, +int flags);static errcode_t blocks_to_move (ext2_resize_t rfs);static errcode_t block_mover (ext2_resize_t rfs);static errcode_t inode_scan_and_fix (ext2_resize_t rfs);@@ -102,7 +103,7 @@ errcode_t resize_fs(ext2_filsys fs, blk64_t *new_size, int flags,if (retval) goto errout; - retval =adjust_superblock (rfs, *new_size); + retval =adjust_superblock (rfs, *new_size, flags);if (retval) goto errout;@@ -288,7 +289,8 @@ static void free_gdp_blocks(ext2_filsys fs,* filesystem. */ errcode_t adjust_fs_info (ext2_filsys fs,ext2_filsys old_fs, -ext2fs_block_bitmap reserve_blocks,blk64_t new_size) +ext2fs_block_bitmap reserve_blocks,blk64_t new_size, +int flags) {errcode_t retval;blk64_t overhead =0 ;@@ -497,8 +499,12 @@ retry: adjblocks =0 ;ext2fs_bg_flags_zap (fs, i); -if (csum_flag) +if (csum_flag && (flags &RESIZE_LAZY_ITABLE_INIT )) +ext2fs_bg_flags_set (fs, i,EXT2_BG_INODE_UNINIT ); +else if (csum_flag)ext2fs_bg_flags_set (fs, i,EXT2_BG_INODE_UNINIT |EXT2_BG_INODE_ZEROED ); +else + flags &= ~RESIZE_LAZY_ITABLE_INIT ;if (i == fs->group_desc_count-1 ) { numblocks = (ext2fs_blocks_count (fs->super) - fs->super->s_first_data_block) %@@ -562,18 +568,57 @@ errout:return (retval); } +static errcode_t write_inode_tables (ext2_resize_t rfs,ext2_filsys fs) +{ +unsigned long i, max_group; +errcode_t retval; +int adj =0 ; + +memset (rfs->itable_buf,0 , fs->blocksize * fs->inode_blocks_per_group); + adj = rfs->old_fs->group_desc_count; + max_group = fs->group_desc_count - adj; +if (rfs->progress) { + retval = rfs->progress (rfs,E2_RSZ_EXTEND_ITABLE_PASS , +0 , max_group); +if (retval) + goto out; + } + +for (i = rfs->old_fs->group_desc_count; + i < fs->group_desc_count; i++) { +/* +* Write out the new inode table +*/ + retval =io_channel_write_blk64 (fs->io, +ext2fs_inode_table_loc (fs, i), + fs->inode_blocks_per_group, + rfs->itable_buf); +if (retval) +break ; + +io_channel_flush (fs->io); +if (rfs->progress) { + retval = rfs->progress (rfs,E2_RSZ_EXTEND_ITABLE_PASS , + i - adj +1 , max_group); +if (retval) +break ; + } + } +io_channel_flush (fs->io); +out: +return retval; +} + +/* * This routine adjusts the superblock and other data structures, both * in disk as well as in memory... */ -static errcode_t adjust_superblock (ext2_resize_t rfs,blk64_t new_size) +static errcode_t adjust_superblock (ext2_resize_t rfs,blk64_t new_size, +int flags) { -ext2_filsys fs; -int adj =0 ; +ext2_filsys fs;errcode_t retval; -blk64_t group_block; -unsigned long i; -unsigned long max_group; fs = rfs->new_fs;ext2fs_mark_super_dirty (fs);@@ -585,7 +630,8 @@ static errcode_t adjust_superblock(ext2_resize_t rfs, blk64_t new_size)if (retval)return retval; - retval =adjust_fs_info (fs, rfs->old_fs, rfs->reserve_blocks, new_size); + retval =adjust_fs_info (fs, rfs->old_fs, rfs->reserve_blocks, new_size, + flags);if (retval) goto errout;@@ -626,41 +672,8 @@ static errcode_t adjust_superblock(ext2_resize_t rfs, blk64_t new_size)if (retval) goto errout; -memset (rfs->itable_buf,0 , fs->blocksize * fs->inode_blocks_per_group); - group_block = fs->super->s_first_data_block + - rfs->old_fs->group_desc_count * fs->super->s_blocks_per_group; - - adj = rfs->old_fs->group_desc_count; - max_group = fs->group_desc_count - adj; -if (rfs->progress) { - retval = rfs->progress (rfs,E2_RSZ_EXTEND_ITABLE_PASS , -0 , max_group); -if (retval) - goto errout; - } -for (i = rfs->old_fs->group_desc_count; - i < fs->group_desc_count; i++) { -/* -* Write out the new inode table -*/ - retval =io_channel_write_blk64 (fs->io, -ext2fs_inode_table_loc (fs, i), - fs->inode_blocks_per_group, - rfs->itable_buf); -if (retval) goto errout; - -io_channel_flush (fs->io); -if (rfs->progress) { - retval = rfs->progress (rfs,E2_RSZ_EXTEND_ITABLE_PASS , - i - adj +1 , max_group); -if (retval) - goto errout; - } - group_block += fs->super->s_blocks_per_group; - } -io_channel_flush (fs->io); - retval =0 ; - +if (!(flags &RESIZE_LAZY_ITABLE_INIT )) + retval =write_inode_tables (rfs, fs); errout:return retval; }resize/resize2fs.h +2
-1@@ -79,6 +79,7 @@ typedef struct ext2_sim_progress *ext2_sim_progmeter;#define RESIZE_PERCENT_COMPLETE 0x0100#define RESIZE_VERBOSE 0x0200 +#define RESIZE_LAZY_ITABLE_INIT 0x0400/* Do not initialize inode tables*/ /* * The core state structure for the ext2 resizer @@ -129,7 +130,7 @@ extern errcode_t resize_fs(ext2_filsys fs, blk64_t *new_size, int flags,extern errcode_t adjust_fs_info (ext2_filsys fs,ext2_filsys old_fs,ext2fs_block_bitmap reserve_blocks, -blk64_t new_size); +blk64_t new_size,int flags);extern blk64_t calculate_minimum_resize_size (ext2_filsys fs);
Quoted 7 lines · Lukas Czerner
Quoted 5 lines · Lukas Czerner
Lazy inode table initialization speeds up file system resize operation because we can let the inode tables uninitialized. For some time now the mke2fs has similar option and now, when we have in-kernel lazyinit implementation we can add this feature to the resize2fs as well.
Quoted 8 lines
Quoted 6 lines
This commit adds extended options '-E' to the resize2fs code along with the first extended option lazy_itable_init=n. With
lazy_itable_initextended option one can instruct resize2fs to skip inode table initialization to significantly speed-up file system resize. If the option is omitted and the file system supports lazy inode table initialization it defaults to 1.ping
ping^2
Quoted 365 lines
Quoted 363 lines
Signed-off-by Lukas Czerner <[email protected]>--- resize/main.c | 68 +++++++++++++++++++++++++++++++- resize/online.c | 2 +- resize/resize2fs.8.in | 20 +++++++++ resize/resize2fs.c | 105 +++++++++++++++++++++++++++--------------------- resize/resize2fs.h | 3 +- 5 files changed, 148 insertions(+), 50 deletions(-)resize/main.c +66
-2@@ -40,7 +40,8 @@ char *program_name, *device_name, *io_options;static void usage (char *prog) {fprintf (stderr,_ ("Usage: %s [-d debug_flags] [-f] [-F] [-M] [-P] " -"[-p] device [new_size]\n\n" ), prog); +"[-p] [-E extended_options] device [new_size]\n\n" ), + prog);exit (1 ); }@@ -146,6 +147,59 @@ static void determine_fs_stride(ext2_filsys fs)#endif } +static void parse_extended_opts (int *flags,const char *opts) +{ +char *buf, *token, *next, *p, *arg, *badopt =0 ; +int len; +int r_usage =0 ; + + len =strlen (opts); + buf =malloc (len+1 ); +if (!buf) { +fprintf (stderr, +_ ("Couldn't allocate memory to parse options!\n" )); +exit (1 ); + } +strcpy (buf, opts); +for (token = buf; token && *token; token = next) { + p =strchr (token,',' ); + next =0 ; +if (p) { + *p =0 ; + next = p+1 ; + } + arg =strchr (token,'=' ); +if (arg) { + *arg =0 ; + arg++; + } +if (!strcmp (token,"lazy_itable_init" )) { +int lazy; +if (arg) + lazy =strtoul (arg, &p,0 ); +else + lazy =1 ; +if (lazy) + *flags |=RESIZE_LAZY_ITABLE_INIT ; + }else { + r_usage++; + badopt = token; + } + } +if (r_usage) { +fprintf (stderr,_ ("\nBad option(s) specified: %s\n\n" +"Extended options are separated by commas, " +"and may take an argument which\n" +"\tis set off by an equals ('=') sign.\n\n" +"Valid extended options are:\n" +"\tlazy_itable_init=<0 to disable, 1 to enable>\n\n" ), + badopt ? badopt :"" ); +free (buf); +exit (1 ); + } +free (buf); +} +int main (int argc,char ** argv) {errcode_t retval;@@ -174,6 +228,7 @@ int main (int argc, char ** argv)long sysval;int len, mount_flags;char *mtpt; +char * extended_opts =NULL ;#ifdef ENABLE_NLS setlocale (LC_MESSAGES ,"" );@@ -189,7 +244,7 @@ int main (int argc, char ** argv)if (argc && *argv) program_name = *argv; -while ((c =getopt (argc, argv,"d:fFhMPpS:" )) !=EOF ) { +while ((c =getopt (argc, argv,"d:fFhMPpS:E:" )) !=EOF ) {switch (c) {case 'h' :usage (program_name);@@ -215,6 +270,9 @@ int main (int argc, char ** argv)case 'S' : use_stride =atoi (optarg);break ; +case 'E' : + extended_opts = optarg; +break ;default :usage (program_name); }@@ -232,6 +290,12 @@ int main (int argc, char ** argv)if (io_options) *io_options++ =0 ; +if (access ("/sys/fs/ext4/features/lazy_itable_init" ,R_OK ) ==0 ) + flags |=RESIZE_LAZY_ITABLE_INIT ; + +if (extended_opts) +parse_extended_opts (&flags, extended_opts); +/* * Figure out whether or not the device is mounted, and if it is * where it is mounted. resize/online.c +1
-1@@ -104,7 +104,7 @@ errcode_t online_resize_fs(ext2_filsys fs, const char *mtpt,* but at least it allows on-line resizing to function. */ new_fs->super->s_feature_incompat &= ~EXT4_FEATURE_INCOMPAT_FLEX_BG ; - retval =adjust_fs_info (new_fs, fs,0 , *new_size); + retval =adjust_fs_info (new_fs, fs,0 , *new_size,0 );if (retval)return retval;resize/resize2fs.8.in +20
-0@@ -18,6 +18,10 @@ resize2fs \- ext2/ext3/ext4 file system resizer .B \-S .I RAID-stride ] +[ +.B \-E +.I extended-options +] .I device [ .I size@@ -128,6 +132,22 @@ The program will heuristically determine the RAID stride that was specified when the filesystem was created. This option allows the user to explicitly specify a RAID stride setting to be used by resize2fs instead. +.TP +.B \-E \fIextended-options +Set extended options for the filesystem. Extended options are comma +separated, and may take an argument using the equals ('=') sign. +The following extended options are supported: +.RS 1.2i +.TP +.B lazy_itable_init\fR[\fB= \fI<0 to disable, 1 to enable>\fR] +If enabled and the uninit_bg feature is enabled, the inode table will +not be fully initialized by +.BR resize2fs . +This speeds up filesystem +resize noticeably, but it requires the kernel to finish +initializing the filesystem in the background when the filesystem is +mounted. If the option value is omitted, it defaults to 1 to +enable lazy inode table initialization. .SH KNOWN BUGS The minimum size of the filesystem as estimated by resize2fs may be incorrect, especially for filesystems with 1k and 2k blocksizes.resize/resize2fs.c +59
-46@@ -41,7 +41,8 @@#endif static void fix_uninit_block_bitmaps (ext2_filsys fs); -static errcode_t adjust_superblock (ext2_resize_t rfs,blk64_t new_size); +static errcode_t adjust_superblock (ext2_resize_t rfs,blk64_t new_size, +int flags);static errcode_t blocks_to_move (ext2_resize_t rfs);static errcode_t block_mover (ext2_resize_t rfs);static errcode_t inode_scan_and_fix (ext2_resize_t rfs);@@ -102,7 +103,7 @@ errcode_t resize_fs(ext2_filsys fs, blk64_t *new_size, int flags,if (retval) goto errout; - retval =adjust_superblock (rfs, *new_size); + retval =adjust_superblock (rfs, *new_size, flags);if (retval) goto errout;@@ -288,7 +289,8 @@ static void free_gdp_blocks(ext2_filsys fs,* filesystem. */ errcode_t adjust_fs_info (ext2_filsys fs,ext2_filsys old_fs, -ext2fs_block_bitmap reserve_blocks,blk64_t new_size) +ext2fs_block_bitmap reserve_blocks,blk64_t new_size, +int flags) {errcode_t retval;blk64_t overhead =0 ;@@ -497,8 +499,12 @@ retry: adjblocks =0 ;ext2fs_bg_flags_zap (fs, i); -if (csum_flag) +if (csum_flag && (flags &RESIZE_LAZY_ITABLE_INIT )) +ext2fs_bg_flags_set (fs, i,EXT2_BG_INODE_UNINIT ); +else if (csum_flag)ext2fs_bg_flags_set (fs, i,EXT2_BG_INODE_UNINIT |EXT2_BG_INODE_ZEROED ); +else + flags &= ~RESIZE_LAZY_ITABLE_INIT ;if (i == fs->group_desc_count-1 ) { numblocks = (ext2fs_blocks_count (fs->super) - fs->super->s_first_data_block) %@@ -562,18 +568,57 @@ errout:return (retval); } +static errcode_t write_inode_tables (ext2_resize_t rfs,ext2_filsys fs) +{ +unsigned long i, max_group; +errcode_t retval; +int adj =0 ; + +memset (rfs->itable_buf,0 , fs->blocksize * fs->inode_blocks_per_group); + adj = rfs->old_fs->group_desc_count; + max_group = fs->group_desc_count - adj; +if (rfs->progress) { + retval = rfs->progress (rfs,E2_RSZ_EXTEND_ITABLE_PASS , +0 , max_group); +if (retval) + goto out; + } + +for (i = rfs->old_fs->group_desc_count; + i < fs->group_desc_count; i++) { +/* +* Write out the new inode table +*/ + retval =io_channel_write_blk64 (fs->io, +ext2fs_inode_table_loc (fs, i), + fs->inode_blocks_per_group, + rfs->itable_buf); +if (retval) +break ; + +io_channel_flush (fs->io); +if (rfs->progress) { + retval = rfs->progress (rfs,E2_RSZ_EXTEND_ITABLE_PASS , + i - adj +1 , max_group); +if (retval) +break ; + } + } +io_channel_flush (fs->io); +out: +return retval; +} + +/* * This routine adjusts the superblock and other data structures, both * in disk as well as in memory... */ -static errcode_t adjust_superblock (ext2_resize_t rfs,blk64_t new_size) +static errcode_t adjust_superblock (ext2_resize_t rfs,blk64_t new_size, +int flags) { -ext2_filsys fs; -int adj =0 ; +ext2_filsys fs;errcode_t retval; -blk64_t group_block; -unsigned long i; -unsigned long max_group; fs = rfs->new_fs;ext2fs_mark_super_dirty (fs);@@ -585,7 +630,8 @@ static errcode_t adjust_superblock(ext2_resize_t rfs, blk64_t new_size)if (retval)return retval; - retval =adjust_fs_info (fs, rfs->old_fs, rfs->reserve_blocks, new_size); + retval =adjust_fs_info (fs, rfs->old_fs, rfs->reserve_blocks, new_size, + flags);if (retval) goto errout;@@ -626,41 +672,8 @@ static errcode_t adjust_superblock(ext2_resize_t rfs, blk64_t new_size)if (retval) goto errout; -memset (rfs->itable_buf,0 , fs->blocksize * fs->inode_blocks_per_group); - group_block = fs->super->s_first_data_block + - rfs->old_fs->group_desc_count * fs->super->s_blocks_per_group; - - adj = rfs->old_fs->group_desc_count; - max_group = fs->group_desc_count - adj; -if (rfs->progress) { - retval = rfs->progress (rfs,E2_RSZ_EXTEND_ITABLE_PASS , -0 , max_group); -if (retval) - goto errout; - } -for (i = rfs->old_fs->group_desc_count; - i < fs->group_desc_count; i++) { -/* -* Write out the new inode table -*/ - retval =io_channel_write_blk64 (fs->io, -ext2fs_inode_table_loc (fs, i), - fs->inode_blocks_per_group, - rfs->itable_buf); -if (retval) goto errout; - -io_channel_flush (fs->io); -if (rfs->progress) { - retval = rfs->progress (rfs,E2_RSZ_EXTEND_ITABLE_PASS , - i - adj +1 , max_group); -if (retval) - goto errout; - } - group_block += fs->super->s_blocks_per_group; - } -io_channel_flush (fs->io); - retval =0 ; - +if (!(flags &RESIZE_LAZY_ITABLE_INIT )) + retval =write_inode_tables (rfs, fs); errout:return retval; }resize/resize2fs.h +2
-1@@ -79,6 +79,7 @@ typedef struct ext2_sim_progress *ext2_sim_progmeter;#define RESIZE_PERCENT_COMPLETE 0x0100#define RESIZE_VERBOSE 0x0200 +#define RESIZE_LAZY_ITABLE_INIT 0x0400/* Do not initialize inode tables*/ /* * The core state structure for the ext2 resizer @@ -129,7 +130,7 @@ extern errcode_t resize_fs(ext2_filsys fs, blk64_t *new_size, int flags,extern errcode_t adjust_fs_info (ext2_filsys fs,ext2_filsys old_fs,ext2fs_block_bitmap reserve_blocks, -blk64_t new_size); +blk64_t new_size,int flags);extern blk64_t calculate_minimum_resize_size (ext2_filsys fs);
Quoted 16 lines · Lukas Czerner
Quoted 14 lines · Lukas Czerner
Quoted 11 lines · Lukas Czerner
Lazy inode table initialization speeds up file system resize operation because we can let the inode tables uninitialized. For some time now the mke2fs has similar option and now, when we have in-kernel lazyinit implementation we can add this feature to the resize2fs as well.
This commit adds extended options '-E' to the resize2fs code along with the first extended option lazy_itable_init=n. With
lazy_itable_initextended option one can instruct resize2fs to skip inode table initialization to significantly speed-up file system resize. If the option is omitted and the file system supports lazy inode table initialization it defaults to 1.
Quoted 3 lines
Quoted 1 line
ping
ping^2
ping^3
Quoted 368 lines
Quoted 366 lines
Quoted 364 lines
Signed-off-by Lukas Czerner <[email protected]>--- resize/main.c | 68 +++++++++++++++++++++++++++++++- resize/online.c | 2 +- resize/resize2fs.8.in | 20 +++++++++ resize/resize2fs.c | 105 +++++++++++++++++++++++++++--------------------- resize/resize2fs.h | 3 +- 5 files changed, 148 insertions(+), 50 deletions(-)resize/main.c +66
-2@@ -40,7 +40,8 @@ char *program_name, *device_name, *io_options;static void usage (char *prog) {fprintf (stderr,_ ("Usage: %s [-d debug_flags] [-f] [-F] [-M] [-P] " -"[-p] device [new_size]\n\n" ), prog); +"[-p] [-E extended_options] device [new_size]\n\n" ), + prog);exit (1 ); }@@ -146,6 +147,59 @@ static void determine_fs_stride(ext2_filsys fs)#endif } +static void parse_extended_opts (int *flags,const char *opts) +{ +char *buf, *token, *next, *p, *arg, *badopt =0 ; +int len; +int r_usage =0 ; + + len =strlen (opts); + buf =malloc (len+1 ); +if (!buf) { +fprintf (stderr, +_ ("Couldn't allocate memory to parse options!\n" )); +exit (1 ); + } +strcpy (buf, opts); +for (token = buf; token && *token; token = next) { + p =strchr (token,',' ); + next =0 ; +if (p) { + *p =0 ; + next = p+1 ; + } + arg =strchr (token,'=' ); +if (arg) { + *arg =0 ; + arg++; + } +if (!strcmp (token,"lazy_itable_init" )) { +int lazy; +if (arg) + lazy =strtoul (arg, &p,0 ); +else + lazy =1 ; +if (lazy) + *flags |=RESIZE_LAZY_ITABLE_INIT ; + }else { + r_usage++; + badopt = token; + } + } +if (r_usage) { +fprintf (stderr,_ ("\nBad option(s) specified: %s\n\n" +"Extended options are separated by commas, " +"and may take an argument which\n" +"\tis set off by an equals ('=') sign.\n\n" +"Valid extended options are:\n" +"\tlazy_itable_init=<0 to disable, 1 to enable>\n\n" ), + badopt ? badopt :"" ); +free (buf); +exit (1 ); + } +free (buf); +} +int main (int argc,char ** argv) {errcode_t retval;@@ -174,6 +228,7 @@ int main (int argc, char ** argv)long sysval;int len, mount_flags;char *mtpt; +char * extended_opts =NULL ;#ifdef ENABLE_NLS setlocale (LC_MESSAGES ,"" );@@ -189,7 +244,7 @@ int main (int argc, char ** argv)if (argc && *argv) program_name = *argv; -while ((c =getopt (argc, argv,"d:fFhMPpS:" )) !=EOF ) { +while ((c =getopt (argc, argv,"d:fFhMPpS:E:" )) !=EOF ) {switch (c) {case 'h' :usage (program_name);@@ -215,6 +270,9 @@ int main (int argc, char ** argv)case 'S' : use_stride =atoi (optarg);break ; +case 'E' : + extended_opts = optarg; +break ;default :usage (program_name); }@@ -232,6 +290,12 @@ int main (int argc, char ** argv)if (io_options) *io_options++ =0 ; +if (access ("/sys/fs/ext4/features/lazy_itable_init" ,R_OK ) ==0 ) + flags |=RESIZE_LAZY_ITABLE_INIT ; + +if (extended_opts) +parse_extended_opts (&flags, extended_opts); +/* * Figure out whether or not the device is mounted, and if it is * where it is mounted. resize/online.c +1
-1@@ -104,7 +104,7 @@ errcode_t online_resize_fs(ext2_filsys fs, const char *mtpt,* but at least it allows on-line resizing to function. */ new_fs->super->s_feature_incompat &= ~EXT4_FEATURE_INCOMPAT_FLEX_BG ; - retval =adjust_fs_info (new_fs, fs,0 , *new_size); + retval =adjust_fs_info (new_fs, fs,0 , *new_size,0 );if (retval)return retval;resize/resize2fs.8.in +20
-0@@ -18,6 +18,10 @@ resize2fs \- ext2/ext3/ext4 file system resizer .B \-S .I RAID-stride ] +[ +.B \-E +.I extended-options +] .I device [ .I size@@ -128,6 +132,22 @@ The program will heuristically determine the RAID stride that was specified when the filesystem was created. This option allows the user to explicitly specify a RAID stride setting to be used by resize2fs instead. +.TP +.B \-E \fIextended-options +Set extended options for the filesystem. Extended options are comma +separated, and may take an argument using the equals ('=') sign. +The following extended options are supported: +.RS 1.2i +.TP +.B lazy_itable_init\fR[\fB= \fI<0 to disable, 1 to enable>\fR] +If enabled and the uninit_bg feature is enabled, the inode table will +not be fully initialized by +.BR resize2fs . +This speeds up filesystem +resize noticeably, but it requires the kernel to finish +initializing the filesystem in the background when the filesystem is +mounted. If the option value is omitted, it defaults to 1 to +enable lazy inode table initialization. .SH KNOWN BUGS The minimum size of the filesystem as estimated by resize2fs may be incorrect, especially for filesystems with 1k and 2k blocksizes.resize/resize2fs.c +59
-46@@ -41,7 +41,8 @@#endif static void fix_uninit_block_bitmaps (ext2_filsys fs); -static errcode_t adjust_superblock (ext2_resize_t rfs,blk64_t new_size); +static errcode_t adjust_superblock (ext2_resize_t rfs,blk64_t new_size, +int flags);static errcode_t blocks_to_move (ext2_resize_t rfs);static errcode_t block_mover (ext2_resize_t rfs);static errcode_t inode_scan_and_fix (ext2_resize_t rfs);@@ -102,7 +103,7 @@ errcode_t resize_fs(ext2_filsys fs, blk64_t *new_size, int flags,if (retval) goto errout; - retval =adjust_superblock (rfs, *new_size); + retval =adjust_superblock (rfs, *new_size, flags);if (retval) goto errout;@@ -288,7 +289,8 @@ static void free_gdp_blocks(ext2_filsys fs,* filesystem. */ errcode_t adjust_fs_info (ext2_filsys fs,ext2_filsys old_fs, -ext2fs_block_bitmap reserve_blocks,blk64_t new_size) +ext2fs_block_bitmap reserve_blocks,blk64_t new_size, +int flags) {errcode_t retval;blk64_t overhead =0 ;@@ -497,8 +499,12 @@ retry: adjblocks =0 ;ext2fs_bg_flags_zap (fs, i); -if (csum_flag) +if (csum_flag && (flags &RESIZE_LAZY_ITABLE_INIT )) +ext2fs_bg_flags_set (fs, i,EXT2_BG_INODE_UNINIT ); +else if (csum_flag)ext2fs_bg_flags_set (fs, i,EXT2_BG_INODE_UNINIT |EXT2_BG_INODE_ZEROED ); +else + flags &= ~RESIZE_LAZY_ITABLE_INIT ;if (i == fs->group_desc_count-1 ) { numblocks = (ext2fs_blocks_count (fs->super) - fs->super->s_first_data_block) %@@ -562,18 +568,57 @@ errout:return (retval); } +static errcode_t write_inode_tables (ext2_resize_t rfs,ext2_filsys fs) +{ +unsigned long i, max_group; +errcode_t retval; +int adj =0 ; + +memset (rfs->itable_buf,0 , fs->blocksize * fs->inode_blocks_per_group); + adj = rfs->old_fs->group_desc_count; + max_group = fs->group_desc_count - adj; +if (rfs->progress) { + retval = rfs->progress (rfs,E2_RSZ_EXTEND_ITABLE_PASS , +0 , max_group); +if (retval) + goto out; + } + +for (i = rfs->old_fs->group_desc_count; + i < fs->group_desc_count; i++) { +/* +* Write out the new inode table +*/ + retval =io_channel_write_blk64 (fs->io, +ext2fs_inode_table_loc (fs, i), + fs->inode_blocks_per_group, + rfs->itable_buf); +if (retval) +break ; + +io_channel_flush (fs->io); +if (rfs->progress) { + retval = rfs->progress (rfs,E2_RSZ_EXTEND_ITABLE_PASS , + i - adj +1 , max_group); +if (retval) +break ; + } + } +io_channel_flush (fs->io); +out: +return retval; +} + +/* * This routine adjusts the superblock and other data structures, both * in disk as well as in memory... */ -static errcode_t adjust_superblock (ext2_resize_t rfs,blk64_t new_size) +static errcode_t adjust_superblock (ext2_resize_t rfs,blk64_t new_size, +int flags) { -ext2_filsys fs; -int adj =0 ; +ext2_filsys fs;errcode_t retval; -blk64_t group_block; -unsigned long i; -unsigned long max_group; fs = rfs->new_fs;ext2fs_mark_super_dirty (fs);@@ -585,7 +630,8 @@ static errcode_t adjust_superblock(ext2_resize_t rfs, blk64_t new_size)if (retval)return retval; - retval =adjust_fs_info (fs, rfs->old_fs, rfs->reserve_blocks, new_size); + retval =adjust_fs_info (fs, rfs->old_fs, rfs->reserve_blocks, new_size, + flags);if (retval) goto errout;@@ -626,41 +672,8 @@ static errcode_t adjust_superblock(ext2_resize_t rfs, blk64_t new_size)if (retval) goto errout; -memset (rfs->itable_buf,0 , fs->blocksize * fs->inode_blocks_per_group); - group_block = fs->super->s_first_data_block + - rfs->old_fs->group_desc_count * fs->super->s_blocks_per_group; - - adj = rfs->old_fs->group_desc_count; - max_group = fs->group_desc_count - adj; -if (rfs->progress) { - retval = rfs->progress (rfs,E2_RSZ_EXTEND_ITABLE_PASS , -0 , max_group); -if (retval) - goto errout; - } -for (i = rfs->old_fs->group_desc_count; - i < fs->group_desc_count; i++) { -/* -* Write out the new inode table -*/ - retval =io_channel_write_blk64 (fs->io, -ext2fs_inode_table_loc (fs, i), - fs->inode_blocks_per_group, - rfs->itable_buf); -if (retval) goto errout; - -io_channel_flush (fs->io); -if (rfs->progress) { - retval = rfs->progress (rfs,E2_RSZ_EXTEND_ITABLE_PASS , - i - adj +1 , max_group); -if (retval) - goto errout; - } - group_block += fs->super->s_blocks_per_group; - } -io_channel_flush (fs->io); - retval =0 ; - +if (!(flags &RESIZE_LAZY_ITABLE_INIT )) + retval =write_inode_tables (rfs, fs); errout:return retval; }resize/resize2fs.h +2
-1@@ -79,6 +79,7 @@ typedef struct ext2_sim_progress *ext2_sim_progmeter;#define RESIZE_PERCENT_COMPLETE 0x0100#define RESIZE_VERBOSE 0x0200 +#define RESIZE_LAZY_ITABLE_INIT 0x0400/* Do not initialize inode tables*/ /* * The core state structure for the ext2 resizer @@ -129,7 +130,7 @@ extern errcode_t resize_fs(ext2_filsys fs, blk64_t *new_size, int flags,extern errcode_t adjust_fs_info (ext2_filsys fs,ext2_filsys old_fs,ext2fs_block_bitmap reserve_blocks, -blk64_t new_size); +blk64_t new_size,int flags);extern blk64_t calculate_minimum_resize_size (ext2_filsys fs);
Quoted 11 lines · Lukas Czerner
Lazy inode table initialization speeds up file system resize operation because we can let the inode tables uninitialized. For some time now the mke2fs has similar option and now, when we have in-kernel lazyinit implementation we can add this feature to the resize2fs as well.
This commit adds extended options '-E' to the resize2fs code along with the first extended option lazy_itable_init=n. With
lazy_itable_initextended option one can instruct resize2fs to skip inode table initialization to significantly speed-up file system resize. If the option is omitted and the file system supports lazy inode table initialization it defaults to 1.
Quadruple ping :)
Hi Ted,
I know that the code has probably already changed since I have posted the patch a _year ago_ not talking about the new resize interface. But do you think that it is worth ti trying to rebase it so you can merge it ? I am just asking so it does not hang in the mailing list for another year again :)
Thanks!
-Lukas
Quoted 362 lines
Signed-off-by Lukas Czerner <[email protected]>--- resize/main.c | 68 +++++++++++++++++++++++++++++++- resize/online.c | 2 +- resize/resize2fs.8.in | 20 +++++++++ resize/resize2fs.c | 105 +++++++++++++++++++++++++++--------------------- resize/resize2fs.h | 3 +- 5 files changed, 148 insertions(+), 50 deletions(-)resize/main.c +66
-2@@ -40,7 +40,8 @@ char *program_name, *device_name, *io_options;static void usage (char *prog) {fprintf (stderr,_ ("Usage: %s [-d debug_flags] [-f] [-F] [-M] [-P] " -"[-p] device [new_size]\n\n" ), prog); +"[-p] [-E extended_options] device [new_size]\n\n" ), + prog);exit (1 ); }@@ -146,6 +147,59 @@ static void determine_fs_stride(ext2_filsys fs)#endif } +static void parse_extended_opts (int *flags,const char *opts) +{ +char *buf, *token, *next, *p, *arg, *badopt =0 ; +int len; +int r_usage =0 ; + + len =strlen (opts); + buf =malloc (len+1 ); +if (!buf) { +fprintf (stderr, +_ ("Couldn't allocate memory to parse options!\n" )); +exit (1 ); + } +strcpy (buf, opts); +for (token = buf; token && *token; token = next) { + p =strchr (token,',' ); + next =0 ; +if (p) { + *p =0 ; + next = p+1 ; + } + arg =strchr (token,'=' ); +if (arg) { + *arg =0 ; + arg++; + } +if (!strcmp (token,"lazy_itable_init" )) { +int lazy; +if (arg) + lazy =strtoul (arg, &p,0 ); +else + lazy =1 ; +if (lazy) + *flags |=RESIZE_LAZY_ITABLE_INIT ; + }else { + r_usage++; + badopt = token; + } + } +if (r_usage) { +fprintf (stderr,_ ("\nBad option(s) specified: %s\n\n" +"Extended options are separated by commas, " +"and may take an argument which\n" +"\tis set off by an equals ('=') sign.\n\n" +"Valid extended options are:\n" +"\tlazy_itable_init=<0 to disable, 1 to enable>\n\n" ), + badopt ? badopt :"" ); +free (buf); +exit (1 ); + } +free (buf); +} +int main (int argc,char ** argv) {errcode_t retval;@@ -174,6 +228,7 @@ int main (int argc, char ** argv)long sysval;int len, mount_flags;char *mtpt; +char * extended_opts =NULL ;#ifdef ENABLE_NLS setlocale (LC_MESSAGES ,"" );@@ -189,7 +244,7 @@ int main (int argc, char ** argv)if (argc && *argv) program_name = *argv; -while ((c =getopt (argc, argv,"d:fFhMPpS:" )) !=EOF ) { +while ((c =getopt (argc, argv,"d:fFhMPpS:E:" )) !=EOF ) {switch (c) {case 'h' :usage (program_name);@@ -215,6 +270,9 @@ int main (int argc, char ** argv)case 'S' : use_stride =atoi (optarg);break ; +case 'E' : + extended_opts = optarg; +break ;default :usage (program_name); }@@ -232,6 +290,12 @@ int main (int argc, char ** argv)if (io_options) *io_options++ =0 ; +if (access ("/sys/fs/ext4/features/lazy_itable_init" ,R_OK ) ==0 ) + flags |=RESIZE_LAZY_ITABLE_INIT ; + +if (extended_opts) +parse_extended_opts (&flags, extended_opts); +/* * Figure out whether or not the device is mounted, and if it is * where it is mounted. resize/online.c +1
-1@@ -104,7 +104,7 @@ errcode_t online_resize_fs(ext2_filsys fs, const char *mtpt,* but at least it allows on-line resizing to function. */ new_fs->super->s_feature_incompat &= ~EXT4_FEATURE_INCOMPAT_FLEX_BG ; - retval =adjust_fs_info (new_fs, fs,0 , *new_size); + retval =adjust_fs_info (new_fs, fs,0 , *new_size,0 );if (retval)return retval;resize/resize2fs.8.in +20
-0@@ -18,6 +18,10 @@ resize2fs \- ext2/ext3/ext4 file system resizer .B \-S .I RAID-stride ] +[ +.B \-E +.I extended-options +] .I device [ .I size@@ -128,6 +132,22 @@ The program will heuristically determine the RAID stride that was specified when the filesystem was created. This option allows the user to explicitly specify a RAID stride setting to be used by resize2fs instead. +.TP +.B \-E \fIextended-options +Set extended options for the filesystem. Extended options are comma +separated, and may take an argument using the equals ('=') sign. +The following extended options are supported: +.RS 1.2i +.TP +.B lazy_itable_init\fR[\fB= \fI<0 to disable, 1 to enable>\fR] +If enabled and the uninit_bg feature is enabled, the inode table will +not be fully initialized by +.BR resize2fs . +This speeds up filesystem +resize noticeably, but it requires the kernel to finish +initializing the filesystem in the background when the filesystem is +mounted. If the option value is omitted, it defaults to 1 to +enable lazy inode table initialization. .SH KNOWN BUGS The minimum size of the filesystem as estimated by resize2fs may be incorrect, especially for filesystems with 1k and 2k blocksizes.resize/resize2fs.c +59
-46@@ -41,7 +41,8 @@#endif static void fix_uninit_block_bitmaps (ext2_filsys fs); -static errcode_t adjust_superblock (ext2_resize_t rfs,blk64_t new_size); +static errcode_t adjust_superblock (ext2_resize_t rfs,blk64_t new_size, +int flags);static errcode_t blocks_to_move (ext2_resize_t rfs);static errcode_t block_mover (ext2_resize_t rfs);static errcode_t inode_scan_and_fix (ext2_resize_t rfs);@@ -102,7 +103,7 @@ errcode_t resize_fs(ext2_filsys fs, blk64_t *new_size, int flags,if (retval) goto errout; - retval =adjust_superblock (rfs, *new_size); + retval =adjust_superblock (rfs, *new_size, flags);if (retval) goto errout;@@ -288,7 +289,8 @@ static void free_gdp_blocks(ext2_filsys fs,* filesystem. */ errcode_t adjust_fs_info (ext2_filsys fs,ext2_filsys old_fs, -ext2fs_block_bitmap reserve_blocks,blk64_t new_size) +ext2fs_block_bitmap reserve_blocks,blk64_t new_size, +int flags) {errcode_t retval;blk64_t overhead =0 ;@@ -497,8 +499,12 @@ retry: adjblocks =0 ;ext2fs_bg_flags_zap (fs, i); -if (csum_flag) +if (csum_flag && (flags &RESIZE_LAZY_ITABLE_INIT )) +ext2fs_bg_flags_set (fs, i,EXT2_BG_INODE_UNINIT ); +else if (csum_flag)ext2fs_bg_flags_set (fs, i,EXT2_BG_INODE_UNINIT |EXT2_BG_INODE_ZEROED ); +else + flags &= ~RESIZE_LAZY_ITABLE_INIT ;if (i == fs->group_desc_count-1 ) { numblocks = (ext2fs_blocks_count (fs->super) - fs->super->s_first_data_block) %@@ -562,18 +568,57 @@ errout:return (retval); } +static errcode_t write_inode_tables (ext2_resize_t rfs,ext2_filsys fs) +{ +unsigned long i, max_group; +errcode_t retval; +int adj =0 ; + +memset (rfs->itable_buf,0 , fs->blocksize * fs->inode_blocks_per_group); + adj = rfs->old_fs->group_desc_count; + max_group = fs->group_desc_count - adj; +if (rfs->progress) { + retval = rfs->progress (rfs,E2_RSZ_EXTEND_ITABLE_PASS , +0 , max_group); +if (retval) + goto out; + } + +for (i = rfs->old_fs->group_desc_count; + i < fs->group_desc_count; i++) { +/* +* Write out the new inode table +*/ + retval =io_channel_write_blk64 (fs->io, +ext2fs_inode_table_loc (fs, i), + fs->inode_blocks_per_group, + rfs->itable_buf); +if (retval) +break ; + +io_channel_flush (fs->io); +if (rfs->progress) { + retval = rfs->progress (rfs,E2_RSZ_EXTEND_ITABLE_PASS , + i - adj +1 , max_group); +if (retval) +break ; + } + } +io_channel_flush (fs->io); +out: +return retval; +} + +/* * This routine adjusts the superblock and other data structures, both * in disk as well as in memory... */ -static errcode_t adjust_superblock (ext2_resize_t rfs,blk64_t new_size) +static errcode_t adjust_superblock (ext2_resize_t rfs,blk64_t new_size, +int flags) { -ext2_filsys fs; -int adj =0 ; +ext2_filsys fs;errcode_t retval; -blk64_t group_block; -unsigned long i; -unsigned long max_group; fs = rfs->new_fs;ext2fs_mark_super_dirty (fs);@@ -585,7 +630,8 @@ static errcode_t adjust_superblock(ext2_resize_t rfs, blk64_t new_size)if (retval)return retval; - retval =adjust_fs_info (fs, rfs->old_fs, rfs->reserve_blocks, new_size); + retval =adjust_fs_info (fs, rfs->old_fs, rfs->reserve_blocks, new_size, + flags);if (retval) goto errout;@@ -626,41 +672,8 @@ static errcode_t adjust_superblock(ext2_resize_t rfs, blk64_t new_size)if (retval) goto errout; -memset (rfs->itable_buf,0 , fs->blocksize * fs->inode_blocks_per_group); - group_block = fs->super->s_first_data_block + - rfs->old_fs->group_desc_count * fs->super->s_blocks_per_group; - - adj = rfs->old_fs->group_desc_count; - max_group = fs->group_desc_count - adj; -if (rfs->progress) { - retval = rfs->progress (rfs,E2_RSZ_EXTEND_ITABLE_PASS , -0 , max_group); -if (retval) - goto errout; - } -for (i = rfs->old_fs->group_desc_count; - i < fs->group_desc_count; i++) { -/* -* Write out the new inode table -*/ - retval =io_channel_write_blk64 (fs->io, -ext2fs_inode_table_loc (fs, i), - fs->inode_blocks_per_group, - rfs->itable_buf); -if (retval) goto errout; - -io_channel_flush (fs->io); -if (rfs->progress) { - retval = rfs->progress (rfs,E2_RSZ_EXTEND_ITABLE_PASS , - i - adj +1 , max_group); -if (retval) - goto errout; - } - group_block += fs->super->s_blocks_per_group; - } -io_channel_flush (fs->io); - retval =0 ; - +if (!(flags &RESIZE_LAZY_ITABLE_INIT )) + retval =write_inode_tables (rfs, fs); errout:return retval; }resize/resize2fs.h +2
-1@@ -79,6 +79,7 @@ typedef struct ext2_sim_progress *ext2_sim_progmeter;#define RESIZE_PERCENT_COMPLETE 0x0100#define RESIZE_VERBOSE 0x0200 +#define RESIZE_LAZY_ITABLE_INIT 0x0400/* Do not initialize inode tables*/ /* * The core state structure for the ext2 resizer @@ -129,7 +130,7 @@ extern errcode_t resize_fs(ext2_filsys fs, blk64_t *new_size, int flags,extern errcode_t adjust_fs_info (ext2_filsys fs,ext2_filsys old_fs,ext2fs_block_bitmap reserve_blocks, -blk64_t new_size); +blk64_t new_size,int flags);extern blk64_t calculate_minimum_resize_size (ext2_filsys fs);