Re: [Cluster-devel] [PATCH] mkfs.gfs2: Scale down journal size for smaller devices

2018-02-13 Thread Andrew Price

On 13/02/18 20:18, Bob Peterson wrote:

- Original Message -
| Currently the default behaviour when the journal size is not specified
| is to use a default size of 128M, which means that mkfs.gfs2 can run out
| of space while writing to a small device. The hard default also means
| that some xfstests fail with gfs2 as they expect it to fit on smaller
| devices using the default options.
|
| This patch addresses these problems by picking a maximum proportion of
| the fs that journals should occupy (1/4) and scaling the journal size
| down (as far as the minimum size) to enforce that rule. As the minimum
| journal size is 8MB that means we effectively get a hard minimum file
| system size of 32MB (per journal).
|
| Signed-off-by: Andrew Price 
| ---

Hi,

Looks good to me. ACK.


Andreas found the 1/4 scaling to be lacking (and still failing small-fs 
xfstests) so I'm about to send a new version.


Andy



Re: [Cluster-devel] [PATCH] mkfs.gfs2: Scale down journal size for smaller devices

2018-02-13 Thread Bob Peterson
- Original Message -
| Currently the default behaviour when the journal size is not specified
| is to use a default size of 128M, which means that mkfs.gfs2 can run out
| of space while writing to a small device. The hard default also means
| that some xfstests fail with gfs2 as they expect it to fit on smaller
| devices using the default options.
| 
| This patch addresses these problems by picking a maximum proportion of
| the fs that journals should occupy (1/4) and scaling the journal size
| down (as far as the minimum size) to enforce that rule. As the minimum
| journal size is 8MB that means we effectively get a hard minimum file
| system size of 32MB (per journal).
| 
| Signed-off-by: Andrew Price 
| ---

Hi,

Looks good to me. ACK.

Bob Peterson
Red Hat File Systems



[Cluster-devel] [PATCH] mkfs.gfs2: Scale down journal size for smaller devices

2018-02-12 Thread Andrew Price
Currently the default behaviour when the journal size is not specified
is to use a default size of 128M, which means that mkfs.gfs2 can run out
of space while writing to a small device. The hard default also means
that some xfstests fail with gfs2 as they expect it to fit on smaller
devices using the default options.

This patch addresses these problems by picking a maximum proportion of
the fs that journals should occupy (1/4) and scaling the journal size
down (as far as the minimum size) to enforce that rule. As the minimum
journal size is 8MB that means we effectively get a hard minimum file
system size of 32MB (per journal).

Signed-off-by: Andrew Price 
---
 gfs2/libgfs2/libgfs2.h |  2 ++
 gfs2/man/mkfs.gfs2.8   |  6 --
 gfs2/mkfs/main_mkfs.c  | 25 +++--
 tests/mkfs.at  | 10 ++
 tests/testsuite.at |  6 ++
 5 files changed, 45 insertions(+), 4 deletions(-)

diff --git a/gfs2/libgfs2/libgfs2.h b/gfs2/libgfs2/libgfs2.h
index 85ac74cb..15d2a9d1 100644
--- a/gfs2/libgfs2/libgfs2.h
+++ b/gfs2/libgfs2/libgfs2.h
@@ -319,6 +319,8 @@ struct metapath {
 
 #define GFS2_DEFAULT_BSIZE  (4096)
 #define GFS2_DEFAULT_JSIZE  (128)
+#define GFS2_MAX_JSIZE  (1024)
+#define GFS2_MIN_JSIZE  (8)
 #define GFS2_DEFAULT_RGSIZE (256)
 #define GFS2_DEFAULT_UTSIZE (1)
 #define GFS2_DEFAULT_QCSIZE (1)
diff --git a/gfs2/man/mkfs.gfs2.8 b/gfs2/man/mkfs.gfs2.8
index 342a636d..e8a70432 100644
--- a/gfs2/man/mkfs.gfs2.8
+++ b/gfs2/man/mkfs.gfs2.8
@@ -32,8 +32,10 @@ Enable debugging output.
 Print out a help message describing the available options, then exit.
 .TP
 \fB-J\fP \fImegabytes\fR
-The size of each journal. The default journal size is 128 megabytes and the
-minimum size is 8 megabytes.
+The size of each journal. The minimum size is 8 megabytes and the maximum is
+1024. If this is not specified, a default value of 128 will be used or, for
+smaller devices, a value based on a sensible proportion of the file system will
+be chosen.
 .TP
 \fB-j\fP \fIjournals\fR
 The number of journals for mkfs.gfs2 to create.  At least one journal is
diff --git a/gfs2/mkfs/main_mkfs.c b/gfs2/mkfs/main_mkfs.c
index 54ff2db6..6e93dfad 100644
--- a/gfs2/mkfs/main_mkfs.c
+++ b/gfs2/mkfs/main_mkfs.c
@@ -552,7 +552,7 @@ static void opts_check(struct mkfs_opts *opts)
if (!opts->journals)
die( _("no journals specified\n"));
 
-   if (opts->jsize < 8 || opts->jsize > 1024)
+   if (opts->jsize < GFS2_MIN_JSIZE || opts->jsize > GFS2_MAX_JSIZE)
die( _("bad journal size\n"));
 
if (!opts->qcsize || opts->qcsize > 64)
@@ -575,6 +575,7 @@ static void print_results(struct gfs2_sb *sb, struct 
mkfs_opts *opts, uint64_t r
printf("%-27s%.2f %s (%"PRIu64" %s)\n", _("Filesystem size:"),
   (fssize / ((float)(1 << 30)) * sb->sb_bsize), _("GB"), fssize, 
_("blocks"));
printf("%-27s%u\n", _("Journals:"), opts->journals);
+   printf("%-27s%uMB\n", _("Journal size:"), opts->jsize);
printf("%-27s%"PRIu64"\n", _("Resource groups:"), rgrps);
printf("%-27s\"%s\"\n", _("Locking protocol:"), opts->lockproto);
printf("%-27s\"%s\"\n", _("Lock table:"), opts->locktable);
@@ -816,6 +817,9 @@ static int place_rgrps(struct gfs2_sbd *sdp, lgfs2_rgrps_t 
rgs, uint64_t *rgaddr
 
 static void sbd_init(struct gfs2_sbd *sdp, struct mkfs_opts *opts, unsigned 
bsize)
 {
+   uint64_t fssize_qtr;
+   unsigned i;
+
memset(sdp, 0, sizeof(struct gfs2_sbd));
sdp->time = time(NULL);
sdp->rgtree.osi_node = NULL;
@@ -838,9 +842,26 @@ static void sbd_init(struct gfs2_sbd *sdp, struct 
mkfs_opts *opts, unsigned bsiz
   opts->dev.size / ((float)(1 << 30)), _("GB"),
   opts->dev.size / sdp->bsize, _("blocks"));
}
-   /* TODO: Check if the fssize is too small, somehow */
sdp->device.length = opts->fssize;
}
+   /* Adjust the journal size to make sure journals take up no more than
+  1/4 of the fs. This enforces a fairly arbitrary minimum fs size
+  (~32M per journal) but it's cleaner than allowing ENOSPC failures
+  further into the mkfs process. */
+   fssize_qtr = sdp->device.length / 4;
+   for (i = opts->jsize; i >= GFS2_MIN_JSIZE; i--) {
+   unsigned jsize_blocks = (i << 20) / sdp->bsize;
+
+   if (jsize_blocks * opts->journals <= fssize_qtr)
+   break;
+   }
+   if (i < GFS2_MIN_JSIZE || (opts->got_jsize && i < opts->jsize)) {
+   fprintf(stderr, _("gfs2 will not fit on this device.\n"));
+   if (i >= GFS2_MIN_JSIZE)
+   fprintf(stderr, _("Maximum journal size for this device 
is %uMB.\n"), i);
+   exit(1);
+   }
+   sdp->jsize = opts->jsize = i;
 }
 
 static int probe_contents(struct mkfs_dev