aboutsummaryrefslogtreecommitdiffstats
path: root/cmd
diff options
context:
space:
mode:
authorBrian Atkinson <[email protected]>2024-09-14 16:47:59 -0400
committerGitHub <[email protected]>2024-09-14 13:47:59 -0700
commita10e552b9992673626f7a2ffcc234337f23410c9 (patch)
tree90825de54248238315a5478c7a824935af09bb3c /cmd
parent1713aa7b4d209616fab96a68e17a6fec6837247c (diff)
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 <[email protected]> Reviewed-by: Alexander Motin <[email protected]> Reviewed-by: Tony Hutter <[email protected]> Signed-off-by: Brian Atkinson <[email protected]> Co-authored-by: Mark Maybee <[email protected]> Co-authored-by: Matt Macy <[email protected]> Co-authored-by: Brian Behlendorf <[email protected]> Closes #10018
Diffstat (limited to 'cmd')
-rw-r--r--cmd/zpool/zpool_main.c30
-rw-r--r--cmd/ztest.c46
2 files changed, 62 insertions, 14 deletions
diff --git a/cmd/zpool/zpool_main.c b/cmd/zpool/zpool_main.c
index 349c208c5..aa7da68aa 100644
--- a/cmd/zpool/zpool_main.c
+++ b/cmd/zpool/zpool_main.c
@@ -522,7 +522,7 @@ get_usage(zpool_help_t idx)
return (gettext("\tstatus [--power] [-j [--json-int, "
"--json-flat-vdevs, ...\n"
"\t --json-pool-key-guid]] [-c [script1,script2,...]] "
- "[-DegiLpPstvx] ...\n"
+ "[-dDegiLpPstvx] ...\n"
"\t [-T d|u] [pool] [interval [count]]\n"));
case HELP_UPGRADE:
return (gettext("\tupgrade\n"
@@ -2602,6 +2602,7 @@ typedef struct status_cbdata {
boolean_t cb_print_unhealthy;
boolean_t cb_print_status;
boolean_t cb_print_slow_ios;
+ boolean_t cb_print_dio_verify;
boolean_t cb_print_vdev_init;
boolean_t cb_print_vdev_trim;
vdev_cmd_data_list_t *vcdl;
@@ -2879,7 +2880,7 @@ print_status_config(zpool_handle_t *zhp, status_cbdata_t *cb, const char *name,
uint_t c, i, vsc, children;
pool_scan_stat_t *ps = NULL;
vdev_stat_t *vs;
- char rbuf[6], wbuf[6], cbuf[6];
+ char rbuf[6], wbuf[6], cbuf[6], dbuf[6];
char *vname;
uint64_t notpresent;
spare_cbdata_t spare_cb;
@@ -2997,6 +2998,17 @@ print_status_config(zpool_handle_t *zhp, status_cbdata_t *cb, const char *name,
printf(" %5s", "-");
}
}
+ if (VDEV_STAT_VALID(vs_dio_verify_errors, vsc) &&
+ cb->cb_print_dio_verify) {
+ zfs_nicenum(vs->vs_dio_verify_errors, dbuf,
+ sizeof (dbuf));
+
+ if (cb->cb_literal)
+ printf(" %5llu",
+ (u_longlong_t)vs->vs_dio_verify_errors);
+ else
+ printf(" %5s", dbuf);
+ }
}
if (nvlist_lookup_uint64(nv, ZPOOL_CONFIG_NOT_PRESENT,
@@ -10873,6 +10885,10 @@ status_callback(zpool_handle_t *zhp, void *data)
printf_color(ANSI_BOLD, " %5s", gettext("POWER"));
}
+ if (cbp->cb_print_dio_verify) {
+ printf_color(ANSI_BOLD, " %5s", gettext("DIO"));
+ }
+
if (cbp->vcdl != NULL)
print_cmd_columns(cbp->vcdl, 0);
@@ -10921,10 +10937,11 @@ status_callback(zpool_handle_t *zhp, void *data)
}
/*
- * zpool status [-c [script1,script2,...]] [-DegiLpPstvx] [--power] [-T d|u] ...
- * [pool] [interval [count]]
+ * zpool status [-c [script1,script2,...]] [-dDegiLpPstvx] [--power] ...
+ * [-T d|u] [pool] [interval [count]]
*
* -c CMD For each vdev, run command CMD
+ * -d Display Direct I/O write verify errors
* -D Display dedup status (undocumented)
* -e Display only unhealthy vdevs
* -g Display guid for individual vdev name.
@@ -10967,7 +10984,7 @@ zpool_do_status(int argc, char **argv)
};
/* check options */
- while ((c = getopt_long(argc, argv, "c:jDegiLpPstT:vx", long_options,
+ while ((c = getopt_long(argc, argv, "c:jdDegiLpPstT:vx", long_options,
NULL)) != -1) {
switch (c) {
case 'c':
@@ -10994,6 +11011,9 @@ zpool_do_status(int argc, char **argv)
}
cmd = optarg;
break;
+ case 'd':
+ cb.cb_print_dio_verify = B_TRUE;
+ break;
case 'D':
if (++cb.cb_dedup_stats > 2)
cb.cb_dedup_stats = 2;
diff --git a/cmd/ztest.c b/cmd/ztest.c
index ce031632e..8ad576627 100644
--- a/cmd/ztest.c
+++ b/cmd/ztest.c
@@ -2262,6 +2262,13 @@ ztest_replay_write(void *arg1, void *arg2, boolean_t byteswap)
if (ztest_random(4) != 0) {
int prefetch = ztest_random(2) ?
DMU_READ_PREFETCH : DMU_READ_NO_PREFETCH;
+
+ /*
+ * We will randomly set when to do O_DIRECT on a read.
+ */
+ if (ztest_random(4) == 0)
+ prefetch |= DMU_DIRECTIO;
+
ztest_block_tag_t rbt;
VERIFY(dmu_read(os, lr->lr_foid, offset,
@@ -2813,6 +2820,13 @@ ztest_io(ztest_ds_t *zd, uint64_t object, uint64_t offset)
enum ztest_io_type io_type;
uint64_t blocksize;
void *data;
+ uint32_t dmu_read_flags = DMU_READ_NO_PREFETCH;
+
+ /*
+ * We will randomly set when to do O_DIRECT on a read.
+ */
+ if (ztest_random(4) == 0)
+ dmu_read_flags |= DMU_DIRECTIO;
VERIFY0(dmu_object_info(zd->zd_os, object, &doi));
blocksize = doi.doi_data_block_size;
@@ -2878,7 +2892,7 @@ ztest_io(ztest_ds_t *zd, uint64_t object, uint64_t offset)
(void) pthread_rwlock_unlock(&ztest_name_lock);
VERIFY0(dmu_read(zd->zd_os, object, offset, blocksize, data,
- DMU_READ_NO_PREFETCH));
+ dmu_read_flags));
(void) ztest_write(zd, object, offset, blocksize, data);
break;
@@ -5045,6 +5059,13 @@ ztest_dmu_read_write(ztest_ds_t *zd, uint64_t id)
uint64_t stride = 123456789ULL;
uint64_t width = 40;
int free_percent = 5;
+ uint32_t dmu_read_flags = DMU_READ_PREFETCH;
+
+ /*
+ * We will randomly set when to do O_DIRECT on a read.
+ */
+ if (ztest_random(4) == 0)
+ dmu_read_flags |= DMU_DIRECTIO;
/*
* This test uses two objects, packobj and bigobj, that are always
@@ -5123,10 +5144,10 @@ ztest_dmu_read_write(ztest_ds_t *zd, uint64_t id)
* Read the current contents of our objects.
*/
error = dmu_read(os, packobj, packoff, packsize, packbuf,
- DMU_READ_PREFETCH);
+ dmu_read_flags);
ASSERT0(error);
error = dmu_read(os, bigobj, bigoff, bigsize, bigbuf,
- DMU_READ_PREFETCH);
+ dmu_read_flags);
ASSERT0(error);
/*
@@ -5244,9 +5265,9 @@ ztest_dmu_read_write(ztest_ds_t *zd, uint64_t id)
void *bigcheck = umem_alloc(bigsize, UMEM_NOFAIL);
VERIFY0(dmu_read(os, packobj, packoff,
- packsize, packcheck, DMU_READ_PREFETCH));
+ packsize, packcheck, dmu_read_flags));
VERIFY0(dmu_read(os, bigobj, bigoff,
- bigsize, bigcheck, DMU_READ_PREFETCH));
+ bigsize, bigcheck, dmu_read_flags));
ASSERT0(memcmp(packbuf, packcheck, packsize));
ASSERT0(memcmp(bigbuf, bigcheck, bigsize));
@@ -5336,6 +5357,13 @@ ztest_dmu_read_write_zcopy(ztest_ds_t *zd, uint64_t id)
dmu_buf_t *bonus_db;
arc_buf_t **bigbuf_arcbufs;
dmu_object_info_t doi;
+ uint32_t dmu_read_flags = DMU_READ_PREFETCH;
+
+ /*
+ * We will randomly set when to do O_DIRECT on a read.
+ */
+ if (ztest_random(4) == 0)
+ dmu_read_flags |= DMU_DIRECTIO;
size = sizeof (ztest_od_t) * OD_ARRAY_SIZE;
od = umem_alloc(size, UMEM_NOFAIL);
@@ -5466,10 +5494,10 @@ ztest_dmu_read_write_zcopy(ztest_ds_t *zd, uint64_t id)
*/
if (i != 0 || ztest_random(2) != 0) {
error = dmu_read(os, packobj, packoff,
- packsize, packbuf, DMU_READ_PREFETCH);
+ packsize, packbuf, dmu_read_flags);
ASSERT0(error);
error = dmu_read(os, bigobj, bigoff, bigsize,
- bigbuf, DMU_READ_PREFETCH);
+ bigbuf, dmu_read_flags);
ASSERT0(error);
}
compare_and_update_pbbufs(s, packbuf, bigbuf, bigsize,
@@ -5529,9 +5557,9 @@ ztest_dmu_read_write_zcopy(ztest_ds_t *zd, uint64_t id)
void *bigcheck = umem_alloc(bigsize, UMEM_NOFAIL);
VERIFY0(dmu_read(os, packobj, packoff,
- packsize, packcheck, DMU_READ_PREFETCH));
+ packsize, packcheck, dmu_read_flags));
VERIFY0(dmu_read(os, bigobj, bigoff,
- bigsize, bigcheck, DMU_READ_PREFETCH));
+ bigsize, bigcheck, dmu_read_flags));
ASSERT0(memcmp(packbuf, packcheck, packsize));
ASSERT0(memcmp(bigbuf, bigcheck, bigsize));