xref: /illumos-gate/usr/src/uts/common/fs/zfs/sys/metaslab_impl.h (revision a15215608b8bd90f714f6db21ee623b584607cb6)
1fa9e4066Sahrens /*
2fa9e4066Sahrens  * CDDL HEADER START
3fa9e4066Sahrens  *
4fa9e4066Sahrens  * The contents of this file are subject to the terms of the
5ecc2d604Sbonwick  * Common Development and Distribution License (the "License").
6ecc2d604Sbonwick  * 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 /*
22d6e555bdSGeorge Wilson  * Copyright 2009 Sun Microsystems, Inc.  All rights reserved.
23fa9e4066Sahrens  * Use is subject to license terms.
24fa9e4066Sahrens  */
25fa9e4066Sahrens 
26fa9e4066Sahrens #ifndef _SYS_METASLAB_IMPL_H
27fa9e4066Sahrens #define	_SYS_METASLAB_IMPL_H
28fa9e4066Sahrens 
29fa9e4066Sahrens #include <sys/metaslab.h>
30fa9e4066Sahrens #include <sys/space_map.h>
31fa9e4066Sahrens #include <sys/vdev.h>
32fa9e4066Sahrens #include <sys/txg.h>
33fa9e4066Sahrens #include <sys/avl.h>
34fa9e4066Sahrens 
35fa9e4066Sahrens #ifdef	__cplusplus
36fa9e4066Sahrens extern "C" {
37fa9e4066Sahrens #endif
38fa9e4066Sahrens 
39fa9e4066Sahrens struct metaslab_class {
4088ecc943SGeorge Wilson 	spa_t			*mc_spa;
41fa9e4066Sahrens 	metaslab_group_t	*mc_rotor;
42d6e555bdSGeorge Wilson 	space_map_ops_t		*mc_ops;
43b24ab676SJeff Bonwick 	uint64_t		mc_aliquot;
44b24ab676SJeff Bonwick 	uint64_t		mc_alloc;	/* total allocated space */
45b24ab676SJeff Bonwick 	uint64_t		mc_deferred;	/* total deferred frees */
46b24ab676SJeff Bonwick 	uint64_t		mc_space;	/* total space (alloc + free) */
47b24ab676SJeff Bonwick 	uint64_t		mc_dspace;	/* total deflated space */
48fa9e4066Sahrens };
49fa9e4066Sahrens 
50fa9e4066Sahrens struct metaslab_group {
51fa9e4066Sahrens 	kmutex_t		mg_lock;
52fa9e4066Sahrens 	avl_tree_t		mg_metaslab_tree;
53fa9e4066Sahrens 	uint64_t		mg_aliquot;
54fa9e4066Sahrens 	int64_t			mg_bias;
55*a1521560SJeff Bonwick 	int64_t			mg_activation_count;
56fa9e4066Sahrens 	metaslab_class_t	*mg_class;
57fa9e4066Sahrens 	vdev_t			*mg_vd;
58fa9e4066Sahrens 	metaslab_group_t	*mg_prev;
59fa9e4066Sahrens 	metaslab_group_t	*mg_next;
60fa9e4066Sahrens };
61fa9e4066Sahrens 
62fa9e4066Sahrens /*
63ecc2d604Sbonwick  * Each metaslab's free space is tracked in space map object in the MOS,
64ecc2d604Sbonwick  * which is only updated in syncing context.  Each time we sync a txg,
65ecc2d604Sbonwick  * we append the allocs and frees from that txg to the space map object.
66ecc2d604Sbonwick  * When the txg is done syncing, metaslab_sync_done() updates ms_smo
67ecc2d604Sbonwick  * to ms_smo_syncing.  Everything in ms_smo is always safe to allocate.
68fa9e4066Sahrens  */
69fa9e4066Sahrens struct metaslab {
70fa9e4066Sahrens 	kmutex_t	ms_lock;	/* metaslab lock		*/
71ecc2d604Sbonwick 	space_map_obj_t	ms_smo;		/* synced space map object	*/
72ecc2d604Sbonwick 	space_map_obj_t	ms_smo_syncing;	/* syncing space map object	*/
73fa9e4066Sahrens 	space_map_t	ms_allocmap[TXG_SIZE];  /* allocated this txg	*/
74fa9e4066Sahrens 	space_map_t	ms_freemap[TXG_SIZE];	/* freed this txg	*/
75468c413aSTim Haley 	space_map_t	ms_defermap[TXG_DEFER_SIZE]; /* deferred frees	*/
76fa9e4066Sahrens 	space_map_t	ms_map;		/* in-core free space map	*/
77468c413aSTim Haley 	int64_t		ms_deferspace;	/* sum of ms_defermap[] space	*/
78ecc2d604Sbonwick 	uint64_t	ms_weight;	/* weight vs. others in group	*/
79ecc2d604Sbonwick 	metaslab_group_t *ms_group;	/* metaslab group		*/
80ecc2d604Sbonwick 	avl_node_t	ms_group_node;	/* node in metaslab group tree	*/
81ecc2d604Sbonwick 	txg_node_t	ms_txg_node;	/* per-txg dirty metaslab links	*/
82fa9e4066Sahrens };
83fa9e4066Sahrens 
84fa9e4066Sahrens #ifdef	__cplusplus
85fa9e4066Sahrens }
86fa9e4066Sahrens #endif
87fa9e4066Sahrens 
88fa9e4066Sahrens #endif	/* _SYS_METASLAB_IMPL_H */
89