Blame SOURCES/bz1440269-1-mkfs_gfs2_Free_unnecessary_cached_pages_disable_readahead.patch

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