Whamcloud - gitweb
mke2fs: add option to use direct I/O (mke2fs -D)
authorTheodore Ts'o <tytso@mit.edu>
Thu, 22 Mar 2012 20:00:49 +0000 (16:00 -0400)
committerTheodore Ts'o <tytso@mit.edu>
Thu, 22 Mar 2012 20:00:49 +0000 (16:00 -0400)
This can be useful when using mke2fs on loaded servers, since
otherwise mke2fs can dirty a huge amount of memory very quickly,
leading to other applications not being happy at all.

Signed-off-by: "Theodore Ts'o" <tytso@mit.edu>
lib/ext2fs/initialize.c
misc/mke2fs.8.in
misc/mke2fs.c

index a63ea18..b06371c 100644 (file)
@@ -119,6 +119,8 @@ errcode_t ext2fs_initialize(const char *name, int flags,
        io_flags = IO_FLAG_RW;
        if (flags & EXT2_FLAG_EXCLUSIVE)
                io_flags |= IO_FLAG_EXCLUSIVE;
+       if (flags & EXT2_FLAG_DIRECT_IO)
+               io_flags |= IO_FLAG_DIRECT_IO;
        retval = manager->open(name, io_flags, &fs->io);
        if (retval)
                goto cleanup;
index 8e78249..6d443a2 100644 (file)
@@ -18,6 +18,9 @@ mke2fs \- create an ext2/ext3/ext4 filesystem
 .I block-size
 ]
 [
+.B \-D
+]
+[
 .B \-f
 .I fragment-size
 ]
@@ -184,6 +187,12 @@ Check the device for bad blocks before creating the file system.  If
 this option is specified twice, then a slower read-write
 test is used instead of a fast read-only test.
 .TP
+.B \-D
+Use direct I/O when writing to the disk.  This avoids mke2fs dirtying a
+lot of buffer cache memory, which may impact other applications running
+on a busy server.  This option will cause mke2fs to run much more
+slowly, however, so there is a tradeoff to using direct I/O.
+.TP
 .BI \-E " extended-options"
 Set extended options for the filesystem.  Extended options are comma
 separated, and may take an argument using the equals ('=') sign.  The
index 51435d2..0d793f7 100644 (file)
@@ -88,6 +88,7 @@ int   verbose;
 int    quiet;
 int    super_only;
 int    discard = 1;    /* attempt to discard device before fs creation */
+int    direct_io;
 int    force;
 int    noaction;
 int    journal_size;
@@ -122,7 +123,7 @@ static void usage(void)
        "[-M last-mounted-directory]\n\t[-O feature[,...]] "
        "[-r fs-revision] [-E extended-option[,...]]\n"
        "\t[-t fs-type] [-T usage-type ] [-U UUID] "
-       "[-jnqvFKSV] device [blocks-count]\n"),
+       "[-jnqvDFKSV] device [blocks-count]\n"),
                program_name);
        exit(1);
 }
@@ -1321,7 +1322,7 @@ profile_error:
        }
 
        while ((c = getopt (argc, argv,
-                   "b:cg:i:jl:m:no:qr:s:t:vC:E:FG:I:J:KL:M:N:O:R:ST:U:V")) != EOF) {
+                   "b:cg:i:jl:m:no:qr:s:t:vC:DE:FG:I:J:KL:M:N:O:R:ST:U:V")) != EOF) {
                switch (c) {
                case 'b':
                        blocksize = strtol(optarg, &tmp, 0);
@@ -1354,6 +1355,9 @@ profile_error:
                                exit(1);
                        }
                        break;
+               case 'D':
+                       direct_io = 1;
+                       break;
                case 'g':
                        fs_param.s_blocks_per_group = strtoul(optarg, &tmp, 0);
                        if (*tmp) {
@@ -2257,6 +2261,8 @@ int main (int argc, char *argv[])
         * Initialize the superblock....
         */
        flags = EXT2_FLAG_EXCLUSIVE;
+       if (direct_io)
+               flags |= EXT2_FLAG_DIRECT_IO;
        profile_get_boolean(profile, "options", "old_bitmaps", 0, 0,
                            &old_bitmaps);
        if (!old_bitmaps)