2008-12-11 22:14:49 +03:00
|
|
|
/*
|
|
|
|
* CDDL HEADER START
|
|
|
|
*
|
|
|
|
* The contents of this file are subject to the terms of the
|
|
|
|
* Common Development and Distribution License (the "License").
|
|
|
|
* You may not use this file except in compliance with the License.
|
|
|
|
*
|
|
|
|
* You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
|
2022-07-12 00:16:13 +03:00
|
|
|
* or https://opensource.org/licenses/CDDL-1.0.
|
2008-12-11 22:14:49 +03:00
|
|
|
* See the License for the specific language governing permissions
|
|
|
|
* and limitations under the License.
|
|
|
|
*
|
|
|
|
* When distributing Covered Code, include this CDDL HEADER in each
|
|
|
|
* file and include the License file at usr/src/OPENSOLARIS.LICENSE.
|
|
|
|
* If applicable, add the following below this CDDL HEADER, with the
|
|
|
|
* fields enclosed by brackets "[]" replaced with your own identifying
|
|
|
|
* information: Portions Copyright [yyyy] [name of copyright owner]
|
|
|
|
*
|
|
|
|
* CDDL HEADER END
|
|
|
|
*/
|
|
|
|
/*
|
2017-01-31 21:13:10 +03:00
|
|
|
* Copyright (c) 2005, 2010, Oracle and/or its affiliates. All rights reserved.
|
|
|
|
* Copyright 2011 Nexenta Systems, Inc. All rights reserved.
|
Implement Redacted Send/Receive
Redacted send/receive allows users to send subsets of their data to
a target system. One possible use case for this feature is to not
transmit sensitive information to a data warehousing, test/dev, or
analytics environment. Another is to save space by not replicating
unimportant data within a given dataset, for example in backup tools
like zrepl.
Redacted send/receive is a three-stage process. First, a clone (or
clones) is made of the snapshot to be sent to the target. In this
clone (or clones), all unnecessary or unwanted data is removed or
modified. This clone is then snapshotted to create the "redaction
snapshot" (or snapshots). Second, the new zfs redact command is used
to create a redaction bookmark. The redaction bookmark stores the
list of blocks in a snapshot that were modified by the redaction
snapshot(s). Finally, the redaction bookmark is passed as a parameter
to zfs send. When sending to the snapshot that was redacted, the
redaction bookmark is used to filter out blocks that contain sensitive
or unwanted information, and those blocks are not included in the send
stream. When sending from the redaction bookmark, the blocks it
contains are considered as candidate blocks in addition to those
blocks in the destination snapshot that were modified since the
creation_txg of the redaction bookmark. This step is necessary to
allow the target to rehydrate data in the case where some blocks are
accidentally or unnecessarily modified in the redaction snapshot.
The changes to bookmarks to enable fast space estimation involve
adding deadlists to bookmarks. There is also logic to manage the
life cycles of these deadlists.
The new size estimation process operates in cases where previously
an accurate estimate could not be provided. In those cases, a send
is performed where no data blocks are read, reducing the runtime
significantly and providing a byte-accurate size estimate.
Reviewed-by: Dan Kimmel <dan.kimmel@delphix.com>
Reviewed-by: Matt Ahrens <mahrens@delphix.com>
Reviewed-by: Prashanth Sreenivasa <pks@delphix.com>
Reviewed-by: John Kennedy <john.kennedy@delphix.com>
Reviewed-by: George Wilson <george.wilson@delphix.com>
Reviewed-by: Chris Williamson <chris.williamson@delphix.com>
Reviewed-by: Pavel Zhakarov <pavel.zakharov@delphix.com>
Reviewed-by: Sebastien Roy <sebastien.roy@delphix.com>
Reviewed-by: Prakash Surya <prakash.surya@delphix.com>
Reviewed-by: Brian Behlendorf <behlendorf1@llnl.gov>
Signed-off-by: Paul Dagnelie <pcd@delphix.com>
Closes #7958
2019-06-19 19:48:13 +03:00
|
|
|
* Copyright (c) 2012, 2018 by Delphix. All rights reserved.
|
2012-05-10 02:05:14 +04:00
|
|
|
* Copyright (c) 2012, Joyent, Inc. All rights reserved.
|
2011-11-08 04:26:52 +04:00
|
|
|
*/
|
2008-12-11 22:14:49 +03:00
|
|
|
|
|
|
|
#ifndef _SYS_ZFS_CONTEXT_H
|
|
|
|
#define _SYS_ZFS_CONTEXT_H
|
|
|
|
|
2020-06-06 22:54:04 +03:00
|
|
|
#ifdef __cplusplus
|
|
|
|
extern "C" {
|
|
|
|
#endif
|
|
|
|
|
2020-10-14 07:05:49 +03:00
|
|
|
/*
|
|
|
|
* This code compiles in three different contexts. When __KERNEL__ is defined,
|
|
|
|
* the code uses "unix-like" kernel interfaces. When _STANDALONE is defined, the
|
|
|
|
* code is running in a reduced capacity environment of the boot loader which is
|
|
|
|
* generally a subset of both POSIX and kernel interfaces (with a few unique
|
|
|
|
* interfaces too). When neither are defined, it's in a userland POSIX or
|
|
|
|
* similar environment.
|
|
|
|
*/
|
|
|
|
#if defined(__KERNEL__) || defined(_STANDALONE)
|
2010-09-05 00:26:23 +04:00
|
|
|
#include <sys/types.h>
|
|
|
|
#include <sys/atomic.h>
|
|
|
|
#include <sys/sysmacros.h>
|
2018-02-16 04:53:18 +03:00
|
|
|
#include <sys/vmsystm.h>
|
|
|
|
#include <sys/condvar.h>
|
2010-09-05 00:26:23 +04:00
|
|
|
#include <sys/cmn_err.h>
|
|
|
|
#include <sys/kmem.h>
|
2014-12-09 03:03:50 +03:00
|
|
|
#include <sys/kmem_cache.h>
|
2014-12-03 22:56:32 +03:00
|
|
|
#include <sys/vmem.h>
|
2022-09-28 19:48:46 +03:00
|
|
|
#include <sys/misc.h>
|
2010-09-05 00:26:23 +04:00
|
|
|
#include <sys/taskq.h>
|
|
|
|
#include <sys/param.h>
|
|
|
|
#include <sys/disp.h>
|
|
|
|
#include <sys/debug.h>
|
|
|
|
#include <sys/random.h>
|
2022-01-22 03:56:46 +03:00
|
|
|
#include <sys/string.h>
|
2010-09-05 00:26:23 +04:00
|
|
|
#include <sys/byteorder.h>
|
|
|
|
#include <sys/list.h>
|
|
|
|
#include <sys/time.h>
|
|
|
|
#include <sys/zone.h>
|
2016-05-12 17:51:24 +03:00
|
|
|
#include <sys/kstat.h>
|
2010-09-05 00:26:23 +04:00
|
|
|
#include <sys/zfs_debug.h>
|
2016-07-28 01:29:15 +03:00
|
|
|
#include <sys/sysevent.h>
|
|
|
|
#include <sys/sysevent/eventdefs.h>
|
Illumos #4045 write throttle & i/o scheduler performance work
4045 zfs write throttle & i/o scheduler performance work
1. The ZFS i/o scheduler (vdev_queue.c) now divides i/os into 5 classes: sync
read, sync write, async read, async write, and scrub/resilver. The scheduler
issues a number of concurrent i/os from each class to the device. Once a class
has been selected, an i/o is selected from this class using either an elevator
algorithem (async, scrub classes) or FIFO (sync classes). The number of
concurrent async write i/os is tuned dynamically based on i/o load, to achieve
good sync i/o latency when there is not a high load of writes, and good write
throughput when there is. See the block comment in vdev_queue.c (reproduced
below) for more details.
2. The write throttle (dsl_pool_tempreserve_space() and
txg_constrain_throughput()) is rewritten to produce much more consistent delays
when under constant load. The new write throttle is based on the amount of
dirty data, rather than guesses about future performance of the system. When
there is a lot of dirty data, each transaction (e.g. write() syscall) will be
delayed by the same small amount. This eliminates the "brick wall of wait"
that the old write throttle could hit, causing all transactions to wait several
seconds until the next txg opens. One of the keys to the new write throttle is
decrementing the amount of dirty data as i/o completes, rather than at the end
of spa_sync(). Note that the write throttle is only applied once the i/o
scheduler is issuing the maximum number of outstanding async writes. See the
block comments in dsl_pool.c and above dmu_tx_delay() (reproduced below) for
more details.
This diff has several other effects, including:
* the commonly-tuned global variable zfs_vdev_max_pending has been removed;
use per-class zfs_vdev_*_max_active values or zfs_vdev_max_active instead.
* the size of each txg (meaning the amount of dirty data written, and thus the
time it takes to write out) is now controlled differently. There is no longer
an explicit time goal; the primary determinant is amount of dirty data.
Systems that are under light or medium load will now often see that a txg is
always syncing, but the impact to performance (e.g. read latency) is minimal.
Tune zfs_dirty_data_max and zfs_dirty_data_sync to control this.
* zio_taskq_batch_pct = 75 -- Only use 75% of all CPUs for compression,
checksum, etc. This improves latency by not allowing these CPU-intensive tasks
to consume all CPU (on machines with at least 4 CPU's; the percentage is
rounded up).
--matt
APPENDIX: problems with the current i/o scheduler
The current ZFS i/o scheduler (vdev_queue.c) is deadline based. The problem
with this is that if there are always i/os pending, then certain classes of
i/os can see very long delays.
For example, if there are always synchronous reads outstanding, then no async
writes will be serviced until they become "past due". One symptom of this
situation is that each pass of the txg sync takes at least several seconds
(typically 3 seconds).
If many i/os become "past due" (their deadline is in the past), then we must
service all of these overdue i/os before any new i/os. This happens when we
enqueue a batch of async writes for the txg sync, with deadlines 2.5 seconds in
the future. If we can't complete all the i/os in 2.5 seconds (e.g. because
there were always reads pending), then these i/os will become past due. Now we
must service all the "async" writes (which could be hundreds of megabytes)
before we service any reads, introducing considerable latency to synchronous
i/os (reads or ZIL writes).
Notes on porting to ZFS on Linux:
- zio_t gained new members io_physdone and io_phys_children. Because
object caches in the Linux port call the constructor only once at
allocation time, objects may contain residual data when retrieved
from the cache. Therefore zio_create() was updated to zero out the two
new fields.
- vdev_mirror_pending() relied on the depth of the per-vdev pending queue
(vq->vq_pending_tree) to select the least-busy leaf vdev to read from.
This tree has been replaced by vq->vq_active_tree which is now used
for the same purpose.
- vdev_queue_init() used the value of zfs_vdev_max_pending to determine
the number of vdev I/O buffers to pre-allocate. That global no longer
exists, so we instead use the sum of the *_max_active values for each of
the five I/O classes described above.
- The Illumos implementation of dmu_tx_delay() delays a transaction by
sleeping in condition variable embedded in the thread
(curthread->t_delay_cv). We do not have an equivalent CV to use in
Linux, so this change replaced the delay logic with a wrapper called
zfs_sleep_until(). This wrapper could be adopted upstream and in other
downstream ports to abstract away operating system-specific delay logic.
- These tunables are added as module parameters, and descriptions added
to the zfs-module-parameters.5 man page.
spa_asize_inflation
zfs_deadman_synctime_ms
zfs_vdev_max_active
zfs_vdev_async_write_active_min_dirty_percent
zfs_vdev_async_write_active_max_dirty_percent
zfs_vdev_async_read_max_active
zfs_vdev_async_read_min_active
zfs_vdev_async_write_max_active
zfs_vdev_async_write_min_active
zfs_vdev_scrub_max_active
zfs_vdev_scrub_min_active
zfs_vdev_sync_read_max_active
zfs_vdev_sync_read_min_active
zfs_vdev_sync_write_max_active
zfs_vdev_sync_write_min_active
zfs_dirty_data_max_percent
zfs_delay_min_dirty_percent
zfs_dirty_data_max_max_percent
zfs_dirty_data_max
zfs_dirty_data_max_max
zfs_dirty_data_sync
zfs_delay_scale
The latter four have type unsigned long, whereas they are uint64_t in
Illumos. This accommodates Linux's module_param() supported types, but
means they may overflow on 32-bit architectures.
The values zfs_dirty_data_max and zfs_dirty_data_max_max are the most
likely to overflow on 32-bit systems, since they express physical RAM
sizes in bytes. In fact, Illumos initializes zfs_dirty_data_max_max to
2^32 which does overflow. To resolve that, this port instead initializes
it in arc_init() to 25% of physical RAM, and adds the tunable
zfs_dirty_data_max_max_percent to override that percentage. While this
solution doesn't completely avoid the overflow issue, it should be a
reasonable default for most systems, and the minority of affected
systems can work around the issue by overriding the defaults.
- Fixed reversed logic in comment above zfs_delay_scale declaration.
- Clarified comments in vdev_queue.c regarding when per-queue minimums take
effect.
- Replaced dmu_tx_write_limit in the dmu_tx kstat file
with dmu_tx_dirty_delay and dmu_tx_dirty_over_max. The first counts
how many times a transaction has been delayed because the pool dirty
data has exceeded zfs_delay_min_dirty_percent. The latter counts how
many times the pool dirty data has exceeded zfs_dirty_data_max (which
we expect to never happen).
- The original patch would have regressed the bug fixed in
zfsonlinux/zfs@c418410, which prevented users from setting the
zfs_vdev_aggregation_limit tuning larger than SPA_MAXBLOCKSIZE.
A similar fix is added to vdev_queue_aggregate().
- In vdev_queue_io_to_issue(), dynamically allocate 'zio_t search' on the
heap instead of the stack. In Linux we can't afford such large
structures on the stack.
Reviewed by: George Wilson <george.wilson@delphix.com>
Reviewed by: Adam Leventhal <ahl@delphix.com>
Reviewed by: Christopher Siden <christopher.siden@delphix.com>
Reviewed by: Ned Bass <bass6@llnl.gov>
Reviewed by: Brendan Gregg <brendan.gregg@joyent.com>
Approved by: Robert Mustacchi <rm@joyent.com>
References:
http://www.illumos.org/issues/4045
illumos/illumos-gate@69962b5647e4a8b9b14998733b765925381b727e
Ported-by: Ned Bass <bass6@llnl.gov>
Signed-off-by: Brian Behlendorf <behlendorf1@llnl.gov>
Closes #1913
2013-08-29 07:01:20 +04:00
|
|
|
#include <sys/zfs_delay.h>
|
2010-09-05 00:26:23 +04:00
|
|
|
#include <sys/sunddi.h>
|
2011-11-15 23:01:27 +04:00
|
|
|
#include <sys/ctype.h>
|
2012-08-24 04:45:31 +04:00
|
|
|
#include <sys/disp.h>
|
Swap DTRACE_PROBE* with Linux tracepoints
This patch leverages Linux tracepoints from within the ZFS on Linux
code base. It also refactors the debug code to bring it back in sync
with Illumos.
The information exported via tracepoints can be used for a variety of
reasons (e.g. debugging, tuning, general exploration/understanding,
etc). It is advantageous to use Linux tracepoints as the mechanism to
export this kind of information (as opposed to something else) for a
number of reasons:
* A number of external tools can make use of our tracepoints
"automatically" (e.g. perf, systemtap)
* Tracepoints are designed to be extremely cheap when disabled
* It's one of the "accepted" ways to export this kind of
information; many other kernel subsystems use tracepoints too.
Unfortunately, though, there are a few caveats as well:
* Linux tracepoints appear to only be available to GPL licensed
modules due to the way certain kernel functions are exported.
Thus, to actually make use of the tracepoints introduced by this
patch, one might have to patch and re-compile the kernel;
exporting the necessary functions to non-GPL modules.
* Prior to upstream kernel version v3.14-rc6-30-g66cc69e, Linux
tracepoints are not available for unsigned kernel modules
(tracepoints will get disabled due to the module's 'F' taint).
Thus, one either has to sign the zfs kernel module prior to
loading it, or use a kernel versioned v3.14-rc6-30-g66cc69e or
newer.
Assuming the above two requirements are satisfied, lets look at an
example of how this patch can be used and what information it exposes
(all commands run as 'root'):
# list all zfs tracepoints available
$ ls /sys/kernel/debug/tracing/events/zfs
enable filter zfs_arc__delete
zfs_arc__evict zfs_arc__hit zfs_arc__miss
zfs_l2arc__evict zfs_l2arc__hit zfs_l2arc__iodone
zfs_l2arc__miss zfs_l2arc__read zfs_l2arc__write
zfs_new_state__mfu zfs_new_state__mru
# enable all zfs tracepoints, clear the tracepoint ring buffer
$ echo 1 > /sys/kernel/debug/tracing/events/zfs/enable
$ echo 0 > /sys/kernel/debug/tracing/trace
# import zpool called 'tank', inspect tracepoint data (each line was
# truncated, they're too long for a commit message otherwise)
$ zpool import tank
$ cat /sys/kernel/debug/tracing/trace | head -n35
# tracer: nop
#
# entries-in-buffer/entries-written: 1219/1219 #P:8
#
# _-----=> irqs-off
# / _----=> need-resched
# | / _---=> hardirq/softirq
# || / _--=> preempt-depth
# ||| / delay
# TASK-PID CPU# |||| TIMESTAMP FUNCTION
# | | | |||| | |
lt-zpool-30132 [003] .... 91344.200050: zfs_arc__miss: hdr...
z_rd_int/0-30156 [003] .... 91344.200611: zfs_new_state__mru...
lt-zpool-30132 [003] .... 91344.201173: zfs_arc__miss: hdr...
z_rd_int/1-30157 [003] .... 91344.201756: zfs_new_state__mru...
lt-zpool-30132 [003] .... 91344.201795: zfs_arc__miss: hdr...
z_rd_int/2-30158 [003] .... 91344.202099: zfs_new_state__mru...
lt-zpool-30132 [003] .... 91344.202126: zfs_arc__hit: hdr ...
lt-zpool-30132 [003] .... 91344.202130: zfs_arc__hit: hdr ...
lt-zpool-30132 [003] .... 91344.202134: zfs_arc__hit: hdr ...
lt-zpool-30132 [003] .... 91344.202146: zfs_arc__miss: hdr...
z_rd_int/3-30159 [003] .... 91344.202457: zfs_new_state__mru...
lt-zpool-30132 [003] .... 91344.202484: zfs_arc__miss: hdr...
z_rd_int/4-30160 [003] .... 91344.202866: zfs_new_state__mru...
lt-zpool-30132 [003] .... 91344.202891: zfs_arc__hit: hdr ...
lt-zpool-30132 [001] .... 91344.203034: zfs_arc__miss: hdr...
z_rd_iss/1-30149 [001] .... 91344.203749: zfs_new_state__mru...
lt-zpool-30132 [001] .... 91344.203789: zfs_arc__hit: hdr ...
lt-zpool-30132 [001] .... 91344.203878: zfs_arc__miss: hdr...
z_rd_iss/3-30151 [001] .... 91344.204315: zfs_new_state__mru...
lt-zpool-30132 [001] .... 91344.204332: zfs_arc__hit: hdr ...
lt-zpool-30132 [001] .... 91344.204337: zfs_arc__hit: hdr ...
lt-zpool-30132 [001] .... 91344.204352: zfs_arc__hit: hdr ...
lt-zpool-30132 [001] .... 91344.204356: zfs_arc__hit: hdr ...
lt-zpool-30132 [001] .... 91344.204360: zfs_arc__hit: hdr ...
To highlight the kind of detailed information that is being exported
using this infrastructure, I've taken the first tracepoint line from the
output above and reformatted it such that it fits in 80 columns:
lt-zpool-30132 [003] .... 91344.200050: zfs_arc__miss:
hdr {
dva 0x1:0x40082
birth 15491
cksum0 0x163edbff3a
flags 0x640
datacnt 1
type 1
size 2048
spa 3133524293419867460
state_type 0
access 0
mru_hits 0
mru_ghost_hits 0
mfu_hits 0
mfu_ghost_hits 0
l2_hits 0
refcount 1
} bp {
dva0 0x1:0x40082
dva1 0x1:0x3000e5
dva2 0x1:0x5a006e
cksum 0x163edbff3a:0x75af30b3dd6:0x1499263ff5f2b:0x288bd118815e00
lsize 2048
} zb {
objset 0
object 0
level -1
blkid 0
}
For the specific tracepoint shown here, 'zfs_arc__miss', data is
exported detailing the arc_buf_hdr_t (hdr), blkptr_t (bp), and
zbookmark_t (zb) that caused the ARC miss (down to the exact DVA!).
This kind of precise and detailed information can be extremely valuable
when trying to answer certain kinds of questions.
For anybody unfamiliar but looking to build on this, I found the XFS
source code along with the following three web links to be extremely
helpful:
* http://lwn.net/Articles/379903/
* http://lwn.net/Articles/381064/
* http://lwn.net/Articles/383362/
I should also node the more "boring" aspects of this patch:
* The ZFS_LINUX_COMPILE_IFELSE autoconf macro was modified to
support a sixth paramter. This parameter is used to populate the
contents of the new conftest.h file. If no sixth parameter is
provided, conftest.h will be empty.
* The ZFS_LINUX_TRY_COMPILE_HEADER autoconf macro was introduced.
This macro is nearly identical to the ZFS_LINUX_TRY_COMPILE macro,
except it has support for a fifth option that is then passed as
the sixth parameter to ZFS_LINUX_COMPILE_IFELSE.
These autoconf changes were needed to test the availability of the Linux
tracepoint macros. Due to the odd nature of the Linux tracepoint macro
API, a separate ".h" must be created (the path and filename is used
internally by the kernel's define_trace.h file).
* The HAVE_DECLARE_EVENT_CLASS autoconf macro was introduced. This
is to determine if we can safely enable the Linux tracepoint
functionality. We need to selectively disable the tracepoint code
due to the kernel exporting certain functions as GPL only. Without
this check, the build process will fail at link time.
In addition, the SET_ERROR macro was modified into a tracepoint as well.
To do this, the 'sdt.h' file was moved into the 'include/sys' directory
and now contains a userspace portion and a kernel space portion. The
dprintf and zfs_dbgmsg* interfaces are now implemented as tracepoint as
well.
Signed-off-by: Prakash Surya <surya1@llnl.gov>
Signed-off-by: Ned Bass <bass6@llnl.gov>
Signed-off-by: Brian Behlendorf <behlendorf1@llnl.gov>
2014-06-13 21:54:48 +04:00
|
|
|
#include <sys/trace.h>
|
2018-09-26 21:08:12 +03:00
|
|
|
#include <sys/procfs_list.h>
|
2019-11-01 20:41:03 +03:00
|
|
|
#include <sys/mod.h>
|
2021-02-21 07:16:50 +03:00
|
|
|
#include <sys/uio_impl.h>
|
2019-12-05 00:12:57 +03:00
|
|
|
#include <sys/zfs_context_os.h>
|
2020-10-14 07:05:49 +03:00
|
|
|
#else /* _KERNEL || _STANDALONE */
|
2008-12-11 22:14:49 +03:00
|
|
|
|
|
|
|
#define _SYS_MUTEX_H
|
|
|
|
#define _SYS_RWLOCK_H
|
|
|
|
#define _SYS_CONDVAR_H
|
|
|
|
#define _SYS_VNODE_H
|
|
|
|
#define _SYS_VFS_H
|
|
|
|
#define _SYS_SUNDDI_H
|
|
|
|
#define _SYS_CALLB_H
|
|
|
|
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <stddef.h>
|
|
|
|
#include <stdarg.h>
|
|
|
|
#include <fcntl.h>
|
|
|
|
#include <unistd.h>
|
|
|
|
#include <errno.h>
|
|
|
|
#include <string.h>
|
2010-08-26 21:43:27 +04:00
|
|
|
#include <pthread.h>
|
2018-02-08 19:16:23 +03:00
|
|
|
#include <setjmp.h>
|
2008-12-11 22:14:49 +03:00
|
|
|
#include <assert.h>
|
|
|
|
#include <umem.h>
|
|
|
|
#include <limits.h>
|
|
|
|
#include <atomic.h>
|
|
|
|
#include <dirent.h>
|
|
|
|
#include <time.h>
|
2011-11-15 23:01:27 +04:00
|
|
|
#include <ctype.h>
|
2013-05-17 01:18:06 +04:00
|
|
|
#include <signal.h>
|
|
|
|
#include <sys/mman.h>
|
2008-12-11 22:14:49 +03:00
|
|
|
#include <sys/types.h>
|
|
|
|
#include <sys/cred.h>
|
|
|
|
#include <sys/sysmacros.h>
|
|
|
|
#include <sys/resource.h>
|
|
|
|
#include <sys/byteorder.h>
|
|
|
|
#include <sys/list.h>
|
2019-11-01 20:41:03 +03:00
|
|
|
#include <sys/mod.h>
|
2008-12-11 22:14:49 +03:00
|
|
|
#include <sys/uio.h>
|
|
|
|
#include <sys/zfs_debug.h>
|
|
|
|
#include <sys/kstat.h>
|
|
|
|
#include <sys/u8_textprep.h>
|
2016-07-28 01:29:15 +03:00
|
|
|
#include <sys/sysevent.h>
|
|
|
|
#include <sys/sysevent/eventdefs.h>
|
2010-05-29 00:45:14 +04:00
|
|
|
#include <sys/sunddi.h>
|
2013-05-11 01:17:03 +04:00
|
|
|
#include <sys/debug.h>
|
2014-10-01 23:02:12 +04:00
|
|
|
#include <sys/utsname.h>
|
Enable use of DTRACE_PROBE* macros in "spl" module
This change modifies some of the infrastructure for enabling the use of
the DTRACE_PROBE* macros, such that we can use tehm in the "spl" module.
Currently, when the DTRACE_PROBE* macros are used, they get expanded to
create new functions, and these dynamically generated functions become
part of the "zfs" module.
Since the "spl" module does not depend on the "zfs" module, the use of
DTRACE_PROBE* in the "spl" module would result in undefined symbols
being used in the "spl" module. Specifically, DTRACE_PROBE* would turn
into a function call, and the function being called would be a symbol
only contained in the "zfs" module; which results in a linker and/or
runtime error.
Thus, this change adds the necessary logic to the "spl" module, to
mirror the tracing functionality available to the "zfs" module. After
this change, we'll have a "trace_zfs.h" header file which defines the
probes available only to the "zfs" module, and a "trace_spl.h" header
file which defines the probes available only to the "spl" module.
Reviewed by: Brad Lewis <brad.lewis@delphix.com>
Reviewed-by: Brian Behlendorf <behlendorf1@llnl.gov>
Signed-off-by: Prakash Surya <prakash.surya@delphix.com>
Closes #9525
2019-10-30 21:02:41 +03:00
|
|
|
#include <sys/trace_zfs.h>
|
2008-12-11 22:14:49 +03:00
|
|
|
|
2019-12-05 00:12:57 +03:00
|
|
|
#include <sys/zfs_context_os.h>
|
|
|
|
|
2010-08-26 21:58:36 +04:00
|
|
|
/*
|
|
|
|
* Stack
|
|
|
|
*/
|
|
|
|
|
2013-03-08 22:41:28 +04:00
|
|
|
#define noinline __attribute__((noinline))
|
2016-08-27 21:12:53 +03:00
|
|
|
#define likely(x) __builtin_expect((x), 1)
|
Implement Redacted Send/Receive
Redacted send/receive allows users to send subsets of their data to
a target system. One possible use case for this feature is to not
transmit sensitive information to a data warehousing, test/dev, or
analytics environment. Another is to save space by not replicating
unimportant data within a given dataset, for example in backup tools
like zrepl.
Redacted send/receive is a three-stage process. First, a clone (or
clones) is made of the snapshot to be sent to the target. In this
clone (or clones), all unnecessary or unwanted data is removed or
modified. This clone is then snapshotted to create the "redaction
snapshot" (or snapshots). Second, the new zfs redact command is used
to create a redaction bookmark. The redaction bookmark stores the
list of blocks in a snapshot that were modified by the redaction
snapshot(s). Finally, the redaction bookmark is passed as a parameter
to zfs send. When sending to the snapshot that was redacted, the
redaction bookmark is used to filter out blocks that contain sensitive
or unwanted information, and those blocks are not included in the send
stream. When sending from the redaction bookmark, the blocks it
contains are considered as candidate blocks in addition to those
blocks in the destination snapshot that were modified since the
creation_txg of the redaction bookmark. This step is necessary to
allow the target to rehydrate data in the case where some blocks are
accidentally or unnecessarily modified in the redaction snapshot.
The changes to bookmarks to enable fast space estimation involve
adding deadlists to bookmarks. There is also logic to manage the
life cycles of these deadlists.
The new size estimation process operates in cases where previously
an accurate estimate could not be provided. In those cases, a send
is performed where no data blocks are read, reducing the runtime
significantly and providing a byte-accurate size estimate.
Reviewed-by: Dan Kimmel <dan.kimmel@delphix.com>
Reviewed-by: Matt Ahrens <mahrens@delphix.com>
Reviewed-by: Prashanth Sreenivasa <pks@delphix.com>
Reviewed-by: John Kennedy <john.kennedy@delphix.com>
Reviewed-by: George Wilson <george.wilson@delphix.com>
Reviewed-by: Chris Williamson <chris.williamson@delphix.com>
Reviewed-by: Pavel Zhakarov <pavel.zakharov@delphix.com>
Reviewed-by: Sebastien Roy <sebastien.roy@delphix.com>
Reviewed-by: Prakash Surya <prakash.surya@delphix.com>
Reviewed-by: Brian Behlendorf <behlendorf1@llnl.gov>
Signed-off-by: Paul Dagnelie <pcd@delphix.com>
Closes #7958
2019-06-19 19:48:13 +03:00
|
|
|
#define unlikely(x) __builtin_expect((x), 0)
|
2010-08-26 21:58:36 +04:00
|
|
|
|
2008-12-11 22:14:49 +03:00
|
|
|
/*
|
|
|
|
* Debugging
|
|
|
|
*/
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Note that we are not using the debugging levels.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#define CE_CONT 0 /* continuation */
|
|
|
|
#define CE_NOTE 1 /* notice */
|
|
|
|
#define CE_WARN 2 /* warning */
|
|
|
|
#define CE_PANIC 3 /* panic */
|
|
|
|
#define CE_IGNORE 4 /* print nothing */
|
|
|
|
|
|
|
|
/*
|
|
|
|
* ZFS debugging
|
|
|
|
*/
|
|
|
|
|
|
|
|
extern void dprintf_setup(int *argc, char **argv);
|
Swap DTRACE_PROBE* with Linux tracepoints
This patch leverages Linux tracepoints from within the ZFS on Linux
code base. It also refactors the debug code to bring it back in sync
with Illumos.
The information exported via tracepoints can be used for a variety of
reasons (e.g. debugging, tuning, general exploration/understanding,
etc). It is advantageous to use Linux tracepoints as the mechanism to
export this kind of information (as opposed to something else) for a
number of reasons:
* A number of external tools can make use of our tracepoints
"automatically" (e.g. perf, systemtap)
* Tracepoints are designed to be extremely cheap when disabled
* It's one of the "accepted" ways to export this kind of
information; many other kernel subsystems use tracepoints too.
Unfortunately, though, there are a few caveats as well:
* Linux tracepoints appear to only be available to GPL licensed
modules due to the way certain kernel functions are exported.
Thus, to actually make use of the tracepoints introduced by this
patch, one might have to patch and re-compile the kernel;
exporting the necessary functions to non-GPL modules.
* Prior to upstream kernel version v3.14-rc6-30-g66cc69e, Linux
tracepoints are not available for unsigned kernel modules
(tracepoints will get disabled due to the module's 'F' taint).
Thus, one either has to sign the zfs kernel module prior to
loading it, or use a kernel versioned v3.14-rc6-30-g66cc69e or
newer.
Assuming the above two requirements are satisfied, lets look at an
example of how this patch can be used and what information it exposes
(all commands run as 'root'):
# list all zfs tracepoints available
$ ls /sys/kernel/debug/tracing/events/zfs
enable filter zfs_arc__delete
zfs_arc__evict zfs_arc__hit zfs_arc__miss
zfs_l2arc__evict zfs_l2arc__hit zfs_l2arc__iodone
zfs_l2arc__miss zfs_l2arc__read zfs_l2arc__write
zfs_new_state__mfu zfs_new_state__mru
# enable all zfs tracepoints, clear the tracepoint ring buffer
$ echo 1 > /sys/kernel/debug/tracing/events/zfs/enable
$ echo 0 > /sys/kernel/debug/tracing/trace
# import zpool called 'tank', inspect tracepoint data (each line was
# truncated, they're too long for a commit message otherwise)
$ zpool import tank
$ cat /sys/kernel/debug/tracing/trace | head -n35
# tracer: nop
#
# entries-in-buffer/entries-written: 1219/1219 #P:8
#
# _-----=> irqs-off
# / _----=> need-resched
# | / _---=> hardirq/softirq
# || / _--=> preempt-depth
# ||| / delay
# TASK-PID CPU# |||| TIMESTAMP FUNCTION
# | | | |||| | |
lt-zpool-30132 [003] .... 91344.200050: zfs_arc__miss: hdr...
z_rd_int/0-30156 [003] .... 91344.200611: zfs_new_state__mru...
lt-zpool-30132 [003] .... 91344.201173: zfs_arc__miss: hdr...
z_rd_int/1-30157 [003] .... 91344.201756: zfs_new_state__mru...
lt-zpool-30132 [003] .... 91344.201795: zfs_arc__miss: hdr...
z_rd_int/2-30158 [003] .... 91344.202099: zfs_new_state__mru...
lt-zpool-30132 [003] .... 91344.202126: zfs_arc__hit: hdr ...
lt-zpool-30132 [003] .... 91344.202130: zfs_arc__hit: hdr ...
lt-zpool-30132 [003] .... 91344.202134: zfs_arc__hit: hdr ...
lt-zpool-30132 [003] .... 91344.202146: zfs_arc__miss: hdr...
z_rd_int/3-30159 [003] .... 91344.202457: zfs_new_state__mru...
lt-zpool-30132 [003] .... 91344.202484: zfs_arc__miss: hdr...
z_rd_int/4-30160 [003] .... 91344.202866: zfs_new_state__mru...
lt-zpool-30132 [003] .... 91344.202891: zfs_arc__hit: hdr ...
lt-zpool-30132 [001] .... 91344.203034: zfs_arc__miss: hdr...
z_rd_iss/1-30149 [001] .... 91344.203749: zfs_new_state__mru...
lt-zpool-30132 [001] .... 91344.203789: zfs_arc__hit: hdr ...
lt-zpool-30132 [001] .... 91344.203878: zfs_arc__miss: hdr...
z_rd_iss/3-30151 [001] .... 91344.204315: zfs_new_state__mru...
lt-zpool-30132 [001] .... 91344.204332: zfs_arc__hit: hdr ...
lt-zpool-30132 [001] .... 91344.204337: zfs_arc__hit: hdr ...
lt-zpool-30132 [001] .... 91344.204352: zfs_arc__hit: hdr ...
lt-zpool-30132 [001] .... 91344.204356: zfs_arc__hit: hdr ...
lt-zpool-30132 [001] .... 91344.204360: zfs_arc__hit: hdr ...
To highlight the kind of detailed information that is being exported
using this infrastructure, I've taken the first tracepoint line from the
output above and reformatted it such that it fits in 80 columns:
lt-zpool-30132 [003] .... 91344.200050: zfs_arc__miss:
hdr {
dva 0x1:0x40082
birth 15491
cksum0 0x163edbff3a
flags 0x640
datacnt 1
type 1
size 2048
spa 3133524293419867460
state_type 0
access 0
mru_hits 0
mru_ghost_hits 0
mfu_hits 0
mfu_ghost_hits 0
l2_hits 0
refcount 1
} bp {
dva0 0x1:0x40082
dva1 0x1:0x3000e5
dva2 0x1:0x5a006e
cksum 0x163edbff3a:0x75af30b3dd6:0x1499263ff5f2b:0x288bd118815e00
lsize 2048
} zb {
objset 0
object 0
level -1
blkid 0
}
For the specific tracepoint shown here, 'zfs_arc__miss', data is
exported detailing the arc_buf_hdr_t (hdr), blkptr_t (bp), and
zbookmark_t (zb) that caused the ARC miss (down to the exact DVA!).
This kind of precise and detailed information can be extremely valuable
when trying to answer certain kinds of questions.
For anybody unfamiliar but looking to build on this, I found the XFS
source code along with the following three web links to be extremely
helpful:
* http://lwn.net/Articles/379903/
* http://lwn.net/Articles/381064/
* http://lwn.net/Articles/383362/
I should also node the more "boring" aspects of this patch:
* The ZFS_LINUX_COMPILE_IFELSE autoconf macro was modified to
support a sixth paramter. This parameter is used to populate the
contents of the new conftest.h file. If no sixth parameter is
provided, conftest.h will be empty.
* The ZFS_LINUX_TRY_COMPILE_HEADER autoconf macro was introduced.
This macro is nearly identical to the ZFS_LINUX_TRY_COMPILE macro,
except it has support for a fifth option that is then passed as
the sixth parameter to ZFS_LINUX_COMPILE_IFELSE.
These autoconf changes were needed to test the availability of the Linux
tracepoint macros. Due to the odd nature of the Linux tracepoint macro
API, a separate ".h" must be created (the path and filename is used
internally by the kernel's define_trace.h file).
* The HAVE_DECLARE_EVENT_CLASS autoconf macro was introduced. This
is to determine if we can safely enable the Linux tracepoint
functionality. We need to selectively disable the tracepoint code
due to the kernel exporting certain functions as GPL only. Without
this check, the build process will fail at link time.
In addition, the SET_ERROR macro was modified into a tracepoint as well.
To do this, the 'sdt.h' file was moved into the 'include/sys' directory
and now contains a userspace portion and a kernel space portion. The
dprintf and zfs_dbgmsg* interfaces are now implemented as tracepoint as
well.
Signed-off-by: Prakash Surya <surya1@llnl.gov>
Signed-off-by: Ned Bass <bass6@llnl.gov>
Signed-off-by: Brian Behlendorf <behlendorf1@llnl.gov>
2014-06-13 21:54:48 +04:00
|
|
|
|
Reduce false positives from Static Analyzers
Both Clang's Static Analyzer and Synopsys' Coverity would ignore
assertions. Following Clang's advice, we annotate our assertions:
https://clang-analyzer.llvm.org/annotations.html#custom_assertions
This makes both Clang's Static Analyzer and Coverity properly identify
assertions. This change reduced Clang's reported defects from 246 to
180. It also reduced the false positives reported by Coverityi by 10,
while enabling Coverity to find 9 more defects that previously were
false negatives.
A couple examples of this would be CID-1524417 and CID-1524423. After
submitting a build to coverity with the modified assertions, CID-1524417
disappeared while the report for CID-1524423 no longer claimed that the
assertion tripped.
Coincidentally, it turns out that it is possible to more accurately
annotate our headers than the Coverity modelling file permits in the
case of format strings. Since we can do that and this patch annotates
headers whenever `__coverity_panic__()` would have been used in the
model file, we drop all models that use `__coverity_panic__()` from the
model file.
Upon seeing the success in eliminating false positives involving
assertions, it occurred to me that we could also modify our headers to
eliminate coverity's false positives involving byte swaps. We now have
coverity specific byteswap macros, that do nothing, to disable
Coverity's false positives when we do byte swaps. This allowed us to
also drop the byteswap definitions from the model file.
Lastly, a model file update has been done beyond the mentioned
deletions:
* The definitions of `umem_alloc_aligned()`, `umem_alloc()` andi
`umem_zalloc()` were originally implemented in a way that was
intended to inform coverity that when KM_SLEEP has been passed these
functions, they do not return NULL. A small error in how this was
done was found, so we correct it.
* Definitions for umem_cache_alloc() and umem_cache_free() have been
added.
In practice, no false positives were avoided by making these changes,
but in the interest of correctness from future coverity builds, we make
them anyway.
Reviewed-by: Brian Behlendorf <behlendorf1@llnl.gov>
Reviewed-by: Ryan Moeller <ryan@iXsystems.com>
Signed-off-by: Richard Yao <richard.yao@alumni.stonybrook.edu>
Closes #13902
2022-10-01 01:30:12 +03:00
|
|
|
extern void cmn_err(int, const char *, ...)
|
|
|
|
__attribute__((format(printf, 2, 3)));
|
|
|
|
extern void vcmn_err(int, const char *, va_list)
|
|
|
|
__attribute__((format(printf, 2, 0)));
|
|
|
|
extern void panic(const char *, ...)
|
|
|
|
__attribute__((format(printf, 1, 2), noreturn));
|
|
|
|
extern void vpanic(const char *, va_list)
|
|
|
|
__attribute__((format(printf, 1, 0), noreturn));
|
2008-12-11 22:14:49 +03:00
|
|
|
|
|
|
|
#define fm_panic panic
|
|
|
|
|
|
|
|
/*
|
|
|
|
* DTrace SDT probes have different signatures in userland than they do in
|
2015-12-22 04:31:57 +03:00
|
|
|
* the kernel. If they're being used in kernel code, re-define them out of
|
2008-12-11 22:14:49 +03:00
|
|
|
* existence for their counterparts in libzpool.
|
2015-12-22 04:31:57 +03:00
|
|
|
*
|
|
|
|
* Here's an example of how to use the set-error probes in userland:
|
|
|
|
* zfs$target:::set-error /arg0 == EBUSY/ {stack();}
|
|
|
|
*
|
|
|
|
* Here's an example of how to use DTRACE_PROBE probes in userland:
|
|
|
|
* If there is a probe declared as follows:
|
|
|
|
* DTRACE_PROBE2(zfs__probe_name, uint64_t, blkid, dnode_t *, dn);
|
|
|
|
* Then you can use it as follows:
|
|
|
|
* zfs$target:::probe2 /copyinstr(arg0) == "zfs__probe_name"/
|
|
|
|
* {printf("%u %p\n", arg1, arg2);}
|
2008-12-11 22:14:49 +03:00
|
|
|
*/
|
|
|
|
|
|
|
|
#ifdef DTRACE_PROBE
|
|
|
|
#undef DTRACE_PROBE
|
|
|
|
#endif /* DTRACE_PROBE */
|
2019-10-25 23:38:37 +03:00
|
|
|
#define DTRACE_PROBE(a)
|
2008-12-11 22:14:49 +03:00
|
|
|
|
|
|
|
#ifdef DTRACE_PROBE1
|
|
|
|
#undef DTRACE_PROBE1
|
|
|
|
#endif /* DTRACE_PROBE1 */
|
2019-10-25 23:38:37 +03:00
|
|
|
#define DTRACE_PROBE1(a, b, c)
|
2008-12-11 22:14:49 +03:00
|
|
|
|
|
|
|
#ifdef DTRACE_PROBE2
|
|
|
|
#undef DTRACE_PROBE2
|
|
|
|
#endif /* DTRACE_PROBE2 */
|
2019-10-25 23:38:37 +03:00
|
|
|
#define DTRACE_PROBE2(a, b, c, d, e)
|
2008-12-11 22:14:49 +03:00
|
|
|
|
|
|
|
#ifdef DTRACE_PROBE3
|
|
|
|
#undef DTRACE_PROBE3
|
|
|
|
#endif /* DTRACE_PROBE3 */
|
2019-10-25 23:38:37 +03:00
|
|
|
#define DTRACE_PROBE3(a, b, c, d, e, f, g)
|
2008-12-11 22:14:49 +03:00
|
|
|
|
|
|
|
#ifdef DTRACE_PROBE4
|
|
|
|
#undef DTRACE_PROBE4
|
|
|
|
#endif /* DTRACE_PROBE4 */
|
2019-10-25 23:38:37 +03:00
|
|
|
#define DTRACE_PROBE4(a, b, c, d, e, f, g, h, i)
|
2008-12-11 22:14:49 +03:00
|
|
|
|
2019-09-06 00:49:49 +03:00
|
|
|
/*
|
|
|
|
* Tunables.
|
|
|
|
*/
|
2019-10-27 01:22:19 +03:00
|
|
|
typedef struct zfs_kernel_param {
|
|
|
|
const char *name; /* unused stub */
|
|
|
|
} zfs_kernel_param_t;
|
|
|
|
|
2019-09-06 00:49:49 +03:00
|
|
|
#define ZFS_MODULE_PARAM(scope_prefix, name_prefix, name, type, perm, desc)
|
2020-04-07 20:06:22 +03:00
|
|
|
#define ZFS_MODULE_PARAM_ARGS void
|
2019-10-27 01:22:19 +03:00
|
|
|
#define ZFS_MODULE_PARAM_CALL(scope_prefix, name_prefix, name, setfunc, \
|
|
|
|
getfunc, perm, desc)
|
2019-09-06 00:49:49 +03:00
|
|
|
|
2008-12-11 22:14:49 +03:00
|
|
|
/*
|
Simplify threads, mutexs, cvs and rwlocks
* Simplify threads, mutexs, cvs and rwlocks
* Update the zk_thread_create() function to use the same trick
as Illumos. Specifically, cast the new pthread_t to a void
pointer and return that as the kthread_t *. This avoids the
issues associated with managing a wrapper structure and is
safe as long as the callers never attempt to dereference it.
* Update all function prototypes passed to pthread_create() to
match the expected prototype. We were getting away this with
before since the function were explicitly cast.
* Replaced direct zk_thread_create() calls with thread_create()
for code consistency. All consumers of libzpool now use the
proper wrappers.
* The mutex_held() calls were converted to MUTEX_HELD().
* Removed all mutex_owner() calls and retired the interface.
Instead use MUTEX_HELD() which provides the same information
and allows the implementation details to be hidden. In this
case the use of the pthread_equals() function.
* The kthread_t, kmutex_t, krwlock_t, and krwlock_t types had
any non essential fields removed. In the case of kthread_t
and kcondvar_t they could be directly typedef'd to pthread_t
and pthread_cond_t respectively.
* Removed all extra ASSERTS from the thread, mutex, rwlock, and
cv wrapper functions. In practice, pthreads already provides
the vast majority of checks as long as we check the return
code. Removing this code from our wrappers help readability.
* Added TS_JOINABLE state flag to pass to request a joinable rather
than detached thread. This isn't a standard thread_create() state
but it's the least invasive way to pass this information and is
only used by ztest.
TEST_ZTEST_TIMEOUT=3600
Chunwei Chen <tuxoko@gmail.com>
Reviewed-by: Tom Caputi <tcaputi@datto.com>
Signed-off-by: Brian Behlendorf <behlendorf1@llnl.gov>
Closes #4547
Closes #5503
Closes #5523
Closes #6377
Closes #6495
2017-08-11 18:51:44 +03:00
|
|
|
* Threads.
|
2008-12-11 22:14:49 +03:00
|
|
|
*/
|
Simplify threads, mutexs, cvs and rwlocks
* Simplify threads, mutexs, cvs and rwlocks
* Update the zk_thread_create() function to use the same trick
as Illumos. Specifically, cast the new pthread_t to a void
pointer and return that as the kthread_t *. This avoids the
issues associated with managing a wrapper structure and is
safe as long as the callers never attempt to dereference it.
* Update all function prototypes passed to pthread_create() to
match the expected prototype. We were getting away this with
before since the function were explicitly cast.
* Replaced direct zk_thread_create() calls with thread_create()
for code consistency. All consumers of libzpool now use the
proper wrappers.
* The mutex_held() calls were converted to MUTEX_HELD().
* Removed all mutex_owner() calls and retired the interface.
Instead use MUTEX_HELD() which provides the same information
and allows the implementation details to be hidden. In this
case the use of the pthread_equals() function.
* The kthread_t, kmutex_t, krwlock_t, and krwlock_t types had
any non essential fields removed. In the case of kthread_t
and kcondvar_t they could be directly typedef'd to pthread_t
and pthread_cond_t respectively.
* Removed all extra ASSERTS from the thread, mutex, rwlock, and
cv wrapper functions. In practice, pthreads already provides
the vast majority of checks as long as we check the return
code. Removing this code from our wrappers help readability.
* Added TS_JOINABLE state flag to pass to request a joinable rather
than detached thread. This isn't a standard thread_create() state
but it's the least invasive way to pass this information and is
only used by ztest.
TEST_ZTEST_TIMEOUT=3600
Chunwei Chen <tuxoko@gmail.com>
Reviewed-by: Tom Caputi <tcaputi@datto.com>
Signed-off-by: Brian Behlendorf <behlendorf1@llnl.gov>
Closes #4547
Closes #5503
Closes #5523
Closes #6377
Closes #6495
2017-08-11 18:51:44 +03:00
|
|
|
typedef pthread_t kthread_t;
|
|
|
|
|
|
|
|
#define TS_RUN 0x00000002
|
|
|
|
#define TS_JOINABLE 0x00000004
|
|
|
|
|
|
|
|
#define curthread ((void *)(uintptr_t)pthread_self())
|
|
|
|
#define getcomm() "unknown"
|
|
|
|
|
2020-07-29 19:43:33 +03:00
|
|
|
#define thread_create_named(name, stk, stksize, func, arg, len, \
|
|
|
|
pp, state, pri) \
|
|
|
|
zk_thread_create(func, arg, stksize, state)
|
Simplify threads, mutexs, cvs and rwlocks
* Simplify threads, mutexs, cvs and rwlocks
* Update the zk_thread_create() function to use the same trick
as Illumos. Specifically, cast the new pthread_t to a void
pointer and return that as the kthread_t *. This avoids the
issues associated with managing a wrapper structure and is
safe as long as the callers never attempt to dereference it.
* Update all function prototypes passed to pthread_create() to
match the expected prototype. We were getting away this with
before since the function were explicitly cast.
* Replaced direct zk_thread_create() calls with thread_create()
for code consistency. All consumers of libzpool now use the
proper wrappers.
* The mutex_held() calls were converted to MUTEX_HELD().
* Removed all mutex_owner() calls and retired the interface.
Instead use MUTEX_HELD() which provides the same information
and allows the implementation details to be hidden. In this
case the use of the pthread_equals() function.
* The kthread_t, kmutex_t, krwlock_t, and krwlock_t types had
any non essential fields removed. In the case of kthread_t
and kcondvar_t they could be directly typedef'd to pthread_t
and pthread_cond_t respectively.
* Removed all extra ASSERTS from the thread, mutex, rwlock, and
cv wrapper functions. In practice, pthreads already provides
the vast majority of checks as long as we check the return
code. Removing this code from our wrappers help readability.
* Added TS_JOINABLE state flag to pass to request a joinable rather
than detached thread. This isn't a standard thread_create() state
but it's the least invasive way to pass this information and is
only used by ztest.
TEST_ZTEST_TIMEOUT=3600
Chunwei Chen <tuxoko@gmail.com>
Reviewed-by: Tom Caputi <tcaputi@datto.com>
Signed-off-by: Brian Behlendorf <behlendorf1@llnl.gov>
Closes #4547
Closes #5503
Closes #5523
Closes #6377
Closes #6495
2017-08-11 18:51:44 +03:00
|
|
|
#define thread_create(stk, stksize, func, arg, len, pp, state, pri) \
|
|
|
|
zk_thread_create(func, arg, stksize, state)
|
|
|
|
#define thread_exit() pthread_exit(NULL)
|
|
|
|
#define thread_join(t) pthread_join((pthread_t)(t), NULL)
|
|
|
|
|
|
|
|
#define newproc(f, a, cid, pri, ctp, pid) (ENOSYS)
|
2010-05-29 00:45:14 +04:00
|
|
|
|
|
|
|
/* in libzpool, p0 exists only to have its address taken */
|
2010-08-26 21:43:27 +04:00
|
|
|
typedef struct proc {
|
2010-05-29 00:45:14 +04:00
|
|
|
uintptr_t this_is_never_used_dont_dereference_it;
|
2010-08-26 21:43:27 +04:00
|
|
|
} proc_t;
|
2010-05-29 00:45:14 +04:00
|
|
|
|
|
|
|
extern struct proc p0;
|
2012-05-10 02:05:14 +04:00
|
|
|
#define curproc (&p0)
|
2010-05-29 00:45:14 +04:00
|
|
|
|
Simplify threads, mutexs, cvs and rwlocks
* Simplify threads, mutexs, cvs and rwlocks
* Update the zk_thread_create() function to use the same trick
as Illumos. Specifically, cast the new pthread_t to a void
pointer and return that as the kthread_t *. This avoids the
issues associated with managing a wrapper structure and is
safe as long as the callers never attempt to dereference it.
* Update all function prototypes passed to pthread_create() to
match the expected prototype. We were getting away this with
before since the function were explicitly cast.
* Replaced direct zk_thread_create() calls with thread_create()
for code consistency. All consumers of libzpool now use the
proper wrappers.
* The mutex_held() calls were converted to MUTEX_HELD().
* Removed all mutex_owner() calls and retired the interface.
Instead use MUTEX_HELD() which provides the same information
and allows the implementation details to be hidden. In this
case the use of the pthread_equals() function.
* The kthread_t, kmutex_t, krwlock_t, and krwlock_t types had
any non essential fields removed. In the case of kthread_t
and kcondvar_t they could be directly typedef'd to pthread_t
and pthread_cond_t respectively.
* Removed all extra ASSERTS from the thread, mutex, rwlock, and
cv wrapper functions. In practice, pthreads already provides
the vast majority of checks as long as we check the return
code. Removing this code from our wrappers help readability.
* Added TS_JOINABLE state flag to pass to request a joinable rather
than detached thread. This isn't a standard thread_create() state
but it's the least invasive way to pass this information and is
only used by ztest.
TEST_ZTEST_TIMEOUT=3600
Chunwei Chen <tuxoko@gmail.com>
Reviewed-by: Tom Caputi <tcaputi@datto.com>
Signed-off-by: Brian Behlendorf <behlendorf1@llnl.gov>
Closes #4547
Closes #5503
Closes #5523
Closes #6377
Closes #6495
2017-08-11 18:51:44 +03:00
|
|
|
#define PS_NONE -1
|
2008-12-11 22:14:49 +03:00
|
|
|
|
Simplify threads, mutexs, cvs and rwlocks
* Simplify threads, mutexs, cvs and rwlocks
* Update the zk_thread_create() function to use the same trick
as Illumos. Specifically, cast the new pthread_t to a void
pointer and return that as the kthread_t *. This avoids the
issues associated with managing a wrapper structure and is
safe as long as the callers never attempt to dereference it.
* Update all function prototypes passed to pthread_create() to
match the expected prototype. We were getting away this with
before since the function were explicitly cast.
* Replaced direct zk_thread_create() calls with thread_create()
for code consistency. All consumers of libzpool now use the
proper wrappers.
* The mutex_held() calls were converted to MUTEX_HELD().
* Removed all mutex_owner() calls and retired the interface.
Instead use MUTEX_HELD() which provides the same information
and allows the implementation details to be hidden. In this
case the use of the pthread_equals() function.
* The kthread_t, kmutex_t, krwlock_t, and krwlock_t types had
any non essential fields removed. In the case of kthread_t
and kcondvar_t they could be directly typedef'd to pthread_t
and pthread_cond_t respectively.
* Removed all extra ASSERTS from the thread, mutex, rwlock, and
cv wrapper functions. In practice, pthreads already provides
the vast majority of checks as long as we check the return
code. Removing this code from our wrappers help readability.
* Added TS_JOINABLE state flag to pass to request a joinable rather
than detached thread. This isn't a standard thread_create() state
but it's the least invasive way to pass this information and is
only used by ztest.
TEST_ZTEST_TIMEOUT=3600
Chunwei Chen <tuxoko@gmail.com>
Reviewed-by: Tom Caputi <tcaputi@datto.com>
Signed-off-by: Brian Behlendorf <behlendorf1@llnl.gov>
Closes #4547
Closes #5503
Closes #5523
Closes #6377
Closes #6495
2017-08-11 18:51:44 +03:00
|
|
|
extern kthread_t *zk_thread_create(void (*func)(void *), void *arg,
|
|
|
|
size_t stksize, int state);
|
2010-08-26 21:43:27 +04:00
|
|
|
|
Simplify threads, mutexs, cvs and rwlocks
* Simplify threads, mutexs, cvs and rwlocks
* Update the zk_thread_create() function to use the same trick
as Illumos. Specifically, cast the new pthread_t to a void
pointer and return that as the kthread_t *. This avoids the
issues associated with managing a wrapper structure and is
safe as long as the callers never attempt to dereference it.
* Update all function prototypes passed to pthread_create() to
match the expected prototype. We were getting away this with
before since the function were explicitly cast.
* Replaced direct zk_thread_create() calls with thread_create()
for code consistency. All consumers of libzpool now use the
proper wrappers.
* The mutex_held() calls were converted to MUTEX_HELD().
* Removed all mutex_owner() calls and retired the interface.
Instead use MUTEX_HELD() which provides the same information
and allows the implementation details to be hidden. In this
case the use of the pthread_equals() function.
* The kthread_t, kmutex_t, krwlock_t, and krwlock_t types had
any non essential fields removed. In the case of kthread_t
and kcondvar_t they could be directly typedef'd to pthread_t
and pthread_cond_t respectively.
* Removed all extra ASSERTS from the thread, mutex, rwlock, and
cv wrapper functions. In practice, pthreads already provides
the vast majority of checks as long as we check the return
code. Removing this code from our wrappers help readability.
* Added TS_JOINABLE state flag to pass to request a joinable rather
than detached thread. This isn't a standard thread_create() state
but it's the least invasive way to pass this information and is
only used by ztest.
TEST_ZTEST_TIMEOUT=3600
Chunwei Chen <tuxoko@gmail.com>
Reviewed-by: Tom Caputi <tcaputi@datto.com>
Signed-off-by: Brian Behlendorf <behlendorf1@llnl.gov>
Closes #4547
Closes #5503
Closes #5523
Closes #6377
Closes #6495
2017-08-11 18:51:44 +03:00
|
|
|
#define issig(why) (FALSE)
|
|
|
|
#define ISSIG(thr, why) (FALSE)
|
2010-08-26 21:43:27 +04:00
|
|
|
|
Cleanup: Use OpenSolaris functions to call scheduler
In our codebase, `cond_resched() and `schedule()` are Linux kernel
functions that have replaced the OpenSolaris `kpreempt()` functions in
the codebase to such an extent that `kpreempt()` in zfs_context.h was
broken. Nobody noticed because we did not actually use it. The header
had defined `kpreempt()` as `yield()`, which works on OpenSolaris and
Illumos where `sched_yield()` is a wrapper for `yield()`, but that does
not work on any other platform.
The FreeBSD platform specific code implemented shims for these, but the
shim for `schedule()` forced us to wait, which is different than merely
rescheduling to another thread as the original Linux code does, while
the shim for `cond_resched()` had the same definition as its kernel
kpreempt() shim.
After studying this, I have concluded that we should reintroduce the
kpreempt() function in platform independent code with the following
definitions:
- In the Linux kernel:
kpreempt(unused) -> cond_resched()
- In the FreeBSD kernel:
kpreempt(unused) -> kern_yield(PRI_USER)
- In userspace:
kpreempt(unused) -> sched_yield()
In userspace, nothing changes from this cleanup. In the kernels, the
function `fm_fini()` will now call `kern_yield(PRI_USER)` on FreeBSD and
`cond_resched()` on Linux. This is instead of `pause("schedule", 1)` on
FreeBSD and `schedule()` on Linux. This makes our behavior consistent
across platforms.
Note that Linux's SPL continues to use `cond_resched()` and
`schedule()`. However, those functions have been removed from both the
FreeBSD code and userspace code.
This should have the benefit of making it slightly easier to port the
code to new platforms by making how things should be mapped less
confusing.
Reviewed-by: Alexander Motin <mav@FreeBSD.org>
Reviewed-by: Brian Behlendorf <behlendorf1@llnl.gov>
Reviewed-by: Neal Gompa <ngompa@datto.com>
Signed-off-by: Richard Yao <richard.yao@alumni.stonybrook.edu>
Closes #13845
2022-09-12 19:55:37 +03:00
|
|
|
#define KPREEMPT_SYNC (-1)
|
|
|
|
|
|
|
|
#define kpreempt(x) sched_yield()
|
2012-08-24 04:45:31 +04:00
|
|
|
#define kpreempt_disable() ((void)0)
|
|
|
|
#define kpreempt_enable() ((void)0)
|
|
|
|
|
2008-12-11 22:14:49 +03:00
|
|
|
/*
|
|
|
|
* Mutexes
|
|
|
|
*/
|
|
|
|
typedef struct kmutex {
|
Simplify threads, mutexs, cvs and rwlocks
* Simplify threads, mutexs, cvs and rwlocks
* Update the zk_thread_create() function to use the same trick
as Illumos. Specifically, cast the new pthread_t to a void
pointer and return that as the kthread_t *. This avoids the
issues associated with managing a wrapper structure and is
safe as long as the callers never attempt to dereference it.
* Update all function prototypes passed to pthread_create() to
match the expected prototype. We were getting away this with
before since the function were explicitly cast.
* Replaced direct zk_thread_create() calls with thread_create()
for code consistency. All consumers of libzpool now use the
proper wrappers.
* The mutex_held() calls were converted to MUTEX_HELD().
* Removed all mutex_owner() calls and retired the interface.
Instead use MUTEX_HELD() which provides the same information
and allows the implementation details to be hidden. In this
case the use of the pthread_equals() function.
* The kthread_t, kmutex_t, krwlock_t, and krwlock_t types had
any non essential fields removed. In the case of kthread_t
and kcondvar_t they could be directly typedef'd to pthread_t
and pthread_cond_t respectively.
* Removed all extra ASSERTS from the thread, mutex, rwlock, and
cv wrapper functions. In practice, pthreads already provides
the vast majority of checks as long as we check the return
code. Removing this code from our wrappers help readability.
* Added TS_JOINABLE state flag to pass to request a joinable rather
than detached thread. This isn't a standard thread_create() state
but it's the least invasive way to pass this information and is
only used by ztest.
TEST_ZTEST_TIMEOUT=3600
Chunwei Chen <tuxoko@gmail.com>
Reviewed-by: Tom Caputi <tcaputi@datto.com>
Signed-off-by: Brian Behlendorf <behlendorf1@llnl.gov>
Closes #4547
Closes #5503
Closes #5523
Closes #6377
Closes #6495
2017-08-11 18:51:44 +03:00
|
|
|
pthread_mutex_t m_lock;
|
|
|
|
pthread_t m_owner;
|
2008-12-11 22:14:49 +03:00
|
|
|
} kmutex_t;
|
|
|
|
|
Simplify threads, mutexs, cvs and rwlocks
* Simplify threads, mutexs, cvs and rwlocks
* Update the zk_thread_create() function to use the same trick
as Illumos. Specifically, cast the new pthread_t to a void
pointer and return that as the kthread_t *. This avoids the
issues associated with managing a wrapper structure and is
safe as long as the callers never attempt to dereference it.
* Update all function prototypes passed to pthread_create() to
match the expected prototype. We were getting away this with
before since the function were explicitly cast.
* Replaced direct zk_thread_create() calls with thread_create()
for code consistency. All consumers of libzpool now use the
proper wrappers.
* The mutex_held() calls were converted to MUTEX_HELD().
* Removed all mutex_owner() calls and retired the interface.
Instead use MUTEX_HELD() which provides the same information
and allows the implementation details to be hidden. In this
case the use of the pthread_equals() function.
* The kthread_t, kmutex_t, krwlock_t, and krwlock_t types had
any non essential fields removed. In the case of kthread_t
and kcondvar_t they could be directly typedef'd to pthread_t
and pthread_cond_t respectively.
* Removed all extra ASSERTS from the thread, mutex, rwlock, and
cv wrapper functions. In practice, pthreads already provides
the vast majority of checks as long as we check the return
code. Removing this code from our wrappers help readability.
* Added TS_JOINABLE state flag to pass to request a joinable rather
than detached thread. This isn't a standard thread_create() state
but it's the least invasive way to pass this information and is
only used by ztest.
TEST_ZTEST_TIMEOUT=3600
Chunwei Chen <tuxoko@gmail.com>
Reviewed-by: Tom Caputi <tcaputi@datto.com>
Signed-off-by: Brian Behlendorf <behlendorf1@llnl.gov>
Closes #4547
Closes #5503
Closes #5523
Closes #6377
Closes #6495
2017-08-11 18:51:44 +03:00
|
|
|
#define MUTEX_DEFAULT 0
|
|
|
|
#define MUTEX_NOLOCKDEP MUTEX_DEFAULT
|
|
|
|
#define MUTEX_HELD(mp) pthread_equal((mp)->m_owner, pthread_self())
|
|
|
|
#define MUTEX_NOT_HELD(mp) !MUTEX_HELD(mp)
|
2008-12-11 22:14:49 +03:00
|
|
|
|
2010-08-26 21:43:27 +04:00
|
|
|
extern void mutex_init(kmutex_t *mp, char *name, int type, void *cookie);
|
|
|
|
extern void mutex_destroy(kmutex_t *mp);
|
2008-12-11 22:14:49 +03:00
|
|
|
extern void mutex_enter(kmutex_t *mp);
|
|
|
|
extern void mutex_exit(kmutex_t *mp);
|
|
|
|
extern int mutex_tryenter(kmutex_t *mp);
|
|
|
|
|
2019-07-17 19:18:24 +03:00
|
|
|
#define NESTED_SINGLE 1
|
|
|
|
#define mutex_enter_nested(mp, class) mutex_enter(mp)
|
2008-12-11 22:14:49 +03:00
|
|
|
/*
|
|
|
|
* RW locks
|
|
|
|
*/
|
|
|
|
typedef struct krwlock {
|
2010-08-26 21:43:27 +04:00
|
|
|
pthread_rwlock_t rw_lock;
|
Simplify threads, mutexs, cvs and rwlocks
* Simplify threads, mutexs, cvs and rwlocks
* Update the zk_thread_create() function to use the same trick
as Illumos. Specifically, cast the new pthread_t to a void
pointer and return that as the kthread_t *. This avoids the
issues associated with managing a wrapper structure and is
safe as long as the callers never attempt to dereference it.
* Update all function prototypes passed to pthread_create() to
match the expected prototype. We were getting away this with
before since the function were explicitly cast.
* Replaced direct zk_thread_create() calls with thread_create()
for code consistency. All consumers of libzpool now use the
proper wrappers.
* The mutex_held() calls were converted to MUTEX_HELD().
* Removed all mutex_owner() calls and retired the interface.
Instead use MUTEX_HELD() which provides the same information
and allows the implementation details to be hidden. In this
case the use of the pthread_equals() function.
* The kthread_t, kmutex_t, krwlock_t, and krwlock_t types had
any non essential fields removed. In the case of kthread_t
and kcondvar_t they could be directly typedef'd to pthread_t
and pthread_cond_t respectively.
* Removed all extra ASSERTS from the thread, mutex, rwlock, and
cv wrapper functions. In practice, pthreads already provides
the vast majority of checks as long as we check the return
code. Removing this code from our wrappers help readability.
* Added TS_JOINABLE state flag to pass to request a joinable rather
than detached thread. This isn't a standard thread_create() state
but it's the least invasive way to pass this information and is
only used by ztest.
TEST_ZTEST_TIMEOUT=3600
Chunwei Chen <tuxoko@gmail.com>
Reviewed-by: Tom Caputi <tcaputi@datto.com>
Signed-off-by: Brian Behlendorf <behlendorf1@llnl.gov>
Closes #4547
Closes #5503
Closes #5523
Closes #6377
Closes #6495
2017-08-11 18:51:44 +03:00
|
|
|
pthread_t rw_owner;
|
2010-08-26 21:43:27 +04:00
|
|
|
uint_t rw_readers;
|
2008-12-11 22:14:49 +03:00
|
|
|
} krwlock_t;
|
|
|
|
|
|
|
|
typedef int krw_t;
|
|
|
|
|
Simplify threads, mutexs, cvs and rwlocks
* Simplify threads, mutexs, cvs and rwlocks
* Update the zk_thread_create() function to use the same trick
as Illumos. Specifically, cast the new pthread_t to a void
pointer and return that as the kthread_t *. This avoids the
issues associated with managing a wrapper structure and is
safe as long as the callers never attempt to dereference it.
* Update all function prototypes passed to pthread_create() to
match the expected prototype. We were getting away this with
before since the function were explicitly cast.
* Replaced direct zk_thread_create() calls with thread_create()
for code consistency. All consumers of libzpool now use the
proper wrappers.
* The mutex_held() calls were converted to MUTEX_HELD().
* Removed all mutex_owner() calls and retired the interface.
Instead use MUTEX_HELD() which provides the same information
and allows the implementation details to be hidden. In this
case the use of the pthread_equals() function.
* The kthread_t, kmutex_t, krwlock_t, and krwlock_t types had
any non essential fields removed. In the case of kthread_t
and kcondvar_t they could be directly typedef'd to pthread_t
and pthread_cond_t respectively.
* Removed all extra ASSERTS from the thread, mutex, rwlock, and
cv wrapper functions. In practice, pthreads already provides
the vast majority of checks as long as we check the return
code. Removing this code from our wrappers help readability.
* Added TS_JOINABLE state flag to pass to request a joinable rather
than detached thread. This isn't a standard thread_create() state
but it's the least invasive way to pass this information and is
only used by ztest.
TEST_ZTEST_TIMEOUT=3600
Chunwei Chen <tuxoko@gmail.com>
Reviewed-by: Tom Caputi <tcaputi@datto.com>
Signed-off-by: Brian Behlendorf <behlendorf1@llnl.gov>
Closes #4547
Closes #5503
Closes #5523
Closes #6377
Closes #6495
2017-08-11 18:51:44 +03:00
|
|
|
#define RW_READER 0
|
|
|
|
#define RW_WRITER 1
|
|
|
|
#define RW_DEFAULT RW_READER
|
|
|
|
#define RW_NOLOCKDEP RW_READER
|
2008-12-11 22:14:49 +03:00
|
|
|
|
Simplify threads, mutexs, cvs and rwlocks
* Simplify threads, mutexs, cvs and rwlocks
* Update the zk_thread_create() function to use the same trick
as Illumos. Specifically, cast the new pthread_t to a void
pointer and return that as the kthread_t *. This avoids the
issues associated with managing a wrapper structure and is
safe as long as the callers never attempt to dereference it.
* Update all function prototypes passed to pthread_create() to
match the expected prototype. We were getting away this with
before since the function were explicitly cast.
* Replaced direct zk_thread_create() calls with thread_create()
for code consistency. All consumers of libzpool now use the
proper wrappers.
* The mutex_held() calls were converted to MUTEX_HELD().
* Removed all mutex_owner() calls and retired the interface.
Instead use MUTEX_HELD() which provides the same information
and allows the implementation details to be hidden. In this
case the use of the pthread_equals() function.
* The kthread_t, kmutex_t, krwlock_t, and krwlock_t types had
any non essential fields removed. In the case of kthread_t
and kcondvar_t they could be directly typedef'd to pthread_t
and pthread_cond_t respectively.
* Removed all extra ASSERTS from the thread, mutex, rwlock, and
cv wrapper functions. In practice, pthreads already provides
the vast majority of checks as long as we check the return
code. Removing this code from our wrappers help readability.
* Added TS_JOINABLE state flag to pass to request a joinable rather
than detached thread. This isn't a standard thread_create() state
but it's the least invasive way to pass this information and is
only used by ztest.
TEST_ZTEST_TIMEOUT=3600
Chunwei Chen <tuxoko@gmail.com>
Reviewed-by: Tom Caputi <tcaputi@datto.com>
Signed-off-by: Brian Behlendorf <behlendorf1@llnl.gov>
Closes #4547
Closes #5503
Closes #5523
Closes #6377
Closes #6495
2017-08-11 18:51:44 +03:00
|
|
|
#define RW_READ_HELD(rw) ((rw)->rw_readers > 0)
|
|
|
|
#define RW_WRITE_HELD(rw) pthread_equal((rw)->rw_owner, pthread_self())
|
|
|
|
#define RW_LOCK_HELD(rw) (RW_READ_HELD(rw) || RW_WRITE_HELD(rw))
|
2013-09-04 16:00:57 +04:00
|
|
|
|
2008-12-11 22:14:49 +03:00
|
|
|
extern void rw_init(krwlock_t *rwlp, char *name, int type, void *arg);
|
|
|
|
extern void rw_destroy(krwlock_t *rwlp);
|
|
|
|
extern void rw_enter(krwlock_t *rwlp, krw_t rw);
|
|
|
|
extern int rw_tryenter(krwlock_t *rwlp, krw_t rw);
|
|
|
|
extern int rw_tryupgrade(krwlock_t *rwlp);
|
|
|
|
extern void rw_exit(krwlock_t *rwlp);
|
|
|
|
#define rw_downgrade(rwlp) do { } while (0)
|
|
|
|
|
Simplify threads, mutexs, cvs and rwlocks
* Simplify threads, mutexs, cvs and rwlocks
* Update the zk_thread_create() function to use the same trick
as Illumos. Specifically, cast the new pthread_t to a void
pointer and return that as the kthread_t *. This avoids the
issues associated with managing a wrapper structure and is
safe as long as the callers never attempt to dereference it.
* Update all function prototypes passed to pthread_create() to
match the expected prototype. We were getting away this with
before since the function were explicitly cast.
* Replaced direct zk_thread_create() calls with thread_create()
for code consistency. All consumers of libzpool now use the
proper wrappers.
* The mutex_held() calls were converted to MUTEX_HELD().
* Removed all mutex_owner() calls and retired the interface.
Instead use MUTEX_HELD() which provides the same information
and allows the implementation details to be hidden. In this
case the use of the pthread_equals() function.
* The kthread_t, kmutex_t, krwlock_t, and krwlock_t types had
any non essential fields removed. In the case of kthread_t
and kcondvar_t they could be directly typedef'd to pthread_t
and pthread_cond_t respectively.
* Removed all extra ASSERTS from the thread, mutex, rwlock, and
cv wrapper functions. In practice, pthreads already provides
the vast majority of checks as long as we check the return
code. Removing this code from our wrappers help readability.
* Added TS_JOINABLE state flag to pass to request a joinable rather
than detached thread. This isn't a standard thread_create() state
but it's the least invasive way to pass this information and is
only used by ztest.
TEST_ZTEST_TIMEOUT=3600
Chunwei Chen <tuxoko@gmail.com>
Reviewed-by: Tom Caputi <tcaputi@datto.com>
Signed-off-by: Brian Behlendorf <behlendorf1@llnl.gov>
Closes #4547
Closes #5503
Closes #5523
Closes #6377
Closes #6495
2017-08-11 18:51:44 +03:00
|
|
|
/*
|
|
|
|
* Credentials
|
|
|
|
*/
|
2008-12-11 22:14:49 +03:00
|
|
|
extern uid_t crgetuid(cred_t *cr);
|
2013-08-28 15:45:09 +04:00
|
|
|
extern uid_t crgetruid(cred_t *cr);
|
2008-12-11 22:14:49 +03:00
|
|
|
extern gid_t crgetgid(cred_t *cr);
|
|
|
|
extern int crgetngroups(cred_t *cr);
|
|
|
|
extern gid_t *crgetgroups(cred_t *cr);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Condition variables
|
|
|
|
*/
|
Simplify threads, mutexs, cvs and rwlocks
* Simplify threads, mutexs, cvs and rwlocks
* Update the zk_thread_create() function to use the same trick
as Illumos. Specifically, cast the new pthread_t to a void
pointer and return that as the kthread_t *. This avoids the
issues associated with managing a wrapper structure and is
safe as long as the callers never attempt to dereference it.
* Update all function prototypes passed to pthread_create() to
match the expected prototype. We were getting away this with
before since the function were explicitly cast.
* Replaced direct zk_thread_create() calls with thread_create()
for code consistency. All consumers of libzpool now use the
proper wrappers.
* The mutex_held() calls were converted to MUTEX_HELD().
* Removed all mutex_owner() calls and retired the interface.
Instead use MUTEX_HELD() which provides the same information
and allows the implementation details to be hidden. In this
case the use of the pthread_equals() function.
* The kthread_t, kmutex_t, krwlock_t, and krwlock_t types had
any non essential fields removed. In the case of kthread_t
and kcondvar_t they could be directly typedef'd to pthread_t
and pthread_cond_t respectively.
* Removed all extra ASSERTS from the thread, mutex, rwlock, and
cv wrapper functions. In practice, pthreads already provides
the vast majority of checks as long as we check the return
code. Removing this code from our wrappers help readability.
* Added TS_JOINABLE state flag to pass to request a joinable rather
than detached thread. This isn't a standard thread_create() state
but it's the least invasive way to pass this information and is
only used by ztest.
TEST_ZTEST_TIMEOUT=3600
Chunwei Chen <tuxoko@gmail.com>
Reviewed-by: Tom Caputi <tcaputi@datto.com>
Signed-off-by: Brian Behlendorf <behlendorf1@llnl.gov>
Closes #4547
Closes #5503
Closes #5523
Closes #6377
Closes #6495
2017-08-11 18:51:44 +03:00
|
|
|
typedef pthread_cond_t kcondvar_t;
|
2008-12-11 22:14:49 +03:00
|
|
|
|
Simplify threads, mutexs, cvs and rwlocks
* Simplify threads, mutexs, cvs and rwlocks
* Update the zk_thread_create() function to use the same trick
as Illumos. Specifically, cast the new pthread_t to a void
pointer and return that as the kthread_t *. This avoids the
issues associated with managing a wrapper structure and is
safe as long as the callers never attempt to dereference it.
* Update all function prototypes passed to pthread_create() to
match the expected prototype. We were getting away this with
before since the function were explicitly cast.
* Replaced direct zk_thread_create() calls with thread_create()
for code consistency. All consumers of libzpool now use the
proper wrappers.
* The mutex_held() calls were converted to MUTEX_HELD().
* Removed all mutex_owner() calls and retired the interface.
Instead use MUTEX_HELD() which provides the same information
and allows the implementation details to be hidden. In this
case the use of the pthread_equals() function.
* The kthread_t, kmutex_t, krwlock_t, and krwlock_t types had
any non essential fields removed. In the case of kthread_t
and kcondvar_t they could be directly typedef'd to pthread_t
and pthread_cond_t respectively.
* Removed all extra ASSERTS from the thread, mutex, rwlock, and
cv wrapper functions. In practice, pthreads already provides
the vast majority of checks as long as we check the return
code. Removing this code from our wrappers help readability.
* Added TS_JOINABLE state flag to pass to request a joinable rather
than detached thread. This isn't a standard thread_create() state
but it's the least invasive way to pass this information and is
only used by ztest.
TEST_ZTEST_TIMEOUT=3600
Chunwei Chen <tuxoko@gmail.com>
Reviewed-by: Tom Caputi <tcaputi@datto.com>
Signed-off-by: Brian Behlendorf <behlendorf1@llnl.gov>
Closes #4547
Closes #5503
Closes #5523
Closes #6377
Closes #6495
2017-08-11 18:51:44 +03:00
|
|
|
#define CV_DEFAULT 0
|
2016-05-16 01:18:25 +03:00
|
|
|
#define CALLOUT_FLAG_ABSOLUTE 0x2
|
2008-12-11 22:14:49 +03:00
|
|
|
|
|
|
|
extern void cv_init(kcondvar_t *cv, char *name, int type, void *arg);
|
|
|
|
extern void cv_destroy(kcondvar_t *cv);
|
|
|
|
extern void cv_wait(kcondvar_t *cv, kmutex_t *mp);
|
Implement Redacted Send/Receive
Redacted send/receive allows users to send subsets of their data to
a target system. One possible use case for this feature is to not
transmit sensitive information to a data warehousing, test/dev, or
analytics environment. Another is to save space by not replicating
unimportant data within a given dataset, for example in backup tools
like zrepl.
Redacted send/receive is a three-stage process. First, a clone (or
clones) is made of the snapshot to be sent to the target. In this
clone (or clones), all unnecessary or unwanted data is removed or
modified. This clone is then snapshotted to create the "redaction
snapshot" (or snapshots). Second, the new zfs redact command is used
to create a redaction bookmark. The redaction bookmark stores the
list of blocks in a snapshot that were modified by the redaction
snapshot(s). Finally, the redaction bookmark is passed as a parameter
to zfs send. When sending to the snapshot that was redacted, the
redaction bookmark is used to filter out blocks that contain sensitive
or unwanted information, and those blocks are not included in the send
stream. When sending from the redaction bookmark, the blocks it
contains are considered as candidate blocks in addition to those
blocks in the destination snapshot that were modified since the
creation_txg of the redaction bookmark. This step is necessary to
allow the target to rehydrate data in the case where some blocks are
accidentally or unnecessarily modified in the redaction snapshot.
The changes to bookmarks to enable fast space estimation involve
adding deadlists to bookmarks. There is also logic to manage the
life cycles of these deadlists.
The new size estimation process operates in cases where previously
an accurate estimate could not be provided. In those cases, a send
is performed where no data blocks are read, reducing the runtime
significantly and providing a byte-accurate size estimate.
Reviewed-by: Dan Kimmel <dan.kimmel@delphix.com>
Reviewed-by: Matt Ahrens <mahrens@delphix.com>
Reviewed-by: Prashanth Sreenivasa <pks@delphix.com>
Reviewed-by: John Kennedy <john.kennedy@delphix.com>
Reviewed-by: George Wilson <george.wilson@delphix.com>
Reviewed-by: Chris Williamson <chris.williamson@delphix.com>
Reviewed-by: Pavel Zhakarov <pavel.zakharov@delphix.com>
Reviewed-by: Sebastien Roy <sebastien.roy@delphix.com>
Reviewed-by: Prakash Surya <prakash.surya@delphix.com>
Reviewed-by: Brian Behlendorf <behlendorf1@llnl.gov>
Signed-off-by: Paul Dagnelie <pcd@delphix.com>
Closes #7958
2019-06-19 19:48:13 +03:00
|
|
|
extern int cv_wait_sig(kcondvar_t *cv, kmutex_t *mp);
|
2020-06-18 20:17:50 +03:00
|
|
|
extern int cv_timedwait(kcondvar_t *cv, kmutex_t *mp, clock_t abstime);
|
|
|
|
extern int cv_timedwait_hires(kcondvar_t *cvp, kmutex_t *mp, hrtime_t tim,
|
2013-08-29 03:05:48 +04:00
|
|
|
hrtime_t res, int flag);
|
2008-12-11 22:14:49 +03:00
|
|
|
extern void cv_signal(kcondvar_t *cv);
|
|
|
|
extern void cv_broadcast(kcondvar_t *cv);
|
Simplify threads, mutexs, cvs and rwlocks
* Simplify threads, mutexs, cvs and rwlocks
* Update the zk_thread_create() function to use the same trick
as Illumos. Specifically, cast the new pthread_t to a void
pointer and return that as the kthread_t *. This avoids the
issues associated with managing a wrapper structure and is
safe as long as the callers never attempt to dereference it.
* Update all function prototypes passed to pthread_create() to
match the expected prototype. We were getting away this with
before since the function were explicitly cast.
* Replaced direct zk_thread_create() calls with thread_create()
for code consistency. All consumers of libzpool now use the
proper wrappers.
* The mutex_held() calls were converted to MUTEX_HELD().
* Removed all mutex_owner() calls and retired the interface.
Instead use MUTEX_HELD() which provides the same information
and allows the implementation details to be hidden. In this
case the use of the pthread_equals() function.
* The kthread_t, kmutex_t, krwlock_t, and krwlock_t types had
any non essential fields removed. In the case of kthread_t
and kcondvar_t they could be directly typedef'd to pthread_t
and pthread_cond_t respectively.
* Removed all extra ASSERTS from the thread, mutex, rwlock, and
cv wrapper functions. In practice, pthreads already provides
the vast majority of checks as long as we check the return
code. Removing this code from our wrappers help readability.
* Added TS_JOINABLE state flag to pass to request a joinable rather
than detached thread. This isn't a standard thread_create() state
but it's the least invasive way to pass this information and is
only used by ztest.
TEST_ZTEST_TIMEOUT=3600
Chunwei Chen <tuxoko@gmail.com>
Reviewed-by: Tom Caputi <tcaputi@datto.com>
Signed-off-by: Brian Behlendorf <behlendorf1@llnl.gov>
Closes #4547
Closes #5503
Closes #5523
Closes #6377
Closes #6495
2017-08-11 18:51:44 +03:00
|
|
|
|
2017-12-19 01:06:07 +03:00
|
|
|
#define cv_timedwait_io(cv, mp, at) cv_timedwait(cv, mp, at)
|
2020-09-04 06:04:09 +03:00
|
|
|
#define cv_timedwait_idle(cv, mp, at) cv_timedwait(cv, mp, at)
|
2015-06-11 20:47:19 +03:00
|
|
|
#define cv_timedwait_sig(cv, mp, at) cv_timedwait(cv, mp, at)
|
2013-03-08 22:41:28 +04:00
|
|
|
#define cv_wait_io(cv, mp) cv_wait(cv, mp)
|
2020-09-04 06:04:09 +03:00
|
|
|
#define cv_wait_idle(cv, mp) cv_wait(cv, mp)
|
2019-06-23 02:51:46 +03:00
|
|
|
#define cv_wait_io_sig(cv, mp) cv_wait_sig(cv, mp)
|
2016-05-12 02:55:48 +03:00
|
|
|
#define cv_timedwait_sig_hires(cv, mp, t, r, f) \
|
|
|
|
cv_timedwait_hires(cv, mp, t, r, f)
|
2020-09-04 06:04:09 +03:00
|
|
|
#define cv_timedwait_idle_hires(cv, mp, t, r, f) \
|
|
|
|
cv_timedwait_hires(cv, mp, t, r, f)
|
2008-12-11 22:14:49 +03:00
|
|
|
|
2013-09-04 16:00:57 +04:00
|
|
|
/*
|
|
|
|
* Thread-specific data
|
|
|
|
*/
|
|
|
|
#define tsd_get(k) pthread_getspecific(k)
|
|
|
|
#define tsd_set(k, v) pthread_setspecific(k, v)
|
2019-12-05 00:12:57 +03:00
|
|
|
#define tsd_create(kp, d) pthread_key_create((pthread_key_t *)kp, d)
|
2013-09-04 16:00:57 +04:00
|
|
|
#define tsd_destroy(kp) /* nothing */
|
2020-07-26 06:09:50 +03:00
|
|
|
#ifdef __FreeBSD__
|
|
|
|
typedef off_t loff_t;
|
|
|
|
#endif
|
2013-09-04 16:00:57 +04:00
|
|
|
|
2008-12-11 22:14:49 +03:00
|
|
|
/*
|
|
|
|
* kstat creation, installation and deletion
|
|
|
|
*/
|
2013-08-27 04:09:29 +04:00
|
|
|
extern kstat_t *kstat_create(const char *, int,
|
|
|
|
const char *, const char *, uchar_t, ulong_t, uchar_t);
|
2008-12-11 22:14:49 +03:00
|
|
|
extern void kstat_install(kstat_t *);
|
|
|
|
extern void kstat_delete(kstat_t *);
|
Add visibility in to arc_read
This change is an attempt to add visibility into the arc_read calls
occurring on a system, in real time. To do this, a list was added to the
in memory SPA data structure for a pool, with each element on the list
corresponding to a call to arc_read. These entries are then exported
through the kstat interface, which can then be interpreted in userspace.
For each arc_read call, the following information is exported:
* A unique identifier (uint64_t)
* The time the entry was added to the list (hrtime_t)
(*not* wall clock time; relative to the other entries on the list)
* The objset ID (uint64_t)
* The object number (uint64_t)
* The indirection level (uint64_t)
* The block ID (uint64_t)
* The name of the function originating the arc_read call (char[24])
* The arc_flags from the arc_read call (uint32_t)
* The PID of the reading thread (pid_t)
* The command or name of thread originating read (char[16])
From this exported information one can see, in real time, exactly what
is being read, what function is generating the read, and whether or not
the read was found to be already cached.
There is still some work to be done, but this should serve as a good
starting point.
Specifically, dbuf_read's are not accounted for in the currently
exported information. Thus, a follow up patch should probably be added
to export these calls that never call into arc_read (they only hit the
dbuf hash table). In addition, it might be nice to create a utility
similar to "arcstat.py" to digest the exported information and display
it in a more readable format. Or perhaps, log the information and allow
for it to be "replayed" at a later time.
Signed-off-by: Prakash Surya <surya1@llnl.gov>
Signed-off-by: Brian Behlendorf <behlendorf1@llnl.gov>
2013-09-07 03:09:05 +04:00
|
|
|
extern void kstat_set_raw_ops(kstat_t *ksp,
|
|
|
|
int (*headers)(char *buf, size_t size),
|
|
|
|
int (*data)(char *buf, size_t size, void *data),
|
|
|
|
void *(*addr)(kstat_t *ksp, loff_t index));
|
2008-12-11 22:14:49 +03:00
|
|
|
|
2018-09-26 21:08:12 +03:00
|
|
|
/*
|
|
|
|
* procfs list manipulation
|
|
|
|
*/
|
|
|
|
|
|
|
|
typedef struct procfs_list {
|
|
|
|
void *pl_private;
|
|
|
|
kmutex_t pl_lock;
|
|
|
|
list_t pl_list;
|
|
|
|
uint64_t pl_next_id;
|
|
|
|
size_t pl_node_offset;
|
|
|
|
} procfs_list_t;
|
|
|
|
|
2020-06-06 22:54:04 +03:00
|
|
|
#ifndef __cplusplus
|
|
|
|
struct seq_file { };
|
|
|
|
void seq_printf(struct seq_file *m, const char *fmt, ...);
|
|
|
|
|
2018-09-26 21:08:12 +03:00
|
|
|
typedef struct procfs_list_node {
|
|
|
|
list_node_t pln_link;
|
|
|
|
uint64_t pln_id;
|
|
|
|
} procfs_list_node_t;
|
|
|
|
|
|
|
|
void procfs_list_install(const char *module,
|
2020-09-24 02:43:51 +03:00
|
|
|
const char *submodule,
|
2018-09-26 21:08:12 +03:00
|
|
|
const char *name,
|
2019-04-05 04:57:06 +03:00
|
|
|
mode_t mode,
|
2018-09-26 21:08:12 +03:00
|
|
|
procfs_list_t *procfs_list,
|
|
|
|
int (*show)(struct seq_file *f, void *p),
|
|
|
|
int (*show_header)(struct seq_file *f),
|
|
|
|
int (*clear)(procfs_list_t *procfs_list),
|
|
|
|
size_t procfs_list_node_off);
|
|
|
|
void procfs_list_uninstall(procfs_list_t *procfs_list);
|
|
|
|
void procfs_list_destroy(procfs_list_t *procfs_list);
|
|
|
|
void procfs_list_add(procfs_list_t *procfs_list, void *p);
|
2020-06-06 22:54:04 +03:00
|
|
|
#endif
|
2018-09-26 21:08:12 +03:00
|
|
|
|
2008-12-11 22:14:49 +03:00
|
|
|
/*
|
|
|
|
* Kernel memory
|
|
|
|
*/
|
|
|
|
#define KM_SLEEP UMEM_NOFAIL
|
|
|
|
#define KM_PUSHPAGE KM_SLEEP
|
|
|
|
#define KM_NOSLEEP UMEM_DEFAULT
|
2018-02-08 19:16:23 +03:00
|
|
|
#define KM_NORMALPRI 0 /* not needed with UMEM_DEFAULT */
|
2008-12-11 22:14:49 +03:00
|
|
|
#define KMC_NODEBUG UMC_NODEBUG
|
2019-07-21 20:34:10 +03:00
|
|
|
#define KMC_KVMEM 0x0
|
2008-12-11 22:14:49 +03:00
|
|
|
#define kmem_alloc(_s, _f) umem_alloc(_s, _f)
|
|
|
|
#define kmem_zalloc(_s, _f) umem_zalloc(_s, _f)
|
|
|
|
#define kmem_free(_b, _s) umem_free(_b, _s)
|
2010-08-26 22:46:09 +04:00
|
|
|
#define vmem_alloc(_s, _f) kmem_alloc(_s, _f)
|
|
|
|
#define vmem_zalloc(_s, _f) kmem_zalloc(_s, _f)
|
|
|
|
#define vmem_free(_b, _s) kmem_free(_b, _s)
|
2008-12-11 22:14:49 +03:00
|
|
|
#define kmem_cache_create(_a, _b, _c, _d, _e, _f, _g, _h, _i) \
|
|
|
|
umem_cache_create(_a, _b, _c, _d, _e, _f, _g, _h, _i)
|
|
|
|
#define kmem_cache_destroy(_c) umem_cache_destroy(_c)
|
|
|
|
#define kmem_cache_alloc(_c, _f) umem_cache_alloc(_c, _f)
|
|
|
|
#define kmem_cache_free(_c, _b) umem_cache_free(_c, _b)
|
|
|
|
#define kmem_debugging() 0
|
2015-06-25 01:48:22 +03:00
|
|
|
#define kmem_cache_reap_now(_c) umem_cache_reap_now(_c);
|
2010-08-27 01:24:34 +04:00
|
|
|
#define kmem_cache_set_move(_c, _cb) /* nothing */
|
|
|
|
#define POINTER_INVALIDATE(_pp) /* nothing */
|
|
|
|
#define POINTER_IS_VALID(_p) 0
|
2008-12-11 22:14:49 +03:00
|
|
|
|
|
|
|
typedef umem_cache_t kmem_cache_t;
|
|
|
|
|
2010-08-27 01:24:34 +04:00
|
|
|
typedef enum kmem_cbrc {
|
|
|
|
KMEM_CBRC_YES,
|
|
|
|
KMEM_CBRC_NO,
|
|
|
|
KMEM_CBRC_LATER,
|
|
|
|
KMEM_CBRC_DONT_NEED,
|
|
|
|
KMEM_CBRC_DONT_KNOW
|
|
|
|
} kmem_cbrc_t;
|
|
|
|
|
2008-12-11 22:14:49 +03:00
|
|
|
/*
|
|
|
|
* Task queues
|
|
|
|
*/
|
2016-05-12 17:51:24 +03:00
|
|
|
|
|
|
|
#define TASKQ_NAMELEN 31
|
|
|
|
|
2008-12-11 22:14:49 +03:00
|
|
|
typedef uintptr_t taskqid_t;
|
|
|
|
typedef void (task_func_t)(void *);
|
|
|
|
|
2011-11-08 04:26:52 +04:00
|
|
|
typedef struct taskq_ent {
|
|
|
|
struct taskq_ent *tqent_next;
|
|
|
|
struct taskq_ent *tqent_prev;
|
|
|
|
task_func_t *tqent_func;
|
|
|
|
void *tqent_arg;
|
|
|
|
uintptr_t tqent_flags;
|
|
|
|
} taskq_ent_t;
|
|
|
|
|
2016-05-12 17:51:24 +03:00
|
|
|
typedef struct taskq {
|
|
|
|
char tq_name[TASKQ_NAMELEN + 1];
|
|
|
|
kmutex_t tq_lock;
|
|
|
|
krwlock_t tq_threadlock;
|
|
|
|
kcondvar_t tq_dispatch_cv;
|
|
|
|
kcondvar_t tq_wait_cv;
|
|
|
|
kthread_t **tq_threadlist;
|
|
|
|
int tq_flags;
|
|
|
|
int tq_active;
|
|
|
|
int tq_nthreads;
|
|
|
|
int tq_nalloc;
|
|
|
|
int tq_minalloc;
|
|
|
|
int tq_maxalloc;
|
|
|
|
kcondvar_t tq_maxalloc_cv;
|
|
|
|
int tq_maxalloc_wait;
|
|
|
|
taskq_ent_t *tq_freelist;
|
|
|
|
taskq_ent_t tq_task;
|
|
|
|
} taskq_t;
|
|
|
|
|
2011-11-08 04:26:52 +04:00
|
|
|
#define TQENT_FLAG_PREALLOC 0x1 /* taskq_dispatch_ent used */
|
|
|
|
|
2008-12-11 22:14:49 +03:00
|
|
|
#define TASKQ_PREPOPULATE 0x0001
|
|
|
|
#define TASKQ_CPR_SAFE 0x0002 /* Use CPR safe protocol */
|
|
|
|
#define TASKQ_DYNAMIC 0x0004 /* Use dynamic thread scheduling */
|
2010-05-29 00:45:14 +04:00
|
|
|
#define TASKQ_THREADS_CPU_PCT 0x0008 /* Scale # threads by # cpus */
|
|
|
|
#define TASKQ_DC_BATCH 0x0010 /* Mark threads as batch */
|
2008-12-11 22:14:49 +03:00
|
|
|
|
|
|
|
#define TQ_SLEEP KM_SLEEP /* Can block for memory */
|
|
|
|
#define TQ_NOSLEEP KM_NOSLEEP /* cannot block for memory; may fail */
|
2010-05-29 00:45:14 +04:00
|
|
|
#define TQ_NOQUEUE 0x02 /* Do not enqueue if can't dispatch */
|
|
|
|
#define TQ_FRONT 0x08 /* Queue in front */
|
2008-12-11 22:14:49 +03:00
|
|
|
|
2016-10-29 01:40:14 +03:00
|
|
|
#define TASKQID_INVALID ((taskqid_t)0)
|
|
|
|
|
2008-12-11 22:14:49 +03:00
|
|
|
extern taskq_t *system_taskq;
|
2016-12-01 00:56:50 +03:00
|
|
|
extern taskq_t *system_delay_taskq;
|
2008-12-11 22:14:49 +03:00
|
|
|
|
|
|
|
extern taskq_t *taskq_create(const char *, int, pri_t, int, int, uint_t);
|
2010-05-29 00:45:14 +04:00
|
|
|
#define taskq_create_proc(a, b, c, d, e, p, f) \
|
|
|
|
(taskq_create(a, b, c, d, e, f))
|
|
|
|
#define taskq_create_sysdc(a, b, d, e, p, dc, f) \
|
2022-01-15 02:37:55 +03:00
|
|
|
((void) sizeof (dc), taskq_create(a, b, maxclsyspri, d, e, f))
|
2008-12-11 22:14:49 +03:00
|
|
|
extern taskqid_t taskq_dispatch(taskq_t *, task_func_t, void *, uint_t);
|
2013-04-30 02:49:23 +04:00
|
|
|
extern taskqid_t taskq_dispatch_delay(taskq_t *, task_func_t, void *, uint_t,
|
|
|
|
clock_t);
|
2011-11-08 04:26:52 +04:00
|
|
|
extern void taskq_dispatch_ent(taskq_t *, task_func_t, void *, uint_t,
|
|
|
|
taskq_ent_t *);
|
|
|
|
extern int taskq_empty_ent(taskq_ent_t *);
|
|
|
|
extern void taskq_init_ent(taskq_ent_t *);
|
2008-12-11 22:14:49 +03:00
|
|
|
extern void taskq_destroy(taskq_t *);
|
|
|
|
extern void taskq_wait(taskq_t *);
|
2013-05-04 01:17:21 +04:00
|
|
|
extern void taskq_wait_id(taskq_t *, taskqid_t);
|
2015-06-05 02:25:37 +03:00
|
|
|
extern void taskq_wait_outstanding(taskq_t *, taskqid_t);
|
2010-08-26 21:43:27 +04:00
|
|
|
extern int taskq_member(taskq_t *, kthread_t *);
|
2020-03-03 21:29:38 +03:00
|
|
|
extern taskq_t *taskq_of_curthread(void);
|
2013-04-30 02:49:23 +04:00
|
|
|
extern int taskq_cancel_id(taskq_t *, taskqid_t);
|
2008-12-11 22:14:49 +03:00
|
|
|
extern void system_taskq_init(void);
|
2010-05-29 00:45:14 +04:00
|
|
|
extern void system_taskq_fini(void);
|
2008-12-11 22:14:49 +03:00
|
|
|
|
|
|
|
#define XVA_MAPSIZE 3
|
|
|
|
#define XVA_MAGIC 0x78766174
|
|
|
|
|
2016-01-01 16:42:58 +03:00
|
|
|
extern char *vn_dumpdir;
|
2010-05-29 00:45:14 +04:00
|
|
|
#define AV_SCANSTAMP_SZ 32 /* length of anti-virus scanstamp */
|
2008-12-11 22:14:49 +03:00
|
|
|
|
|
|
|
typedef struct xoptattr {
|
2018-06-20 07:51:18 +03:00
|
|
|
inode_timespec_t xoa_createtime; /* Create time of file */
|
2008-12-11 22:14:49 +03:00
|
|
|
uint8_t xoa_archive;
|
|
|
|
uint8_t xoa_system;
|
|
|
|
uint8_t xoa_readonly;
|
|
|
|
uint8_t xoa_hidden;
|
|
|
|
uint8_t xoa_nounlink;
|
|
|
|
uint8_t xoa_immutable;
|
|
|
|
uint8_t xoa_appendonly;
|
|
|
|
uint8_t xoa_nodump;
|
|
|
|
uint8_t xoa_settable;
|
|
|
|
uint8_t xoa_opaque;
|
|
|
|
uint8_t xoa_av_quarantined;
|
|
|
|
uint8_t xoa_av_modified;
|
2010-05-29 00:45:14 +04:00
|
|
|
uint8_t xoa_av_scanstamp[AV_SCANSTAMP_SZ];
|
|
|
|
uint8_t xoa_reparse;
|
2010-08-27 01:24:34 +04:00
|
|
|
uint8_t xoa_offline;
|
|
|
|
uint8_t xoa_sparse;
|
2008-12-11 22:14:49 +03:00
|
|
|
} xoptattr_t;
|
|
|
|
|
|
|
|
typedef struct vattr {
|
|
|
|
uint_t va_mask; /* bit-mask of attributes */
|
|
|
|
u_offset_t va_size; /* file size in bytes */
|
|
|
|
} vattr_t;
|
|
|
|
|
|
|
|
|
|
|
|
typedef struct xvattr {
|
|
|
|
vattr_t xva_vattr; /* Embedded vattr structure */
|
|
|
|
uint32_t xva_magic; /* Magic Number */
|
|
|
|
uint32_t xva_mapsize; /* Size of attr bitmap (32-bit words) */
|
|
|
|
uint32_t *xva_rtnattrmapp; /* Ptr to xva_rtnattrmap[] */
|
|
|
|
uint32_t xva_reqattrmap[XVA_MAPSIZE]; /* Requested attrs */
|
|
|
|
uint32_t xva_rtnattrmap[XVA_MAPSIZE]; /* Returned attrs */
|
|
|
|
xoptattr_t xva_xoptattrs; /* Optional attributes */
|
|
|
|
} xvattr_t;
|
|
|
|
|
|
|
|
typedef struct vsecattr {
|
|
|
|
uint_t vsa_mask; /* See below */
|
|
|
|
int vsa_aclcnt; /* ACL entry count */
|
|
|
|
void *vsa_aclentp; /* pointer to ACL entries */
|
|
|
|
int vsa_dfaclcnt; /* default ACL entry count */
|
|
|
|
void *vsa_dfaclentp; /* pointer to default ACL entries */
|
|
|
|
size_t vsa_aclentsz; /* ACE size in bytes of vsa_aclentp */
|
|
|
|
} vsecattr_t;
|
|
|
|
|
|
|
|
#define AT_MODE 0x00002
|
|
|
|
#define AT_UID 0x00004
|
|
|
|
#define AT_GID 0x00008
|
|
|
|
#define AT_FSID 0x00010
|
|
|
|
#define AT_NODEID 0x00020
|
|
|
|
#define AT_NLINK 0x00040
|
|
|
|
#define AT_SIZE 0x00080
|
|
|
|
#define AT_ATIME 0x00100
|
|
|
|
#define AT_MTIME 0x00200
|
|
|
|
#define AT_CTIME 0x00400
|
|
|
|
#define AT_RDEV 0x00800
|
|
|
|
#define AT_BLKSIZE 0x01000
|
|
|
|
#define AT_NBLOCKS 0x02000
|
|
|
|
#define AT_SEQ 0x08000
|
|
|
|
#define AT_XVATTR 0x10000
|
|
|
|
|
|
|
|
#define CRCREAT 0
|
|
|
|
|
2019-03-29 19:13:20 +03:00
|
|
|
#define F_FREESP 11
|
2019-11-21 20:32:57 +03:00
|
|
|
#define FIGNORECASE 0x80000 /* request case-insensitive lookups */
|
2008-12-11 22:14:49 +03:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Random stuff
|
|
|
|
*/
|
2010-05-29 00:45:14 +04:00
|
|
|
#define ddi_get_lbolt() (gethrtime() >> 23)
|
|
|
|
#define ddi_get_lbolt64() (gethrtime() >> 23)
|
2008-12-11 22:14:49 +03:00
|
|
|
#define hz 119 /* frequency when using gethrtime() >> 23 for lbolt */
|
|
|
|
|
2014-02-25 13:32:21 +04:00
|
|
|
#define ddi_time_before(a, b) (a < b)
|
|
|
|
#define ddi_time_after(a, b) ddi_time_before(b, a)
|
|
|
|
#define ddi_time_before_eq(a, b) (!ddi_time_after(a, b))
|
|
|
|
#define ddi_time_after_eq(a, b) ddi_time_before_eq(b, a)
|
|
|
|
|
|
|
|
#define ddi_time_before64(a, b) (a < b)
|
|
|
|
#define ddi_time_after64(a, b) ddi_time_before64(b, a)
|
|
|
|
#define ddi_time_before_eq64(a, b) (!ddi_time_after64(a, b))
|
|
|
|
#define ddi_time_after_eq64(a, b) ddi_time_before_eq64(b, a)
|
|
|
|
|
2008-12-11 22:14:49 +03:00
|
|
|
extern void delay(clock_t ticks);
|
|
|
|
|
2013-04-30 02:49:23 +04:00
|
|
|
#define SEC_TO_TICK(sec) ((sec) * hz)
|
2020-09-08 21:39:16 +03:00
|
|
|
#define MSEC_TO_TICK(msec) (howmany((hrtime_t)(msec) * hz, MILLISEC))
|
|
|
|
#define USEC_TO_TICK(usec) (howmany((hrtime_t)(usec) * hz, MICROSEC))
|
|
|
|
#define NSEC_TO_TICK(nsec) (howmany((hrtime_t)(nsec) * hz, NANOSEC))
|
2013-04-30 02:49:23 +04:00
|
|
|
|
2008-12-11 22:14:49 +03:00
|
|
|
#define max_ncpus 64
|
2015-06-26 21:28:18 +03:00
|
|
|
#define boot_ncpus (sysconf(_SC_NPROCESSORS_ONLN))
|
2008-12-11 22:14:49 +03:00
|
|
|
|
2015-07-24 20:08:31 +03:00
|
|
|
/*
|
|
|
|
* Process priorities as defined by setpriority(2) and getpriority(2).
|
|
|
|
*/
|
|
|
|
#define minclsyspri 19
|
|
|
|
#define maxclsyspri -20
|
|
|
|
#define defclsyspri 0
|
2008-12-11 22:14:49 +03:00
|
|
|
|
2016-03-01 17:32:52 +03:00
|
|
|
#define CPU_SEQID ((uintptr_t)pthread_self() & (max_ncpus - 1))
|
2020-11-02 22:51:12 +03:00
|
|
|
#define CPU_SEQID_UNSTABLE CPU_SEQID
|
2008-12-11 22:14:49 +03:00
|
|
|
|
|
|
|
#define kcred NULL
|
|
|
|
#define CRED() NULL
|
|
|
|
|
|
|
|
#define ptob(x) ((x) * PAGESIZE)
|
|
|
|
|
2017-06-13 12:16:45 +03:00
|
|
|
#define NN_DIVISOR_1000 (1U << 0)
|
|
|
|
#define NN_NUMBUF_SZ (6)
|
|
|
|
|
2008-12-11 22:14:49 +03:00
|
|
|
extern uint64_t physmem;
|
2021-04-08 23:17:38 +03:00
|
|
|
extern const char *random_path;
|
|
|
|
extern const char *urandom_path;
|
2008-12-11 22:14:49 +03:00
|
|
|
|
2014-04-16 07:40:22 +04:00
|
|
|
extern int highbit64(uint64_t i);
|
2016-02-29 21:05:23 +03:00
|
|
|
extern int lowbit64(uint64_t i);
|
2008-12-11 22:14:49 +03:00
|
|
|
extern int random_get_bytes(uint8_t *ptr, size_t len);
|
|
|
|
extern int random_get_pseudo_bytes(uint8_t *ptr, size_t len);
|
|
|
|
|
2021-06-23 02:35:23 +03:00
|
|
|
static __inline__ uint32_t
|
|
|
|
random_in_range(uint32_t range)
|
|
|
|
{
|
|
|
|
uint32_t r;
|
|
|
|
|
|
|
|
ASSERT(range != 0);
|
|
|
|
|
|
|
|
if (range == 1)
|
|
|
|
return (0);
|
|
|
|
|
2021-06-25 20:28:51 +03:00
|
|
|
(void) random_get_pseudo_bytes((uint8_t *)&r, sizeof (r));
|
2021-06-23 02:35:23 +03:00
|
|
|
|
|
|
|
return (r % range);
|
|
|
|
}
|
|
|
|
|
2019-11-21 20:32:57 +03:00
|
|
|
extern void kernel_init(int mode);
|
2008-12-11 22:14:49 +03:00
|
|
|
extern void kernel_fini(void);
|
2016-05-12 17:51:24 +03:00
|
|
|
extern void random_init(void);
|
|
|
|
extern void random_fini(void);
|
2008-12-11 22:14:49 +03:00
|
|
|
|
|
|
|
struct spa;
|
|
|
|
extern void show_pool_stats(struct spa *);
|
2021-02-16 14:27:48 +03:00
|
|
|
extern int set_global_var(char const *arg);
|
2008-12-11 22:14:49 +03:00
|
|
|
|
|
|
|
typedef struct callb_cpr {
|
|
|
|
kmutex_t *cc_lockp;
|
|
|
|
} callb_cpr_t;
|
|
|
|
|
|
|
|
#define CALLB_CPR_INIT(cp, lockp, func, name) { \
|
|
|
|
(cp)->cc_lockp = lockp; \
|
|
|
|
}
|
|
|
|
|
|
|
|
#define CALLB_CPR_SAFE_BEGIN(cp) { \
|
|
|
|
ASSERT(MUTEX_HELD((cp)->cc_lockp)); \
|
|
|
|
}
|
|
|
|
|
|
|
|
#define CALLB_CPR_SAFE_END(cp, lockp) { \
|
|
|
|
ASSERT(MUTEX_HELD((cp)->cc_lockp)); \
|
|
|
|
}
|
|
|
|
|
|
|
|
#define CALLB_CPR_EXIT(cp) { \
|
|
|
|
ASSERT(MUTEX_HELD((cp)->cc_lockp)); \
|
|
|
|
mutex_exit((cp)->cc_lockp); \
|
|
|
|
}
|
|
|
|
|
|
|
|
#define zone_dataset_visible(x, y) (1)
|
|
|
|
#define INGLOBALZONE(z) (1)
|
OpenZFS 9075 - Improve ZFS pool import/load process and corrupted pool recovery
Some work has been done lately to improve the debugability of the ZFS pool
load (and import) process. This includes:
7638 Refactor spa_load_impl into several functions
8961 SPA load/import should tell us why it failed
7277 zdb should be able to print zfs_dbgmsg's
To iterate on top of that, there's a few changes that were made to make the
import process more resilient and crash free. One of the first tasks during the
pool load process is to parse a config provided from userland that describes
what devices the pool is composed of. A vdev tree is generated from that config,
and then all the vdevs are opened.
The Meta Object Set (MOS) of the pool is accessed, and several metadata objects
that are necessary to load the pool are read. The exact configuration of the
pool is also stored inside the MOS. Since the configuration provided from
userland is external and might not accurately describe the vdev tree
of the pool at the txg that is being loaded, it cannot be relied upon to safely
operate the pool. For that reason, the configuration in the MOS is read early
on. In the past, the two configurations were compared together and if there was
a mismatch then the load process was aborted and an error was returned.
The latter was a good way to ensure a pool does not get corrupted, however it
made the pool load process needlessly fragile in cases where the vdev
configuration changed or the userland configuration was outdated. Since the MOS
is stored in 3 copies, the configuration provided by userland doesn't have to be
perfect in order to read its contents. Hence, a new approach has been adopted:
The pool is first opened with the untrusted userland configuration just so that
the real configuration can be read from the MOS. The trusted MOS configuration
is then used to generate a new vdev tree and the pool is re-opened.
When the pool is opened with an untrusted configuration, writes are disabled
to avoid accidentally damaging it. During reads, some sanity checks are
performed on block pointers to see if each DVA points to a known vdev;
when the configuration is untrusted, instead of panicking the system if those
checks fail we simply avoid issuing reads to the invalid DVAs.
This new two-step pool load process now allows rewinding pools accross
vdev tree changes such as device replacement, addition, etc. Loading a pool
from an external config file in a clustering environment also becomes much
safer now since the pool will import even if the config is outdated and didn't,
for instance, register a recent device addition.
With this code in place, it became relatively easy to implement a
long-sought-after feature: the ability to import a pool with missing top level
(i.e. non-redundant) devices. Note that since this almost guarantees some loss
of data, this feature is for now restricted to a read-only import.
Porting notes (ZTS):
* Fix 'make dist' target in zpool_import
* The maximum path length allowed by tar is 99 characters. Several
of the new test cases exceeded this limit resulting in them not
being included in the tarball. Shorten the names slightly.
* Set/get tunables using accessor functions.
* Get last synced txg via the "zfs_txg_history" mechanism.
* Clear zinject handlers in cleanup for import_cache_device_replaced
and import_rewind_device_replaced in order that the zpool can be
exported if there is an error.
* Increase FILESIZE to 8G in zfs-test.sh to allow for a larger
ext4 file system to be created on ZFS_DISK2. Also, there's
no need to partition ZFS_DISK2 at all. The partitioning had
already been disabled for multipath devices. Among other things,
the partitioning steals some space from the ext4 file system,
makes it difficult to accurately calculate the paramters to
parted and can make some of the tests fail.
* Increase FS_SIZE and FILE_SIZE in the zpool_import test
configuration now that FILESIZE is larger.
* Write more data in order that device evacuation take lonnger in
a couple tests.
* Use mkdir -p to avoid errors when the directory already exists.
* Remove use of sudo in import_rewind_config_changed.
Authored by: Pavel Zakharov <pavel.zakharov@delphix.com>
Reviewed by: George Wilson <george.wilson@delphix.com>
Reviewed by: Matthew Ahrens <mahrens@delphix.com>
Reviewed by: Andrew Stormont <andyjstormont@gmail.com>
Approved by: Hans Rosenfeld <rosenfeld@grumpf.hope-2000.org>
Ported-by: Tim Chase <tim@chase2k.com>
Signed-off-by: Tim Chase <tim@chase2k.com>
OpenZFS-issue: https://illumos.org/issues/9075
OpenZFS-commit: https://github.com/openzfs/openzfs/commit/619c0123
Closes #7459
2016-07-22 17:39:36 +03:00
|
|
|
extern uint32_t zone_get_hostid(void *zonep);
|
2008-12-11 22:14:49 +03:00
|
|
|
|
2010-08-26 22:46:09 +04:00
|
|
|
extern char *kmem_vasprintf(const char *fmt, va_list adx);
|
2010-05-29 00:45:14 +04:00
|
|
|
extern char *kmem_asprintf(const char *fmt, ...);
|
2019-10-10 19:47:06 +03:00
|
|
|
#define kmem_strfree(str) kmem_free((str), strlen(str) + 1)
|
|
|
|
#define kmem_strdup(s) strdup(s)
|
2010-05-29 00:45:14 +04:00
|
|
|
|
Introduce kmem_scnprintf()
`snprintf()` is meant to protect against buffer overflows, but operating
on the buffer using its return value, possibly by calling it again, can
cause a buffer overflow, because it will return how many characters it
would have written if it had enough space even when it did not. In a
number of places, we repeatedly call snprintf() by successively
incrementing a buffer offset and decrementing a buffer length, by its
return value. This is a potentially unsafe usage of `snprintf()`
whenever the buffer length is reached. CodeQL complained about this.
To fix this, we introduce `kmem_scnprintf()`, which will return 0 when
the buffer is zero or the number of written characters, minus 1 to
exclude the NULL character, when the buffer was too small. In all other
cases, it behaves like snprintf(). The name is inspired by the Linux and
XNU kernels' `scnprintf()`. The implementation was written before I
thought to look at `scnprintf()` and had a good name for it, but it
turned out to have identical semantics to the Linux kernel version.
That lead to the name, `kmem_scnprintf()`.
CodeQL only catches this issue in loops, so repeated use of snprintf()
outside of a loop was not caught. As a result, a thorough audit of the
codebase was done to examine all instances of `snprintf()` usage for
potential problems and a few were caught. Fixes for them are included in
this patch.
Unfortunately, ZED is one of the places where `snprintf()` is
potentially used incorrectly. Since using `kmem_scnprintf()` in it would
require changing how it is linked, we modify its usage to make it safe,
no matter what buffer length is used. In addition, there was a bug in
the use of the return value where the NULL format character was not
being written by pwrite(). That has been fixed.
Reviewed-by: Brian Behlendorf <behlendorf1@llnl.gov>
Signed-off-by: Richard Yao <richard.yao@alumni.stonybrook.edu>
Closes #14098
2022-10-27 21:16:04 +03:00
|
|
|
extern int kmem_scnprintf(char *restrict str, size_t size,
|
|
|
|
const char *restrict fmt, ...);
|
|
|
|
|
2008-12-11 22:14:49 +03:00
|
|
|
/*
|
|
|
|
* Hostname information
|
|
|
|
*/
|
2010-05-29 00:45:14 +04:00
|
|
|
extern int ddi_strtoull(const char *str, char **nptr, int base,
|
|
|
|
u_longlong_t *result);
|
|
|
|
|
2014-10-01 23:02:12 +04:00
|
|
|
typedef struct utsname utsname_t;
|
|
|
|
extern utsname_t *utsname(void);
|
|
|
|
|
2008-12-11 22:14:49 +03:00
|
|
|
/* ZFS Boot Related stuff. */
|
|
|
|
|
|
|
|
struct _buf {
|
|
|
|
intptr_t _fd;
|
|
|
|
};
|
|
|
|
|
|
|
|
struct bootstat {
|
|
|
|
uint64_t st_size;
|
|
|
|
};
|
|
|
|
|
|
|
|
typedef struct ace_object {
|
|
|
|
uid_t a_who;
|
|
|
|
uint32_t a_access_mask;
|
|
|
|
uint16_t a_flags;
|
|
|
|
uint16_t a_type;
|
|
|
|
uint8_t a_obj_type[16];
|
|
|
|
uint8_t a_inherit_obj_type[16];
|
|
|
|
} ace_object_t;
|
|
|
|
|
|
|
|
|
|
|
|
#define ACE_ACCESS_ALLOWED_OBJECT_ACE_TYPE 0x05
|
|
|
|
#define ACE_ACCESS_DENIED_OBJECT_ACE_TYPE 0x06
|
|
|
|
#define ACE_SYSTEM_AUDIT_OBJECT_ACE_TYPE 0x07
|
|
|
|
#define ACE_SYSTEM_ALARM_OBJECT_ACE_TYPE 0x08
|
|
|
|
|
|
|
|
extern int zfs_secpolicy_snapshot_perms(const char *name, cred_t *cr);
|
|
|
|
extern int zfs_secpolicy_rename_perms(const char *from, const char *to,
|
|
|
|
cred_t *cr);
|
|
|
|
extern int zfs_secpolicy_destroy_perms(const char *name, cred_t *cr);
|
2016-06-07 19:16:52 +03:00
|
|
|
extern int secpolicy_zfs(const cred_t *cr);
|
2020-07-12 03:18:02 +03:00
|
|
|
extern int secpolicy_zfs_proc(const cred_t *cr, proc_t *proc);
|
2008-12-11 22:14:49 +03:00
|
|
|
extern zoneid_t getzoneid(void);
|
|
|
|
|
|
|
|
/* SID stuff */
|
|
|
|
typedef struct ksiddomain {
|
|
|
|
uint_t kd_ref;
|
|
|
|
uint_t kd_len;
|
|
|
|
char *kd_name;
|
|
|
|
} ksiddomain_t;
|
|
|
|
|
|
|
|
ksiddomain_t *ksid_lookupdomain(const char *);
|
|
|
|
void ksiddomain_rele(ksiddomain_t *);
|
|
|
|
|
2009-07-03 02:44:48 +04:00
|
|
|
#define DDI_SLEEP KM_SLEEP
|
|
|
|
#define ddi_log_sysevent(_a, _b, _c, _d, _e, _f, _g) \
|
|
|
|
sysevent_post_event(_c, _d, _b, "libzpool", _e, _f)
|
|
|
|
|
2013-11-01 23:26:11 +04:00
|
|
|
#define zfs_sleep_until(wakeup) \
|
Illumos #4045 write throttle & i/o scheduler performance work
4045 zfs write throttle & i/o scheduler performance work
1. The ZFS i/o scheduler (vdev_queue.c) now divides i/os into 5 classes: sync
read, sync write, async read, async write, and scrub/resilver. The scheduler
issues a number of concurrent i/os from each class to the device. Once a class
has been selected, an i/o is selected from this class using either an elevator
algorithem (async, scrub classes) or FIFO (sync classes). The number of
concurrent async write i/os is tuned dynamically based on i/o load, to achieve
good sync i/o latency when there is not a high load of writes, and good write
throughput when there is. See the block comment in vdev_queue.c (reproduced
below) for more details.
2. The write throttle (dsl_pool_tempreserve_space() and
txg_constrain_throughput()) is rewritten to produce much more consistent delays
when under constant load. The new write throttle is based on the amount of
dirty data, rather than guesses about future performance of the system. When
there is a lot of dirty data, each transaction (e.g. write() syscall) will be
delayed by the same small amount. This eliminates the "brick wall of wait"
that the old write throttle could hit, causing all transactions to wait several
seconds until the next txg opens. One of the keys to the new write throttle is
decrementing the amount of dirty data as i/o completes, rather than at the end
of spa_sync(). Note that the write throttle is only applied once the i/o
scheduler is issuing the maximum number of outstanding async writes. See the
block comments in dsl_pool.c and above dmu_tx_delay() (reproduced below) for
more details.
This diff has several other effects, including:
* the commonly-tuned global variable zfs_vdev_max_pending has been removed;
use per-class zfs_vdev_*_max_active values or zfs_vdev_max_active instead.
* the size of each txg (meaning the amount of dirty data written, and thus the
time it takes to write out) is now controlled differently. There is no longer
an explicit time goal; the primary determinant is amount of dirty data.
Systems that are under light or medium load will now often see that a txg is
always syncing, but the impact to performance (e.g. read latency) is minimal.
Tune zfs_dirty_data_max and zfs_dirty_data_sync to control this.
* zio_taskq_batch_pct = 75 -- Only use 75% of all CPUs for compression,
checksum, etc. This improves latency by not allowing these CPU-intensive tasks
to consume all CPU (on machines with at least 4 CPU's; the percentage is
rounded up).
--matt
APPENDIX: problems with the current i/o scheduler
The current ZFS i/o scheduler (vdev_queue.c) is deadline based. The problem
with this is that if there are always i/os pending, then certain classes of
i/os can see very long delays.
For example, if there are always synchronous reads outstanding, then no async
writes will be serviced until they become "past due". One symptom of this
situation is that each pass of the txg sync takes at least several seconds
(typically 3 seconds).
If many i/os become "past due" (their deadline is in the past), then we must
service all of these overdue i/os before any new i/os. This happens when we
enqueue a batch of async writes for the txg sync, with deadlines 2.5 seconds in
the future. If we can't complete all the i/os in 2.5 seconds (e.g. because
there were always reads pending), then these i/os will become past due. Now we
must service all the "async" writes (which could be hundreds of megabytes)
before we service any reads, introducing considerable latency to synchronous
i/os (reads or ZIL writes).
Notes on porting to ZFS on Linux:
- zio_t gained new members io_physdone and io_phys_children. Because
object caches in the Linux port call the constructor only once at
allocation time, objects may contain residual data when retrieved
from the cache. Therefore zio_create() was updated to zero out the two
new fields.
- vdev_mirror_pending() relied on the depth of the per-vdev pending queue
(vq->vq_pending_tree) to select the least-busy leaf vdev to read from.
This tree has been replaced by vq->vq_active_tree which is now used
for the same purpose.
- vdev_queue_init() used the value of zfs_vdev_max_pending to determine
the number of vdev I/O buffers to pre-allocate. That global no longer
exists, so we instead use the sum of the *_max_active values for each of
the five I/O classes described above.
- The Illumos implementation of dmu_tx_delay() delays a transaction by
sleeping in condition variable embedded in the thread
(curthread->t_delay_cv). We do not have an equivalent CV to use in
Linux, so this change replaced the delay logic with a wrapper called
zfs_sleep_until(). This wrapper could be adopted upstream and in other
downstream ports to abstract away operating system-specific delay logic.
- These tunables are added as module parameters, and descriptions added
to the zfs-module-parameters.5 man page.
spa_asize_inflation
zfs_deadman_synctime_ms
zfs_vdev_max_active
zfs_vdev_async_write_active_min_dirty_percent
zfs_vdev_async_write_active_max_dirty_percent
zfs_vdev_async_read_max_active
zfs_vdev_async_read_min_active
zfs_vdev_async_write_max_active
zfs_vdev_async_write_min_active
zfs_vdev_scrub_max_active
zfs_vdev_scrub_min_active
zfs_vdev_sync_read_max_active
zfs_vdev_sync_read_min_active
zfs_vdev_sync_write_max_active
zfs_vdev_sync_write_min_active
zfs_dirty_data_max_percent
zfs_delay_min_dirty_percent
zfs_dirty_data_max_max_percent
zfs_dirty_data_max
zfs_dirty_data_max_max
zfs_dirty_data_sync
zfs_delay_scale
The latter four have type unsigned long, whereas they are uint64_t in
Illumos. This accommodates Linux's module_param() supported types, but
means they may overflow on 32-bit architectures.
The values zfs_dirty_data_max and zfs_dirty_data_max_max are the most
likely to overflow on 32-bit systems, since they express physical RAM
sizes in bytes. In fact, Illumos initializes zfs_dirty_data_max_max to
2^32 which does overflow. To resolve that, this port instead initializes
it in arc_init() to 25% of physical RAM, and adds the tunable
zfs_dirty_data_max_max_percent to override that percentage. While this
solution doesn't completely avoid the overflow issue, it should be a
reasonable default for most systems, and the minority of affected
systems can work around the issue by overriding the defaults.
- Fixed reversed logic in comment above zfs_delay_scale declaration.
- Clarified comments in vdev_queue.c regarding when per-queue minimums take
effect.
- Replaced dmu_tx_write_limit in the dmu_tx kstat file
with dmu_tx_dirty_delay and dmu_tx_dirty_over_max. The first counts
how many times a transaction has been delayed because the pool dirty
data has exceeded zfs_delay_min_dirty_percent. The latter counts how
many times the pool dirty data has exceeded zfs_dirty_data_max (which
we expect to never happen).
- The original patch would have regressed the bug fixed in
zfsonlinux/zfs@c418410, which prevented users from setting the
zfs_vdev_aggregation_limit tuning larger than SPA_MAXBLOCKSIZE.
A similar fix is added to vdev_queue_aggregate().
- In vdev_queue_io_to_issue(), dynamically allocate 'zio_t search' on the
heap instead of the stack. In Linux we can't afford such large
structures on the stack.
Reviewed by: George Wilson <george.wilson@delphix.com>
Reviewed by: Adam Leventhal <ahl@delphix.com>
Reviewed by: Christopher Siden <christopher.siden@delphix.com>
Reviewed by: Ned Bass <bass6@llnl.gov>
Reviewed by: Brendan Gregg <brendan.gregg@joyent.com>
Approved by: Robert Mustacchi <rm@joyent.com>
References:
http://www.illumos.org/issues/4045
illumos/illumos-gate@69962b5647e4a8b9b14998733b765925381b727e
Ported-by: Ned Bass <bass6@llnl.gov>
Signed-off-by: Brian Behlendorf <behlendorf1@llnl.gov>
Closes #1913
2013-08-29 07:01:20 +04:00
|
|
|
do { \
|
|
|
|
hrtime_t delta = wakeup - gethrtime(); \
|
|
|
|
struct timespec ts; \
|
|
|
|
ts.tv_sec = delta / NANOSEC; \
|
|
|
|
ts.tv_nsec = delta % NANOSEC; \
|
|
|
|
(void) nanosleep(&ts, NULL); \
|
|
|
|
} while (0)
|
|
|
|
|
2014-07-13 22:35:19 +04:00
|
|
|
typedef int fstrans_cookie_t;
|
|
|
|
|
|
|
|
extern fstrans_cookie_t spl_fstrans_mark(void);
|
|
|
|
extern void spl_fstrans_unmark(fstrans_cookie_t);
|
2017-05-09 20:38:46 +03:00
|
|
|
extern int __spl_pf_fstrans_check(void);
|
2017-03-16 02:41:52 +03:00
|
|
|
extern int kmem_cache_reap_active(void);
|
2008-12-11 22:14:49 +03:00
|
|
|
|
2017-05-25 21:32:40 +03:00
|
|
|
|
Add zstd support to zfs
This PR adds two new compression types, based on ZStandard:
- zstd: A basic ZStandard compression algorithm Available compression.
Levels for zstd are zstd-1 through zstd-19, where the compression
increases with every level, but speed decreases.
- zstd-fast: A faster version of the ZStandard compression algorithm
zstd-fast is basically a "negative" level of zstd. The compression
decreases with every level, but speed increases.
Available compression levels for zstd-fast:
- zstd-fast-1 through zstd-fast-10
- zstd-fast-20 through zstd-fast-100 (in increments of 10)
- zstd-fast-500 and zstd-fast-1000
For more information check the man page.
Implementation details:
Rather than treat each level of zstd as a different algorithm (as was
done historically with gzip), the block pointer `enum zio_compress`
value is simply zstd for all levels, including zstd-fast, since they all
use the same decompression function.
The compress= property (a 64bit unsigned integer) uses the lower 7 bits
to store the compression algorithm (matching the number of bits used in
a block pointer, as the 8th bit was borrowed for embedded block
pointers). The upper bits are used to store the compression level.
It is necessary to be able to determine what compression level was used
when later reading a block back, so the concept used in LZ4, where the
first 32bits of the on-disk value are the size of the compressed data
(since the allocation is rounded up to the nearest ashift), was
extended, and we store the version of ZSTD and the level as well as the
compressed size. This value is returned when decompressing a block, so
that if the block needs to be recompressed (L2ARC, nop-write, etc), that
the same parameters will be used to result in the matching checksum.
All of the internal ZFS code ( `arc_buf_hdr_t`, `objset_t`,
`zio_prop_t`, etc.) uses the separated _compress and _complevel
variables. Only the properties ZAP contains the combined/bit-shifted
value. The combined value is split when the compression_changed_cb()
callback is called, and sets both objset members (os_compress and
os_complevel).
The userspace tools all use the combined/bit-shifted value.
Additional notes:
zdb can now also decode the ZSTD compression header (flag -Z) and
inspect the size, version and compression level saved in that header.
For each record, if it is ZSTD compressed, the parameters of the decoded
compression header get printed.
ZSTD is included with all current tests and new tests are added
as-needed.
Per-dataset feature flags now get activated when the property is set.
If a compression algorithm requires a feature flag, zfs activates the
feature when the property is set, rather than waiting for the first
block to be born. This is currently only used by zstd but can be
extended as needed.
Portions-Sponsored-By: The FreeBSD Foundation
Co-authored-by: Allan Jude <allanjude@freebsd.org>
Co-authored-by: Brian Behlendorf <behlendorf1@llnl.gov>
Co-authored-by: Sebastian Gottschall <s.gottschall@dd-wrt.com>
Co-authored-by: Kjeld Schouten-Lebbing <kjeld@schouten-lebbing.nl>
Co-authored-by: Michael Niewöhner <foss@mniewoehner.de>
Signed-off-by: Allan Jude <allan@klarasystems.com>
Signed-off-by: Allan Jude <allanjude@freebsd.org>
Signed-off-by: Brian Behlendorf <behlendorf1@llnl.gov>
Signed-off-by: Sebastian Gottschall <s.gottschall@dd-wrt.com>
Signed-off-by: Kjeld Schouten-Lebbing <kjeld@schouten-lebbing.nl>
Signed-off-by: Michael Niewöhner <foss@mniewoehner.de>
Closes #6247
Closes #9024
Closes #10277
Closes #10278
2020-08-18 20:10:17 +03:00
|
|
|
/*
|
|
|
|
* Kernel modules
|
|
|
|
*/
|
|
|
|
#define __init
|
|
|
|
#define __exit
|
|
|
|
|
2020-10-14 07:05:49 +03:00
|
|
|
#endif /* _KERNEL || _STANDALONE */
|
2020-06-06 22:54:04 +03:00
|
|
|
|
|
|
|
#ifdef __cplusplus
|
|
|
|
};
|
|
|
|
#endif
|
|
|
|
|
2008-12-11 22:14:49 +03:00
|
|
|
#endif /* _SYS_ZFS_CONTEXT_H */
|