fa9e4066f08beec538e775443c5be79dd423fcabahrens * CDDL HEADER START
fa9e4066f08beec538e775443c5be79dd423fcabahrens * The contents of this file are subject to the terms of the
5ad820458efd0fdb914baff9c1447c22b819fa23nd * Common Development and Distribution License (the "License").
5ad820458efd0fdb914baff9c1447c22b819fa23nd * You may not use this file except in compliance with the License.
fa9e4066f08beec538e775443c5be79dd423fcabahrens * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
fa9e4066f08beec538e775443c5be79dd423fcabahrens * See the License for the specific language governing permissions
fa9e4066f08beec538e775443c5be79dd423fcabahrens * and limitations under the License.
fa9e4066f08beec538e775443c5be79dd423fcabahrens * When distributing Covered Code, include this CDDL HEADER in each
fa9e4066f08beec538e775443c5be79dd423fcabahrens * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
fa9e4066f08beec538e775443c5be79dd423fcabahrens * If applicable, add the following below this CDDL HEADER, with the
fa9e4066f08beec538e775443c5be79dd423fcabahrens * fields enclosed by brackets "[]" replaced with your own identifying
fa9e4066f08beec538e775443c5be79dd423fcabahrens * information: Portions Copyright [yyyy] [name of copyright owner]
fa9e4066f08beec538e775443c5be79dd423fcabahrens * CDDL HEADER END
3f9d6ad73e45c6823b409f93b0c8d4f62861d2d5Lin Ling * Copyright (c) 2005, 2010, Oracle and/or its affiliates. All rights reserved.
383e7c74ff3827d20f23fa87e37bd52d86fc1a26Xin Li * Portions Copyright 2011 Martin Matuska
73527f441cbbd953fa42cc5a30a413bad75f24a9Alex Reece * Copyright (c) 2012, 2014 by Delphix. All rights reserved.
adbbcfface63b3a71922d5a25d34a2018c0435deAdam H. Leventhal * ZFS Transaction Groups
adbbcfface63b3a71922d5a25d34a2018c0435deAdam H. Leventhal * ----------------------
adbbcfface63b3a71922d5a25d34a2018c0435deAdam H. Leventhal * ZFS transaction groups are, as the name implies, groups of transactions
adbbcfface63b3a71922d5a25d34a2018c0435deAdam H. Leventhal * that act on persistent state. ZFS asserts consistency at the granularity of
adbbcfface63b3a71922d5a25d34a2018c0435deAdam H. Leventhal * these transaction groups. Each successive transaction group (txg) is
adbbcfface63b3a71922d5a25d34a2018c0435deAdam H. Leventhal * assigned a 64-bit consecutive identifier. There are three active
adbbcfface63b3a71922d5a25d34a2018c0435deAdam H. Leventhal * transaction group states: open, quiescing, or syncing. At any given time,
adbbcfface63b3a71922d5a25d34a2018c0435deAdam H. Leventhal * there may be an active txg associated with each state; each active txg may
adbbcfface63b3a71922d5a25d34a2018c0435deAdam H. Leventhal * either be processing, or blocked waiting to enter the next state. There may
adbbcfface63b3a71922d5a25d34a2018c0435deAdam H. Leventhal * be up to three active txgs, and there is always a txg in the open state
adbbcfface63b3a71922d5a25d34a2018c0435deAdam H. Leventhal * (though it may be blocked waiting to enter the quiescing state). In broad
69962b5647e4a8b9b14998733b765925381b727eMatthew Ahrens * strokes, transactions -- operations that change in-memory structures -- are
adbbcfface63b3a71922d5a25d34a2018c0435deAdam H. Leventhal * accepted into the txg in the open state, and are completed while the txg is
adbbcfface63b3a71922d5a25d34a2018c0435deAdam H. Leventhal * in the open or quiescing states. The accumulated changes are written to
adbbcfface63b3a71922d5a25d34a2018c0435deAdam H. Leventhal * disk in the syncing state.
adbbcfface63b3a71922d5a25d34a2018c0435deAdam H. Leventhal * When a new txg becomes active, it first enters the open state. New
69962b5647e4a8b9b14998733b765925381b727eMatthew Ahrens * transactions -- updates to in-memory structures -- are assigned to the
adbbcfface63b3a71922d5a25d34a2018c0435deAdam H. Leventhal * currently open txg. There is always a txg in the open state so that ZFS can
adbbcfface63b3a71922d5a25d34a2018c0435deAdam H. Leventhal * accept new changes (though the txg may refuse new changes if it has hit
adbbcfface63b3a71922d5a25d34a2018c0435deAdam H. Leventhal * some limit). ZFS advances the open txg to the next state for a variety of
adbbcfface63b3a71922d5a25d34a2018c0435deAdam H. Leventhal * reasons such as it hitting a time or size threshold, or the execution of an
adbbcfface63b3a71922d5a25d34a2018c0435deAdam H. Leventhal * administrative action that must be completed in the syncing state.
adbbcfface63b3a71922d5a25d34a2018c0435deAdam H. Leventhal * After a txg exits the open state, it enters the quiescing state. The
adbbcfface63b3a71922d5a25d34a2018c0435deAdam H. Leventhal * quiescing state is intended to provide a buffer between accepting new
adbbcfface63b3a71922d5a25d34a2018c0435deAdam H. Leventhal * transactions in the open state and writing them out to stable storage in
adbbcfface63b3a71922d5a25d34a2018c0435deAdam H. Leventhal * the syncing state. While quiescing, transactions can continue their
adbbcfface63b3a71922d5a25d34a2018c0435deAdam H. Leventhal * operation without delaying either of the other states. Typically, a txg is
adbbcfface63b3a71922d5a25d34a2018c0435deAdam H. Leventhal * in the quiescing state very briefly since the operations are bounded by
adbbcfface63b3a71922d5a25d34a2018c0435deAdam H. Leventhal * software latencies rather than, say, slower I/O latencies. After all
adbbcfface63b3a71922d5a25d34a2018c0435deAdam H. Leventhal * transactions complete, the txg is ready to enter the next state.
adbbcfface63b3a71922d5a25d34a2018c0435deAdam H. Leventhal * In the syncing state, the in-memory state built up during the open and (to
adbbcfface63b3a71922d5a25d34a2018c0435deAdam H. Leventhal * a lesser degree) the quiescing states is written to stable storage. The
adbbcfface63b3a71922d5a25d34a2018c0435deAdam H. Leventhal * process of writing out modified data can, in turn modify more data. For
adbbcfface63b3a71922d5a25d34a2018c0435deAdam H. Leventhal * example when we write new blocks, we need to allocate space for them; those
adbbcfface63b3a71922d5a25d34a2018c0435deAdam H. Leventhal * allocations modify metadata (space maps)... which themselves must be
adbbcfface63b3a71922d5a25d34a2018c0435deAdam H. Leventhal * written to stable storage. During the sync state, ZFS iterates, writing out
adbbcfface63b3a71922d5a25d34a2018c0435deAdam H. Leventhal * data until it converges and all in-memory changes have been written out.
adbbcfface63b3a71922d5a25d34a2018c0435deAdam H. Leventhal * The first such pass is the largest as it encompasses all the modified user
adbbcfface63b3a71922d5a25d34a2018c0435deAdam H. Leventhal * data (as opposed to filesystem metadata). Subsequent passes typically have
adbbcfface63b3a71922d5a25d34a2018c0435deAdam H. Leventhal * far less data to write as they consist exclusively of filesystem metadata.
adbbcfface63b3a71922d5a25d34a2018c0435deAdam H. Leventhal * To ensure convergence, after a certain number of passes ZFS begins
adbbcfface63b3a71922d5a25d34a2018c0435deAdam H. Leventhal * overwriting locations on stable storage that had been allocated earlier in
adbbcfface63b3a71922d5a25d34a2018c0435deAdam H. Leventhal * the syncing state (and subsequently freed). ZFS usually allocates new
adbbcfface63b3a71922d5a25d34a2018c0435deAdam H. Leventhal * blocks to optimize for large, continuous, writes. For the syncing state to
adbbcfface63b3a71922d5a25d34a2018c0435deAdam H. Leventhal * converge however it must complete a pass where no new blocks are allocated
adbbcfface63b3a71922d5a25d34a2018c0435deAdam H. Leventhal * since each allocation requires a modification of persistent metadata.
adbbcfface63b3a71922d5a25d34a2018c0435deAdam H. Leventhal * Further, to hasten convergence, after a prescribed number of passes, ZFS
adbbcfface63b3a71922d5a25d34a2018c0435deAdam H. Leventhal * also defers frees, and stops compressing.
adbbcfface63b3a71922d5a25d34a2018c0435deAdam H. Leventhal * In addition to writing out user data, we must also execute synctasks during
adbbcfface63b3a71922d5a25d34a2018c0435deAdam H. Leventhal * the syncing context. A synctask is the mechanism by which some
adbbcfface63b3a71922d5a25d34a2018c0435deAdam H. Leventhal * administrative activities work such as creating and destroying snapshots or
adbbcfface63b3a71922d5a25d34a2018c0435deAdam H. Leventhal * datasets. Note that when a synctask is initiated it enters the open txg,
adbbcfface63b3a71922d5a25d34a2018c0435deAdam H. Leventhal * and ZFS then pushes that txg as quickly as possible to completion of the
adbbcfface63b3a71922d5a25d34a2018c0435deAdam H. Leventhal * syncing state in order to reduce the latency of the administrative
adbbcfface63b3a71922d5a25d34a2018c0435deAdam H. Leventhal * activity. To complete the syncing state, ZFS writes out a new uberblock,
adbbcfface63b3a71922d5a25d34a2018c0435deAdam H. Leventhal * the root of the tree of blocks that comprise all state stored on the ZFS
adbbcfface63b3a71922d5a25d34a2018c0435deAdam H. Leventhal * pool. Finally, if there is a quiesced txg waiting, we signal that it can
adbbcfface63b3a71922d5a25d34a2018c0435deAdam H. Leventhal * now transition to the syncing state.
44ecc5327ab4ce0750dcca2a17e05566bf2812e2George Wilsonint zfs_txg_timeout = 5; /* max seconds worth of delta per txg */
fa9e4066f08beec538e775443c5be79dd423fcabahrens * Prepare the txg subsystem.
fa9e4066f08beec538e775443c5be79dd423fcabahrens tx->tx_cpu = kmem_zalloc(max_ncpus * sizeof (tx_cpu_t), KM_SLEEP);
8f38d41910063e19709864b025684a228961299fek for (c = 0; c < max_ncpus; c++) {
5ad820458efd0fdb914baff9c1447c22b819fa23nd mutex_init(&tx->tx_cpu[c].tc_lock, NULL, MUTEX_DEFAULT, NULL);
4a92375985c37d61406d66cd2b10ee642eb1f5e7George Wilson mutex_init(&tx->tx_cpu[c].tc_open_lock, NULL, MUTEX_DEFAULT,
8f38d41910063e19709864b025684a228961299fek for (i = 0; i < TXG_SIZE; i++) {
d20e665c84abf083a9e8b62cca93383ecb55afdfRicardo M. Correia list_create(&tx->tx_cpu[c].tc_callbacks[i],
5ad820458efd0fdb914baff9c1447c22b819fa23nd mutex_init(&tx->tx_sync_lock, NULL, MUTEX_DEFAULT, NULL);
b5e70f9763532dbf8f22010666d457240881c038Ricardo M. Correia cv_init(&tx->tx_sync_more_cv, NULL, CV_DEFAULT, NULL);
b5e70f9763532dbf8f22010666d457240881c038Ricardo M. Correia cv_init(&tx->tx_sync_done_cv, NULL, CV_DEFAULT, NULL);
b5e70f9763532dbf8f22010666d457240881c038Ricardo M. Correia cv_init(&tx->tx_quiesce_more_cv, NULL, CV_DEFAULT, NULL);
b5e70f9763532dbf8f22010666d457240881c038Ricardo M. Correia cv_init(&tx->tx_quiesce_done_cv, NULL, CV_DEFAULT, NULL);
b5e70f9763532dbf8f22010666d457240881c038Ricardo M. Correia cv_init(&tx->tx_exit_cv, NULL, CV_DEFAULT, NULL);
fa9e4066f08beec538e775443c5be79dd423fcabahrens * Close down the txg subsystem.
8f38d41910063e19709864b025684a228961299fek for (c = 0; c < max_ncpus; c++) {
d20e665c84abf083a9e8b62cca93383ecb55afdfRicardo M. Correia for (i = 0; i < TXG_SIZE; i++) {
d20e665c84abf083a9e8b62cca93383ecb55afdfRicardo M. Correia list_destroy(&tx->tx_cpu[c].tc_callbacks[i]);
fa9e4066f08beec538e775443c5be79dd423fcabahrens kmem_free(tx->tx_cpu, max_ncpus * sizeof (tx_cpu_t));
fa9e4066f08beec538e775443c5be79dd423fcabahrens * Start syncing transaction groups.
fa9e4066f08beec538e775443c5be79dd423fcabahrens tx->tx_quiesce_thread = thread_create(NULL, 0, txg_quiesce_thread,
088f389458728c464569a5506b58070254fa4f7dahrens * The sync thread can need a larger-than-default stack size on
088f389458728c464569a5506b58070254fa4f7dahrens * 32-bit x86. This is due in part to nested pools and
088f389458728c464569a5506b58070254fa4f7dahrens * scrub_visitbp() recursion.
3f9d6ad73e45c6823b409f93b0c8d4f62861d2d5Lin Ling tx->tx_sync_thread = thread_create(NULL, 32<<10, txg_sync_thread,
fa9e4066f08beec538e775443c5be79dd423fcabahrens CALLB_CPR_INIT(cpr, &tx->tx_sync_lock, callb_generic_cpr, FTAG);
fa9e4066f08beec538e775443c5be79dd423fcabahrenstxg_thread_exit(tx_state_t *tx, callb_cpr_t *cpr, kthread_t **tpp)
0689f76c08c5e553ff25ac43a852b56c430bb61eAdam Leventhaltxg_thread_wait(tx_state_t *tx, callb_cpr_t *cpr, kcondvar_t *cv, clock_t time)
fa9e4066f08beec538e775443c5be79dd423fcabahrens * Stop syncing transaction groups.
fa9e4066f08beec538e775443c5be79dd423fcabahrens * Finish off any work in progress.
468c413a79615e77179e8d98f22a7e513a8135bdTim Haley * We need to ensure that we've vacated the deferred space_maps.
468c413a79615e77179e8d98f22a7e513a8135bdTim Haley txg_wait_synced(dp, tx->tx_open_txg + TXG_DEFER_SIZE);
1ab7f2ded02e7a1bc3c73516eb27efa79bf2a2ffmaybee * Wake all sync threads and wait for them to die.
d20e665c84abf083a9e8b62cca93383ecb55afdfRicardo M. Correiatxg_register_callbacks(txg_handle_t *th, list_t *tx_callbacks)
d20e665c84abf083a9e8b62cca93383ecb55afdfRicardo M. Correia list_move_tail(&tc->tc_callbacks[g], tx_callbacks);
3e30c24aeefdee1631958ecf17f18da671781956Will Andrews * Blocks until all transactions in the group are committed.
3e30c24aeefdee1631958ecf17f18da671781956Will Andrews * On return, the transaction group has reached a stable state in which it can
3e30c24aeefdee1631958ecf17f18da671781956Will Andrews * then be passed off to the syncing context.
4a92375985c37d61406d66cd2b10ee642eb1f5e7George Wilson * Grab all tc_open_locks so nobody else can get into this txg.
fa9e4066f08beec538e775443c5be79dd423fcabahrens for (c = 0; c < max_ncpus; c++)
0689f76c08c5e553ff25ac43a852b56c430bb61eAdam Leventhal DTRACE_PROBE2(txg__quiescing, dsl_pool_t *, dp, uint64_t, txg);
0689f76c08c5e553ff25ac43a852b56c430bb61eAdam Leventhal DTRACE_PROBE2(txg__opened, dsl_pool_t *, dp, uint64_t, tx->tx_open_txg);
fa9e4066f08beec538e775443c5be79dd423fcabahrens * Now that we've incremented tx_open_txg, we can let threads
fa9e4066f08beec538e775443c5be79dd423fcabahrens * enter the next transaction group.
fa9e4066f08beec538e775443c5be79dd423fcabahrens for (c = 0; c < max_ncpus; c++)
fa9e4066f08beec538e775443c5be79dd423fcabahrens * Quiesce the transaction group by waiting for everyone to txg_exit().
fa9e4066f08beec538e775443c5be79dd423fcabahrens for (c = 0; c < max_ncpus; c++) {
d20e665c84abf083a9e8b62cca93383ecb55afdfRicardo M. Correia * Dispatch the commit callbacks registered on this txg to worker threads.
3e30c24aeefdee1631958ecf17f18da671781956Will Andrews * If no callbacks are registered for a given TXG, nothing happens.
3e30c24aeefdee1631958ecf17f18da671781956Will Andrews * This function creates a taskq for the associated pool, if needed.
d20e665c84abf083a9e8b62cca93383ecb55afdfRicardo M. Correiatxg_dispatch_callbacks(dsl_pool_t *dp, uint64_t txg)
d20e665c84abf083a9e8b62cca93383ecb55afdfRicardo M. Correia for (c = 0; c < max_ncpus; c++) {
3e30c24aeefdee1631958ecf17f18da671781956Will Andrews * No need to lock tx_cpu_t at this point, since this can
3e30c24aeefdee1631958ecf17f18da671781956Will Andrews * only be called once a txg has been synced.
d20e665c84abf083a9e8b62cca93383ecb55afdfRicardo M. Correia * Commit callback taskq hasn't been created yet.
d20e665c84abf083a9e8b62cca93383ecb55afdfRicardo M. Correia tx->tx_commit_cb_taskq = taskq_create("tx_commit_cb",
d20e665c84abf083a9e8b62cca93383ecb55afdfRicardo M. Correia max_ncpus, minclsyspri, max_ncpus, max_ncpus * 2,
d20e665c84abf083a9e8b62cca93383ecb55afdfRicardo M. Correia cb_list = kmem_alloc(sizeof (list_t), KM_SLEEP);
d20e665c84abf083a9e8b62cca93383ecb55afdfRicardo M. Correia list_create(cb_list, sizeof (dmu_tx_callback_t),
d20e665c84abf083a9e8b62cca93383ecb55afdfRicardo M. Correia (void) taskq_dispatch(tx->tx_commit_cb_taskq, (task_func_t *)
3f9d6ad73e45c6823b409f93b0c8d4f62861d2d5Lin Ling * We sync when we're scanning, there's someone waiting
88b7b0f29b20b808b9e06071885b1d6a3ddb6328Matthew Ahrens * on us, or the quiesce thread has handed off a txg to
88b7b0f29b20b808b9e06071885b1d6a3ddb6328Matthew Ahrens * us, or we have reached our timeout.
fa9e4066f08beec538e775443c5be79dd423fcabahrens dprintf("waiting; tx_synced=%llu waiting=%llu dp=%p\n",
1ab7f2ded02e7a1bc3c73516eb27efa79bf2a2ffmaybee txg_thread_wait(tx, &cpr, &tx->tx_sync_more_cv, timer);
fa9e4066f08beec538e775443c5be79dd423fcabahrens * Wait until the quiesce thread hands off a txg to us,
fa9e4066f08beec538e775443c5be79dd423fcabahrens * prompting it to do so if necessary.
fa9e4066f08beec538e775443c5be79dd423fcabahrens while (!tx->tx_exiting && tx->tx_quiesced_txg == 0) {
fa9e4066f08beec538e775443c5be79dd423fcabahrens txg_thread_wait(tx, &cpr, &tx->tx_quiesce_done_cv, 0);
fa9e4066f08beec538e775443c5be79dd423fcabahrens * Consume the quiesced txg which has been handed off to
fa9e4066f08beec538e775443c5be79dd423fcabahrens * us. This may cause the quiescing thread to now be
fa9e4066f08beec538e775443c5be79dd423fcabahrens * able to quiesce another txg, so we must signal it.
0689f76c08c5e553ff25ac43a852b56c430bb61eAdam Leventhal DTRACE_PROBE2(txg__syncing, dsl_pool_t *, dp, uint64_t, txg);
8f38d41910063e19709864b025684a228961299fek txg, tx->tx_quiesce_txg_waiting, tx->tx_sync_txg_waiting);
0689f76c08c5e553ff25ac43a852b56c430bb61eAdam Leventhal DTRACE_PROBE2(txg__synced, dsl_pool_t *, dp, uint64_t, txg);
d20e665c84abf083a9e8b62cca93383ecb55afdfRicardo M. Correia * Dispatch commit callbacks to worker threads.
fa9e4066f08beec538e775443c5be79dd423fcabahrens * We quiesce when there's someone waiting on us.
fa9e4066f08beec538e775443c5be79dd423fcabahrens * However, we can only have one txg in "quiescing" or
fa9e4066f08beec538e775443c5be79dd423fcabahrens * "quiesced, waiting to sync" state. So we wait until
fa9e4066f08beec538e775443c5be79dd423fcabahrens * the "quiesced, waiting to sync" txg has been consumed
fa9e4066f08beec538e775443c5be79dd423fcabahrens * by the sync thread.
fa9e4066f08beec538e775443c5be79dd423fcabahrens txg_thread_wait(tx, &cpr, &tx->tx_quiesce_more_cv, 0);
fa9e4066f08beec538e775443c5be79dd423fcabahrens * Hand this txg off to the sync thread.
fa9e4066f08beec538e775443c5be79dd423fcabahrens dprintf("quiesce done, handing off txg %llu\n", txg);
0689f76c08c5e553ff25ac43a852b56c430bb61eAdam Leventhal DTRACE_PROBE2(txg__quiesced, dsl_pool_t *, dp, uint64_t, txg);
0689f76c08c5e553ff25ac43a852b56c430bb61eAdam Leventhal * Delay this thread by delay nanoseconds if we are still in the open
f7170741490edba9d1d9c697c177c887172bc741Will Andrews * transaction group and there is already a waiting txg quiescing or quiesced.
f7170741490edba9d1d9c697c177c887172bc741Will Andrews * Abort the delay if this txg stalls or enters the quiescing state.
0689f76c08c5e553ff25ac43a852b56c430bb61eAdam Leventhaltxg_delay(dsl_pool_t *dp, uint64_t txg, hrtime_t delay, hrtime_t resolution)
f7170741490edba9d1d9c697c177c887172bc741Will Andrews /* don't delay if this txg could transition to quiescing immediately */
1ab7f2ded02e7a1bc3c73516eb27efa79bf2a2ffmaybee tx->tx_syncing_txg == txg-1 || tx->tx_synced_txg == txg-1)
1ab7f2ded02e7a1bc3c73516eb27efa79bf2a2ffmaybee if (tx->tx_open_txg > txg || tx->tx_synced_txg == txg-1) {
0689f76c08c5e553ff25ac43a852b56c430bb61eAdam Leventhal tx->tx_syncing_txg < txg-1 && !txg_stalled(dp)) {
0689f76c08c5e553ff25ac43a852b56c430bb61eAdam Leventhal (void) cv_timedwait_hires(&tx->tx_quiesce_more_cv,
fa9e4066f08beec538e775443c5be79dd423fcabahrens txg, tx->tx_quiesce_txg_waiting, tx->tx_sync_txg_waiting);
fa9e4066f08beec538e775443c5be79dd423fcabahrens "tx_synced=%llu waiting=%llu dp=%p\n",
fa9e4066f08beec538e775443c5be79dd423fcabahrens txg, tx->tx_quiesce_txg_waiting, tx->tx_sync_txg_waiting);
69962b5647e4a8b9b14998733b765925381b727eMatthew Ahrens * If there isn't a txg syncing or in the pipeline, push another txg through
69962b5647e4a8b9b14998733b765925381b727eMatthew Ahrens * the pipeline by queiscing the open txg.
69962b5647e4a8b9b14998733b765925381b727eMatthew Ahrens tx->tx_quiesce_txg_waiting <= tx->tx_open_txg &&
69962b5647e4a8b9b14998733b765925381b727eMatthew Ahrens tx->tx_sync_txg_waiting <= tx->tx_synced_txg &&
69962b5647e4a8b9b14998733b765925381b727eMatthew Ahrens tx->tx_quiesce_txg_waiting = tx->tx_open_txg + 1;
fa9e4066f08beec538e775443c5be79dd423fcabahrens return (tx->tx_quiesce_txg_waiting > tx->tx_open_txg);
088f389458728c464569a5506b58070254fa4f7dahrens return (tx->tx_syncing_txg <= tx->tx_sync_txg_waiting ||
fa9e4066f08beec538e775443c5be79dd423fcabahrens * Per-txg object lists.
fa9e4066f08beec538e775443c5be79dd423fcabahrens for (t = 0; t < TXG_SIZE; t++)
fa9e4066f08beec538e775443c5be79dd423fcabahrens for (t = 0; t < TXG_SIZE; t++)
73527f441cbbd953fa42cc5a30a413bad75f24a9Alex Reece * Returns true if all txg lists are empty.
73527f441cbbd953fa42cc5a30a413bad75f24a9Alex Reece * Warning: this is inherently racy (an item could be added immediately after this
73527f441cbbd953fa42cc5a30a413bad75f24a9Alex Reece * function returns). We don't bother with the lock because it wouldn't change the
73527f441cbbd953fa42cc5a30a413bad75f24a9Alex Reece * semantics.
73527f441cbbd953fa42cc5a30a413bad75f24a9Alex Reece for (int i = 0; i < TXG_SIZE; i++) {
3b2aab18808792cbd248a12f1edf139b89833c13Matthew Ahrens * Add an entry to the list (unless it's already on the list).
3b2aab18808792cbd248a12f1edf139b89833c13Matthew Ahrens * Returns B_TRUE if it was actually added.
fa9e4066f08beec538e775443c5be79dd423fcabahrens txg_node_t *tn = (txg_node_t *)((char *)p + tl->tl_offset);
3b2aab18808792cbd248a12f1edf139b89833c13Matthew Ahrens * Add an entry to the end of the list, unless it's already on the list.
3b2aab18808792cbd248a12f1edf139b89833c13Matthew Ahrens * (walks list to find end)
3b2aab18808792cbd248a12f1edf139b89833c13Matthew Ahrens * Returns B_TRUE if it was actually added.
495807d7dceb9c0357efb5f483dbf9f951dfeec6Matthew Ahrenstxg_list_add_tail(txg_list_t *tl, void *p, uint64_t txg)
495807d7dceb9c0357efb5f483dbf9f951dfeec6Matthew Ahrens txg_node_t *tn = (txg_node_t *)((char *)p + tl->tl_offset);
495807d7dceb9c0357efb5f483dbf9f951dfeec6Matthew Ahrens for (tp = &tl->tl_head[t]; *tp != NULL; tp = &(*tp)->tn_next[t])
fa9e4066f08beec538e775443c5be79dd423fcabahrens * Remove the head of the list and return it.
fa9e4066f08beec538e775443c5be79dd423fcabahrens return (p);
fa9e4066f08beec538e775443c5be79dd423fcabahrens * Remove a specific item from the list and return it.
fa9e4066f08beec538e775443c5be79dd423fcabahrenstxg_list_remove_this(txg_list_t *tl, void *p, uint64_t txg)
fa9e4066f08beec538e775443c5be79dd423fcabahrens for (tp = &tl->tl_head[t]; (tn = *tp) != NULL; tp = &tn->tn_next[t]) {
fa9e4066f08beec538e775443c5be79dd423fcabahrens return (p);
fa9e4066f08beec538e775443c5be79dd423fcabahrenstxg_list_member(txg_list_t *tl, void *p, uint64_t txg)
fa9e4066f08beec538e775443c5be79dd423fcabahrens txg_node_t *tn = (txg_node_t *)((char *)p + tl->tl_offset);
fa9e4066f08beec538e775443c5be79dd423fcabahrens * Walk a txg list -- only safe if you know it's not changing.
fa9e4066f08beec538e775443c5be79dd423fcabahrens return (tn == NULL ? NULL : (char *)tn - tl->tl_offset);
fa9e4066f08beec538e775443c5be79dd423fcabahrens txg_node_t *tn = (txg_node_t *)((char *)p + tl->tl_offset);