4 * The contents of this file are subject to the terms of the
5 * Common Development and Distribution License (the "License").
6 * You may not use this file except in compliance with the License.
8 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9 * or http://www.opensolaris.org/os/licensing.
10 * See the License for the specific language governing permissions
11 * and limitations under the License.
13 * When distributing Covered Code, include this CDDL HEADER in each
14 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15 * If applicable, add the following below this CDDL HEADER, with the
16 * fields enclosed by brackets "[]" replaced with your own identifying
17 * information: Portions Copyright [yyyy] [name of copyright owner]
22 * Copyright 2010 Sun Microsystems, Inc. All rights reserved.
23 * Use is subject to license terms.
26 * Copyright (c) 2012 by Delphix. All rights reserved.
33 #include <sys/zfs_context.h>
39 #define TXG_CONCURRENT_STATES 3 /* open, quiescing, syncing */
40 #define TXG_SIZE 4 /* next power of 2 */
41 #define TXG_MASK (TXG_SIZE - 1) /* mask for size */
42 #define TXG_INITIAL TXG_SIZE /* initial txg */
43 #define TXG_IDX (txg & TXG_MASK)
45 /* Number of txgs worth of frees we defer adding to in-core spacemaps */
46 #define TXG_DEFER_SIZE 2
49 #define TXG_NOWAIT 2ULL
51 typedef struct tx_cpu tx_cpu_t;
53 typedef struct txg_handle {
58 typedef struct txg_node {
59 struct txg_node *tn_next[TXG_SIZE];
60 uint8_t tn_member[TXG_SIZE];
63 typedef struct txg_list {
66 txg_node_t *tl_head[TXG_SIZE];
71 extern void txg_init(struct dsl_pool *dp, uint64_t txg);
72 extern void txg_fini(struct dsl_pool *dp);
73 extern void txg_sync_start(struct dsl_pool *dp);
74 extern void txg_sync_stop(struct dsl_pool *dp);
75 extern uint64_t txg_hold_open(struct dsl_pool *dp, txg_handle_t *txghp);
76 extern void txg_rele_to_quiesce(txg_handle_t *txghp);
77 extern void txg_rele_to_sync(txg_handle_t *txghp);
78 extern void txg_register_callbacks(txg_handle_t *txghp, list_t *tx_callbacks);
81 * Delay the caller by the specified number of ticks or until
82 * the txg closes (whichever comes first). This is intended
83 * to be used to throttle writers when the system nears its
86 extern void txg_delay(struct dsl_pool *dp, uint64_t txg, int ticks);
89 * Wait until the given transaction group has finished syncing.
90 * Try to make this happen as soon as possible (eg. kick off any
91 * necessary syncs immediately). If txg==0, wait for the currently open
92 * txg to finish syncing.
94 extern void txg_wait_synced(struct dsl_pool *dp, uint64_t txg);
97 * Wait until the given transaction group, or one after it, is
98 * the open transaction group. Try to make this happen as soon
99 * as possible (eg. kick off any necessary syncs immediately).
100 * If txg == 0, wait for the next open txg.
102 extern void txg_wait_open(struct dsl_pool *dp, uint64_t txg);
105 * Returns TRUE if we are "backed up" waiting for the syncing
106 * transaction to complete; otherwise returns FALSE.
108 extern boolean_t txg_stalled(struct dsl_pool *dp);
110 /* returns TRUE if someone is waiting for the next txg to sync */
111 extern boolean_t txg_sync_waiting(struct dsl_pool *dp);
114 * Wait for pending commit callbacks of already-synced transactions to finish
117 extern void txg_wait_callbacks(struct dsl_pool *dp);
120 * Per-txg object lists.
123 #define TXG_CLEAN(txg) ((txg) - 1)
125 extern void txg_list_create(txg_list_t *tl, size_t offset);
126 extern void txg_list_destroy(txg_list_t *tl);
127 extern boolean_t txg_list_empty(txg_list_t *tl, uint64_t txg);
128 extern int txg_list_add(txg_list_t *tl, void *p, uint64_t txg);
129 extern int txg_list_add_tail(txg_list_t *tl, void *p, uint64_t txg);
130 extern void *txg_list_remove(txg_list_t *tl, uint64_t txg);
131 extern void *txg_list_remove_this(txg_list_t *tl, void *p, uint64_t txg);
132 extern int txg_list_member(txg_list_t *tl, void *p, uint64_t txg);
133 extern void *txg_list_head(txg_list_t *tl, uint64_t txg);
134 extern void *txg_list_next(txg_list_t *tl, void *p, uint64_t txg);
137 extern int zfs_txg_timeout;
143 #endif /* _SYS_TXG_H */