2008-11-20 23:01:55 +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
|
|
|
|
* or http://www.opensolaris.org/os/licensing.
|
|
|
|
* 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
|
|
|
|
*/
|
|
|
|
/*
|
2010-05-29 00:45:14 +04:00
|
|
|
* Copyright (c) 2005, 2010, Oracle and/or its affiliates. All rights reserved.
|
2012-12-15 04:13:40 +04:00
|
|
|
* Portions Copyright 2011 Martin Matuska
|
Log Spacemap Project
= Motivation
At Delphix we've seen a lot of customer systems where fragmentation
is over 75% and random writes take a performance hit because a lot
of time is spend on I/Os that update on-disk space accounting metadata.
Specifically, we seen cases where 20% to 40% of sync time is spend
after sync pass 1 and ~30% of the I/Os on the system is spent updating
spacemaps.
The problem is that these pools have existed long enough that we've
touched almost every metaslab at least once, and random writes
scatter frees across all metaslabs every TXG, thus appending to
their spacemaps and resulting in many I/Os. To give an example,
assuming that every VDEV has 200 metaslabs and our writes fit within
a single spacemap block (generally 4K) we have 200 I/Os. Then if we
assume 2 levels of indirection, we need 400 additional I/Os and
since we are talking about metadata for which we keep 2 extra copies
for redundancy we need to triple that number, leading to a total of
1800 I/Os per VDEV every TXG.
We could try and decrease the number of metaslabs so we have less
I/Os per TXG but then each metaslab would cover a wider range on
disk and thus would take more time to be loaded in memory from disk.
In addition, after it's loaded, it's range tree would consume more
memory.
Another idea would be to just increase the spacemap block size
which would allow us to fit more entries within an I/O block
resulting in fewer I/Os per metaslab and a speedup in loading time.
The problem is still that we don't deal with the number of I/Os
going up as the number of metaslabs is increasing and the fact
is that we generally write a lot to a few metaslabs and a little
to the rest of them. Thus, just increasing the block size would
actually waste bandwidth because we won't be utilizing our bigger
block size.
= About this patch
This patch introduces the Log Spacemap project which provides the
solution to the above problem while taking into account all the
aforementioned tradeoffs. The details on how it achieves that can
be found in the references sections below and in the code (see
Big Theory Statement in spa_log_spacemap.c).
Even though the change is fairly constraint within the metaslab
and lower-level SPA codepaths, there is a side-change that is
user-facing. The change is that VDEV IDs from VDEV holes will no
longer be reused. To give some background and reasoning for this,
when a log device is removed and its VDEV structure was replaced
with a hole (or was compacted; if at the end of the vdev array),
its vdev_id could be reused by devices added after that. Now
with the pool-wide space maps recording the vdev ID, this behavior
can cause problems (e.g. is this entry referring to a segment in
the new vdev or the removed log?). Thus, to simplify things the
ID reuse behavior is gone and now vdev IDs for top-level vdevs
are truly unique within a pool.
= Testing
The illumos implementation of this feature has been used internally
for a year and has been in production for ~6 months. For this patch
specifically there don't seem to be any regressions introduced to
ZTS and I have been running zloop for a week without any related
problems.
= Performance Analysis (Linux Specific)
All performance results and analysis for illumos can be found in
the links of the references. Redoing the same experiments in Linux
gave similar results. Below are the specifics of the Linux run.
After the pool reached stable state the percentage of the time
spent in pass 1 per TXG was 64% on average for the stock bits
while the log spacemap bits stayed at 95% during the experiment
(graph: sdimitro.github.io/img/linux-lsm/PercOfSyncInPassOne.png).
Sync times per TXG were 37.6 seconds on average for the stock
bits and 22.7 seconds for the log spacemap bits (related graph:
sdimitro.github.io/img/linux-lsm/SyncTimePerTXG.png). As a result
the log spacemap bits were able to push more TXGs, which is also
the reason why all graphs quantified per TXG have more entries for
the log spacemap bits.
Another interesting aspect in terms of txg syncs is that the stock
bits had 22% of their TXGs reach sync pass 7, 55% reach sync pass 8,
and 20% reach 9. The log space map bits reached sync pass 4 in 79%
of their TXGs, sync pass 7 in 19%, and sync pass 8 at 1%. This
emphasizes the fact that not only we spend less time on metadata
but we also iterate less times to convergence in spa_sync() dirtying
objects.
[related graphs:
stock- sdimitro.github.io/img/linux-lsm/NumberOfPassesPerTXGStock.png
lsm- sdimitro.github.io/img/linux-lsm/NumberOfPassesPerTXGLSM.png]
Finally, the improvement in IOPs that the userland gains from the
change is approximately 40%. There is a consistent win in IOPS as
you can see from the graphs below but the absolute amount of
improvement that the log spacemap gives varies within each minute
interval.
sdimitro.github.io/img/linux-lsm/StockVsLog3Days.png
sdimitro.github.io/img/linux-lsm/StockVsLog10Hours.png
= Porting to Other Platforms
For people that want to port this commit to other platforms below
is a list of ZoL commits that this patch depends on:
Make zdb results for checkpoint tests consistent
db587941c5ff6dea01932bb78f70db63cf7f38ba
Update vdev_is_spacemap_addressable() for new spacemap encoding
419ba5914552c6185afbe1dd17b3ed4b0d526547
Simplify spa_sync by breaking it up to smaller functions
8dc2197b7b1e4d7ebc1420ea30e51c6541f1d834
Factor metaslab_load_wait() in metaslab_load()
b194fab0fb6caad18711abccaff3c69ad8b3f6d3
Rename range_tree_verify to range_tree_verify_not_present
df72b8bebe0ebac0b20e0750984bad182cb6564a
Change target size of metaslabs from 256GB to 16GB
c853f382db731e15a87512f4ef1101d14d778a55
zdb -L should skip leak detection altogether
21e7cf5da89f55ce98ec1115726b150e19eefe89
vs_alloc can underflow in L2ARC vdevs
7558997d2f808368867ca7e5234e5793446e8f3f
Simplify log vdev removal code
6c926f426a26ffb6d7d8e563e33fc176164175cb
Get rid of space_map_update() for ms_synced_length
425d3237ee88abc53d8522a7139c926d278b4b7f
Introduce auxiliary metaslab histograms
928e8ad47d3478a3d5d01f0dd6ae74a9371af65e
Error path in metaslab_load_impl() forgets to drop ms_sync_lock
8eef997679ba54547f7d361553d21b3291f41ae7
= References
Background, Motivation, and Internals of the Feature
- OpenZFS 2017 Presentation:
youtu.be/jj2IxRkl5bQ
- Slides:
slideshare.net/SerapheimNikolaosDim/zfs-log-spacemaps-project
Flushing Algorithm Internals & Performance Results
(Illumos Specific)
- Blogpost:
sdimitro.github.io/post/zfs-lsm-flushing/
- OpenZFS 2018 Presentation:
youtu.be/x6D2dHRjkxw
- Slides:
slideshare.net/SerapheimNikolaosDim/zfs-log-spacemap-flushing-algorithm
Upstream Delphix Issues:
DLPX-51539, DLPX-59659, DLPX-57783, DLPX-61438, DLPX-41227, DLPX-59320
DLPX-63385
Reviewed-by: Sean Eric Fagan <sef@ixsystems.com>
Reviewed-by: Matt Ahrens <matt@delphix.com>
Reviewed-by: George Wilson <gwilson@delphix.com>
Reviewed-by: Brian Behlendorf <behlendorf1@llnl.gov>
Signed-off-by: Serapheim Dimitropoulos <serapheim@delphix.com>
Closes #8442
2019-07-16 20:11:49 +03:00
|
|
|
* Copyright (c) 2012, 2019 by Delphix. All rights reserved.
|
2008-11-20 23:01:55 +03:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include <sys/zfs_context.h>
|
|
|
|
#include <sys/txg_impl.h>
|
|
|
|
#include <sys/dmu_impl.h>
|
2013-10-01 20:50:50 +04:00
|
|
|
#include <sys/spa_impl.h>
|
2010-05-29 00:45:14 +04:00
|
|
|
#include <sys/dmu_tx.h>
|
2008-11-20 23:01:55 +03:00
|
|
|
#include <sys/dsl_pool.h>
|
2010-05-29 00:45:14 +04:00
|
|
|
#include <sys/dsl_scan.h>
|
2017-04-24 19:34:36 +03:00
|
|
|
#include <sys/zil.h>
|
2008-11-20 23:01:55 +03:00
|
|
|
#include <sys/callb.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-11-20 23:01:55 +03:00
|
|
|
|
|
|
|
/*
|
2013-01-30 20:54:17 +04:00
|
|
|
* ZFS Transaction Groups
|
|
|
|
* ----------------------
|
|
|
|
*
|
|
|
|
* ZFS transaction groups are, as the name implies, groups of transactions
|
|
|
|
* that act on persistent state. ZFS asserts consistency at the granularity of
|
|
|
|
* these transaction groups. Each successive transaction group (txg) is
|
|
|
|
* assigned a 64-bit consecutive identifier. There are three active
|
|
|
|
* transaction group states: open, quiescing, or syncing. At any given time,
|
|
|
|
* there may be an active txg associated with each state; each active txg may
|
|
|
|
* either be processing, or blocked waiting to enter the next state. There may
|
|
|
|
* be up to three active txgs, and there is always a txg in the open state
|
|
|
|
* (though it may be blocked waiting to enter the quiescing state). In broad
|
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
|
|
|
* strokes, transactions -- operations that change in-memory structures -- are
|
2013-01-30 20:54:17 +04:00
|
|
|
* accepted into the txg in the open state, and are completed while the txg is
|
|
|
|
* in the open or quiescing states. The accumulated changes are written to
|
|
|
|
* disk in the syncing state.
|
|
|
|
*
|
|
|
|
* Open
|
|
|
|
*
|
|
|
|
* When a new txg becomes active, it first enters the open state. New
|
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
|
|
|
* transactions -- updates to in-memory structures -- are assigned to the
|
2013-01-30 20:54:17 +04:00
|
|
|
* currently open txg. There is always a txg in the open state so that ZFS can
|
|
|
|
* accept new changes (though the txg may refuse new changes if it has hit
|
|
|
|
* some limit). ZFS advances the open txg to the next state for a variety of
|
|
|
|
* reasons such as it hitting a time or size threshold, or the execution of an
|
|
|
|
* administrative action that must be completed in the syncing state.
|
|
|
|
*
|
|
|
|
* Quiescing
|
|
|
|
*
|
|
|
|
* After a txg exits the open state, it enters the quiescing state. The
|
|
|
|
* quiescing state is intended to provide a buffer between accepting new
|
|
|
|
* transactions in the open state and writing them out to stable storage in
|
|
|
|
* the syncing state. While quiescing, transactions can continue their
|
|
|
|
* operation without delaying either of the other states. Typically, a txg is
|
|
|
|
* in the quiescing state very briefly since the operations are bounded by
|
|
|
|
* software latencies rather than, say, slower I/O latencies. After all
|
|
|
|
* transactions complete, the txg is ready to enter the next state.
|
|
|
|
*
|
|
|
|
* Syncing
|
|
|
|
*
|
|
|
|
* In the syncing state, the in-memory state built up during the open and (to
|
|
|
|
* a lesser degree) the quiescing states is written to stable storage. The
|
|
|
|
* process of writing out modified data can, in turn modify more data. For
|
|
|
|
* example when we write new blocks, we need to allocate space for them; those
|
|
|
|
* allocations modify metadata (space maps)... which themselves must be
|
|
|
|
* written to stable storage. During the sync state, ZFS iterates, writing out
|
|
|
|
* data until it converges and all in-memory changes have been written out.
|
|
|
|
* The first such pass is the largest as it encompasses all the modified user
|
|
|
|
* data (as opposed to filesystem metadata). Subsequent passes typically have
|
|
|
|
* far less data to write as they consist exclusively of filesystem metadata.
|
|
|
|
*
|
|
|
|
* To ensure convergence, after a certain number of passes ZFS begins
|
|
|
|
* overwriting locations on stable storage that had been allocated earlier in
|
|
|
|
* the syncing state (and subsequently freed). ZFS usually allocates new
|
|
|
|
* blocks to optimize for large, continuous, writes. For the syncing state to
|
|
|
|
* converge however it must complete a pass where no new blocks are allocated
|
|
|
|
* since each allocation requires a modification of persistent metadata.
|
|
|
|
* Further, to hasten convergence, after a prescribed number of passes, ZFS
|
|
|
|
* also defers frees, and stops compressing.
|
|
|
|
*
|
|
|
|
* In addition to writing out user data, we must also execute synctasks during
|
|
|
|
* the syncing context. A synctask is the mechanism by which some
|
|
|
|
* administrative activities work such as creating and destroying snapshots or
|
|
|
|
* datasets. Note that when a synctask is initiated it enters the open txg,
|
|
|
|
* and ZFS then pushes that txg as quickly as possible to completion of the
|
|
|
|
* syncing state in order to reduce the latency of the administrative
|
|
|
|
* activity. To complete the syncing state, ZFS writes out a new uberblock,
|
|
|
|
* the root of the tree of blocks that comprise all state stored on the ZFS
|
|
|
|
* pool. Finally, if there is a quiesced txg waiting, we signal that it can
|
|
|
|
* now transition to the syncing state.
|
2008-11-20 23:01:55 +03:00
|
|
|
*/
|
|
|
|
|
2022-03-05 03:25:22 +03:00
|
|
|
static _Noreturn void txg_sync_thread(void *arg);
|
|
|
|
static _Noreturn void txg_quiesce_thread(void *arg);
|
2008-11-20 23:01:55 +03:00
|
|
|
|
2010-08-27 01:24:34 +04:00
|
|
|
int zfs_txg_timeout = 5; /* max seconds worth of delta per txg */
|
2008-11-20 23:01:55 +03:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Prepare the txg subsystem.
|
|
|
|
*/
|
|
|
|
void
|
|
|
|
txg_init(dsl_pool_t *dp, uint64_t txg)
|
|
|
|
{
|
|
|
|
tx_state_t *tx = &dp->dp_tx;
|
|
|
|
int c;
|
|
|
|
bzero(tx, sizeof (tx_state_t));
|
|
|
|
|
2010-08-26 22:46:09 +04:00
|
|
|
tx->tx_cpu = vmem_zalloc(max_ncpus * sizeof (tx_cpu_t), KM_SLEEP);
|
2008-11-20 23:01:55 +03:00
|
|
|
|
|
|
|
for (c = 0; c < max_ncpus; c++) {
|
|
|
|
int i;
|
|
|
|
|
|
|
|
mutex_init(&tx->tx_cpu[c].tc_lock, NULL, MUTEX_DEFAULT, NULL);
|
Identify locks flagged by lockdep
When running a kernel with CONFIG_LOCKDEP=y, lockdep reports possible
recursive locking in some cases and possible circular locking dependency
in others, within the SPL and ZFS modules.
This patch uses a mutex type defined in SPL, MUTEX_NOLOCKDEP, to mark
such mutexes when they are initialized. This mutex type causes
attempts to take or release those locks to be wrapped in lockdep_off()
and lockdep_on() calls to silence the dependency checker and allow the
use of lock_stats to examine contention.
For RW locks, it uses an analogous lock type, RW_NOLOCKDEP.
The goal is that these locks are ultimately changed back to type
MUTEX_DEFAULT or RW_DEFAULT, after the locks are annotated to reflect
their relationship (e.g. z_name_lock below) or any real problem with the
lock dependencies are fixed.
Some of the affected locks are:
tc_open_lock:
=============
This is an array of locks, all with same name, which txg_quiesce must
take all of in order to move txg to next state. All default to the same
lockdep class, and so to lockdep appears recursive.
zp->z_name_lock:
================
In zfs_rmdir,
dzp = znode for the directory (input to zfs_dirent_lock)
zp = znode for the entry being removed (output of zfs_dirent_lock)
zfs_rmdir()->zfs_dirent_lock() takes z_name_lock in dzp
zfs_rmdir() takes z_name_lock in zp
Since both dzp and zp are type znode_t, the locks have the same default
class, and lockdep considers it a possible recursive lock attempt.
l->l_rwlock:
============
zap_expand_leaf() sometimes creates two new zap leaf structures, via
these call paths:
zap_deref_leaf()->zap_get_leaf_byblk()->zap_leaf_open()
zap_expand_leaf()->zap_create_leaf()->zap_expand_leaf()->zap_create_leaf()
Because both zap_leaf_open() and zap_create_leaf() initialize
l->l_rwlock in their (separate) leaf structures, the lockdep class is
the same, and the linux kernel believes these might both be the same
lock, and emits a possible recursive lock warning.
Signed-off-by: Olaf Faaland <faaland1@llnl.gov>
Signed-off-by: Brian Behlendorf <behlendorf1@llnl.gov>
Closes #3895
2015-10-15 23:08:27 +03:00
|
|
|
mutex_init(&tx->tx_cpu[c].tc_open_lock, NULL, MUTEX_NOLOCKDEP,
|
2013-04-23 21:31:42 +04:00
|
|
|
NULL);
|
2008-11-20 23:01:55 +03:00
|
|
|
for (i = 0; i < TXG_SIZE; i++) {
|
|
|
|
cv_init(&tx->tx_cpu[c].tc_cv[i], NULL, CV_DEFAULT,
|
|
|
|
NULL);
|
2010-05-29 00:45:14 +04:00
|
|
|
list_create(&tx->tx_cpu[c].tc_callbacks[i],
|
|
|
|
sizeof (dmu_tx_callback_t),
|
|
|
|
offsetof(dmu_tx_callback_t, dcb_node));
|
2008-11-20 23:01:55 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
mutex_init(&tx->tx_sync_lock, NULL, MUTEX_DEFAULT, NULL);
|
|
|
|
|
2009-01-16 00:59:39 +03:00
|
|
|
cv_init(&tx->tx_sync_more_cv, NULL, CV_DEFAULT, NULL);
|
|
|
|
cv_init(&tx->tx_sync_done_cv, NULL, CV_DEFAULT, NULL);
|
|
|
|
cv_init(&tx->tx_quiesce_more_cv, NULL, CV_DEFAULT, NULL);
|
|
|
|
cv_init(&tx->tx_quiesce_done_cv, NULL, CV_DEFAULT, NULL);
|
|
|
|
cv_init(&tx->tx_exit_cv, NULL, CV_DEFAULT, NULL);
|
|
|
|
|
2008-11-20 23:01:55 +03:00
|
|
|
tx->tx_open_txg = txg;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Close down the txg subsystem.
|
|
|
|
*/
|
|
|
|
void
|
|
|
|
txg_fini(dsl_pool_t *dp)
|
|
|
|
{
|
|
|
|
tx_state_t *tx = &dp->dp_tx;
|
|
|
|
int c;
|
|
|
|
|
OpenZFS 8585 - improve batching done in zil_commit()
Authored by: Prakash Surya <prakash.surya@delphix.com>
Reviewed by: Brad Lewis <brad.lewis@delphix.com>
Reviewed by: Matt Ahrens <mahrens@delphix.com>
Reviewed by: George Wilson <george.wilson@delphix.com>
Reviewed-by: Brian Behlendorf <behlendorf1@llnl.gov>
Approved by: Dan McDonald <danmcd@joyent.com>
Ported-by: Prakash Surya <prakash.surya@delphix.com>
Problem
=======
The current implementation of zil_commit() can introduce significant
latency, beyond what is inherent due to the latency of the underlying
storage. The additional latency comes from two main problems:
1. When there's outstanding ZIL blocks being written (i.e. there's
already a "writer thread" in progress), then any new calls to
zil_commit() will block waiting for the currently oustanding ZIL
blocks to complete. The blocks written for each "writer thread" is
coined a "batch", and there can only ever be a single "batch" being
written at a time. When a batch is being written, any new ZIL
transactions will have to wait for the next batch to be written,
which won't occur until the current batch finishes.
As a result, the underlying storage may not be used as efficiently
as possible. While "new" threads enter zil_commit() and are blocked
waiting for the next batch, it's possible that the underlying
storage isn't fully utilized by the current batch of ZIL blocks. In
that case, it'd be better to allow these new threads to generate
(and issue) a new ZIL block, such that it could be serviced by the
underlying storage concurrently with the other ZIL blocks that are
being serviced.
2. Any call to zil_commit() must wait for all ZIL blocks in its "batch"
to complete, prior to zil_commit() returning. The size of any given
batch is proportional to the number of ZIL transaction in the queue
at the time that the batch starts processing the queue; which
doesn't occur until the previous batch completes. Thus, if there's a
lot of transactions in the queue, the batch could be composed of
many ZIL blocks, and each call to zil_commit() will have to wait for
all of these writes to complete (even if the thread calling
zil_commit() only cared about one of the transactions in the batch).
To further complicate the situation, these two issues result in the
following side effect:
3. If a given batch takes longer to complete than normal, this results
in larger batch sizes, which then take longer to complete and
further drive up the latency of zil_commit(). This can occur for a
number of reasons, including (but not limited to): transient changes
in the workload, and storage latency irregularites.
Solution
========
The solution attempted by this change has the following goals:
1. no on-disk changes; maintain current on-disk format.
2. modify the "batch size" to be equal to the "ZIL block size".
3. allow new batches to be generated and issued to disk, while there's
already batches being serviced by the disk.
4. allow zil_commit() to wait for as few ZIL blocks as possible.
5. use as few ZIL blocks as possible, for the same amount of ZIL
transactions, without introducing significant latency to any
individual ZIL transaction. i.e. use fewer, but larger, ZIL blocks.
In theory, with these goals met, the new allgorithm will allow the
following improvements:
1. new ZIL blocks can be generated and issued, while there's already
oustanding ZIL blocks being serviced by the storage.
2. the latency of zil_commit() should be proportional to the underlying
storage latency, rather than the incoming synchronous workload.
Porting Notes
=============
Due to the changes made in commit 119a394ab0, the lifetime of an itx
structure differs than in OpenZFS. Specifically, the itx structure is
kept around until the data associated with the itx is considered to be
safe on disk; this is so that the itx's callback can be called after the
data is committed to stable storage. Since OpenZFS doesn't have this itx
callback mechanism, it's able to destroy the itx structure immediately
after the itx is committed to an lwb (before the lwb is written to
disk).
To support this difference, and to ensure the itx's callbacks can still
be called after the itx's data is on disk, a few changes had to be made:
* A list of itxs was added to the lwb structure. This list contains
all of the itxs that have been committed to the lwb, such that the
callbacks for these itxs can be called from zil_lwb_flush_vdevs_done(),
after the data for the itxs is committed to disk.
* A list of itxs was added on the stack of the zil_process_commit_list()
function; the "nolwb_itxs" list. In some circumstances, an itx may
not be committed to an lwb (e.g. if allocating the "next" ZIL block
on disk fails), so this list is used to keep track of which itxs
fall into this state, such that their callbacks can be called after
the ZIL's writer pipeline is "stalled".
* The logic to actually call the itx's callback was moved into the
zil_itx_destroy() function. Since all consumers of zil_itx_destroy()
were effectively performing the same logic (i.e. if callback is
non-null, call the callback), it seemed like useful code cleanup to
consolidate this logic into a single function.
Additionally, the existing Linux tracepoint infrastructure dealing with
the ZIL's probes and structures had to be updated to reflect these code
changes. Specifically:
* The "zil__cw1" and "zil__cw2" probes were removed, so they had to be
removed from "trace_zil.h" as well.
* Some of the zilog structure's fields were removed, which affected
the tracepoint definitions of the structure.
* New tracepoints had to be added for the following 3 new probes:
* zil__process__commit__itx
* zil__process__normal__itx
* zil__commit__io__error
OpenZFS-issue: https://www.illumos.org/issues/8585
OpenZFS-commit: https://github.com/openzfs/openzfs/commit/5d95a3a
Closes #6566
2017-12-05 20:39:16 +03:00
|
|
|
ASSERT0(tx->tx_threads);
|
2008-11-20 23:01:55 +03:00
|
|
|
|
|
|
|
mutex_destroy(&tx->tx_sync_lock);
|
|
|
|
|
2009-01-16 00:59:39 +03:00
|
|
|
cv_destroy(&tx->tx_sync_more_cv);
|
|
|
|
cv_destroy(&tx->tx_sync_done_cv);
|
|
|
|
cv_destroy(&tx->tx_quiesce_more_cv);
|
|
|
|
cv_destroy(&tx->tx_quiesce_done_cv);
|
|
|
|
cv_destroy(&tx->tx_exit_cv);
|
|
|
|
|
2008-11-20 23:01:55 +03:00
|
|
|
for (c = 0; c < max_ncpus; c++) {
|
|
|
|
int i;
|
|
|
|
|
2013-04-23 21:31:42 +04:00
|
|
|
mutex_destroy(&tx->tx_cpu[c].tc_open_lock);
|
2008-11-20 23:01:55 +03:00
|
|
|
mutex_destroy(&tx->tx_cpu[c].tc_lock);
|
2010-05-29 00:45:14 +04:00
|
|
|
for (i = 0; i < TXG_SIZE; i++) {
|
2008-11-20 23:01:55 +03:00
|
|
|
cv_destroy(&tx->tx_cpu[c].tc_cv[i]);
|
2010-05-29 00:45:14 +04:00
|
|
|
list_destroy(&tx->tx_cpu[c].tc_callbacks[i]);
|
|
|
|
}
|
2008-11-20 23:01:55 +03:00
|
|
|
}
|
|
|
|
|
2010-05-29 00:45:14 +04:00
|
|
|
if (tx->tx_commit_cb_taskq != NULL)
|
|
|
|
taskq_destroy(tx->tx_commit_cb_taskq);
|
|
|
|
|
2010-08-26 22:46:09 +04:00
|
|
|
vmem_free(tx->tx_cpu, max_ncpus * sizeof (tx_cpu_t));
|
2008-11-20 23:01:55 +03:00
|
|
|
|
|
|
|
bzero(tx, sizeof (tx_state_t));
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Start syncing transaction groups.
|
|
|
|
*/
|
|
|
|
void
|
|
|
|
txg_sync_start(dsl_pool_t *dp)
|
|
|
|
{
|
|
|
|
tx_state_t *tx = &dp->dp_tx;
|
|
|
|
|
|
|
|
mutex_enter(&tx->tx_sync_lock);
|
|
|
|
|
|
|
|
dprintf("pool %p\n", dp);
|
|
|
|
|
OpenZFS 8585 - improve batching done in zil_commit()
Authored by: Prakash Surya <prakash.surya@delphix.com>
Reviewed by: Brad Lewis <brad.lewis@delphix.com>
Reviewed by: Matt Ahrens <mahrens@delphix.com>
Reviewed by: George Wilson <george.wilson@delphix.com>
Reviewed-by: Brian Behlendorf <behlendorf1@llnl.gov>
Approved by: Dan McDonald <danmcd@joyent.com>
Ported-by: Prakash Surya <prakash.surya@delphix.com>
Problem
=======
The current implementation of zil_commit() can introduce significant
latency, beyond what is inherent due to the latency of the underlying
storage. The additional latency comes from two main problems:
1. When there's outstanding ZIL blocks being written (i.e. there's
already a "writer thread" in progress), then any new calls to
zil_commit() will block waiting for the currently oustanding ZIL
blocks to complete. The blocks written for each "writer thread" is
coined a "batch", and there can only ever be a single "batch" being
written at a time. When a batch is being written, any new ZIL
transactions will have to wait for the next batch to be written,
which won't occur until the current batch finishes.
As a result, the underlying storage may not be used as efficiently
as possible. While "new" threads enter zil_commit() and are blocked
waiting for the next batch, it's possible that the underlying
storage isn't fully utilized by the current batch of ZIL blocks. In
that case, it'd be better to allow these new threads to generate
(and issue) a new ZIL block, such that it could be serviced by the
underlying storage concurrently with the other ZIL blocks that are
being serviced.
2. Any call to zil_commit() must wait for all ZIL blocks in its "batch"
to complete, prior to zil_commit() returning. The size of any given
batch is proportional to the number of ZIL transaction in the queue
at the time that the batch starts processing the queue; which
doesn't occur until the previous batch completes. Thus, if there's a
lot of transactions in the queue, the batch could be composed of
many ZIL blocks, and each call to zil_commit() will have to wait for
all of these writes to complete (even if the thread calling
zil_commit() only cared about one of the transactions in the batch).
To further complicate the situation, these two issues result in the
following side effect:
3. If a given batch takes longer to complete than normal, this results
in larger batch sizes, which then take longer to complete and
further drive up the latency of zil_commit(). This can occur for a
number of reasons, including (but not limited to): transient changes
in the workload, and storage latency irregularites.
Solution
========
The solution attempted by this change has the following goals:
1. no on-disk changes; maintain current on-disk format.
2. modify the "batch size" to be equal to the "ZIL block size".
3. allow new batches to be generated and issued to disk, while there's
already batches being serviced by the disk.
4. allow zil_commit() to wait for as few ZIL blocks as possible.
5. use as few ZIL blocks as possible, for the same amount of ZIL
transactions, without introducing significant latency to any
individual ZIL transaction. i.e. use fewer, but larger, ZIL blocks.
In theory, with these goals met, the new allgorithm will allow the
following improvements:
1. new ZIL blocks can be generated and issued, while there's already
oustanding ZIL blocks being serviced by the storage.
2. the latency of zil_commit() should be proportional to the underlying
storage latency, rather than the incoming synchronous workload.
Porting Notes
=============
Due to the changes made in commit 119a394ab0, the lifetime of an itx
structure differs than in OpenZFS. Specifically, the itx structure is
kept around until the data associated with the itx is considered to be
safe on disk; this is so that the itx's callback can be called after the
data is committed to stable storage. Since OpenZFS doesn't have this itx
callback mechanism, it's able to destroy the itx structure immediately
after the itx is committed to an lwb (before the lwb is written to
disk).
To support this difference, and to ensure the itx's callbacks can still
be called after the itx's data is on disk, a few changes had to be made:
* A list of itxs was added to the lwb structure. This list contains
all of the itxs that have been committed to the lwb, such that the
callbacks for these itxs can be called from zil_lwb_flush_vdevs_done(),
after the data for the itxs is committed to disk.
* A list of itxs was added on the stack of the zil_process_commit_list()
function; the "nolwb_itxs" list. In some circumstances, an itx may
not be committed to an lwb (e.g. if allocating the "next" ZIL block
on disk fails), so this list is used to keep track of which itxs
fall into this state, such that their callbacks can be called after
the ZIL's writer pipeline is "stalled".
* The logic to actually call the itx's callback was moved into the
zil_itx_destroy() function. Since all consumers of zil_itx_destroy()
were effectively performing the same logic (i.e. if callback is
non-null, call the callback), it seemed like useful code cleanup to
consolidate this logic into a single function.
Additionally, the existing Linux tracepoint infrastructure dealing with
the ZIL's probes and structures had to be updated to reflect these code
changes. Specifically:
* The "zil__cw1" and "zil__cw2" probes were removed, so they had to be
removed from "trace_zil.h" as well.
* Some of the zilog structure's fields were removed, which affected
the tracepoint definitions of the structure.
* New tracepoints had to be added for the following 3 new probes:
* zil__process__commit__itx
* zil__process__normal__itx
* zil__commit__io__error
OpenZFS-issue: https://www.illumos.org/issues/8585
OpenZFS-commit: https://github.com/openzfs/openzfs/commit/5d95a3a
Closes #6566
2017-12-05 20:39:16 +03:00
|
|
|
ASSERT0(tx->tx_threads);
|
2008-11-20 23:01:55 +03:00
|
|
|
|
|
|
|
tx->tx_threads = 2;
|
|
|
|
|
|
|
|
tx->tx_quiesce_thread = thread_create(NULL, 0, txg_quiesce_thread,
|
2015-07-24 20:08:31 +03:00
|
|
|
dp, 0, &p0, TS_RUN, defclsyspri);
|
2008-11-20 23:01:55 +03:00
|
|
|
|
2008-12-03 23:09:06 +03:00
|
|
|
/*
|
|
|
|
* The sync thread can need a larger-than-default stack size on
|
|
|
|
* 32-bit x86. This is due in part to nested pools and
|
|
|
|
* scrub_visitbp() recursion.
|
|
|
|
*/
|
2016-01-13 21:41:24 +03:00
|
|
|
tx->tx_sync_thread = thread_create(NULL, 0, txg_sync_thread,
|
2015-07-24 20:08:31 +03:00
|
|
|
dp, 0, &p0, TS_RUN, defclsyspri);
|
2008-11-20 23:01:55 +03:00
|
|
|
|
|
|
|
mutex_exit(&tx->tx_sync_lock);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
txg_thread_enter(tx_state_t *tx, callb_cpr_t *cpr)
|
|
|
|
{
|
|
|
|
CALLB_CPR_INIT(cpr, &tx->tx_sync_lock, callb_generic_cpr, FTAG);
|
|
|
|
mutex_enter(&tx->tx_sync_lock);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
txg_thread_exit(tx_state_t *tx, callb_cpr_t *cpr, kthread_t **tpp)
|
|
|
|
{
|
|
|
|
ASSERT(*tpp != NULL);
|
|
|
|
*tpp = NULL;
|
|
|
|
tx->tx_threads--;
|
|
|
|
cv_broadcast(&tx->tx_exit_cv);
|
|
|
|
CALLB_CPR_EXIT(cpr); /* drops &tx->tx_sync_lock */
|
|
|
|
thread_exit();
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2013-08-29 03:05:48 +04:00
|
|
|
txg_thread_wait(tx_state_t *tx, callb_cpr_t *cpr, kcondvar_t *cv, clock_t time)
|
2008-11-20 23:01:55 +03:00
|
|
|
{
|
|
|
|
CALLB_CPR_SAFE_BEGIN(cpr);
|
|
|
|
|
2019-04-04 19:44:46 +03:00
|
|
|
if (time) {
|
2020-09-04 06:04:09 +03:00
|
|
|
(void) cv_timedwait_idle(cv, &tx->tx_sync_lock,
|
2010-05-29 00:45:14 +04:00
|
|
|
ddi_get_lbolt() + time);
|
2019-04-04 19:44:46 +03:00
|
|
|
} else {
|
2020-09-04 06:04:09 +03:00
|
|
|
cv_wait_idle(cv, &tx->tx_sync_lock);
|
2019-04-04 19:44:46 +03:00
|
|
|
}
|
2008-11-20 23:01:55 +03:00
|
|
|
|
|
|
|
CALLB_CPR_SAFE_END(cpr, &tx->tx_sync_lock);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Stop syncing transaction groups.
|
|
|
|
*/
|
|
|
|
void
|
|
|
|
txg_sync_stop(dsl_pool_t *dp)
|
|
|
|
{
|
|
|
|
tx_state_t *tx = &dp->dp_tx;
|
|
|
|
|
|
|
|
dprintf("pool %p\n", dp);
|
|
|
|
/*
|
|
|
|
* Finish off any work in progress.
|
|
|
|
*/
|
OpenZFS 8585 - improve batching done in zil_commit()
Authored by: Prakash Surya <prakash.surya@delphix.com>
Reviewed by: Brad Lewis <brad.lewis@delphix.com>
Reviewed by: Matt Ahrens <mahrens@delphix.com>
Reviewed by: George Wilson <george.wilson@delphix.com>
Reviewed-by: Brian Behlendorf <behlendorf1@llnl.gov>
Approved by: Dan McDonald <danmcd@joyent.com>
Ported-by: Prakash Surya <prakash.surya@delphix.com>
Problem
=======
The current implementation of zil_commit() can introduce significant
latency, beyond what is inherent due to the latency of the underlying
storage. The additional latency comes from two main problems:
1. When there's outstanding ZIL blocks being written (i.e. there's
already a "writer thread" in progress), then any new calls to
zil_commit() will block waiting for the currently oustanding ZIL
blocks to complete. The blocks written for each "writer thread" is
coined a "batch", and there can only ever be a single "batch" being
written at a time. When a batch is being written, any new ZIL
transactions will have to wait for the next batch to be written,
which won't occur until the current batch finishes.
As a result, the underlying storage may not be used as efficiently
as possible. While "new" threads enter zil_commit() and are blocked
waiting for the next batch, it's possible that the underlying
storage isn't fully utilized by the current batch of ZIL blocks. In
that case, it'd be better to allow these new threads to generate
(and issue) a new ZIL block, such that it could be serviced by the
underlying storage concurrently with the other ZIL blocks that are
being serviced.
2. Any call to zil_commit() must wait for all ZIL blocks in its "batch"
to complete, prior to zil_commit() returning. The size of any given
batch is proportional to the number of ZIL transaction in the queue
at the time that the batch starts processing the queue; which
doesn't occur until the previous batch completes. Thus, if there's a
lot of transactions in the queue, the batch could be composed of
many ZIL blocks, and each call to zil_commit() will have to wait for
all of these writes to complete (even if the thread calling
zil_commit() only cared about one of the transactions in the batch).
To further complicate the situation, these two issues result in the
following side effect:
3. If a given batch takes longer to complete than normal, this results
in larger batch sizes, which then take longer to complete and
further drive up the latency of zil_commit(). This can occur for a
number of reasons, including (but not limited to): transient changes
in the workload, and storage latency irregularites.
Solution
========
The solution attempted by this change has the following goals:
1. no on-disk changes; maintain current on-disk format.
2. modify the "batch size" to be equal to the "ZIL block size".
3. allow new batches to be generated and issued to disk, while there's
already batches being serviced by the disk.
4. allow zil_commit() to wait for as few ZIL blocks as possible.
5. use as few ZIL blocks as possible, for the same amount of ZIL
transactions, without introducing significant latency to any
individual ZIL transaction. i.e. use fewer, but larger, ZIL blocks.
In theory, with these goals met, the new allgorithm will allow the
following improvements:
1. new ZIL blocks can be generated and issued, while there's already
oustanding ZIL blocks being serviced by the storage.
2. the latency of zil_commit() should be proportional to the underlying
storage latency, rather than the incoming synchronous workload.
Porting Notes
=============
Due to the changes made in commit 119a394ab0, the lifetime of an itx
structure differs than in OpenZFS. Specifically, the itx structure is
kept around until the data associated with the itx is considered to be
safe on disk; this is so that the itx's callback can be called after the
data is committed to stable storage. Since OpenZFS doesn't have this itx
callback mechanism, it's able to destroy the itx structure immediately
after the itx is committed to an lwb (before the lwb is written to
disk).
To support this difference, and to ensure the itx's callbacks can still
be called after the itx's data is on disk, a few changes had to be made:
* A list of itxs was added to the lwb structure. This list contains
all of the itxs that have been committed to the lwb, such that the
callbacks for these itxs can be called from zil_lwb_flush_vdevs_done(),
after the data for the itxs is committed to disk.
* A list of itxs was added on the stack of the zil_process_commit_list()
function; the "nolwb_itxs" list. In some circumstances, an itx may
not be committed to an lwb (e.g. if allocating the "next" ZIL block
on disk fails), so this list is used to keep track of which itxs
fall into this state, such that their callbacks can be called after
the ZIL's writer pipeline is "stalled".
* The logic to actually call the itx's callback was moved into the
zil_itx_destroy() function. Since all consumers of zil_itx_destroy()
were effectively performing the same logic (i.e. if callback is
non-null, call the callback), it seemed like useful code cleanup to
consolidate this logic into a single function.
Additionally, the existing Linux tracepoint infrastructure dealing with
the ZIL's probes and structures had to be updated to reflect these code
changes. Specifically:
* The "zil__cw1" and "zil__cw2" probes were removed, so they had to be
removed from "trace_zil.h" as well.
* Some of the zilog structure's fields were removed, which affected
the tracepoint definitions of the structure.
* New tracepoints had to be added for the following 3 new probes:
* zil__process__commit__itx
* zil__process__normal__itx
* zil__commit__io__error
OpenZFS-issue: https://www.illumos.org/issues/8585
OpenZFS-commit: https://github.com/openzfs/openzfs/commit/5d95a3a
Closes #6566
2017-12-05 20:39:16 +03:00
|
|
|
ASSERT3U(tx->tx_threads, ==, 2);
|
2010-05-29 00:45:14 +04:00
|
|
|
|
|
|
|
/*
|
Log Spacemap Project
= Motivation
At Delphix we've seen a lot of customer systems where fragmentation
is over 75% and random writes take a performance hit because a lot
of time is spend on I/Os that update on-disk space accounting metadata.
Specifically, we seen cases where 20% to 40% of sync time is spend
after sync pass 1 and ~30% of the I/Os on the system is spent updating
spacemaps.
The problem is that these pools have existed long enough that we've
touched almost every metaslab at least once, and random writes
scatter frees across all metaslabs every TXG, thus appending to
their spacemaps and resulting in many I/Os. To give an example,
assuming that every VDEV has 200 metaslabs and our writes fit within
a single spacemap block (generally 4K) we have 200 I/Os. Then if we
assume 2 levels of indirection, we need 400 additional I/Os and
since we are talking about metadata for which we keep 2 extra copies
for redundancy we need to triple that number, leading to a total of
1800 I/Os per VDEV every TXG.
We could try and decrease the number of metaslabs so we have less
I/Os per TXG but then each metaslab would cover a wider range on
disk and thus would take more time to be loaded in memory from disk.
In addition, after it's loaded, it's range tree would consume more
memory.
Another idea would be to just increase the spacemap block size
which would allow us to fit more entries within an I/O block
resulting in fewer I/Os per metaslab and a speedup in loading time.
The problem is still that we don't deal with the number of I/Os
going up as the number of metaslabs is increasing and the fact
is that we generally write a lot to a few metaslabs and a little
to the rest of them. Thus, just increasing the block size would
actually waste bandwidth because we won't be utilizing our bigger
block size.
= About this patch
This patch introduces the Log Spacemap project which provides the
solution to the above problem while taking into account all the
aforementioned tradeoffs. The details on how it achieves that can
be found in the references sections below and in the code (see
Big Theory Statement in spa_log_spacemap.c).
Even though the change is fairly constraint within the metaslab
and lower-level SPA codepaths, there is a side-change that is
user-facing. The change is that VDEV IDs from VDEV holes will no
longer be reused. To give some background and reasoning for this,
when a log device is removed and its VDEV structure was replaced
with a hole (or was compacted; if at the end of the vdev array),
its vdev_id could be reused by devices added after that. Now
with the pool-wide space maps recording the vdev ID, this behavior
can cause problems (e.g. is this entry referring to a segment in
the new vdev or the removed log?). Thus, to simplify things the
ID reuse behavior is gone and now vdev IDs for top-level vdevs
are truly unique within a pool.
= Testing
The illumos implementation of this feature has been used internally
for a year and has been in production for ~6 months. For this patch
specifically there don't seem to be any regressions introduced to
ZTS and I have been running zloop for a week without any related
problems.
= Performance Analysis (Linux Specific)
All performance results and analysis for illumos can be found in
the links of the references. Redoing the same experiments in Linux
gave similar results. Below are the specifics of the Linux run.
After the pool reached stable state the percentage of the time
spent in pass 1 per TXG was 64% on average for the stock bits
while the log spacemap bits stayed at 95% during the experiment
(graph: sdimitro.github.io/img/linux-lsm/PercOfSyncInPassOne.png).
Sync times per TXG were 37.6 seconds on average for the stock
bits and 22.7 seconds for the log spacemap bits (related graph:
sdimitro.github.io/img/linux-lsm/SyncTimePerTXG.png). As a result
the log spacemap bits were able to push more TXGs, which is also
the reason why all graphs quantified per TXG have more entries for
the log spacemap bits.
Another interesting aspect in terms of txg syncs is that the stock
bits had 22% of their TXGs reach sync pass 7, 55% reach sync pass 8,
and 20% reach 9. The log space map bits reached sync pass 4 in 79%
of their TXGs, sync pass 7 in 19%, and sync pass 8 at 1%. This
emphasizes the fact that not only we spend less time on metadata
but we also iterate less times to convergence in spa_sync() dirtying
objects.
[related graphs:
stock- sdimitro.github.io/img/linux-lsm/NumberOfPassesPerTXGStock.png
lsm- sdimitro.github.io/img/linux-lsm/NumberOfPassesPerTXGLSM.png]
Finally, the improvement in IOPs that the userland gains from the
change is approximately 40%. There is a consistent win in IOPS as
you can see from the graphs below but the absolute amount of
improvement that the log spacemap gives varies within each minute
interval.
sdimitro.github.io/img/linux-lsm/StockVsLog3Days.png
sdimitro.github.io/img/linux-lsm/StockVsLog10Hours.png
= Porting to Other Platforms
For people that want to port this commit to other platforms below
is a list of ZoL commits that this patch depends on:
Make zdb results for checkpoint tests consistent
db587941c5ff6dea01932bb78f70db63cf7f38ba
Update vdev_is_spacemap_addressable() for new spacemap encoding
419ba5914552c6185afbe1dd17b3ed4b0d526547
Simplify spa_sync by breaking it up to smaller functions
8dc2197b7b1e4d7ebc1420ea30e51c6541f1d834
Factor metaslab_load_wait() in metaslab_load()
b194fab0fb6caad18711abccaff3c69ad8b3f6d3
Rename range_tree_verify to range_tree_verify_not_present
df72b8bebe0ebac0b20e0750984bad182cb6564a
Change target size of metaslabs from 256GB to 16GB
c853f382db731e15a87512f4ef1101d14d778a55
zdb -L should skip leak detection altogether
21e7cf5da89f55ce98ec1115726b150e19eefe89
vs_alloc can underflow in L2ARC vdevs
7558997d2f808368867ca7e5234e5793446e8f3f
Simplify log vdev removal code
6c926f426a26ffb6d7d8e563e33fc176164175cb
Get rid of space_map_update() for ms_synced_length
425d3237ee88abc53d8522a7139c926d278b4b7f
Introduce auxiliary metaslab histograms
928e8ad47d3478a3d5d01f0dd6ae74a9371af65e
Error path in metaslab_load_impl() forgets to drop ms_sync_lock
8eef997679ba54547f7d361553d21b3291f41ae7
= References
Background, Motivation, and Internals of the Feature
- OpenZFS 2017 Presentation:
youtu.be/jj2IxRkl5bQ
- Slides:
slideshare.net/SerapheimNikolaosDim/zfs-log-spacemaps-project
Flushing Algorithm Internals & Performance Results
(Illumos Specific)
- Blogpost:
sdimitro.github.io/post/zfs-lsm-flushing/
- OpenZFS 2018 Presentation:
youtu.be/x6D2dHRjkxw
- Slides:
slideshare.net/SerapheimNikolaosDim/zfs-log-spacemap-flushing-algorithm
Upstream Delphix Issues:
DLPX-51539, DLPX-59659, DLPX-57783, DLPX-61438, DLPX-41227, DLPX-59320
DLPX-63385
Reviewed-by: Sean Eric Fagan <sef@ixsystems.com>
Reviewed-by: Matt Ahrens <matt@delphix.com>
Reviewed-by: George Wilson <gwilson@delphix.com>
Reviewed-by: Brian Behlendorf <behlendorf1@llnl.gov>
Signed-off-by: Serapheim Dimitropoulos <serapheim@delphix.com>
Closes #8442
2019-07-16 20:11:49 +03:00
|
|
|
* We need to ensure that we've vacated the deferred metaslab trees.
|
2010-05-29 00:45:14 +04:00
|
|
|
*/
|
|
|
|
txg_wait_synced(dp, tx->tx_open_txg + TXG_DEFER_SIZE);
|
2008-11-20 23:01:55 +03:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Wake all sync threads and wait for them to die.
|
|
|
|
*/
|
|
|
|
mutex_enter(&tx->tx_sync_lock);
|
|
|
|
|
OpenZFS 8585 - improve batching done in zil_commit()
Authored by: Prakash Surya <prakash.surya@delphix.com>
Reviewed by: Brad Lewis <brad.lewis@delphix.com>
Reviewed by: Matt Ahrens <mahrens@delphix.com>
Reviewed by: George Wilson <george.wilson@delphix.com>
Reviewed-by: Brian Behlendorf <behlendorf1@llnl.gov>
Approved by: Dan McDonald <danmcd@joyent.com>
Ported-by: Prakash Surya <prakash.surya@delphix.com>
Problem
=======
The current implementation of zil_commit() can introduce significant
latency, beyond what is inherent due to the latency of the underlying
storage. The additional latency comes from two main problems:
1. When there's outstanding ZIL blocks being written (i.e. there's
already a "writer thread" in progress), then any new calls to
zil_commit() will block waiting for the currently oustanding ZIL
blocks to complete. The blocks written for each "writer thread" is
coined a "batch", and there can only ever be a single "batch" being
written at a time. When a batch is being written, any new ZIL
transactions will have to wait for the next batch to be written,
which won't occur until the current batch finishes.
As a result, the underlying storage may not be used as efficiently
as possible. While "new" threads enter zil_commit() and are blocked
waiting for the next batch, it's possible that the underlying
storage isn't fully utilized by the current batch of ZIL blocks. In
that case, it'd be better to allow these new threads to generate
(and issue) a new ZIL block, such that it could be serviced by the
underlying storage concurrently with the other ZIL blocks that are
being serviced.
2. Any call to zil_commit() must wait for all ZIL blocks in its "batch"
to complete, prior to zil_commit() returning. The size of any given
batch is proportional to the number of ZIL transaction in the queue
at the time that the batch starts processing the queue; which
doesn't occur until the previous batch completes. Thus, if there's a
lot of transactions in the queue, the batch could be composed of
many ZIL blocks, and each call to zil_commit() will have to wait for
all of these writes to complete (even if the thread calling
zil_commit() only cared about one of the transactions in the batch).
To further complicate the situation, these two issues result in the
following side effect:
3. If a given batch takes longer to complete than normal, this results
in larger batch sizes, which then take longer to complete and
further drive up the latency of zil_commit(). This can occur for a
number of reasons, including (but not limited to): transient changes
in the workload, and storage latency irregularites.
Solution
========
The solution attempted by this change has the following goals:
1. no on-disk changes; maintain current on-disk format.
2. modify the "batch size" to be equal to the "ZIL block size".
3. allow new batches to be generated and issued to disk, while there's
already batches being serviced by the disk.
4. allow zil_commit() to wait for as few ZIL blocks as possible.
5. use as few ZIL blocks as possible, for the same amount of ZIL
transactions, without introducing significant latency to any
individual ZIL transaction. i.e. use fewer, but larger, ZIL blocks.
In theory, with these goals met, the new allgorithm will allow the
following improvements:
1. new ZIL blocks can be generated and issued, while there's already
oustanding ZIL blocks being serviced by the storage.
2. the latency of zil_commit() should be proportional to the underlying
storage latency, rather than the incoming synchronous workload.
Porting Notes
=============
Due to the changes made in commit 119a394ab0, the lifetime of an itx
structure differs than in OpenZFS. Specifically, the itx structure is
kept around until the data associated with the itx is considered to be
safe on disk; this is so that the itx's callback can be called after the
data is committed to stable storage. Since OpenZFS doesn't have this itx
callback mechanism, it's able to destroy the itx structure immediately
after the itx is committed to an lwb (before the lwb is written to
disk).
To support this difference, and to ensure the itx's callbacks can still
be called after the itx's data is on disk, a few changes had to be made:
* A list of itxs was added to the lwb structure. This list contains
all of the itxs that have been committed to the lwb, such that the
callbacks for these itxs can be called from zil_lwb_flush_vdevs_done(),
after the data for the itxs is committed to disk.
* A list of itxs was added on the stack of the zil_process_commit_list()
function; the "nolwb_itxs" list. In some circumstances, an itx may
not be committed to an lwb (e.g. if allocating the "next" ZIL block
on disk fails), so this list is used to keep track of which itxs
fall into this state, such that their callbacks can be called after
the ZIL's writer pipeline is "stalled".
* The logic to actually call the itx's callback was moved into the
zil_itx_destroy() function. Since all consumers of zil_itx_destroy()
were effectively performing the same logic (i.e. if callback is
non-null, call the callback), it seemed like useful code cleanup to
consolidate this logic into a single function.
Additionally, the existing Linux tracepoint infrastructure dealing with
the ZIL's probes and structures had to be updated to reflect these code
changes. Specifically:
* The "zil__cw1" and "zil__cw2" probes were removed, so they had to be
removed from "trace_zil.h" as well.
* Some of the zilog structure's fields were removed, which affected
the tracepoint definitions of the structure.
* New tracepoints had to be added for the following 3 new probes:
* zil__process__commit__itx
* zil__process__normal__itx
* zil__commit__io__error
OpenZFS-issue: https://www.illumos.org/issues/8585
OpenZFS-commit: https://github.com/openzfs/openzfs/commit/5d95a3a
Closes #6566
2017-12-05 20:39:16 +03:00
|
|
|
ASSERT3U(tx->tx_threads, ==, 2);
|
2008-11-20 23:01:55 +03:00
|
|
|
|
|
|
|
tx->tx_exiting = 1;
|
|
|
|
|
|
|
|
cv_broadcast(&tx->tx_quiesce_more_cv);
|
|
|
|
cv_broadcast(&tx->tx_quiesce_done_cv);
|
|
|
|
cv_broadcast(&tx->tx_sync_more_cv);
|
|
|
|
|
|
|
|
while (tx->tx_threads != 0)
|
|
|
|
cv_wait(&tx->tx_exit_cv, &tx->tx_sync_lock);
|
|
|
|
|
|
|
|
tx->tx_exiting = 0;
|
|
|
|
|
|
|
|
mutex_exit(&tx->tx_sync_lock);
|
|
|
|
}
|
|
|
|
|
2021-01-25 15:13:45 +03:00
|
|
|
/*
|
|
|
|
* Get a handle on the currently open txg and keep it open.
|
|
|
|
*
|
|
|
|
* The txg is guaranteed to stay open until txg_rele_to_quiesce() is called for
|
|
|
|
* the handle. Once txg_rele_to_quiesce() has been called, the txg stays
|
|
|
|
* in quiescing state until txg_rele_to_sync() is called for the handle.
|
|
|
|
*
|
|
|
|
* It is guaranteed that subsequent calls return monotonically increasing
|
|
|
|
* txgs for the same dsl_pool_t. Of course this is not strong monotonicity,
|
|
|
|
* because the same txg can be returned multiple times in a row. This
|
|
|
|
* guarantee holds both for subsequent calls from one thread and for multiple
|
|
|
|
* threads. For example, it is impossible to observe the following sequence
|
|
|
|
* of events:
|
|
|
|
*
|
|
|
|
* Thread 1 Thread 2
|
|
|
|
*
|
|
|
|
* 1 <- txg_hold_open(P, ...)
|
|
|
|
* 2 <- txg_hold_open(P, ...)
|
|
|
|
* 1 <- txg_hold_open(P, ...)
|
|
|
|
*
|
|
|
|
*/
|
2008-11-20 23:01:55 +03:00
|
|
|
uint64_t
|
|
|
|
txg_hold_open(dsl_pool_t *dp, txg_handle_t *th)
|
|
|
|
{
|
|
|
|
tx_state_t *tx = &dp->dp_tx;
|
2012-08-24 04:45:31 +04:00
|
|
|
tx_cpu_t *tc;
|
2008-11-20 23:01:55 +03:00
|
|
|
uint64_t txg;
|
|
|
|
|
2012-08-24 04:45:31 +04:00
|
|
|
/*
|
|
|
|
* It appears the processor id is simply used as a "random"
|
|
|
|
* number to index into the array, and there isn't any other
|
|
|
|
* significance to the chosen tx_cpu. Because.. Why not use
|
|
|
|
* the current cpu to index into the array?
|
|
|
|
*/
|
2020-11-02 22:51:12 +03:00
|
|
|
tc = &tx->tx_cpu[CPU_SEQID_UNSTABLE];
|
2012-08-24 04:45:31 +04:00
|
|
|
|
2013-04-23 21:31:42 +04:00
|
|
|
mutex_enter(&tc->tc_open_lock);
|
2008-11-20 23:01:55 +03:00
|
|
|
txg = tx->tx_open_txg;
|
2013-04-23 21:31:42 +04:00
|
|
|
|
|
|
|
mutex_enter(&tc->tc_lock);
|
2008-11-20 23:01:55 +03:00
|
|
|
tc->tc_count[txg & TXG_MASK]++;
|
2013-04-23 21:31:42 +04:00
|
|
|
mutex_exit(&tc->tc_lock);
|
2008-11-20 23:01:55 +03:00
|
|
|
|
|
|
|
th->th_cpu = tc;
|
|
|
|
th->th_txg = txg;
|
|
|
|
|
|
|
|
return (txg);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
txg_rele_to_quiesce(txg_handle_t *th)
|
|
|
|
{
|
|
|
|
tx_cpu_t *tc = th->th_cpu;
|
|
|
|
|
2013-04-23 21:31:42 +04:00
|
|
|
ASSERT(!MUTEX_HELD(&tc->tc_lock));
|
|
|
|
mutex_exit(&tc->tc_open_lock);
|
2008-11-20 23:01:55 +03:00
|
|
|
}
|
|
|
|
|
2010-05-29 00:45:14 +04:00
|
|
|
void
|
|
|
|
txg_register_callbacks(txg_handle_t *th, list_t *tx_callbacks)
|
|
|
|
{
|
|
|
|
tx_cpu_t *tc = th->th_cpu;
|
|
|
|
int g = th->th_txg & TXG_MASK;
|
|
|
|
|
|
|
|
mutex_enter(&tc->tc_lock);
|
|
|
|
list_move_tail(&tc->tc_callbacks[g], tx_callbacks);
|
|
|
|
mutex_exit(&tc->tc_lock);
|
|
|
|
}
|
|
|
|
|
2008-11-20 23:01:55 +03:00
|
|
|
void
|
|
|
|
txg_rele_to_sync(txg_handle_t *th)
|
|
|
|
{
|
|
|
|
tx_cpu_t *tc = th->th_cpu;
|
|
|
|
int g = th->th_txg & TXG_MASK;
|
|
|
|
|
|
|
|
mutex_enter(&tc->tc_lock);
|
|
|
|
ASSERT(tc->tc_count[g] != 0);
|
|
|
|
if (--tc->tc_count[g] == 0)
|
|
|
|
cv_broadcast(&tc->tc_cv[g]);
|
|
|
|
mutex_exit(&tc->tc_lock);
|
|
|
|
|
|
|
|
th->th_cpu = NULL; /* defensive */
|
|
|
|
}
|
|
|
|
|
2013-06-11 21:12:34 +04:00
|
|
|
/*
|
|
|
|
* Blocks until all transactions in the group are committed.
|
|
|
|
*
|
|
|
|
* On return, the transaction group has reached a stable state in which it can
|
|
|
|
* then be passed off to the syncing context.
|
|
|
|
*/
|
2008-11-20 23:01:55 +03:00
|
|
|
static void
|
|
|
|
txg_quiesce(dsl_pool_t *dp, uint64_t txg)
|
|
|
|
{
|
|
|
|
tx_state_t *tx = &dp->dp_tx;
|
2016-02-18 00:16:25 +03:00
|
|
|
uint64_t tx_open_time;
|
2008-11-20 23:01:55 +03:00
|
|
|
int g = txg & TXG_MASK;
|
|
|
|
int c;
|
|
|
|
|
|
|
|
/*
|
2013-04-23 21:31:42 +04:00
|
|
|
* Grab all tc_open_locks so nobody else can get into this txg.
|
2008-11-20 23:01:55 +03:00
|
|
|
*/
|
|
|
|
for (c = 0; c < max_ncpus; c++)
|
2013-04-23 21:31:42 +04:00
|
|
|
mutex_enter(&tx->tx_cpu[c].tc_open_lock);
|
2008-11-20 23:01:55 +03:00
|
|
|
|
|
|
|
ASSERT(txg == tx->tx_open_txg);
|
|
|
|
tx->tx_open_txg++;
|
2016-02-18 00:16:25 +03:00
|
|
|
tx->tx_open_time = tx_open_time = gethrtime();
|
2013-10-01 20:50:50 +04:00
|
|
|
|
2013-08-29 03:05:48 +04:00
|
|
|
DTRACE_PROBE2(txg__quiescing, dsl_pool_t *, dp, uint64_t, txg);
|
|
|
|
DTRACE_PROBE2(txg__opened, dsl_pool_t *, dp, uint64_t, tx->tx_open_txg);
|
|
|
|
|
2013-04-26 03:29:22 +04:00
|
|
|
/*
|
|
|
|
* Now that we've incremented tx_open_txg, we can let threads
|
|
|
|
* enter the next transaction group.
|
|
|
|
*/
|
|
|
|
for (c = 0; c < max_ncpus; c++)
|
2013-04-23 21:31:42 +04:00
|
|
|
mutex_exit(&tx->tx_cpu[c].tc_open_lock);
|
2013-04-26 03:29:22 +04:00
|
|
|
|
2016-02-18 00:16:25 +03:00
|
|
|
spa_txg_history_set(dp->dp_spa, txg, TXG_STATE_OPEN, tx_open_time);
|
|
|
|
spa_txg_history_add(dp->dp_spa, txg + 1, tx_open_time);
|
|
|
|
|
2008-11-20 23:01:55 +03:00
|
|
|
/*
|
2021-01-25 15:13:45 +03:00
|
|
|
* Quiesce the transaction group by waiting for everyone to
|
|
|
|
* call txg_rele_to_sync() for their open transaction handles.
|
2008-11-20 23:01:55 +03:00
|
|
|
*/
|
|
|
|
for (c = 0; c < max_ncpus; c++) {
|
|
|
|
tx_cpu_t *tc = &tx->tx_cpu[c];
|
|
|
|
mutex_enter(&tc->tc_lock);
|
|
|
|
while (tc->tc_count[g] != 0)
|
|
|
|
cv_wait(&tc->tc_cv[g], &tc->tc_lock);
|
|
|
|
mutex_exit(&tc->tc_lock);
|
|
|
|
}
|
2013-10-01 20:50:50 +04:00
|
|
|
|
|
|
|
spa_txg_history_set(dp->dp_spa, txg, TXG_STATE_QUIESCED, gethrtime());
|
2008-11-20 23:01:55 +03:00
|
|
|
}
|
|
|
|
|
2010-05-29 00:45:14 +04:00
|
|
|
static void
|
|
|
|
txg_do_callbacks(list_t *cb_list)
|
|
|
|
{
|
|
|
|
dmu_tx_do_callbacks(cb_list, 0);
|
|
|
|
|
|
|
|
list_destroy(cb_list);
|
|
|
|
|
|
|
|
kmem_free(cb_list, sizeof (list_t));
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Dispatch the commit callbacks registered on this txg to worker threads.
|
2013-06-11 21:12:34 +04:00
|
|
|
*
|
|
|
|
* If no callbacks are registered for a given TXG, nothing happens.
|
|
|
|
* This function creates a taskq for the associated pool, if needed.
|
2010-05-29 00:45:14 +04:00
|
|
|
*/
|
|
|
|
static void
|
|
|
|
txg_dispatch_callbacks(dsl_pool_t *dp, uint64_t txg)
|
|
|
|
{
|
|
|
|
int c;
|
|
|
|
tx_state_t *tx = &dp->dp_tx;
|
|
|
|
list_t *cb_list;
|
|
|
|
|
|
|
|
for (c = 0; c < max_ncpus; c++) {
|
|
|
|
tx_cpu_t *tc = &tx->tx_cpu[c];
|
2013-06-11 21:12:34 +04:00
|
|
|
/*
|
|
|
|
* No need to lock tx_cpu_t at this point, since this can
|
|
|
|
* only be called once a txg has been synced.
|
|
|
|
*/
|
2010-05-29 00:45:14 +04:00
|
|
|
|
|
|
|
int g = txg & TXG_MASK;
|
|
|
|
|
|
|
|
if (list_is_empty(&tc->tc_callbacks[g]))
|
|
|
|
continue;
|
|
|
|
|
|
|
|
if (tx->tx_commit_cb_taskq == NULL) {
|
|
|
|
/*
|
|
|
|
* Commit callback taskq hasn't been created yet.
|
|
|
|
*/
|
|
|
|
tx->tx_commit_cb_taskq = taskq_create("tx_commit_cb",
|
2020-12-11 01:09:23 +03:00
|
|
|
100, defclsyspri, boot_ncpus, boot_ncpus * 2,
|
|
|
|
TASKQ_PREPOPULATE | TASKQ_DYNAMIC |
|
|
|
|
TASKQ_THREADS_CPU_PCT);
|
2010-05-29 00:45:14 +04:00
|
|
|
}
|
|
|
|
|
2014-11-21 03:09:39 +03:00
|
|
|
cb_list = kmem_alloc(sizeof (list_t), KM_SLEEP);
|
2010-05-29 00:45:14 +04:00
|
|
|
list_create(cb_list, sizeof (dmu_tx_callback_t),
|
|
|
|
offsetof(dmu_tx_callback_t, dcb_node));
|
|
|
|
|
2010-08-26 21:17:18 +04:00
|
|
|
list_move_tail(cb_list, &tc->tc_callbacks[g]);
|
2010-05-29 00:45:14 +04:00
|
|
|
|
|
|
|
(void) taskq_dispatch(tx->tx_commit_cb_taskq, (task_func_t *)
|
|
|
|
txg_do_callbacks, cb_list, TQ_SLEEP);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-01-22 01:35:41 +03:00
|
|
|
/*
|
|
|
|
* Wait for pending commit callbacks of already-synced transactions to finish
|
|
|
|
* processing.
|
|
|
|
* Calling this function from within a commit callback will deadlock.
|
|
|
|
*/
|
|
|
|
void
|
|
|
|
txg_wait_callbacks(dsl_pool_t *dp)
|
|
|
|
{
|
|
|
|
tx_state_t *tx = &dp->dp_tx;
|
|
|
|
|
|
|
|
if (tx->tx_commit_cb_taskq != NULL)
|
2015-06-05 21:26:35 +03:00
|
|
|
taskq_wait_outstanding(tx->tx_commit_cb_taskq, 0);
|
2011-01-22 01:35:41 +03:00
|
|
|
}
|
|
|
|
|
2017-12-05 20:45:46 +03:00
|
|
|
static boolean_t
|
|
|
|
txg_is_quiescing(dsl_pool_t *dp)
|
|
|
|
{
|
|
|
|
tx_state_t *tx = &dp->dp_tx;
|
|
|
|
ASSERT(MUTEX_HELD(&tx->tx_sync_lock));
|
|
|
|
return (tx->tx_quiescing_txg != 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
static boolean_t
|
|
|
|
txg_has_quiesced_to_sync(dsl_pool_t *dp)
|
|
|
|
{
|
|
|
|
tx_state_t *tx = &dp->dp_tx;
|
|
|
|
ASSERT(MUTEX_HELD(&tx->tx_sync_lock));
|
|
|
|
return (tx->tx_quiesced_txg != 0);
|
|
|
|
}
|
|
|
|
|
2022-03-05 03:25:22 +03:00
|
|
|
static _Noreturn void
|
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
|
|
|
txg_sync_thread(void *arg)
|
2008-11-20 23:01:55 +03:00
|
|
|
{
|
2017-10-27 22:46:35 +03:00
|
|
|
dsl_pool_t *dp = arg;
|
2010-05-29 00:45:14 +04:00
|
|
|
spa_t *spa = dp->dp_spa;
|
2008-11-20 23:01:55 +03:00
|
|
|
tx_state_t *tx = &dp->dp_tx;
|
|
|
|
callb_cpr_t cpr;
|
2014-02-25 13:32:21 +04:00
|
|
|
clock_t start, delta;
|
2008-11-20 23:01:55 +03:00
|
|
|
|
2014-07-13 22:35:19 +04:00
|
|
|
(void) spl_fstrans_mark();
|
2008-11-20 23:01:55 +03:00
|
|
|
txg_thread_enter(tx, &cpr);
|
|
|
|
|
|
|
|
start = delta = 0;
|
|
|
|
for (;;) {
|
2016-12-03 02:57:49 +03:00
|
|
|
clock_t timeout = zfs_txg_timeout * hz;
|
|
|
|
clock_t timer;
|
2008-12-03 23:09:06 +03:00
|
|
|
uint64_t txg;
|
2012-10-12 00:56:32 +04:00
|
|
|
|
2008-11-20 23:01:55 +03:00
|
|
|
/*
|
2010-05-29 00:45:14 +04:00
|
|
|
* We sync when we're scanning, there's someone waiting
|
2008-12-03 23:09:06 +03:00
|
|
|
* on us, or the quiesce thread has handed off a txg to
|
|
|
|
* us, or we have reached our timeout.
|
2008-11-20 23:01:55 +03:00
|
|
|
*/
|
|
|
|
timer = (delta >= timeout ? 0 : timeout - delta);
|
2010-05-29 00:45:14 +04:00
|
|
|
while (!dsl_scan_active(dp->dp_scan) &&
|
2008-12-03 23:09:06 +03:00
|
|
|
!tx->tx_exiting && timer > 0 &&
|
2008-11-20 23:01:55 +03:00
|
|
|
tx->tx_synced_txg >= tx->tx_sync_txg_waiting &&
|
2021-07-01 18:20:27 +03:00
|
|
|
!txg_has_quiesced_to_sync(dp)) {
|
2008-11-20 23:01:55 +03:00
|
|
|
dprintf("waiting; tx_synced=%llu waiting=%llu dp=%p\n",
|
2021-06-23 07:53:45 +03:00
|
|
|
(u_longlong_t)tx->tx_synced_txg,
|
|
|
|
(u_longlong_t)tx->tx_sync_txg_waiting, dp);
|
2008-11-20 23:01:55 +03:00
|
|
|
txg_thread_wait(tx, &cpr, &tx->tx_sync_more_cv, timer);
|
2010-05-29 00:45:14 +04:00
|
|
|
delta = ddi_get_lbolt() - start;
|
2008-11-20 23:01:55 +03:00
|
|
|
timer = (delta > timeout ? 0 : timeout - delta);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Wait until the quiesce thread hands off a txg to us,
|
|
|
|
* prompting it to do so if necessary.
|
|
|
|
*/
|
2017-12-05 20:45:46 +03:00
|
|
|
while (!tx->tx_exiting && !txg_has_quiesced_to_sync(dp)) {
|
2021-07-01 18:20:27 +03:00
|
|
|
if (txg_is_quiescing(dp)) {
|
|
|
|
txg_thread_wait(tx, &cpr,
|
|
|
|
&tx->tx_quiesce_done_cv, 0);
|
|
|
|
continue;
|
|
|
|
}
|
2008-11-20 23:01:55 +03:00
|
|
|
if (tx->tx_quiesce_txg_waiting < tx->tx_open_txg+1)
|
|
|
|
tx->tx_quiesce_txg_waiting = tx->tx_open_txg+1;
|
|
|
|
cv_broadcast(&tx->tx_quiesce_more_cv);
|
|
|
|
txg_thread_wait(tx, &cpr, &tx->tx_quiesce_done_cv, 0);
|
|
|
|
}
|
|
|
|
|
2016-12-03 02:57:49 +03:00
|
|
|
if (tx->tx_exiting)
|
2008-11-20 23:01:55 +03:00
|
|
|
txg_thread_exit(tx, &cpr, &tx->tx_sync_thread);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Consume the quiesced txg which has been handed off to
|
|
|
|
* us. This may cause the quiescing thread to now be
|
|
|
|
* able to quiesce another txg, so we must signal it.
|
|
|
|
*/
|
2017-12-05 20:45:46 +03:00
|
|
|
ASSERT(tx->tx_quiesced_txg != 0);
|
2008-11-20 23:01:55 +03:00
|
|
|
txg = tx->tx_quiesced_txg;
|
|
|
|
tx->tx_quiesced_txg = 0;
|
|
|
|
tx->tx_syncing_txg = txg;
|
2013-08-29 03:05:48 +04:00
|
|
|
DTRACE_PROBE2(txg__syncing, dsl_pool_t *, dp, uint64_t, txg);
|
2008-11-20 23:01:55 +03:00
|
|
|
cv_broadcast(&tx->tx_quiesce_more_cv);
|
|
|
|
|
|
|
|
dprintf("txg=%llu quiesce_txg=%llu sync_txg=%llu\n",
|
2021-06-23 07:53:45 +03:00
|
|
|
(u_longlong_t)txg, (u_longlong_t)tx->tx_quiesce_txg_waiting,
|
|
|
|
(u_longlong_t)tx->tx_sync_txg_waiting);
|
2008-11-20 23:01:55 +03:00
|
|
|
mutex_exit(&tx->tx_sync_lock);
|
2008-12-03 23:09:06 +03:00
|
|
|
|
2018-10-17 00:00:55 +03:00
|
|
|
txg_stat_t *ts = spa_txg_history_init_io(spa, txg, dp);
|
2010-05-29 00:45:14 +04:00
|
|
|
start = ddi_get_lbolt();
|
|
|
|
spa_sync(spa, txg);
|
|
|
|
delta = ddi_get_lbolt() - start;
|
2018-10-17 00:00:55 +03:00
|
|
|
spa_txg_history_fini_io(spa, ts);
|
2008-11-20 23:01:55 +03:00
|
|
|
|
|
|
|
mutex_enter(&tx->tx_sync_lock);
|
|
|
|
tx->tx_synced_txg = txg;
|
|
|
|
tx->tx_syncing_txg = 0;
|
2013-08-29 03:05:48 +04:00
|
|
|
DTRACE_PROBE2(txg__synced, dsl_pool_t *, dp, uint64_t, txg);
|
2008-11-20 23:01:55 +03:00
|
|
|
cv_broadcast(&tx->tx_sync_done_cv);
|
2010-05-29 00:45:14 +04:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Dispatch commit callbacks to worker threads.
|
|
|
|
*/
|
|
|
|
txg_dispatch_callbacks(dp, txg);
|
2008-11-20 23:01:55 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-03-05 03:25:22 +03:00
|
|
|
static _Noreturn void
|
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
|
|
|
txg_quiesce_thread(void *arg)
|
2008-11-20 23:01:55 +03:00
|
|
|
{
|
2017-10-27 22:46:35 +03:00
|
|
|
dsl_pool_t *dp = arg;
|
2008-11-20 23:01:55 +03:00
|
|
|
tx_state_t *tx = &dp->dp_tx;
|
|
|
|
callb_cpr_t cpr;
|
|
|
|
|
|
|
|
txg_thread_enter(tx, &cpr);
|
|
|
|
|
|
|
|
for (;;) {
|
|
|
|
uint64_t txg;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* We quiesce when there's someone waiting on us.
|
|
|
|
* However, we can only have one txg in "quiescing" or
|
|
|
|
* "quiesced, waiting to sync" state. So we wait until
|
|
|
|
* the "quiesced, waiting to sync" txg has been consumed
|
|
|
|
* by the sync thread.
|
|
|
|
*/
|
|
|
|
while (!tx->tx_exiting &&
|
|
|
|
(tx->tx_open_txg >= tx->tx_quiesce_txg_waiting ||
|
2017-12-05 20:45:46 +03:00
|
|
|
txg_has_quiesced_to_sync(dp)))
|
2008-11-20 23:01:55 +03:00
|
|
|
txg_thread_wait(tx, &cpr, &tx->tx_quiesce_more_cv, 0);
|
|
|
|
|
|
|
|
if (tx->tx_exiting)
|
|
|
|
txg_thread_exit(tx, &cpr, &tx->tx_quiesce_thread);
|
|
|
|
|
|
|
|
txg = tx->tx_open_txg;
|
|
|
|
dprintf("txg=%llu quiesce_txg=%llu sync_txg=%llu\n",
|
2021-06-23 07:53:45 +03:00
|
|
|
(u_longlong_t)txg,
|
|
|
|
(u_longlong_t)tx->tx_quiesce_txg_waiting,
|
|
|
|
(u_longlong_t)tx->tx_sync_txg_waiting);
|
2017-12-05 20:45:46 +03:00
|
|
|
tx->tx_quiescing_txg = txg;
|
|
|
|
|
2008-11-20 23:01:55 +03:00
|
|
|
mutex_exit(&tx->tx_sync_lock);
|
|
|
|
txg_quiesce(dp, txg);
|
|
|
|
mutex_enter(&tx->tx_sync_lock);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Hand this txg off to the sync thread.
|
|
|
|
*/
|
2021-06-23 07:53:45 +03:00
|
|
|
dprintf("quiesce done, handing off txg %llu\n",
|
|
|
|
(u_longlong_t)txg);
|
2017-12-05 20:45:46 +03:00
|
|
|
tx->tx_quiescing_txg = 0;
|
2008-11-20 23:01:55 +03:00
|
|
|
tx->tx_quiesced_txg = txg;
|
2013-08-29 03:05:48 +04:00
|
|
|
DTRACE_PROBE2(txg__quiesced, dsl_pool_t *, dp, uint64_t, txg);
|
2008-11-20 23:01:55 +03:00
|
|
|
cv_broadcast(&tx->tx_sync_more_cv);
|
|
|
|
cv_broadcast(&tx->tx_quiesce_done_cv);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
2013-08-29 03:05:48 +04:00
|
|
|
* Delay this thread by delay nanoseconds if we are still in the open
|
2019-09-03 03:56:41 +03:00
|
|
|
* transaction group and there is already a waiting txg quiescing or quiesced.
|
|
|
|
* Abort the delay if this txg stalls or enters the quiescing state.
|
2008-11-20 23:01:55 +03:00
|
|
|
*/
|
|
|
|
void
|
2013-08-29 03:05:48 +04:00
|
|
|
txg_delay(dsl_pool_t *dp, uint64_t txg, hrtime_t delay, hrtime_t resolution)
|
2008-11-20 23:01:55 +03:00
|
|
|
{
|
|
|
|
tx_state_t *tx = &dp->dp_tx;
|
2013-08-29 03:05:48 +04:00
|
|
|
hrtime_t start = gethrtime();
|
2008-11-20 23:01:55 +03:00
|
|
|
|
2013-06-11 21:12:34 +04:00
|
|
|
/* don't delay if this txg could transition to quiescing immediately */
|
2008-11-20 23:01:55 +03:00
|
|
|
if (tx->tx_open_txg > txg ||
|
|
|
|
tx->tx_syncing_txg == txg-1 || tx->tx_synced_txg == txg-1)
|
|
|
|
return;
|
|
|
|
|
|
|
|
mutex_enter(&tx->tx_sync_lock);
|
|
|
|
if (tx->tx_open_txg > txg || tx->tx_synced_txg == txg-1) {
|
|
|
|
mutex_exit(&tx->tx_sync_lock);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2013-08-29 03:05:48 +04:00
|
|
|
while (gethrtime() - start < delay &&
|
|
|
|
tx->tx_syncing_txg < txg-1 && !txg_stalled(dp)) {
|
|
|
|
(void) cv_timedwait_hires(&tx->tx_quiesce_more_cv,
|
|
|
|
&tx->tx_sync_lock, delay, resolution, 0);
|
|
|
|
}
|
2008-11-20 23:01:55 +03:00
|
|
|
|
2012-01-20 22:58:57 +04:00
|
|
|
DMU_TX_STAT_BUMP(dmu_tx_delay);
|
|
|
|
|
2008-11-20 23:01:55 +03:00
|
|
|
mutex_exit(&tx->tx_sync_lock);
|
|
|
|
}
|
|
|
|
|
2019-06-23 02:51:46 +03:00
|
|
|
static boolean_t
|
|
|
|
txg_wait_synced_impl(dsl_pool_t *dp, uint64_t txg, boolean_t wait_sig)
|
2008-11-20 23:01:55 +03:00
|
|
|
{
|
|
|
|
tx_state_t *tx = &dp->dp_tx;
|
|
|
|
|
2013-09-04 16:00:57 +04:00
|
|
|
ASSERT(!dsl_pool_config_held(dp));
|
|
|
|
|
2008-11-20 23:01:55 +03:00
|
|
|
mutex_enter(&tx->tx_sync_lock);
|
OpenZFS 8585 - improve batching done in zil_commit()
Authored by: Prakash Surya <prakash.surya@delphix.com>
Reviewed by: Brad Lewis <brad.lewis@delphix.com>
Reviewed by: Matt Ahrens <mahrens@delphix.com>
Reviewed by: George Wilson <george.wilson@delphix.com>
Reviewed-by: Brian Behlendorf <behlendorf1@llnl.gov>
Approved by: Dan McDonald <danmcd@joyent.com>
Ported-by: Prakash Surya <prakash.surya@delphix.com>
Problem
=======
The current implementation of zil_commit() can introduce significant
latency, beyond what is inherent due to the latency of the underlying
storage. The additional latency comes from two main problems:
1. When there's outstanding ZIL blocks being written (i.e. there's
already a "writer thread" in progress), then any new calls to
zil_commit() will block waiting for the currently oustanding ZIL
blocks to complete. The blocks written for each "writer thread" is
coined a "batch", and there can only ever be a single "batch" being
written at a time. When a batch is being written, any new ZIL
transactions will have to wait for the next batch to be written,
which won't occur until the current batch finishes.
As a result, the underlying storage may not be used as efficiently
as possible. While "new" threads enter zil_commit() and are blocked
waiting for the next batch, it's possible that the underlying
storage isn't fully utilized by the current batch of ZIL blocks. In
that case, it'd be better to allow these new threads to generate
(and issue) a new ZIL block, such that it could be serviced by the
underlying storage concurrently with the other ZIL blocks that are
being serviced.
2. Any call to zil_commit() must wait for all ZIL blocks in its "batch"
to complete, prior to zil_commit() returning. The size of any given
batch is proportional to the number of ZIL transaction in the queue
at the time that the batch starts processing the queue; which
doesn't occur until the previous batch completes. Thus, if there's a
lot of transactions in the queue, the batch could be composed of
many ZIL blocks, and each call to zil_commit() will have to wait for
all of these writes to complete (even if the thread calling
zil_commit() only cared about one of the transactions in the batch).
To further complicate the situation, these two issues result in the
following side effect:
3. If a given batch takes longer to complete than normal, this results
in larger batch sizes, which then take longer to complete and
further drive up the latency of zil_commit(). This can occur for a
number of reasons, including (but not limited to): transient changes
in the workload, and storage latency irregularites.
Solution
========
The solution attempted by this change has the following goals:
1. no on-disk changes; maintain current on-disk format.
2. modify the "batch size" to be equal to the "ZIL block size".
3. allow new batches to be generated and issued to disk, while there's
already batches being serviced by the disk.
4. allow zil_commit() to wait for as few ZIL blocks as possible.
5. use as few ZIL blocks as possible, for the same amount of ZIL
transactions, without introducing significant latency to any
individual ZIL transaction. i.e. use fewer, but larger, ZIL blocks.
In theory, with these goals met, the new allgorithm will allow the
following improvements:
1. new ZIL blocks can be generated and issued, while there's already
oustanding ZIL blocks being serviced by the storage.
2. the latency of zil_commit() should be proportional to the underlying
storage latency, rather than the incoming synchronous workload.
Porting Notes
=============
Due to the changes made in commit 119a394ab0, the lifetime of an itx
structure differs than in OpenZFS. Specifically, the itx structure is
kept around until the data associated with the itx is considered to be
safe on disk; this is so that the itx's callback can be called after the
data is committed to stable storage. Since OpenZFS doesn't have this itx
callback mechanism, it's able to destroy the itx structure immediately
after the itx is committed to an lwb (before the lwb is written to
disk).
To support this difference, and to ensure the itx's callbacks can still
be called after the itx's data is on disk, a few changes had to be made:
* A list of itxs was added to the lwb structure. This list contains
all of the itxs that have been committed to the lwb, such that the
callbacks for these itxs can be called from zil_lwb_flush_vdevs_done(),
after the data for the itxs is committed to disk.
* A list of itxs was added on the stack of the zil_process_commit_list()
function; the "nolwb_itxs" list. In some circumstances, an itx may
not be committed to an lwb (e.g. if allocating the "next" ZIL block
on disk fails), so this list is used to keep track of which itxs
fall into this state, such that their callbacks can be called after
the ZIL's writer pipeline is "stalled".
* The logic to actually call the itx's callback was moved into the
zil_itx_destroy() function. Since all consumers of zil_itx_destroy()
were effectively performing the same logic (i.e. if callback is
non-null, call the callback), it seemed like useful code cleanup to
consolidate this logic into a single function.
Additionally, the existing Linux tracepoint infrastructure dealing with
the ZIL's probes and structures had to be updated to reflect these code
changes. Specifically:
* The "zil__cw1" and "zil__cw2" probes were removed, so they had to be
removed from "trace_zil.h" as well.
* Some of the zilog structure's fields were removed, which affected
the tracepoint definitions of the structure.
* New tracepoints had to be added for the following 3 new probes:
* zil__process__commit__itx
* zil__process__normal__itx
* zil__commit__io__error
OpenZFS-issue: https://www.illumos.org/issues/8585
OpenZFS-commit: https://github.com/openzfs/openzfs/commit/5d95a3a
Closes #6566
2017-12-05 20:39:16 +03:00
|
|
|
ASSERT3U(tx->tx_threads, ==, 2);
|
2008-11-20 23:01:55 +03:00
|
|
|
if (txg == 0)
|
2010-05-29 00:45:14 +04:00
|
|
|
txg = tx->tx_open_txg + TXG_DEFER_SIZE;
|
2008-11-20 23:01:55 +03:00
|
|
|
if (tx->tx_sync_txg_waiting < txg)
|
|
|
|
tx->tx_sync_txg_waiting = txg;
|
|
|
|
dprintf("txg=%llu quiesce_txg=%llu sync_txg=%llu\n",
|
2021-06-23 07:53:45 +03:00
|
|
|
(u_longlong_t)txg, (u_longlong_t)tx->tx_quiesce_txg_waiting,
|
|
|
|
(u_longlong_t)tx->tx_sync_txg_waiting);
|
2008-11-20 23:01:55 +03:00
|
|
|
while (tx->tx_synced_txg < txg) {
|
|
|
|
dprintf("broadcasting sync more "
|
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
|
|
|
"tx_synced=%llu waiting=%llu dp=%px\n",
|
2021-06-23 07:53:45 +03:00
|
|
|
(u_longlong_t)tx->tx_synced_txg,
|
|
|
|
(u_longlong_t)tx->tx_sync_txg_waiting, dp);
|
2008-11-20 23:01:55 +03:00
|
|
|
cv_broadcast(&tx->tx_sync_more_cv);
|
2019-06-23 02:51:46 +03:00
|
|
|
if (wait_sig) {
|
|
|
|
/*
|
|
|
|
* Condition wait here but stop if the thread receives a
|
|
|
|
* signal. The caller may call txg_wait_synced*() again
|
|
|
|
* to resume waiting for this txg.
|
|
|
|
*/
|
|
|
|
if (cv_wait_io_sig(&tx->tx_sync_done_cv,
|
|
|
|
&tx->tx_sync_lock) == 0) {
|
|
|
|
mutex_exit(&tx->tx_sync_lock);
|
|
|
|
return (B_TRUE);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
cv_wait_io(&tx->tx_sync_done_cv, &tx->tx_sync_lock);
|
|
|
|
}
|
2008-11-20 23:01:55 +03:00
|
|
|
}
|
|
|
|
mutex_exit(&tx->tx_sync_lock);
|
2019-06-23 02:51:46 +03:00
|
|
|
return (B_FALSE);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
txg_wait_synced(dsl_pool_t *dp, uint64_t txg)
|
|
|
|
{
|
|
|
|
VERIFY0(txg_wait_synced_impl(dp, txg, B_FALSE));
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Similar to a txg_wait_synced but it can be interrupted from a signal.
|
|
|
|
* Returns B_TRUE if the thread was signaled while waiting.
|
|
|
|
*/
|
|
|
|
boolean_t
|
|
|
|
txg_wait_synced_sig(dsl_pool_t *dp, uint64_t txg)
|
|
|
|
{
|
|
|
|
return (txg_wait_synced_impl(dp, txg, B_TRUE));
|
2008-11-20 23:01:55 +03:00
|
|
|
}
|
|
|
|
|
2019-03-29 19:13:20 +03:00
|
|
|
/*
|
|
|
|
* Wait for the specified open transaction group. Set should_quiesce
|
|
|
|
* when the current open txg should be quiesced immediately.
|
|
|
|
*/
|
2008-11-20 23:01:55 +03:00
|
|
|
void
|
2019-03-29 19:13:20 +03:00
|
|
|
txg_wait_open(dsl_pool_t *dp, uint64_t txg, boolean_t should_quiesce)
|
2008-11-20 23:01:55 +03:00
|
|
|
{
|
|
|
|
tx_state_t *tx = &dp->dp_tx;
|
|
|
|
|
2013-09-04 16:00:57 +04:00
|
|
|
ASSERT(!dsl_pool_config_held(dp));
|
|
|
|
|
2008-11-20 23:01:55 +03:00
|
|
|
mutex_enter(&tx->tx_sync_lock);
|
OpenZFS 8585 - improve batching done in zil_commit()
Authored by: Prakash Surya <prakash.surya@delphix.com>
Reviewed by: Brad Lewis <brad.lewis@delphix.com>
Reviewed by: Matt Ahrens <mahrens@delphix.com>
Reviewed by: George Wilson <george.wilson@delphix.com>
Reviewed-by: Brian Behlendorf <behlendorf1@llnl.gov>
Approved by: Dan McDonald <danmcd@joyent.com>
Ported-by: Prakash Surya <prakash.surya@delphix.com>
Problem
=======
The current implementation of zil_commit() can introduce significant
latency, beyond what is inherent due to the latency of the underlying
storage. The additional latency comes from two main problems:
1. When there's outstanding ZIL blocks being written (i.e. there's
already a "writer thread" in progress), then any new calls to
zil_commit() will block waiting for the currently oustanding ZIL
blocks to complete. The blocks written for each "writer thread" is
coined a "batch", and there can only ever be a single "batch" being
written at a time. When a batch is being written, any new ZIL
transactions will have to wait for the next batch to be written,
which won't occur until the current batch finishes.
As a result, the underlying storage may not be used as efficiently
as possible. While "new" threads enter zil_commit() and are blocked
waiting for the next batch, it's possible that the underlying
storage isn't fully utilized by the current batch of ZIL blocks. In
that case, it'd be better to allow these new threads to generate
(and issue) a new ZIL block, such that it could be serviced by the
underlying storage concurrently with the other ZIL blocks that are
being serviced.
2. Any call to zil_commit() must wait for all ZIL blocks in its "batch"
to complete, prior to zil_commit() returning. The size of any given
batch is proportional to the number of ZIL transaction in the queue
at the time that the batch starts processing the queue; which
doesn't occur until the previous batch completes. Thus, if there's a
lot of transactions in the queue, the batch could be composed of
many ZIL blocks, and each call to zil_commit() will have to wait for
all of these writes to complete (even if the thread calling
zil_commit() only cared about one of the transactions in the batch).
To further complicate the situation, these two issues result in the
following side effect:
3. If a given batch takes longer to complete than normal, this results
in larger batch sizes, which then take longer to complete and
further drive up the latency of zil_commit(). This can occur for a
number of reasons, including (but not limited to): transient changes
in the workload, and storage latency irregularites.
Solution
========
The solution attempted by this change has the following goals:
1. no on-disk changes; maintain current on-disk format.
2. modify the "batch size" to be equal to the "ZIL block size".
3. allow new batches to be generated and issued to disk, while there's
already batches being serviced by the disk.
4. allow zil_commit() to wait for as few ZIL blocks as possible.
5. use as few ZIL blocks as possible, for the same amount of ZIL
transactions, without introducing significant latency to any
individual ZIL transaction. i.e. use fewer, but larger, ZIL blocks.
In theory, with these goals met, the new allgorithm will allow the
following improvements:
1. new ZIL blocks can be generated and issued, while there's already
oustanding ZIL blocks being serviced by the storage.
2. the latency of zil_commit() should be proportional to the underlying
storage latency, rather than the incoming synchronous workload.
Porting Notes
=============
Due to the changes made in commit 119a394ab0, the lifetime of an itx
structure differs than in OpenZFS. Specifically, the itx structure is
kept around until the data associated with the itx is considered to be
safe on disk; this is so that the itx's callback can be called after the
data is committed to stable storage. Since OpenZFS doesn't have this itx
callback mechanism, it's able to destroy the itx structure immediately
after the itx is committed to an lwb (before the lwb is written to
disk).
To support this difference, and to ensure the itx's callbacks can still
be called after the itx's data is on disk, a few changes had to be made:
* A list of itxs was added to the lwb structure. This list contains
all of the itxs that have been committed to the lwb, such that the
callbacks for these itxs can be called from zil_lwb_flush_vdevs_done(),
after the data for the itxs is committed to disk.
* A list of itxs was added on the stack of the zil_process_commit_list()
function; the "nolwb_itxs" list. In some circumstances, an itx may
not be committed to an lwb (e.g. if allocating the "next" ZIL block
on disk fails), so this list is used to keep track of which itxs
fall into this state, such that their callbacks can be called after
the ZIL's writer pipeline is "stalled".
* The logic to actually call the itx's callback was moved into the
zil_itx_destroy() function. Since all consumers of zil_itx_destroy()
were effectively performing the same logic (i.e. if callback is
non-null, call the callback), it seemed like useful code cleanup to
consolidate this logic into a single function.
Additionally, the existing Linux tracepoint infrastructure dealing with
the ZIL's probes and structures had to be updated to reflect these code
changes. Specifically:
* The "zil__cw1" and "zil__cw2" probes were removed, so they had to be
removed from "trace_zil.h" as well.
* Some of the zilog structure's fields were removed, which affected
the tracepoint definitions of the structure.
* New tracepoints had to be added for the following 3 new probes:
* zil__process__commit__itx
* zil__process__normal__itx
* zil__commit__io__error
OpenZFS-issue: https://www.illumos.org/issues/8585
OpenZFS-commit: https://github.com/openzfs/openzfs/commit/5d95a3a
Closes #6566
2017-12-05 20:39:16 +03:00
|
|
|
ASSERT3U(tx->tx_threads, ==, 2);
|
2008-11-20 23:01:55 +03:00
|
|
|
if (txg == 0)
|
|
|
|
txg = tx->tx_open_txg + 1;
|
2019-03-29 19:13:20 +03:00
|
|
|
if (tx->tx_quiesce_txg_waiting < txg && should_quiesce)
|
2008-11-20 23:01:55 +03:00
|
|
|
tx->tx_quiesce_txg_waiting = txg;
|
|
|
|
dprintf("txg=%llu quiesce_txg=%llu sync_txg=%llu\n",
|
2021-06-23 07:53:45 +03:00
|
|
|
(u_longlong_t)txg, (u_longlong_t)tx->tx_quiesce_txg_waiting,
|
|
|
|
(u_longlong_t)tx->tx_sync_txg_waiting);
|
2008-11-20 23:01:55 +03:00
|
|
|
while (tx->tx_open_txg < txg) {
|
|
|
|
cv_broadcast(&tx->tx_quiesce_more_cv);
|
2019-04-04 19:44:46 +03:00
|
|
|
/*
|
|
|
|
* Callers setting should_quiesce will use cv_wait_io() and
|
|
|
|
* be accounted for as iowait time. Otherwise, the caller is
|
|
|
|
* understood to be idle and cv_wait_sig() is used to prevent
|
|
|
|
* incorrectly inflating the system load average.
|
|
|
|
*/
|
|
|
|
if (should_quiesce == B_TRUE) {
|
|
|
|
cv_wait_io(&tx->tx_quiesce_done_cv, &tx->tx_sync_lock);
|
|
|
|
} else {
|
2020-09-04 06:04:09 +03:00
|
|
|
cv_wait_idle(&tx->tx_quiesce_done_cv,
|
|
|
|
&tx->tx_sync_lock);
|
2019-04-04 19:44:46 +03:00
|
|
|
}
|
2008-11-20 23:01:55 +03:00
|
|
|
}
|
|
|
|
mutex_exit(&tx->tx_sync_lock);
|
|
|
|
}
|
|
|
|
|
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
|
|
|
/*
|
2021-07-01 18:20:27 +03:00
|
|
|
* Pass in the txg number that should be synced.
|
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
|
|
|
*/
|
|
|
|
void
|
2021-07-01 18:20:27 +03:00
|
|
|
txg_kick(dsl_pool_t *dp, uint64_t txg)
|
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
|
|
|
{
|
|
|
|
tx_state_t *tx = &dp->dp_tx;
|
|
|
|
|
|
|
|
ASSERT(!dsl_pool_config_held(dp));
|
|
|
|
|
2021-07-01 18:20:27 +03:00
|
|
|
if (tx->tx_sync_txg_waiting >= txg)
|
|
|
|
return;
|
|
|
|
|
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
|
|
|
mutex_enter(&tx->tx_sync_lock);
|
2021-07-01 18:20:27 +03:00
|
|
|
if (tx->tx_sync_txg_waiting < txg) {
|
|
|
|
tx->tx_sync_txg_waiting = txg;
|
|
|
|
cv_broadcast(&tx->tx_sync_more_cv);
|
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
|
|
|
}
|
|
|
|
mutex_exit(&tx->tx_sync_lock);
|
|
|
|
}
|
|
|
|
|
2008-12-03 23:09:06 +03:00
|
|
|
boolean_t
|
2008-11-20 23:01:55 +03:00
|
|
|
txg_stalled(dsl_pool_t *dp)
|
|
|
|
{
|
|
|
|
tx_state_t *tx = &dp->dp_tx;
|
|
|
|
return (tx->tx_quiesce_txg_waiting > tx->tx_open_txg);
|
|
|
|
}
|
|
|
|
|
2008-12-03 23:09:06 +03:00
|
|
|
boolean_t
|
|
|
|
txg_sync_waiting(dsl_pool_t *dp)
|
|
|
|
{
|
|
|
|
tx_state_t *tx = &dp->dp_tx;
|
|
|
|
|
|
|
|
return (tx->tx_syncing_txg <= tx->tx_sync_txg_waiting ||
|
|
|
|
tx->tx_quiesced_txg != 0);
|
|
|
|
}
|
|
|
|
|
2017-04-24 19:34:36 +03:00
|
|
|
/*
|
|
|
|
* Verify that this txg is active (open, quiescing, syncing). Non-active
|
|
|
|
* txg's should not be manipulated.
|
|
|
|
*/
|
2018-08-20 23:41:53 +03:00
|
|
|
#ifdef ZFS_DEBUG
|
2017-04-24 19:34:36 +03:00
|
|
|
void
|
|
|
|
txg_verify(spa_t *spa, uint64_t txg)
|
|
|
|
{
|
2019-12-05 23:37:00 +03:00
|
|
|
dsl_pool_t *dp __maybe_unused = spa_get_dsl(spa);
|
2017-04-24 19:34:36 +03:00
|
|
|
if (txg <= TXG_INITIAL || txg == ZILTEST_TXG)
|
|
|
|
return;
|
|
|
|
ASSERT3U(txg, <=, dp->dp_tx.tx_open_txg);
|
|
|
|
ASSERT3U(txg, >=, dp->dp_tx.tx_synced_txg);
|
|
|
|
ASSERT3U(txg, >=, dp->dp_tx.tx_open_txg - TXG_CONCURRENT_STATES);
|
|
|
|
}
|
2018-08-20 23:41:53 +03:00
|
|
|
#endif
|
2017-04-24 19:34:36 +03:00
|
|
|
|
2008-11-20 23:01:55 +03:00
|
|
|
/*
|
|
|
|
* Per-txg object lists.
|
|
|
|
*/
|
|
|
|
void
|
2017-04-24 19:34:36 +03:00
|
|
|
txg_list_create(txg_list_t *tl, spa_t *spa, size_t offset)
|
2008-11-20 23:01:55 +03:00
|
|
|
{
|
|
|
|
int t;
|
|
|
|
|
|
|
|
mutex_init(&tl->tl_lock, NULL, MUTEX_DEFAULT, NULL);
|
|
|
|
|
|
|
|
tl->tl_offset = offset;
|
2017-04-24 19:34:36 +03:00
|
|
|
tl->tl_spa = spa;
|
2008-11-20 23:01:55 +03:00
|
|
|
|
|
|
|
for (t = 0; t < TXG_SIZE; t++)
|
|
|
|
tl->tl_head[t] = NULL;
|
|
|
|
}
|
|
|
|
|
2018-08-20 23:41:53 +03:00
|
|
|
static boolean_t
|
|
|
|
txg_list_empty_impl(txg_list_t *tl, uint64_t txg)
|
|
|
|
{
|
|
|
|
ASSERT(MUTEX_HELD(&tl->tl_lock));
|
|
|
|
TXG_VERIFY(tl->tl_spa, txg);
|
|
|
|
return (tl->tl_head[txg & TXG_MASK] == NULL);
|
|
|
|
}
|
|
|
|
|
|
|
|
boolean_t
|
|
|
|
txg_list_empty(txg_list_t *tl, uint64_t txg)
|
|
|
|
{
|
|
|
|
mutex_enter(&tl->tl_lock);
|
|
|
|
boolean_t ret = txg_list_empty_impl(tl, txg);
|
|
|
|
mutex_exit(&tl->tl_lock);
|
|
|
|
|
|
|
|
return (ret);
|
|
|
|
}
|
|
|
|
|
2008-11-20 23:01:55 +03:00
|
|
|
void
|
|
|
|
txg_list_destroy(txg_list_t *tl)
|
|
|
|
{
|
|
|
|
int t;
|
|
|
|
|
2018-08-20 23:41:53 +03:00
|
|
|
mutex_enter(&tl->tl_lock);
|
2008-11-20 23:01:55 +03:00
|
|
|
for (t = 0; t < TXG_SIZE; t++)
|
2018-08-20 23:41:53 +03:00
|
|
|
ASSERT(txg_list_empty_impl(tl, t));
|
|
|
|
mutex_exit(&tl->tl_lock);
|
2008-11-20 23:01:55 +03:00
|
|
|
|
|
|
|
mutex_destroy(&tl->tl_lock);
|
|
|
|
}
|
|
|
|
|
2014-07-18 19:08:31 +04:00
|
|
|
/*
|
|
|
|
* Returns true if all txg lists are empty.
|
|
|
|
*
|
|
|
|
* Warning: this is inherently racy (an item could be added immediately
|
2018-08-20 23:41:53 +03:00
|
|
|
* after this function returns).
|
2014-07-18 19:08:31 +04:00
|
|
|
*/
|
|
|
|
boolean_t
|
|
|
|
txg_all_lists_empty(txg_list_t *tl)
|
|
|
|
{
|
2018-08-20 23:41:53 +03:00
|
|
|
mutex_enter(&tl->tl_lock);
|
2017-11-04 23:25:13 +03:00
|
|
|
for (int i = 0; i < TXG_SIZE; i++) {
|
2018-08-20 23:41:53 +03:00
|
|
|
if (!txg_list_empty_impl(tl, i)) {
|
|
|
|
mutex_exit(&tl->tl_lock);
|
2014-07-18 19:08:31 +04:00
|
|
|
return (B_FALSE);
|
|
|
|
}
|
|
|
|
}
|
2018-08-20 23:41:53 +03:00
|
|
|
mutex_exit(&tl->tl_lock);
|
2014-07-18 19:08:31 +04:00
|
|
|
return (B_TRUE);
|
|
|
|
}
|
|
|
|
|
2008-11-20 23:01:55 +03:00
|
|
|
/*
|
2013-09-04 16:00:57 +04:00
|
|
|
* Add an entry to the list (unless it's already on the list).
|
|
|
|
* Returns B_TRUE if it was actually added.
|
2008-11-20 23:01:55 +03:00
|
|
|
*/
|
2013-09-04 16:00:57 +04:00
|
|
|
boolean_t
|
2008-11-20 23:01:55 +03:00
|
|
|
txg_list_add(txg_list_t *tl, void *p, uint64_t txg)
|
|
|
|
{
|
|
|
|
int t = txg & TXG_MASK;
|
|
|
|
txg_node_t *tn = (txg_node_t *)((char *)p + tl->tl_offset);
|
2013-09-04 16:00:57 +04:00
|
|
|
boolean_t add;
|
2008-11-20 23:01:55 +03:00
|
|
|
|
2018-08-20 23:41:53 +03:00
|
|
|
TXG_VERIFY(tl->tl_spa, txg);
|
2008-11-20 23:01:55 +03:00
|
|
|
mutex_enter(&tl->tl_lock);
|
2013-09-04 16:00:57 +04:00
|
|
|
add = (tn->tn_member[t] == 0);
|
|
|
|
if (add) {
|
2008-11-20 23:01:55 +03:00
|
|
|
tn->tn_member[t] = 1;
|
|
|
|
tn->tn_next[t] = tl->tl_head[t];
|
|
|
|
tl->tl_head[t] = tn;
|
|
|
|
}
|
|
|
|
mutex_exit(&tl->tl_lock);
|
|
|
|
|
2013-09-04 16:00:57 +04:00
|
|
|
return (add);
|
2008-11-20 23:01:55 +03:00
|
|
|
}
|
|
|
|
|
2010-05-29 00:45:14 +04:00
|
|
|
/*
|
2013-09-04 16:00:57 +04:00
|
|
|
* Add an entry to the end of the list, unless it's already on the list.
|
|
|
|
* (walks list to find end)
|
|
|
|
* Returns B_TRUE if it was actually added.
|
2010-05-29 00:45:14 +04:00
|
|
|
*/
|
2013-09-04 16:00:57 +04:00
|
|
|
boolean_t
|
2010-05-29 00:45:14 +04:00
|
|
|
txg_list_add_tail(txg_list_t *tl, void *p, uint64_t txg)
|
|
|
|
{
|
|
|
|
int t = txg & TXG_MASK;
|
|
|
|
txg_node_t *tn = (txg_node_t *)((char *)p + tl->tl_offset);
|
2013-09-04 16:00:57 +04:00
|
|
|
boolean_t add;
|
2010-05-29 00:45:14 +04:00
|
|
|
|
2018-08-20 23:41:53 +03:00
|
|
|
TXG_VERIFY(tl->tl_spa, txg);
|
2010-05-29 00:45:14 +04:00
|
|
|
mutex_enter(&tl->tl_lock);
|
2013-09-04 16:00:57 +04:00
|
|
|
add = (tn->tn_member[t] == 0);
|
|
|
|
if (add) {
|
2010-05-29 00:45:14 +04:00
|
|
|
txg_node_t **tp;
|
|
|
|
|
|
|
|
for (tp = &tl->tl_head[t]; *tp != NULL; tp = &(*tp)->tn_next[t])
|
|
|
|
continue;
|
|
|
|
|
|
|
|
tn->tn_member[t] = 1;
|
|
|
|
tn->tn_next[t] = NULL;
|
|
|
|
*tp = tn;
|
|
|
|
}
|
|
|
|
mutex_exit(&tl->tl_lock);
|
|
|
|
|
2013-09-04 16:00:57 +04:00
|
|
|
return (add);
|
2010-05-29 00:45:14 +04:00
|
|
|
}
|
|
|
|
|
2008-11-20 23:01:55 +03:00
|
|
|
/*
|
|
|
|
* Remove the head of the list and return it.
|
|
|
|
*/
|
|
|
|
void *
|
|
|
|
txg_list_remove(txg_list_t *tl, uint64_t txg)
|
|
|
|
{
|
|
|
|
int t = txg & TXG_MASK;
|
|
|
|
txg_node_t *tn;
|
|
|
|
void *p = NULL;
|
|
|
|
|
2018-08-20 23:41:53 +03:00
|
|
|
TXG_VERIFY(tl->tl_spa, txg);
|
2008-11-20 23:01:55 +03:00
|
|
|
mutex_enter(&tl->tl_lock);
|
|
|
|
if ((tn = tl->tl_head[t]) != NULL) {
|
OpenZFS 7614, 9064 - zfs device evacuation/removal
OpenZFS 7614 - zfs device evacuation/removal
OpenZFS 9064 - remove_mirror should wait for device removal to complete
This project allows top-level vdevs to be removed from the storage pool
with "zpool remove", reducing the total amount of storage in the pool.
This operation copies all allocated regions of the device to be removed
onto other devices, recording the mapping from old to new location.
After the removal is complete, read and free operations to the removed
(now "indirect") vdev must be remapped and performed at the new location
on disk. The indirect mapping table is kept in memory whenever the pool
is loaded, so there is minimal performance overhead when doing operations
on the indirect vdev.
The size of the in-memory mapping table will be reduced when its entries
become "obsolete" because they are no longer used by any block pointers
in the pool. An entry becomes obsolete when all the blocks that use
it are freed. An entry can also become obsolete when all the snapshots
that reference it are deleted, and the block pointers that reference it
have been "remapped" in all filesystems/zvols (and clones). Whenever an
indirect block is written, all the block pointers in it will be "remapped"
to their new (concrete) locations if possible. This process can be
accelerated by using the "zfs remap" command to proactively rewrite all
indirect blocks that reference indirect (removed) vdevs.
Note that when a device is removed, we do not verify the checksum of
the data that is copied. This makes the process much faster, but if it
were used on redundant vdevs (i.e. mirror or raidz vdevs), it would be
possible to copy the wrong data, when we have the correct data on e.g.
the other side of the mirror.
At the moment, only mirrors and simple top-level vdevs can be removed
and no removal is allowed if any of the top-level vdevs are raidz.
Porting Notes:
* Avoid zero-sized kmem_alloc() in vdev_compact_children().
The device evacuation code adds a dependency that
vdev_compact_children() be able to properly empty the vdev_child
array by setting it to NULL and zeroing vdev_children. Under Linux,
kmem_alloc() and related functions return a sentinel pointer rather
than NULL for zero-sized allocations.
* Remove comment regarding "mpt" driver where zfs_remove_max_segment
is initialized to SPA_MAXBLOCKSIZE.
Change zfs_condense_indirect_commit_entry_delay_ticks to
zfs_condense_indirect_commit_entry_delay_ms for consistency with
most other tunables in which delays are specified in ms.
* ZTS changes:
Use set_tunable rather than mdb
Use zpool sync as appropriate
Use sync_pool instead of sync
Kill jobs during test_removal_with_operation to allow unmount/export
Don't add non-disk names such as "mirror" or "raidz" to $DISKS
Use $TEST_BASE_DIR instead of /tmp
Increase HZ from 100 to 1000 which is more common on Linux
removal_multiple_indirection.ksh
Reduce iterations in order to not time out on the code
coverage builders.
removal_resume_export:
Functionally, the test case is correct but there exists a race
where the kernel thread hasn't been fully started yet and is
not visible. Wait for up to 1 second for the removal thread
to be started before giving up on it. Also, increase the
amount of data copied in order that the removal not finish
before the export has a chance to fail.
* MMP compatibility, the concept of concrete versus non-concrete devices
has slightly changed the semantics of vdev_writeable(). Update
mmp_random_leaf_impl() accordingly.
* Updated dbuf_remap() to handle the org.zfsonlinux:large_dnode pool
feature which is not supported by OpenZFS.
* Added support for new vdev removal tracepoints.
* Test cases removal_with_zdb and removal_condense_export have been
intentionally disabled. When run manually they pass as intended,
but when running in the automated test environment they produce
unreliable results on the latest Fedora release.
They may work better once the upstream pool import refectoring is
merged into ZoL at which point they will be re-enabled.
Authored by: Matthew Ahrens <mahrens@delphix.com>
Reviewed-by: Alex Reece <alex@delphix.com>
Reviewed-by: George Wilson <george.wilson@delphix.com>
Reviewed-by: John Kennedy <john.kennedy@delphix.com>
Reviewed-by: Prakash Surya <prakash.surya@delphix.com>
Reviewed by: Richard Laager <rlaager@wiktel.com>
Reviewed by: Tim Chase <tim@chase2k.com>
Reviewed by: Brian Behlendorf <behlendorf1@llnl.gov>
Approved by: Garrett D'Amore <garrett@damore.org>
Ported-by: Tim Chase <tim@chase2k.com>
Signed-off-by: Tim Chase <tim@chase2k.com>
OpenZFS-issue: https://www.illumos.org/issues/7614
OpenZFS-commit: https://github.com/openzfs/openzfs/commit/f539f1eb
Closes #6900
2016-09-22 19:30:13 +03:00
|
|
|
ASSERT(tn->tn_member[t]);
|
|
|
|
ASSERT(tn->tn_next[t] == NULL || tn->tn_next[t]->tn_member[t]);
|
2008-11-20 23:01:55 +03:00
|
|
|
p = (char *)tn - tl->tl_offset;
|
|
|
|
tl->tl_head[t] = tn->tn_next[t];
|
|
|
|
tn->tn_next[t] = NULL;
|
|
|
|
tn->tn_member[t] = 0;
|
|
|
|
}
|
|
|
|
mutex_exit(&tl->tl_lock);
|
|
|
|
|
|
|
|
return (p);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Remove a specific item from the list and return it.
|
|
|
|
*/
|
|
|
|
void *
|
|
|
|
txg_list_remove_this(txg_list_t *tl, void *p, uint64_t txg)
|
|
|
|
{
|
|
|
|
int t = txg & TXG_MASK;
|
|
|
|
txg_node_t *tn, **tp;
|
|
|
|
|
2018-08-20 23:41:53 +03:00
|
|
|
TXG_VERIFY(tl->tl_spa, txg);
|
2008-11-20 23:01:55 +03:00
|
|
|
mutex_enter(&tl->tl_lock);
|
|
|
|
|
|
|
|
for (tp = &tl->tl_head[t]; (tn = *tp) != NULL; tp = &tn->tn_next[t]) {
|
|
|
|
if ((char *)tn - tl->tl_offset == p) {
|
|
|
|
*tp = tn->tn_next[t];
|
|
|
|
tn->tn_next[t] = NULL;
|
|
|
|
tn->tn_member[t] = 0;
|
|
|
|
mutex_exit(&tl->tl_lock);
|
|
|
|
return (p);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
mutex_exit(&tl->tl_lock);
|
|
|
|
|
|
|
|
return (NULL);
|
|
|
|
}
|
|
|
|
|
2013-09-04 16:00:57 +04:00
|
|
|
boolean_t
|
2008-11-20 23:01:55 +03:00
|
|
|
txg_list_member(txg_list_t *tl, void *p, uint64_t txg)
|
|
|
|
{
|
|
|
|
int t = txg & TXG_MASK;
|
|
|
|
txg_node_t *tn = (txg_node_t *)((char *)p + tl->tl_offset);
|
|
|
|
|
2018-08-20 23:41:53 +03:00
|
|
|
TXG_VERIFY(tl->tl_spa, txg);
|
2013-09-04 16:00:57 +04:00
|
|
|
return (tn->tn_member[t] != 0);
|
2008-11-20 23:01:55 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
2018-08-20 23:41:53 +03:00
|
|
|
* Walk a txg list
|
2008-11-20 23:01:55 +03:00
|
|
|
*/
|
|
|
|
void *
|
|
|
|
txg_list_head(txg_list_t *tl, uint64_t txg)
|
|
|
|
{
|
|
|
|
int t = txg & TXG_MASK;
|
2018-08-20 23:41:53 +03:00
|
|
|
txg_node_t *tn;
|
|
|
|
|
|
|
|
mutex_enter(&tl->tl_lock);
|
|
|
|
tn = tl->tl_head[t];
|
|
|
|
mutex_exit(&tl->tl_lock);
|
2008-11-20 23:01:55 +03:00
|
|
|
|
2018-08-20 23:41:53 +03:00
|
|
|
TXG_VERIFY(tl->tl_spa, txg);
|
2008-11-20 23:01:55 +03:00
|
|
|
return (tn == NULL ? NULL : (char *)tn - tl->tl_offset);
|
|
|
|
}
|
|
|
|
|
|
|
|
void *
|
|
|
|
txg_list_next(txg_list_t *tl, void *p, uint64_t txg)
|
|
|
|
{
|
|
|
|
int t = txg & TXG_MASK;
|
|
|
|
txg_node_t *tn = (txg_node_t *)((char *)p + tl->tl_offset);
|
|
|
|
|
2018-08-20 23:41:53 +03:00
|
|
|
TXG_VERIFY(tl->tl_spa, txg);
|
|
|
|
|
|
|
|
mutex_enter(&tl->tl_lock);
|
2008-11-20 23:01:55 +03:00
|
|
|
tn = tn->tn_next[t];
|
2018-08-20 23:41:53 +03:00
|
|
|
mutex_exit(&tl->tl_lock);
|
2008-11-20 23:01:55 +03:00
|
|
|
|
|
|
|
return (tn == NULL ? NULL : (char *)tn - tl->tl_offset);
|
|
|
|
}
|
2010-08-26 22:49:16 +04:00
|
|
|
|
|
|
|
EXPORT_SYMBOL(txg_init);
|
|
|
|
EXPORT_SYMBOL(txg_fini);
|
|
|
|
EXPORT_SYMBOL(txg_sync_start);
|
|
|
|
EXPORT_SYMBOL(txg_sync_stop);
|
|
|
|
EXPORT_SYMBOL(txg_hold_open);
|
|
|
|
EXPORT_SYMBOL(txg_rele_to_quiesce);
|
|
|
|
EXPORT_SYMBOL(txg_rele_to_sync);
|
|
|
|
EXPORT_SYMBOL(txg_register_callbacks);
|
|
|
|
EXPORT_SYMBOL(txg_delay);
|
|
|
|
EXPORT_SYMBOL(txg_wait_synced);
|
|
|
|
EXPORT_SYMBOL(txg_wait_open);
|
2011-01-22 01:35:41 +03:00
|
|
|
EXPORT_SYMBOL(txg_wait_callbacks);
|
2010-08-26 22:49:16 +04:00
|
|
|
EXPORT_SYMBOL(txg_stalled);
|
|
|
|
EXPORT_SYMBOL(txg_sync_waiting);
|
2012-10-12 00:56:32 +04:00
|
|
|
|
2020-04-15 21:14:47 +03:00
|
|
|
ZFS_MODULE_PARAM(zfs_txg, zfs_txg_, timeout, INT, ZMOD_RW,
|
2019-09-06 00:49:49 +03:00
|
|
|
"Max seconds worth of delta per txg");
|