public inbox for linux-xfs@vger.kernel.org
 help / color / mirror / Atom feed
* Review: fix mapping invalidation callouts
@ 2007-01-08  4:03 David Chinner
  2007-01-08  9:09 ` Christoph Hellwig
  2007-01-10  6:23 ` David Chinner
  0 siblings, 2 replies; 10+ messages in thread
From: David Chinner @ 2007-01-08  4:03 UTC (permalink / raw)
  To: xfs-dev; +Cc: xfs

With the recent cancel_dirty_page() changes, a warning was
added if we cancel a dirty page that is still mapped into
the page tables.
This happens in XFS from fs_tosspages() and fs_flushinval_pages()
because they call truncate_inode_pages().

truncate_inode_pages() does not invalidate existing page mappings;
it is expected taht this is called only when truncating the file
or destroying the inode and on both these cases there can be
no mapped ptes. However, we call this when doing direct I/O writes
to remove pages from the page cache. As a result, we can rip
a page from the page cache that still has mappings attached.

The correct fix is to use invalidate_inode_pages2_range() instead
of truncate_inode_pages(). They essentially do the same thing, but
the former also removes any pte mappings before removing the page
from the page cache.

Comments?

Cheers,

Dave.
-- 
Dave Chinner
Principal Engineer
SGI Australian Software Group


---
 fs/xfs/linux-2.6/xfs_fs_subr.c |   10 ++++++++--
 1 file changed, 8 insertions(+), 2 deletions(-)

Index: 2.6.x-xfs-new/fs/xfs/linux-2.6/xfs_fs_subr.c
===================================================================
--- 2.6.x-xfs-new.orig/fs/xfs/linux-2.6/xfs_fs_subr.c	2006-12-12 12:05:17.000000000 +1100
+++ 2.6.x-xfs-new/fs/xfs/linux-2.6/xfs_fs_subr.c	2007-01-08 09:30:22.056571711 +1100
@@ -21,6 +21,8 @@ int  fs_noerr(void) { return 0; }
 int  fs_nosys(void) { return ENOSYS; }
 void fs_noval(void) { return; }
 
+#define XFS_OFF_TO_PCSIZE(off)	\
+	(((off) + PAGE_CACHE_SIZE - 1) >> PAGE_CACHE_SHIFT)
 void
 fs_tosspages(
 	bhv_desc_t	*bdp,
@@ -32,7 +34,9 @@ fs_tosspages(
 	struct inode	*ip = vn_to_inode(vp);
 
 	if (VN_CACHED(vp))
-		truncate_inode_pages(ip->i_mapping, first);
+		invalidate_inode_pages2_range(ip->i_mapping,
+					XFS_OFF_TO_PCSIZE(first),
+					XFS_OFF_TO_PCSIZE(last));
 }
 
 void
@@ -49,7 +53,9 @@ fs_flushinval_pages(
 		if (VN_TRUNC(vp))
 			VUNTRUNCATE(vp);
 		filemap_write_and_wait(ip->i_mapping);
-		truncate_inode_pages(ip->i_mapping, first);
+		invalidate_inode_pages2_range(ip->i_mapping,
+					XFS_OFF_TO_PCSIZE(first),
+					XFS_OFF_TO_PCSIZE(last));
 	}
 }
 

^ permalink raw reply	[flat|nested] 10+ messages in thread

end of thread, other threads:[~2007-01-11  8:02 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2007-01-08  4:03 Review: fix mapping invalidation callouts David Chinner
2007-01-08  9:09 ` Christoph Hellwig
2007-01-08 23:04   ` David Chinner
2007-01-09 11:57     ` Lachlan McIlroy
2007-01-10  0:10       ` David Chinner
2007-01-10  6:23 ` David Chinner
2007-01-10  8:39   ` Lachlan McIlroy
2007-01-11  6:49     ` David Chinner
2007-01-11  8:00       ` David Chinner
2007-01-11  8:01       ` David Chatterton

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox