From 0cdad5e2289100eeafacac357029ee4631acced9 Mon Sep 17 00:00:00 2001
From: Pawel Jakub Dawidek <pjd@FreeBSD.org>
Date: Tue, 24 Apr 2007 16:53:01 +0000
Subject: [PATCH] MFp4: Once page is written successfully, we should clear the
 dirty bits. This fixes slow operations on mmaped files, because without this
 fix, pages were written to disk multiple times.

If one is looking for even greater speed up for such operation, he should
disable ZIL (by setting vfs.zfs.zil_disable to 1 in /boot/loader.conf).
Disabling ZIL makes fsx run ~9 times faster.
---
 sys/cddl/contrib/opensolaris/uts/common/fs/zfs/zfs_vnops.c | 3 +++
 sys/contrib/opensolaris/uts/common/fs/zfs/zfs_vnops.c      | 3 +++
 2 files changed, 6 insertions(+)

diff --git a/sys/cddl/contrib/opensolaris/uts/common/fs/zfs/zfs_vnops.c b/sys/cddl/contrib/opensolaris/uts/common/fs/zfs/zfs_vnops.c
index d1e523000336..2d154819ab4d 100644
--- a/sys/cddl/contrib/opensolaris/uts/common/fs/zfs/zfs_vnops.c
+++ b/sys/cddl/contrib/opensolaris/uts/common/fs/zfs/zfs_vnops.c
@@ -318,6 +318,9 @@ mappedwrite(vnode_t *vp, int nbytes, uio_t *uio, dmu_tx_t *tx)
 			sf_buf_free(sf);
 			sched_unpin();
 			VM_OBJECT_LOCK(obj);
+			vm_page_lock_queues();
+			vm_page_set_validclean(m, off, bytes);
+			vm_page_unlock_queues();
 			vm_page_wakeup(m);
 		} else {
 			VM_OBJECT_UNLOCK(obj);
diff --git a/sys/contrib/opensolaris/uts/common/fs/zfs/zfs_vnops.c b/sys/contrib/opensolaris/uts/common/fs/zfs/zfs_vnops.c
index d1e523000336..2d154819ab4d 100644
--- a/sys/contrib/opensolaris/uts/common/fs/zfs/zfs_vnops.c
+++ b/sys/contrib/opensolaris/uts/common/fs/zfs/zfs_vnops.c
@@ -318,6 +318,9 @@ mappedwrite(vnode_t *vp, int nbytes, uio_t *uio, dmu_tx_t *tx)
 			sf_buf_free(sf);
 			sched_unpin();
 			VM_OBJECT_LOCK(obj);
+			vm_page_lock_queues();
+			vm_page_set_validclean(m, off, bytes);
+			vm_page_unlock_queues();
 			vm_page_wakeup(m);
 		} else {
 			VM_OBJECT_UNLOCK(obj);