summaryrefslogtreecommitdiffstats
path: root/module/zfs/zpl_file.c
diff options
context:
space:
mode:
authorBrian Behlendorf <[email protected]>2011-08-01 21:28:51 -0700
committerBrian Behlendorf <[email protected]>2011-08-02 10:34:55 -0700
commit3c0e5c0f455576d045fa443cbab74834d70ded55 (patch)
treea9c65bf5845dfbf41315efef2e5733a6af82ea9f /module/zfs/zpl_file.c
parentddd0fd9ef64648333b79b4cc8a13216399cefec9 (diff)
Cleanup mmap(2) writes
While the existing implementation of .writepage()/zpl_putpage() was functional it was not entirely correct. In particular, it would move dirty pages in to a clean state simply after copying them in to the ARC cache. This would result in the pages being lost if the system were to crash enough though the Linux VFS believed them to be safe on stable storage. Since at the moment virtually all I/O, except mmap(2), bypasses the page cache this isn't as bad as it sounds. However, as hopefully start using the page cache more getting this right becomes more important so it's good to improve this now. This patch takes a big step in that direction by updating the code to correctly move dirty pages through a writeback phase before they are marked clean. When a dirty page is copied in to the ARC it will now be set in writeback and a completion callback is registered with the transaction. The page will stay in writeback until the dmu runs the completion callback indicating the page is on stable storage. At this point the page can be safely marked clean. This process is normally entirely asynchronous and will be repeated for every dirty page. This may initially sound inefficient but most of these pages will end up in a few txgs. That means when they are eventually written to disk they should be nicely batched. However, there is room for improvement. It may still be desirable to batch up the pages in to larger writes for the dmu. This would reduce the number of callbacks and small 4k buffer required by the ARC. Finally, if the caller requires that the I/O be done synchronously by setting WB_SYNC_ALL or if ZFS_SYNC_ALWAYS is set. Then the I/O will trigger a zil_commit() to flush the data to stable storage. At which point the registered callbacks will be run leaving the date safe of disk and marked clean before returning from .writepage. Signed-off-by: Brian Behlendorf <[email protected]>
Diffstat (limited to 'module/zfs/zpl_file.c')
-rw-r--r--module/zfs/zpl_file.c19
1 files changed, 6 insertions, 13 deletions
diff --git a/module/zfs/zpl_file.c b/module/zfs/zpl_file.c
index c2e3a6bdc..7eaf65c6e 100644
--- a/module/zfs/zpl_file.c
+++ b/module/zfs/zpl_file.c
@@ -352,7 +352,10 @@ zpl_readpage(struct file *filp, struct page *pp)
int
zpl_putpage(struct page *pp, struct writeback_control *wbc, void *data)
{
- int error;
+ struct address_space *mapping = data;
+
+ ASSERT(PageLocked(pp));
+ ASSERT(!PageWriteback(pp));
/*
* Disable the normal reclaim path for zpl_putpage(). This
@@ -362,20 +365,10 @@ zpl_putpage(struct page *pp, struct writeback_control *wbc, void *data)
* zpl_putpage() again resulting in a deadlock.
*/
current->flags |= PF_MEMALLOC;
- error = -zfs_putpage(pp, wbc, data);
+ (void) zfs_putpage(mapping->host, pp, wbc);
current->flags &= ~PF_MEMALLOC;
- if (error) {
- SetPageError(pp);
- ClearPageUptodate(pp);
- } else {
- ClearPageError(pp);
- SetPageUptodate(pp);
- flush_dcache_page(pp);
- }
-
- unlock_page(pp);
- return error;
+ return (0);
}
static int