mirror_zfs/module/zfs
Richard Yao cd3939c5f0 Linux AIO Support
nfsd uses do_readv_writev() to implement fops->read and fops->write.
do_readv_writev() will attempt to read/write using fops->aio_read and
fops->aio_write, but it will fallback to fops->read and fops->write when
AIO is not available. However, the fallback will perform a call for each
individual data page. Since our default recordsize is 128KB, sequential
operations on NFS will generate 32 DMU transactions where only 1
transaction was needed. That was unnecessary overhead and we implement
fops->aio_read and fops->aio_write to eliminate it.

ZFS originated in OpenSolaris, where the AIO API is entirely implemented
in userland's libc by intelligently mapping them to VOP_WRITE, VOP_READ
and VOP_FSYNC.  Linux implements AIO inside the kernel itself. Linux
filesystems therefore must implement their own AIO logic and nearly all
of them implement fops->aio_write synchronously. Consequently, they do
not implement aio_fsync(). However, since the ZPL works by mapping
Linux's VFS calls to the functions implementing Illumos' VFS operations,
we instead implement AIO in the kernel by mapping the operations to the
VOP_READ, VOP_WRITE and VOP_FSYNC equivalents. We therefore implement
fops->aio_fsync.

One might be inclined to make our fops->aio_write implementation
synchronous to make software that expects this behavior safe. However,
there are several reasons not to do this:

1. Other platforms do not implement aio_write() synchronously and since
the majority of userland software using AIO should be cross platform,
expectations of synchronous behavior should not be a problem.

2. We would hurt the performance of programs that use POSIX interfaces
properly while simultaneously encouraging the creation of more
non-compliant software.

3. The broader community concluded that userland software should be
patched to properly use POSIX interfaces instead of implementing hacks
in filesystems to cater to broken software. This concept is best
described as the O_PONIES debate.

4. Making an asynchronous write synchronous is non sequitur.

Any software dependent on synchronous aio_write behavior will suffer
data loss on ZFSOnLinux in a kernel panic / system failure of at most
zfs_txg_timeout seconds, which by default is 5 seconds. This seems like
a reasonable consequence of using non-compliant software.

It should be noted that this is also a problem in the kernel itself
where nfsd does not pass O_SYNC on files opened with it and instead
relies on a open()/write()/close() to enforce synchronous behavior when
the flush is only guarenteed on last close.

Exporting any filesystem that does not implement AIO via NFS risks data
loss in the event of a kernel panic / system failure when something else
is also accessing the file. Exporting any file system that implements
AIO the way this patch does bears similar risk. However, it seems
reasonable to forgo crippling our AIO implementation in favor of
developing patches to fix this problem in Linux's nfsd for the reasons
stated earlier. In the interim, the risk will remain. Failing to
implement AIO will not change the problem that nfsd created, so there is
no reason for nfsd's mistake to block our implementation of AIO.

It also should be noted that `aio_cancel()` will always return
`AIO_NOTCANCELED` under this implementation. It is possible to implement
aio_cancel by deferring work to taskqs and use `kiocb_set_cancel_fn()`
to set a callback function for cancelling work sent to taskqs, but the
simpler approach is allowed by the specification:

```
Which operations are cancelable is implementation-defined.
```

http://pubs.opengroup.org/onlinepubs/009695399/functions/aio_cancel.html

The only programs on my system that are capable of using `aio_cancel()`
are QEMU, beecrypt and fio use it according to a recursive grep of my
system's `/usr/src/debug`. That suggests that `aio_cancel()` users are
rare. Implementing aio_cancel() is left to a future date when it is
clear that there are consumers that benefit from its implementation to
justify the work.

Lastly, it is important to know that handling of the iovec updates differs
between Illumos and Linux in the implementation of read/write. On Linux,
it is the VFS' responsibility whle on Illumos, it is the filesystem's
responsibility.  We take the intermediate solution of copying the iovec
so that the ZFS code can update it like on Solaris while leaving the
originals alone. This imposes some overhead. We could always revisit
this should profiling show that the allocations are a problem.

Signed-off-by: Richard Yao <ryao@gentoo.org>
Signed-off-by: Brian Behlendorf <behlendorf1@llnl.gov>
Closes #223
Closes #2373
2014-09-05 15:11:43 -07:00
..
arc.c Illumos 5034 - ARC's buf_hash_table is too small 2014-08-26 16:14:49 -07:00
blkptr.c Illumos 4757, 4913 2014-08-01 14:28:05 -07:00
bplist.c Illumos #3464 2013-09-04 16:01:24 -07:00
bpobj.c Illumos 4757, 4913 2014-08-01 14:28:05 -07:00
bptree.c Illumos 4914 - zfs on-disk bookmark structure should be named *_phys_t 2014-08-06 14:48:41 -07:00
dbuf_stats.c cstyle: Resolve C style issues 2013-12-18 16:46:35 -08:00
dbuf.c Illumos 4631 - zvol_get_stats triggering too many reads 2014-08-20 09:17:00 -07:00
ddt_zap.c cstyle: Resolve C style issues 2013-12-18 16:46:35 -08:00
ddt.c Change the default 'zfs_dedup_prefetch' value to '0' 2014-09-04 09:50:45 -07:00
dmu_diff.c Illumos 4914 - zfs on-disk bookmark structure should be named *_phys_t 2014-08-06 14:48:41 -07:00
dmu_object.c Illumos 4171, 4172 2014-07-25 16:40:07 -07:00
dmu_objset.c Illumos 4914 - zfs on-disk bookmark structure should be named *_phys_t 2014-08-06 14:48:41 -07:00
dmu_send.c Illumos 4914 - zfs on-disk bookmark structure should be named *_phys_t 2014-08-06 14:48:41 -07:00
dmu_traverse.c Illumos 4914 - zfs on-disk bookmark structure should be named *_phys_t 2014-08-06 14:48:41 -07:00
dmu_tx.c Improve reporting of tx assignment wait times 2014-03-04 12:22:24 -08:00
dmu_zfetch.c Use enum type(zfetch_dirn_t) instead 2014-01-23 12:56:33 -08:00
dmu.c Illumos 4914 - zfs on-disk bookmark structure should be named *_phys_t 2014-08-06 14:48:41 -07:00
dnode_sync.c Illumos 4757, 4913 2014-08-01 14:28:05 -07:00
dnode.c Illumos 4757, 4913 2014-08-01 14:28:05 -07:00
dsl_bookmark.c Illumos 4368, 4369. 2014-07-29 10:55:29 -07:00
dsl_dataset.c Fix invalid locking order in rename operation 2014-09-04 09:50:46 -07:00
dsl_deadlist.c Illumos #3104: eliminate empty bpobjs 2013-01-08 10:35:43 -08:00
dsl_deleg.c cstyle: Resolve C style issues 2013-12-18 16:46:35 -08:00
dsl_destroy.c Illumos 4914 - zfs on-disk bookmark structure should be named *_phys_t 2014-08-06 14:48:41 -07:00
dsl_dir.c Illumos 4171, 4172 2014-07-25 16:40:07 -07:00
dsl_pool.c Illumos 4390 - I/O errors can corrupt space map when deleting fs/vol 2014-08-04 11:50:52 -07:00
dsl_prop.c Check the dataset type more rigorously when fetching properties. 2014-05-06 10:41:46 -07:00
dsl_scan.c Illumos 4914 - zfs on-disk bookmark structure should be named *_phys_t 2014-08-06 14:48:41 -07:00
dsl_synctask.c Export symbols dsl_sync_task{_nowait} 2014-03-07 10:01:36 -08:00
dsl_userhold.c Illumos 4757, 4913 2014-08-01 14:28:05 -07:00
fm.c Fixed memory leaks in zevent handling 2014-08-20 10:45:16 -07:00
gzip.c cstyle: Resolve C style issues 2013-12-18 16:46:35 -08:00
lz4.c Illumos #4936 fix potential overflow in lz4 2014-07-01 14:10:47 -07:00
lzjb.c cstyle: Resolve C style issues 2013-12-18 16:46:35 -08:00
Makefile.in Illumos 4757, 4913 2014-08-01 14:28:05 -07:00
metaslab.c Don't upgrade a metaslab when the pool is not writable 2014-08-18 08:47:19 -07:00
range_tree.c Illumos 4976-4984 - metaslab improvements 2014-08-18 08:40:49 -07:00
refcount.c Illumos #3464 2013-09-04 16:01:24 -07:00
rrwlock.c Fix several new KM_SLEEP warnings 2013-09-25 15:44:22 -07:00
sa.c Calculate header size correctly in sa_find_sizes() 2014-05-19 11:55:50 -07:00
sha256.c Add linux sha2 support 2010-08-31 13:41:59 -07:00
spa_boot.c Add linux kernel module support 2010-08-31 13:41:58 -07:00
spa_config.c Implement -t option to zpool import for temporary pool names 2014-03-20 12:05:30 -07:00
spa_errlog.c Illumos 4914 - zfs on-disk bookmark structure should be named *_phys_t 2014-08-06 14:48:41 -07:00
spa_history.c cstyle: Resolve C style issues 2013-12-18 16:46:35 -08:00
spa_misc.c Illumos 4757, 4913 2014-08-01 14:28:05 -07:00
spa_stats.c Illumos 4914 - zfs on-disk bookmark structure should be named *_phys_t 2014-08-06 14:48:41 -07:00
spa.c Illumos 4970-4974 - extreme rewind enhancements 2014-08-26 16:29:57 -07:00
space_map.c Illumos 4976-4984 - metaslab improvements 2014-08-18 08:40:49 -07:00
space_reftree.c Illumos #4101, #4102, #4103, #4105, #4106 2014-07-22 09:39:16 -07:00
txg.c Illumos 4976-4984 - metaslab improvements 2014-08-18 08:40:49 -07:00
uberblock.c Illumos #3598 2013-10-31 14:58:04 -07:00
unique.c Switch KM_SLEEP to KM_PUSHPAGE 2012-08-27 12:01:37 -07:00
vdev_cache.c Illumos 4370, 4371 2014-07-28 14:29:58 -07:00
vdev_disk.c Illumos #4374 2014-07-30 09:20:35 -07:00
vdev_file.c Honor zfs_nocacheflush for file vdevs 2014-05-19 13:30:48 -07:00
vdev_label.c Illumos #4101, #4102, #4103, #4105, #4106 2014-07-22 09:39:16 -07:00
vdev_mirror.c Illumos #4045 write throttle & i/o scheduler performance work 2013-12-06 09:32:43 -08:00
vdev_missing.c Illumos #3598 2013-10-31 14:58:04 -07:00
vdev_queue.c Avoid dynamic allocation of 'search zio' 2014-08-11 08:44:54 -07:00
vdev_raidz.c Illumos #4045 write throttle & i/o scheduler performance work 2013-12-06 09:32:43 -08:00
vdev_root.c Illumos #3598 2013-10-31 14:58:04 -07:00
vdev.c Illumos 5049 - panic when removing log device 2014-09-05 09:06:27 -07:00
zap_leaf.c Illumos #4374 2014-07-30 09:20:35 -07:00
zap_micro.c Avoid 128K kmem allocations in mzap_upgrade() 2014-08-11 16:10:32 -07:00
zap.c Illumos #4374 2014-07-30 09:20:35 -07:00
zfeature_common.c Illumos 4757, 4913 2014-08-01 14:28:05 -07:00
zfeature.c Illumos 4370, 4371 2014-07-28 14:29:58 -07:00
zfs_acl.c Allow chown/chgrp when no ACL SAs exist. 2014-01-23 11:07:29 -08:00
zfs_byteswap.c Add linux kernel module support 2010-08-31 13:41:58 -07:00
zfs_ctldir.c Illumos 4368, 4369. 2014-07-29 10:55:29 -07:00
zfs_debug.c Illumos 4390 - I/O errors can corrupt space map when deleting fs/vol 2014-08-04 11:50:52 -07:00
zfs_dir.c Revert "Revert "Revert "Fix unlink/xattr deadlock""" 2014-08-11 16:12:36 -07:00
zfs_fm.c Fixed memory leaks in zevent handling 2014-08-20 10:45:16 -07:00
zfs_fuid.c Illumos #3522 2013-10-30 14:51:27 -07:00
zfs_ioctl.c Illumos 4757, 4913 2014-08-01 14:28:05 -07:00
zfs_log.c Only commit the ZIL once in zpl_writepages() (msync() case). 2013-11-23 15:08:29 -08:00
zfs_onexit.c Illumos #3598 2013-10-31 14:58:04 -07:00
zfs_replay.c Linux AIO Support 2014-09-05 15:11:43 -07:00
zfs_rlock.c cstyle: Resolve C style issues 2013-12-18 16:46:35 -08:00
zfs_sa.c cstyle: Resolve C style issues 2013-12-18 16:46:35 -08:00
zfs_vfsops.c Improve handling of filesystem versions 2014-09-03 09:17:14 -07:00
zfs_vnops.c Add zfs_iput_async() interface 2014-08-11 16:11:43 -07:00
zfs_znode.c Add zfs_iput_async() interface 2014-08-11 16:11:43 -07:00
zil.c Illumos 4914 - zfs on-disk bookmark structure should be named *_phys_t 2014-08-06 14:48:41 -07:00
zio_checksum.c Illumos 4757, 4913 2014-08-01 14:28:05 -07:00
zio_compress.c Illumos 4757, 4913 2014-08-01 14:28:05 -07:00
zio_inject.c Illumos 4914 - zfs on-disk bookmark structure should be named *_phys_t 2014-08-06 14:48:41 -07:00
zio.c Illumos 4914 - zfs on-disk bookmark structure should be named *_phys_t 2014-08-06 14:48:41 -07:00
zle.c Update core ZFS code from build 121 to build 141. 2010-05-28 13:45:14 -07:00
zpl_ctldir.c cstyle: Resolve C style issues 2013-12-18 16:46:35 -08:00
zpl_export.c cstyle: Resolve C style issues 2013-12-18 16:46:35 -08:00
zpl_file.c Linux AIO Support 2014-09-05 15:11:43 -07:00
zpl_inode.c cstyle: Resolve C style issues 2013-12-18 16:46:35 -08:00
zpl_super.c Prune metadata from ghost lists in arc_adjust_meta 2014-02-21 16:10:49 -08:00
zpl_xattr.c Linux AIO Support 2014-09-05 15:11:43 -07:00
zrlock.c Export ZFS symbols needed by Lustre. 2010-09-17 16:24:15 -07:00
zvol.c Use long holds in zvol_set_volsize() 2014-01-14 14:46:12 -08:00