xref: /onnv-gate/usr/src/uts/common/fs/zfs/sys/txg.h (revision 11816:a30797f77200)
1789Sahrens /*
2789Sahrens  * CDDL HEADER START
3789Sahrens  *
4789Sahrens  * The contents of this file are subject to the terms of the
56245Smaybee  * Common Development and Distribution License (the "License").
66245Smaybee  * You may not use this file except in compliance with the License.
7789Sahrens  *
8789Sahrens  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9789Sahrens  * or http://www.opensolaris.org/os/licensing.
10789Sahrens  * See the License for the specific language governing permissions
11789Sahrens  * and limitations under the License.
12789Sahrens  *
13789Sahrens  * When distributing Covered Code, include this CDDL HEADER in each
14789Sahrens  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15789Sahrens  * If applicable, add the following below this CDDL HEADER, with the
16789Sahrens  * fields enclosed by brackets "[]" replaced with your own identifying
17789Sahrens  * information: Portions Copyright [yyyy] [name of copyright owner]
18789Sahrens  *
19789Sahrens  * CDDL HEADER END
20789Sahrens  */
21789Sahrens /*
22*11816SMatthew.Ahrens@Sun.COM  * Copyright 2010 Sun Microsystems, Inc.  All rights reserved.
23789Sahrens  * Use is subject to license terms.
24789Sahrens  */
25789Sahrens 
26789Sahrens #ifndef _SYS_TXG_H
27789Sahrens #define	_SYS_TXG_H
28789Sahrens 
29789Sahrens #include <sys/spa.h>
30789Sahrens #include <sys/zfs_context.h>
31789Sahrens 
32789Sahrens #ifdef	__cplusplus
33789Sahrens extern "C" {
34789Sahrens #endif
35789Sahrens 
36789Sahrens #define	TXG_CONCURRENT_STATES	3	/* open, quiescing, syncing	*/
37789Sahrens #define	TXG_SIZE		4		/* next power of 2	*/
38789Sahrens #define	TXG_MASK		(TXG_SIZE - 1)	/* mask for size	*/
39789Sahrens #define	TXG_INITIAL		TXG_SIZE	/* initial txg 		*/
40789Sahrens #define	TXG_IDX			(txg & TXG_MASK)
41789Sahrens 
4210921STim.Haley@Sun.COM /* Number of txgs worth of frees we defer adding to in-core spacemaps */
4310921STim.Haley@Sun.COM #define	TXG_DEFER_SIZE		2
4410921STim.Haley@Sun.COM 
45789Sahrens #define	TXG_WAIT		1ULL
46789Sahrens #define	TXG_NOWAIT		2ULL
47789Sahrens 
48789Sahrens typedef struct tx_cpu tx_cpu_t;
49789Sahrens 
50789Sahrens typedef struct txg_handle {
51789Sahrens 	tx_cpu_t	*th_cpu;
52789Sahrens 	uint64_t	th_txg;
53789Sahrens } txg_handle_t;
54789Sahrens 
55789Sahrens typedef struct txg_node {
56789Sahrens 	struct txg_node	*tn_next[TXG_SIZE];
57789Sahrens 	uint8_t		tn_member[TXG_SIZE];
58789Sahrens } txg_node_t;
59789Sahrens 
60789Sahrens typedef struct txg_list {
61789Sahrens 	kmutex_t	tl_lock;
62789Sahrens 	size_t		tl_offset;
63789Sahrens 	txg_node_t	*tl_head[TXG_SIZE];
64789Sahrens } txg_list_t;
65789Sahrens 
66789Sahrens struct dsl_pool;
67789Sahrens 
68789Sahrens extern void txg_init(struct dsl_pool *dp, uint64_t txg);
69789Sahrens extern void txg_fini(struct dsl_pool *dp);
70789Sahrens extern void txg_sync_start(struct dsl_pool *dp);
71789Sahrens extern void txg_sync_stop(struct dsl_pool *dp);
72789Sahrens extern uint64_t txg_hold_open(struct dsl_pool *dp, txg_handle_t *txghp);
73789Sahrens extern void txg_rele_to_quiesce(txg_handle_t *txghp);
74789Sahrens extern void txg_rele_to_sync(txg_handle_t *txghp);
7510612SRicardo.M.Correia@Sun.COM extern void txg_register_callbacks(txg_handle_t *txghp, list_t *tx_callbacks);
76789Sahrens 
77789Sahrens /*
786245Smaybee  * Delay the caller by the specified number of ticks or until
796245Smaybee  * the txg closes (whichever comes first).  This is intended
806245Smaybee  * to be used to throttle writers when the system nears its
816245Smaybee  * capacity.
826245Smaybee  */
836245Smaybee extern void txg_delay(struct dsl_pool *dp, uint64_t txg, int ticks);
846245Smaybee 
856245Smaybee /*
86789Sahrens  * Wait until the given transaction group has finished syncing.
87789Sahrens  * Try to make this happen as soon as possible (eg. kick off any
88789Sahrens  * necessary syncs immediately).  If txg==0, wait for the currently open
89789Sahrens  * txg to finish syncing.
90789Sahrens  */
91789Sahrens extern void txg_wait_synced(struct dsl_pool *dp, uint64_t txg);
92789Sahrens 
93789Sahrens /*
94789Sahrens  * Wait until the given transaction group, or one after it, is
95789Sahrens  * the open transaction group.  Try to make this happen as soon
96789Sahrens  * as possible (eg. kick off any necessary syncs immediately).
97789Sahrens  * If txg == 0, wait for the next open txg.
98789Sahrens  */
99789Sahrens extern void txg_wait_open(struct dsl_pool *dp, uint64_t txg);
100789Sahrens 
101789Sahrens /*
102789Sahrens  * Returns TRUE if we are "backed up" waiting for the syncing
103789Sahrens  * transaction to complete; otherwise returns FALSE.
104789Sahrens  */
1057046Sahrens extern boolean_t txg_stalled(struct dsl_pool *dp);
1067046Sahrens 
1077046Sahrens /* returns TRUE if someone is waiting for the next txg to sync */
1087046Sahrens extern boolean_t txg_sync_waiting(struct dsl_pool *dp);
109789Sahrens 
110789Sahrens /*
111789Sahrens  * Per-txg object lists.
112789Sahrens  */
113789Sahrens 
114789Sahrens #define	TXG_CLEAN(txg)	((txg) - 1)
115789Sahrens 
116789Sahrens extern void txg_list_create(txg_list_t *tl, size_t offset);
117789Sahrens extern void txg_list_destroy(txg_list_t *tl);
118789Sahrens extern int txg_list_empty(txg_list_t *tl, uint64_t txg);
119789Sahrens extern int txg_list_add(txg_list_t *tl, void *p, uint64_t txg);
120*11816SMatthew.Ahrens@Sun.COM extern int txg_list_add_tail(txg_list_t *tl, void *p, uint64_t txg);
121789Sahrens extern void *txg_list_remove(txg_list_t *tl, uint64_t txg);
122789Sahrens extern void *txg_list_remove_this(txg_list_t *tl, void *p, uint64_t txg);
123789Sahrens extern int txg_list_member(txg_list_t *tl, void *p, uint64_t txg);
124789Sahrens extern void *txg_list_head(txg_list_t *tl, uint64_t txg);
125789Sahrens extern void *txg_list_next(txg_list_t *tl, void *p, uint64_t txg);
126789Sahrens 
127789Sahrens #ifdef	__cplusplus
128789Sahrens }
129789Sahrens #endif
130789Sahrens 
131789Sahrens #endif	/* _SYS_TXG_H */
132