xref: /onnv-gate/usr/src/uts/common/fs/zfs/sys/metaslab_impl.h (revision 11146:7e58f40bcb1c)
1789Sahrens /*
2789Sahrens  * CDDL HEADER START
3789Sahrens  *
4789Sahrens  * The contents of this file are subject to the terms of the
51732Sbonwick  * Common Development and Distribution License (the "License").
61732Sbonwick  * 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 /*
229480SGeorge.Wilson@Sun.COM  * Copyright 2009 Sun Microsystems, Inc.  All rights reserved.
23789Sahrens  * Use is subject to license terms.
24789Sahrens  */
25789Sahrens 
26789Sahrens #ifndef _SYS_METASLAB_IMPL_H
27789Sahrens #define	_SYS_METASLAB_IMPL_H
28789Sahrens 
29789Sahrens #include <sys/metaslab.h>
30789Sahrens #include <sys/space_map.h>
31789Sahrens #include <sys/vdev.h>
32789Sahrens #include <sys/txg.h>
33789Sahrens #include <sys/avl.h>
34789Sahrens 
35789Sahrens #ifdef	__cplusplus
36789Sahrens extern "C" {
37789Sahrens #endif
38789Sahrens 
39789Sahrens struct metaslab_class {
4010594SGeorge.Wilson@Sun.COM 	spa_t			*mc_spa;
41789Sahrens 	metaslab_group_t	*mc_rotor;
429480SGeorge.Wilson@Sun.COM 	space_map_ops_t		*mc_ops;
4310922SJeff.Bonwick@Sun.COM 	uint64_t		mc_aliquot;
4410922SJeff.Bonwick@Sun.COM 	uint64_t		mc_alloc;	/* total allocated space */
4510922SJeff.Bonwick@Sun.COM 	uint64_t		mc_deferred;	/* total deferred frees */
4610922SJeff.Bonwick@Sun.COM 	uint64_t		mc_space;	/* total space (alloc + free) */
4710922SJeff.Bonwick@Sun.COM 	uint64_t		mc_dspace;	/* total deflated space */
48789Sahrens };
49789Sahrens 
50789Sahrens struct metaslab_group {
51789Sahrens 	kmutex_t		mg_lock;
52789Sahrens 	avl_tree_t		mg_metaslab_tree;
53789Sahrens 	uint64_t		mg_aliquot;
54*11146SGeorge.Wilson@Sun.COM 	uint64_t		mg_bonus_area;
55789Sahrens 	int64_t			mg_bias;
5610974SJeff.Bonwick@Sun.COM 	int64_t			mg_activation_count;
57789Sahrens 	metaslab_class_t	*mg_class;
58789Sahrens 	vdev_t			*mg_vd;
59789Sahrens 	metaslab_group_t	*mg_prev;
60789Sahrens 	metaslab_group_t	*mg_next;
61789Sahrens };
62789Sahrens 
63789Sahrens /*
641732Sbonwick  * Each metaslab's free space is tracked in space map object in the MOS,
651732Sbonwick  * which is only updated in syncing context.  Each time we sync a txg,
661732Sbonwick  * we append the allocs and frees from that txg to the space map object.
671732Sbonwick  * When the txg is done syncing, metaslab_sync_done() updates ms_smo
681732Sbonwick  * to ms_smo_syncing.  Everything in ms_smo is always safe to allocate.
69789Sahrens  */
70789Sahrens struct metaslab {
71789Sahrens 	kmutex_t	ms_lock;	/* metaslab lock		*/
721732Sbonwick 	space_map_obj_t	ms_smo;		/* synced space map object	*/
731732Sbonwick 	space_map_obj_t	ms_smo_syncing;	/* syncing space map object	*/
74789Sahrens 	space_map_t	ms_allocmap[TXG_SIZE];  /* allocated this txg	*/
75789Sahrens 	space_map_t	ms_freemap[TXG_SIZE];	/* freed this txg	*/
7610921STim.Haley@Sun.COM 	space_map_t	ms_defermap[TXG_DEFER_SIZE]; /* deferred frees	*/
771732Sbonwick 	space_map_t	ms_map;		/* in-core free space map	*/
7810921STim.Haley@Sun.COM 	int64_t		ms_deferspace;	/* sum of ms_defermap[] space	*/
791732Sbonwick 	uint64_t	ms_weight;	/* weight vs. others in group	*/
801732Sbonwick 	metaslab_group_t *ms_group;	/* metaslab group		*/
811732Sbonwick 	avl_node_t	ms_group_node;	/* node in metaslab group tree	*/
82789Sahrens 	txg_node_t	ms_txg_node;	/* per-txg dirty metaslab links	*/
83789Sahrens };
84789Sahrens 
85789Sahrens #ifdef	__cplusplus
86789Sahrens }
87789Sahrens #endif
88789Sahrens 
89789Sahrens #endif	/* _SYS_METASLAB_IMPL_H */
90