Blame SOURCES/bz1440269-1-mkfs_gfs2_Free_unnecessary_cached_pages_disable_readahead.patch

a440e7
commit 10deb2492c8b0dd4dceb963850c91e053bb8d6df
a440e7
Author: Andrew Price <anprice@redhat.com>
a440e7
Date:   Thu Apr 13 06:51:15 2017 -0400
a440e7
a440e7
    mkfs.gfs2: Free unnecessary cached pages, disable readahead
a440e7
    
a440e7
    With a 300T file system, cached pages built up quite heavily and could
a440e7
    be left over from previous io on the device. Use POSIX_FADV_DONTNEED
a440e7
    where appropriate.
a440e7
    
a440e7
    Also, readahead isn't required as mkfs.gfs2 mainly writing full block
a440e7
    ranges at unpredictable locations so use POSIX_FADV_RANDOM to minimise
a440e7
    the overhead from that.
a440e7
    
a440e7
    Resolves: rhbz#1440269
a440e7
    
a440e7
    Signed-off-by: Andrew Price <anprice@redhat.com>
a440e7
a440e7
diff --git a/gfs2/mkfs/main_mkfs.c b/gfs2/mkfs/main_mkfs.c
a440e7
index 0801a4b..83065fb 100644
a440e7
--- a/gfs2/mkfs/main_mkfs.c
a440e7
+++ b/gfs2/mkfs/main_mkfs.c
a440e7
@@ -817,6 +817,7 @@ static int place_rgrps(struct gfs2_sbd *sdp, lgfs2_rgrps_t rgs, struct mkfs_opts
a440e7
 		gfs2_progress_update(&progress, (sdp->rgrps));
a440e7
 	}
a440e7
 	gfs2_progress_close(&progress, _("Done\n"));
a440e7
+	posix_fadvise(sdp->device_fd, 0, sdp->fssize * sdp->bsize, POSIX_FADV_DONTNEED);
a440e7
 
a440e7
 	return 0;
a440e7
 }
a440e7
@@ -909,6 +910,11 @@ static void open_dev(struct mkfs_dev *dev, int withprobe)
a440e7
 		exit(1);
a440e7
 	}
a440e7
 
a440e7
+	/* Freshen up the cache */
a440e7
+	posix_fadvise(dev->fd, 0, 0, POSIX_FADV_DONTNEED);
a440e7
+	/* Turn off readahead, we're just writing new blocks */
a440e7
+	posix_fadvise(dev->fd, 0, 0, POSIX_FADV_RANDOM);
a440e7
+
a440e7
 	error = fstat(dev->fd, &dev->stat);
a440e7
 	if (error < 0) {
a440e7
 		perror(dev->path);
a440e7
@@ -1075,7 +1081,7 @@ int main(int argc, char *argv[])
a440e7
 		perror(opts.dev.path);
a440e7
 		exit(EXIT_FAILURE);
a440e7
 	}
a440e7
-
a440e7
+	posix_fadvise(opts.dev.fd, 0, 0, POSIX_FADV_DONTNEED);
a440e7
 	error = close(opts.dev.fd);
a440e7
 	if (error){
a440e7
 		perror(opts.dev.path);