From: Dave Chinner Date: Thu, 9 May 2013 12:16:09 +0000 (-0500) Subject: xfs_fsr: file reads should be O_DIRECT X-Git-Tag: v3.2.0-alpha1~142 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=108e985bc596a1f1a33d31a348fdb430213fb8c0;p=thirdparty%2Fxfsprogs-dev.git xfs_fsr: file reads should be O_DIRECT When running xfs_fsr on a sparse filesystem image containing approximately 8 million extents and 80GB of data, I noticed that the page cache grew and consumed all the memory in the machine. It turns out that xfs_fsr is using direct IO to write data, but buffered IO to read data. Convert the read side to use direct IO to prevent page cache blowouts. Signed-off-by: Dave Chinner Reviewed-by: Christoph Hellwig Reviewed-by: Mark Tinguely Signed-off-by: Rich Johnston --- diff --git a/fsr/xfs_fsr.c b/fsr/xfs_fsr.c index 6852b3f7a..d4ec9a3be 100644 --- a/fsr/xfs_fsr.c +++ b/fsr/xfs_fsr.c @@ -732,7 +732,8 @@ fsrfs(char *mntdir, xfs_ino_t startino, int targetrange) (p->bs_extents < 2)) continue; - if ((fd = jdm_open(fshandlep, p, O_RDWR)) < 0) { + fd = jdm_open(fshandlep, p, O_RDWR|O_DIRECT); + if (fd < 0) { /* This probably means the file was * removed while in progress of handling * it. Just quietly ignore this file. @@ -836,7 +837,7 @@ fsrfile(char *fname, xfs_ino_t ino) return -1; } - fd = jdm_open( fshandlep, &statbuf, O_RDWR); + fd = jdm_open(fshandlep, &statbuf, O_RDWR|O_DIRECT); if (fd < 0) { fsrprintf(_("unable to open handle %s: %s\n"), fname, strerror(errno));