xref: /titanic_50/usr/src/uts/common/fs/zfs/sys/txg.h (revision 73527f441cbbd953fa42cc5a30a413bad75f24a9)
1fa9e4066Sahrens /*
2fa9e4066Sahrens  * CDDL HEADER START
3fa9e4066Sahrens  *
4fa9e4066Sahrens  * The contents of this file are subject to the terms of the
51ab7f2deSmaybee  * Common Development and Distribution License (the "License").
61ab7f2deSmaybee  * You may not use this file except in compliance with the License.
7fa9e4066Sahrens  *
8fa9e4066Sahrens  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9fa9e4066Sahrens  * or http://www.opensolaris.org/os/licensing.
10fa9e4066Sahrens  * See the License for the specific language governing permissions
11fa9e4066Sahrens  * and limitations under the License.
12fa9e4066Sahrens  *
13fa9e4066Sahrens  * When distributing Covered Code, include this CDDL HEADER in each
14fa9e4066Sahrens  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15fa9e4066Sahrens  * If applicable, add the following below this CDDL HEADER, with the
16fa9e4066Sahrens  * fields enclosed by brackets "[]" replaced with your own identifying
17fa9e4066Sahrens  * information: Portions Copyright [yyyy] [name of copyright owner]
18fa9e4066Sahrens  *
19fa9e4066Sahrens  * CDDL HEADER END
20fa9e4066Sahrens  */
21fa9e4066Sahrens /*
22495807d7SMatthew Ahrens  * Copyright 2010 Sun Microsystems, Inc.  All rights reserved.
23fa9e4066Sahrens  * Use is subject to license terms.
24fa9e4066Sahrens  */
25ce636f8bSMatthew Ahrens /*
26*73527f44SAlex Reece  * Copyright (c) 2012, 2014 by Delphix. All rights reserved.
27ce636f8bSMatthew Ahrens  */
28fa9e4066Sahrens 
29fa9e4066Sahrens #ifndef _SYS_TXG_H
30fa9e4066Sahrens #define	_SYS_TXG_H
31fa9e4066Sahrens 
32fa9e4066Sahrens #include <sys/spa.h>
33fa9e4066Sahrens #include <sys/zfs_context.h>
34fa9e4066Sahrens 
35fa9e4066Sahrens #ifdef	__cplusplus
36fa9e4066Sahrens extern "C" {
37fa9e4066Sahrens #endif
38fa9e4066Sahrens 
39fa9e4066Sahrens #define	TXG_CONCURRENT_STATES	3	/* open, quiescing, syncing	*/
40fa9e4066Sahrens #define	TXG_SIZE		4		/* next power of 2	*/
41fa9e4066Sahrens #define	TXG_MASK		(TXG_SIZE - 1)	/* mask for size	*/
42fa9e4066Sahrens #define	TXG_INITIAL		TXG_SIZE	/* initial txg 		*/
43fa9e4066Sahrens #define	TXG_IDX			(txg & TXG_MASK)
44fa9e4066Sahrens 
45468c413aSTim Haley /* Number of txgs worth of frees we defer adding to in-core spacemaps */
46468c413aSTim Haley #define	TXG_DEFER_SIZE		2
47468c413aSTim Haley 
48fa9e4066Sahrens typedef struct tx_cpu tx_cpu_t;
49fa9e4066Sahrens 
50fa9e4066Sahrens typedef struct txg_handle {
51fa9e4066Sahrens 	tx_cpu_t	*th_cpu;
52fa9e4066Sahrens 	uint64_t	th_txg;
53fa9e4066Sahrens } txg_handle_t;
54fa9e4066Sahrens 
55fa9e4066Sahrens typedef struct txg_node {
56fa9e4066Sahrens 	struct txg_node	*tn_next[TXG_SIZE];
57fa9e4066Sahrens 	uint8_t		tn_member[TXG_SIZE];
58fa9e4066Sahrens } txg_node_t;
59fa9e4066Sahrens 
60fa9e4066Sahrens typedef struct txg_list {
61fa9e4066Sahrens 	kmutex_t	tl_lock;
62fa9e4066Sahrens 	size_t		tl_offset;
63fa9e4066Sahrens 	txg_node_t	*tl_head[TXG_SIZE];
64fa9e4066Sahrens } txg_list_t;
65fa9e4066Sahrens 
66fa9e4066Sahrens struct dsl_pool;
67fa9e4066Sahrens 
68fa9e4066Sahrens extern void txg_init(struct dsl_pool *dp, uint64_t txg);
69fa9e4066Sahrens extern void txg_fini(struct dsl_pool *dp);
70fa9e4066Sahrens extern void txg_sync_start(struct dsl_pool *dp);
71fa9e4066Sahrens extern void txg_sync_stop(struct dsl_pool *dp);
72fa9e4066Sahrens extern uint64_t txg_hold_open(struct dsl_pool *dp, txg_handle_t *txghp);
73fa9e4066Sahrens extern void txg_rele_to_quiesce(txg_handle_t *txghp);
74fa9e4066Sahrens extern void txg_rele_to_sync(txg_handle_t *txghp);
75d20e665cSRicardo M. Correia extern void txg_register_callbacks(txg_handle_t *txghp, list_t *tx_callbacks);
76fa9e4066Sahrens 
770689f76cSAdam Leventhal extern void txg_delay(struct dsl_pool *dp, uint64_t txg, hrtime_t delta,
780689f76cSAdam Leventhal     hrtime_t resolution);
7969962b56SMatthew Ahrens extern void txg_kick(struct dsl_pool *dp);
801ab7f2deSmaybee 
811ab7f2deSmaybee /*
82fa9e4066Sahrens  * Wait until the given transaction group has finished syncing.
83fa9e4066Sahrens  * Try to make this happen as soon as possible (eg. kick off any
84fa9e4066Sahrens  * necessary syncs immediately).  If txg==0, wait for the currently open
85fa9e4066Sahrens  * txg to finish syncing.
86fa9e4066Sahrens  */
87fa9e4066Sahrens extern void txg_wait_synced(struct dsl_pool *dp, uint64_t txg);
88fa9e4066Sahrens 
89fa9e4066Sahrens /*
90fa9e4066Sahrens  * Wait until the given transaction group, or one after it, is
91fa9e4066Sahrens  * the open transaction group.  Try to make this happen as soon
92fa9e4066Sahrens  * as possible (eg. kick off any necessary syncs immediately).
93fa9e4066Sahrens  * If txg == 0, wait for the next open txg.
94fa9e4066Sahrens  */
95fa9e4066Sahrens extern void txg_wait_open(struct dsl_pool *dp, uint64_t txg);
96fa9e4066Sahrens 
97fa9e4066Sahrens /*
98fa9e4066Sahrens  * Returns TRUE if we are "backed up" waiting for the syncing
99fa9e4066Sahrens  * transaction to complete; otherwise returns FALSE.
100fa9e4066Sahrens  */
101088f3894Sahrens extern boolean_t txg_stalled(struct dsl_pool *dp);
102088f3894Sahrens 
103088f3894Sahrens /* returns TRUE if someone is waiting for the next txg to sync */
104088f3894Sahrens extern boolean_t txg_sync_waiting(struct dsl_pool *dp);
105fa9e4066Sahrens 
106fa9e4066Sahrens /*
107fa9e4066Sahrens  * Per-txg object lists.
108fa9e4066Sahrens  */
109fa9e4066Sahrens 
110fa9e4066Sahrens #define	TXG_CLEAN(txg)	((txg) - 1)
111fa9e4066Sahrens 
112fa9e4066Sahrens extern void txg_list_create(txg_list_t *tl, size_t offset);
113fa9e4066Sahrens extern void txg_list_destroy(txg_list_t *tl);
114ce636f8bSMatthew Ahrens extern boolean_t txg_list_empty(txg_list_t *tl, uint64_t txg);
115*73527f44SAlex Reece extern boolean_t txg_all_lists_empty(txg_list_t *tl);
1163b2aab18SMatthew Ahrens extern boolean_t txg_list_add(txg_list_t *tl, void *p, uint64_t txg);
1173b2aab18SMatthew Ahrens extern boolean_t txg_list_add_tail(txg_list_t *tl, void *p, uint64_t txg);
118fa9e4066Sahrens extern void *txg_list_remove(txg_list_t *tl, uint64_t txg);
119fa9e4066Sahrens extern void *txg_list_remove_this(txg_list_t *tl, void *p, uint64_t txg);
1203b2aab18SMatthew Ahrens extern boolean_t txg_list_member(txg_list_t *tl, void *p, uint64_t txg);
121fa9e4066Sahrens extern void *txg_list_head(txg_list_t *tl, uint64_t txg);
122fa9e4066Sahrens extern void *txg_list_next(txg_list_t *tl, void *p, uint64_t txg);
123fa9e4066Sahrens 
124fa9e4066Sahrens #ifdef	__cplusplus
125fa9e4066Sahrens }
126fa9e4066Sahrens #endif
127fa9e4066Sahrens 
128fa9e4066Sahrens #endif	/* _SYS_TXG_H */
129