mirror_zfs/include/os/freebsd/spl/sys
Brian Atkinson a10e552b99
Adding Direct IO Support
Adding O_DIRECT support to ZFS to bypass the ARC for writes/reads.

O_DIRECT support in ZFS will always ensure there is coherency between
buffered and O_DIRECT IO requests. This ensures that all IO requests,
whether buffered or direct, will see the same file contents at all
times. Just as in other FS's , O_DIRECT does not imply O_SYNC. While
data is written directly to VDEV disks, metadata will not be synced
until the associated  TXG is synced.
For both O_DIRECT read and write request the offset and request sizes,
at a minimum, must be PAGE_SIZE aligned. In the event they are not,
then EINVAL is returned unless the direct property is set to always (see
below).

For O_DIRECT writes:
The request also must be block aligned (recordsize) or the write
request will take the normal (buffered) write path. In the event that
request is block aligned and a cached copy of the buffer in the ARC,
then it will be discarded from the ARC forcing all further reads to
retrieve the data from disk.

For O_DIRECT reads:
The only alignment restrictions are PAGE_SIZE alignment. In the event
that the requested data is in buffered (in the ARC) it will just be
copied from the ARC into the user buffer.

For both O_DIRECT writes and reads the O_DIRECT flag will be ignored in
the event that file contents are mmap'ed. In this case, all requests
that are at least PAGE_SIZE aligned will just fall back to the buffered
paths. If the request however is not PAGE_SIZE aligned, EINVAL will
be returned as always regardless if the file's contents are mmap'ed.

Since O_DIRECT writes go through the normal ZIO pipeline, the
following operations are supported just as with normal buffered writes:
Checksum
Compression
Encryption
Erasure Coding
There is one caveat for the data integrity of O_DIRECT writes that is
distinct for each of the OS's supported by ZFS.
FreeBSD - FreeBSD is able to place user pages under write protection so
          any data in the user buffers and written directly down to the
	  VDEV disks is guaranteed to not change. There is no concern
	  with data integrity and O_DIRECT writes.
Linux - Linux is not able to place anonymous user pages under write
        protection. Because of this, if the user decides to manipulate
	the page contents while the write operation is occurring, data
	integrity can not be guaranteed. However, there is a module
	parameter `zfs_vdev_direct_write_verify` that controls the
	if a O_DIRECT writes that can occur to a top-level VDEV before
	a checksum verify is run before the contents of the I/O buffer
        are committed to disk. In the event of a checksum verification
	failure the write will return EIO. The number of O_DIRECT write
	checksum verification errors can be observed by doing
	`zpool status -d`, which will list all verification errors that
	have occurred on a top-level VDEV. Along with `zpool status`, a
	ZED event will be issues as `dio_verify` when a checksum
	verification error occurs.

ZVOLs and dedup is not currently supported with Direct I/O.

A new dataset property `direct` has been added with the following 3
allowable values:
disabled - Accepts O_DIRECT flag, but silently ignores it and treats
	   the request as a buffered IO request.
standard - Follows the alignment restrictions  outlined above for
	   write/read IO requests when the O_DIRECT flag is used.
always   - Treats every write/read IO request as though it passed
           O_DIRECT and will do O_DIRECT if the alignment restrictions
	   are met otherwise will redirect through the ARC. This
	   property will not allow a request to fail.

There is also a module parameter zfs_dio_enabled that can be used to
force all reads and writes through the ARC. By setting this module
parameter to 0, it mimics as if the  direct dataset property is set to
disabled.

Reviewed-by: Brian Behlendorf <behlendorf@llnl.gov>
Reviewed-by: Alexander Motin <mav@FreeBSD.org>
Reviewed-by: Tony Hutter <hutter2@llnl.gov>
Signed-off-by: Brian Atkinson <batkinson@lanl.gov>
Co-authored-by: Mark Maybee <mark.maybee@delphix.com>
Co-authored-by: Matt Macy <mmacy@FreeBSD.org>
Co-authored-by: Brian Behlendorf <behlendorf@llnl.gov>
Closes #10018
2024-09-14 13:47:59 -07:00
..
ia32 Use .section .rodata instead of .rodata on FreeBSD 2023-02-24 16:45:48 -08:00
acl_impl.h Replace dead opensolaris.org license link 2022-07-11 14:16:13 -07:00
acl.h Replace dead opensolaris.org license link 2022-07-11 14:16:13 -07:00
atomic.h FreeBSD: Reduce divergence from in-tree sources 2023-10-09 13:27:18 -07:00
byteorder.h Reduce false positives from Static Analyzers 2022-09-30 15:30:12 -07:00
callb.h Replace dead opensolaris.org license link 2022-07-11 14:16:13 -07:00
ccompat.h FreeBSD: remove support for FreeBSD < 13.0-RELEASE (#16372) 2024-08-05 16:56:45 -07:00
ccompile.h Replace P2ALIGN with P2ALIGN_TYPED and delete P2ALIGN. 2024-05-10 08:47:21 -07:00
cmn_err.h spl: cmn_err_once() should be usable in brace-less if else statements 2023-03-15 11:13:25 -07:00
condvar.h FreeBSD: make adjustments for the standalone environment 2020-10-13 21:05:49 -07:00
cred.h Replace dead opensolaris.org license link 2022-07-11 14:16:13 -07:00
ctype.h FreeBSD: Reduce divergence from in-tree sources 2023-10-09 13:27:18 -07:00
debug.h Add custom debug printing for your asserts 2024-04-10 13:30:25 -07:00
dirent.h Add FreeBSD support to OpenZFS 2020-04-14 11:36:28 -07:00
disp.h Cleanup: Use OpenSolaris functions to call scheduler 2022-09-12 09:55:37 -07:00
fcntl.h FreeBSD: fix HEAD build, conditionally remove FDSYNC defines 2021-01-23 15:39:55 -08:00
file.h Rename refcount.h to zfs_refcount.h 2020-07-29 16:35:33 -07:00
freebsd_rwlock.h Add FreeBSD support to OpenZFS 2020-04-14 11:36:28 -07:00
idmap.h Replace dead opensolaris.org license link 2022-07-11 14:16:13 -07:00
inttypes.h Add FreeBSD support to OpenZFS 2020-04-14 11:36:28 -07:00
isa_defs.h freebsd: simplify MD isa_defs.h 2022-11-07 15:55:37 -08:00
kmem_cache.h FreeBSD: make adjustments for the standalone environment 2020-10-13 21:05:49 -07:00
kmem.h Linux: Report reclaimable memory to kernel as such (#16385) 2024-07-30 11:40:47 -07:00
kstat.h Cleanup: Switch to strlcpy from strncpy 2022-09-27 16:35:29 -07:00
list_impl.h Remove list_size struct member from list implementation 2024-01-26 14:46:42 -08:00
list.h Replace dead opensolaris.org license link 2022-07-11 14:16:13 -07:00
lock.h Add FreeBSD support to OpenZFS 2020-04-14 11:36:28 -07:00
misc.h FreeBSD: Add const qualifier to members of struct opensolaris_utsname 2024-05-30 09:58:20 -07:00
mod_os.h spa: make read/write queues configurable 2023-12-20 14:17:14 -08:00
mode.h Add FreeBSD support to OpenZFS 2020-04-14 11:36:28 -07:00
mount.h freebsd: changes necessary to coexist with dtrace in tree 2020-07-01 09:10:08 -07:00
mutex.h Adding Direct IO Support 2024-09-14 13:47:59 -07:00
param.h Adding Direct IO Support 2024-09-14 13:47:59 -07:00
policy.h FreeBSD: remove support for FreeBSD < 13.0-RELEASE (#16372) 2024-08-05 16:56:45 -07:00
proc.h FreeBSD: remove support for FreeBSD < 13.0-RELEASE (#16372) 2024-08-05 16:56:45 -07:00
processor.h Replace dead opensolaris.org license link 2022-07-11 14:16:13 -07:00
procfs_list.h Replace dead opensolaris.org license link 2022-07-11 14:16:13 -07:00
random.h FreeBSD: remove support for FreeBSD < 13.0-RELEASE (#16372) 2024-08-05 16:56:45 -07:00
rwlock.h spl: Don't check FreeBSD rwlocks for double initialization (#13019) 2022-01-31 10:58:45 -08:00
sdt.h FreeBSD: Use a statement expression to implement SET_ERROR() (#16284) 2024-07-08 17:59:08 -07:00
sid.h Fix ACL checks for NFS kernel server 2022-03-18 06:47:57 -06:00
sig.h Simplify issig(). 2024-05-29 10:49:11 -07:00
simd_aarch64.h module: freebsd: fix aarch64 fpu handling 2023-04-10 12:40:18 -07:00
simd_arm.h Miscellaneous FreBSD compilation bugfixes 2023-04-06 10:35:02 -07:00
simd_powerpc.h powerpc64: Support ELFv2 asm on Big Endian 2023-04-27 12:49:21 -07:00
simd_x86.h Miscellaneous FreBSD compilation bugfixes 2023-04-06 10:35:02 -07:00
simd.h Add SHA2 SIMD feature tests for FreeBSD 2023-03-02 13:51:56 -08:00
spl_condvar.h FreeBSD: Reduce divergence from in-tree sources 2023-10-09 13:27:18 -07:00
string.h Add FreeBSD support to OpenZFS 2020-04-14 11:36:28 -07:00
sunddi.h Remove hw_serial, ddi_strtoul() 2022-05-13 10:15:31 -07:00
sysmacros.h Replace P2ALIGN with P2ALIGN_TYPED and delete P2ALIGN. 2024-05-10 08:47:21 -07:00
systeminfo.h Add FreeBSD support to OpenZFS 2020-04-14 11:36:28 -07:00
systm.h Refactor ccompile.h to not include system headers 2020-07-25 20:09:50 -07:00
taskq.h Unbreak FreeBSD world build after 3bd4df384 2023-11-08 16:29:34 -08:00
thread.h Add FreeBSD support to OpenZFS 2020-04-14 11:36:28 -07:00
time.h Use uint64_t instead of u_int64_t 2023-11-30 10:36:33 -08:00
timer.h Cleanup: Use OpenSolaris functions to call scheduler 2022-09-12 09:55:37 -07:00
trace_zfs.h Add FreeBSD support to OpenZFS 2020-04-14 11:36:28 -07:00
trace.h Add FreeBSD support to OpenZFS 2020-04-14 11:36:28 -07:00
types32.h Add FreeBSD support to OpenZFS 2020-04-14 11:36:28 -07:00
types.h Linux 6.3 compat: idmapped mount API changes 2023-04-10 14:15:36 -07:00
uio.h Adding Direct IO Support 2024-09-14 13:47:59 -07:00
uuid.h Replace dead opensolaris.org license link 2022-07-11 14:16:13 -07:00
vfs.h FreeBSD: Fix ZFS so that snapshots under .zfs/snapshot are NFS visible 2023-11-27 16:31:03 -08:00
vm.h FreeBSD: remove support for FreeBSD < 13.0-RELEASE (#16372) 2024-08-05 16:56:45 -07:00
vmsystm.h Add FreeBSD support to OpenZFS 2020-04-14 11:36:28 -07:00
vnode_impl.h FreeBSD: Cleanup zfs_readdir() 2022-09-20 14:50:16 -07:00
vnode.h FreeBSD: remove support for FreeBSD < 13.0-RELEASE (#16372) 2024-08-05 16:56:45 -07:00
wmsum.h Introduce write-mostly sums 2021-05-27 14:27:29 -06:00
zmod.h Replace dead opensolaris.org license link 2022-07-11 14:16:13 -07:00
zone.h FreeBSD: Simplify INGLOBALZONE 2020-08-31 19:43:08 -07:00