From: Hugh Dickins <hughd@google.com>
To: Christoph Hellwig <hch@infradead.org>
Cc: Dave Chinner <david@fromorbit.com>, Ben Myers <bpm@sgi.com>,
xfs@oss.sgi.com, linux-fsdevel@vger.kernel.org,
linux-mm@kvack.org
Subject: [PATCH 2/2] xfs: hole-punch retaining cache beyond
Date: Sun, 13 May 2012 13:51:18 -0700 (PDT) [thread overview]
Message-ID: <alpine.LSU.2.00.1205131350150.1547@eggly.anvils> (raw)
In-Reply-To: <alpine.LSU.2.00.1205131347120.1547@eggly.anvils>
xfs has a very inefficient hole-punch implementation, invalidating all
the cache beyond the hole (after flushing dirty back to disk, from which
all must be read back if wanted again). So if you punch a hole in a
file mlock()ed into userspace, pages beyond the hole are inadvertently
munlock()ed until they are touched again.
Is there a strong internal reason why that has to be so on xfs?
Or is it just a relic from xfs supporting XFS_IOC_UNRESVSP long
before Linux 2.6.16 provided truncate_inode_pages_range()?
If the latter, then this patch mostly fixes it, by passing the proper
range to xfs_flushinval_pages(). But a little more should be done to
get it just right: a partial page on either side of the hole is still
written back to disk, invalidated and munlocked.
Signed-off-by: Hugh Dickins <hughd@google.com>
---
fs/xfs/xfs_vnodeops.c | 14 +++++++++++---
1 file changed, 11 insertions(+), 3 deletions(-)
--- next-20120511/fs/xfs/xfs_vnodeops.c 2012-05-11 00:22:26.095158149 -0700
+++ linux/fs/xfs/xfs_vnodeops.c 2012-05-12 18:01:14.988654723 -0700
@@ -2040,7 +2040,8 @@ xfs_free_file_space(
xfs_fsblock_t firstfsb;
xfs_bmap_free_t free_list;
xfs_bmbt_irec_t imap;
- xfs_off_t ioffset;
+ xfs_off_t startoffset;
+ xfs_off_t endoffset;
xfs_extlen_t mod=0;
xfs_mount_t *mp;
int nimap;
@@ -2074,11 +2075,18 @@ xfs_free_file_space(
inode_dio_wait(VFS_I(ip));
}
+ /*
+ * Round startoffset down and endoffset up: we write out any dirty
+ * blocks in between before truncating, so we can read partial blocks
+ * back from disk afterwards (but that may munlock the partial pages).
+ */
rounding = max_t(uint, 1 << mp->m_sb.sb_blocklog, PAGE_CACHE_SIZE);
- ioffset = offset & ~(rounding - 1);
+ startoffset = round_down(offset, rounding);
+ endoffset = round_up(offset + len, rounding) - 1;
if (VN_CACHED(VFS_I(ip)) != 0) {
- error = xfs_flushinval_pages(ip, ioffset, -1, FI_REMAPF_LOCKED);
+ error = xfs_flushinval_pages(ip, startoffset, endoffset,
+ FI_REMAPF_LOCKED);
if (error)
goto out_unlock_iolock;
}
--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to majordomo@kvack.org. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Fight unfair telecom internet charges in Canada: sign http://stopthemeter.ca/
Don't email: <a href=mailto:"dont@kvack.org"> email@kvack.org </a>
next prev parent reply other threads:[~2012-05-13 20:51 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2012-05-13 20:50 [PATCH 1/2] xfs: hole-punch use truncate_pagecache_range Hugh Dickins
2012-05-13 20:51 ` Hugh Dickins [this message]
2012-05-15 6:58 ` [PATCH 2/2] xfs: hole-punch retaining cache beyond Christoph Hellwig
2012-05-15 6:57 ` [PATCH 1/2] xfs: hole-punch use truncate_pagecache_range Christoph Hellwig
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=alpine.LSU.2.00.1205131350150.1547@eggly.anvils \
--to=hughd@google.com \
--cc=bpm@sgi.com \
--cc=david@fromorbit.com \
--cc=hch@infradead.org \
--cc=linux-fsdevel@vger.kernel.org \
--cc=linux-mm@kvack.org \
--cc=xfs@oss.sgi.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox