freebsd-dev/include
Etienne Dechamps 119a394ab0 Only commit the ZIL once in zpl_writepages() (msync() case).
Currently, using msync() results in the following code path:

    sys_msync -> zpl_fsync -> filemap_write_and_wait_range -> zpl_writepages -> write_cache_pages -> zpl_putpage

In such a code path, zil_commit() is called as part of zpl_putpage().
This means that for each page, the write is handed to the DMU, the ZIL
is committed, and only then do we move on to the next page. As one might
imagine, this results in atrocious performance where there is a large
number of pages to write: instead of committing a batch of N writes,
we do N commits containing one page each. In some extreme cases this
can result in msync() being ~700 times slower than it should be, as well
as very inefficient use of ZIL resources.

This patch fixes this issue by making sure that the requested writes
are batched and then committed only once. Unfortunately, the
implementation is somewhat non-trivial because there is no way to run
write_cache_pages in SYNC mode (so that we get all pages) without
making it wait on the writeback tag for each page.

The solution implemented here is composed of two parts:

 - I added a new callback system to the ZIL, which allows the caller to
   be notified when its ITX gets written to stable storage. One nice
   thing is that the callback is called not only in zil_commit() but
   in zil_sync() as well, which means that the caller doesn't have to
   care whether the write ended up in the ZIL or the DMU: it will get
   notified as soon as it's safe, period. This is an improvement over
   dmu_tx_callback_register() that was used previously, which only
   supports DMU writes. The rationale for this change is to allow
   zpl_putpage() to be notified when a ZIL commit is completed without
   having to block on zil_commit() itself.

 - zpl_writepages() now calls write_cache_pages in non-SYNC mode, which
   will prevent (1) write_cache_pages from blocking, and (2) zpl_putpage
   from issuing ZIL commits. zpl_writepages() will issue the commit
   itself instead of relying on zpl_putpage() to do it, thus nicely
   batching the writes. Note, however, that we still have to call
   write_cache_pages() again in SYNC mode because there is an edge case
   documented in the implementation of write_cache_pages() whereas it
   will not give us all dirty pages when running in non-SYNC mode. Thus
   we need to run it at least once in SYNC mode to make sure we honor
   persistency guarantees. This only happens when the pages are
   modified at the same time msync() is running, which should be rare.
   In most cases there won't be any additional pages and this second
   call will do nothing.

Note that this change also fixes a bug related to #907 whereas calling
msync() on pages that were already handed over to the DMU in a previous
writepages() call would make msync() block until the next TXG sync
instead of returning as soon as the ZIL commit is complete. The new
callback system fixes that problem.

Signed-off-by: Richard Yao <ryao@gentoo.org>
Signed-off-by: Brian Behlendorf <behlendorf1@llnl.gov>
Closes #1849
Closes #907
2013-11-23 15:08:29 -08:00
..
linux Honor CONFIG_FS_POSIX_ACL kernel option 2013-11-05 16:22:05 -08:00
sys Only commit the ZIL once in zpl_writepages() (msync() case). 2013-11-23 15:08:29 -08:00
libnvpair.h Support custom build directories and move includes 2010-09-08 12:38:56 -07:00
libuutil_common.h Support custom build directories and move includes 2010-09-08 12:38:56 -07:00
libuutil_impl.h Support custom build directories and move includes 2010-09-08 12:38:56 -07:00
libuutil.h Support custom build directories and move includes 2010-09-08 12:38:56 -07:00
libzfs_core.h Illumos #3996 2013-11-05 12:23:11 -08:00
libzfs_impl.h Illumos #2882, #2883, #2900 2013-09-04 15:49:00 -07:00
libzfs.h Illumos #2583 2013-11-21 11:13:53 -08:00
Makefile.am Illumos #2882, #2883, #2900 2013-09-04 15:49:00 -07:00
zfeature_common.h Illumos #3035 LZ4 compression support in ZFS and GRUB 2013-01-29 09:28:20 -08:00
zfs_comutil.h Illumos #2882, #2883, #2900 2013-09-04 15:49:00 -07:00
zfs_deleg.h Illumos #278: get rid zfs of python and pyzfs dependencies 2011-08-01 12:09:36 -07:00
zfs_fletcher.h Support custom build directories and move includes 2010-09-08 12:38:56 -07:00
zfs_namecheck.h Support custom build directories and move includes 2010-09-08 12:38:56 -07:00
zfs_prop.h Support custom build directories and move includes 2010-09-08 12:38:56 -07:00
zpios-ctl.h Refresh links to web site 2013-03-06 15:46:41 -08:00
zpios-internal.h Refresh links to web site 2013-03-06 15:46:41 -08:00