Blame SOURCES/bz1440269-1-mkfs_gfs2_Free_unnecessary_cached_pages_disable_readahead.patch

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