xref: /illumos-gate/usr/src/uts/common/fs/zfs/sys/metaslab_impl.h (revision ecc2d604e885a75cc75e647b5641af99d5a6f4a6)
1 /*
2  * CDDL HEADER START
3  *
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.
7  *
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.
12  *
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]
18  *
19  * CDDL HEADER END
20  */
21 /*
22  * Copyright 2006 Sun Microsystems, Inc.  All rights reserved.
23  * Use is subject to license terms.
24  */
25 
26 #ifndef _SYS_METASLAB_IMPL_H
27 #define	_SYS_METASLAB_IMPL_H
28 
29 #pragma ident	"%Z%%M%	%I%	%E% SMI"
30 
31 #include <sys/metaslab.h>
32 #include <sys/space_map.h>
33 #include <sys/vdev.h>
34 #include <sys/txg.h>
35 #include <sys/avl.h>
36 
37 #ifdef	__cplusplus
38 extern "C" {
39 #endif
40 
41 struct metaslab_class {
42 	metaslab_group_t	*mc_rotor;
43 	uint64_t		mc_allocated;
44 };
45 
46 struct metaslab_group {
47 	kmutex_t		mg_lock;
48 	avl_tree_t		mg_metaslab_tree;
49 	uint64_t		mg_aliquot;
50 	int64_t			mg_bias;
51 	metaslab_class_t	*mg_class;
52 	vdev_t			*mg_vd;
53 	metaslab_group_t	*mg_prev;
54 	metaslab_group_t	*mg_next;
55 };
56 
57 /*
58  * Each metaslab's free space is tracked in space map object in the MOS,
59  * which is only updated in syncing context.  Each time we sync a txg,
60  * we append the allocs and frees from that txg to the space map object.
61  * When the txg is done syncing, metaslab_sync_done() updates ms_smo
62  * to ms_smo_syncing.  Everything in ms_smo is always safe to allocate.
63  */
64 struct metaslab {
65 	kmutex_t	ms_lock;	/* metaslab lock		*/
66 	space_map_obj_t	ms_smo;		/* synced space map object	*/
67 	space_map_obj_t	ms_smo_syncing;	/* syncing space map object	*/
68 	space_map_t	ms_allocmap[TXG_SIZE];  /* allocated this txg	*/
69 	space_map_t	ms_freemap[TXG_SIZE];	/* freed this txg	*/
70 	space_map_t	ms_map;		/* in-core free space map	*/
71 	uint64_t	ms_weight;	/* weight vs. others in group	*/
72 	metaslab_group_t *ms_group;	/* metaslab group		*/
73 	avl_node_t	ms_group_node;	/* node in metaslab group tree	*/
74 	txg_node_t	ms_txg_node;	/* per-txg dirty metaslab links	*/
75 };
76 
77 #ifdef	__cplusplus
78 }
79 #endif
80 
81 #endif	/* _SYS_METASLAB_IMPL_H */
82