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.
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.
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]
22 * Copyright 2009 Sun Microsystems, Inc. All rights reserved.
23 * Use is subject to license terms.
27 * Copyright (c) 2012 by Delphix. All rights reserved.
30 #ifndef _SYS_METASLAB_IMPL_H
31 #define _SYS_METASLAB_IMPL_H
33 #include <sys/metaslab.h>
34 #include <sys/space_map.h>
43 struct metaslab_class {
45 metaslab_group_t *mc_rotor;
46 space_map_ops_t *mc_ops;
48 uint64_t mc_alloc; /* total allocated space */
49 uint64_t mc_deferred; /* total deferred frees */
50 uint64_t mc_space; /* total space (alloc + free) */
51 uint64_t mc_dspace; /* total deflated space */
52 kmutex_t mc_fastwrite_lock;
55 struct metaslab_group {
57 avl_tree_t mg_metaslab_tree;
59 uint64_t mg_bonus_area;
60 uint64_t mg_alloc_failures;
62 int64_t mg_activation_count;
63 metaslab_class_t *mg_class;
65 metaslab_group_t *mg_prev;
66 metaslab_group_t *mg_next;
70 * Each metaslab maintains an in-core free map (ms_map) that contains the
71 * current list of free segments. As blocks are allocated, the allocated
72 * segment is removed from the ms_map and added to a per txg allocation map.
73 * As blocks are freed, they are added to the per txg free map. These per
74 * txg maps allow us to process all allocations and frees in syncing context
75 * where it is safe to update the on-disk space maps.
77 * Each metaslab's free space is tracked in a space map object in the MOS,
78 * which is only updated in syncing context. Each time we sync a txg,
79 * we append the allocs and frees from that txg to the space map object.
80 * When the txg is done syncing, metaslab_sync_done() updates ms_smo
81 * to ms_smo_syncing. Everything in ms_smo is always safe to allocate.
83 * To load the in-core free map we read the space map object from disk.
84 * This object contains a series of alloc and free records that are
85 * combined to make up the list of all free segments in this metaslab. These
86 * segments are represented in-core by the ms_map and are stored in an
89 * As the space map objects grows (as a result of the appends) it will
90 * eventually become space-inefficient. When the space map object is
91 * zfs_condense_pct/100 times the size of the minimal on-disk representation,
92 * we rewrite it in its minimized form.
95 kmutex_t ms_lock; /* metaslab lock */
96 space_map_obj_t ms_smo; /* synced space map object */
97 space_map_obj_t ms_smo_syncing; /* syncing space map object */
98 space_map_t *ms_allocmap[TXG_SIZE]; /* allocated this txg */
99 space_map_t *ms_freemap[TXG_SIZE]; /* freed this txg */
100 space_map_t *ms_defermap[TXG_DEFER_SIZE]; /* deferred frees */
101 space_map_t *ms_map; /* in-core free space map */
102 int64_t ms_deferspace; /* sum of ms_defermap[] space */
103 uint64_t ms_weight; /* weight vs. others in group */
104 metaslab_group_t *ms_group; /* metaslab group */
105 avl_node_t ms_group_node; /* node in metaslab group tree */
106 txg_node_t ms_txg_node; /* per-txg dirty metaslab links */
113 #endif /* _SYS_METASLAB_IMPL_H */