xref: /illumos-gate/usr/src/uts/common/fs/zfs/sys/metaslab_impl.h (revision 8671400134a11c848244896ca51a7db4d0f69da4)
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.
2401f55e48SGeorge Wilson  */
2501f55e48SGeorge Wilson 
2601f55e48SGeorge Wilson /*
27*86714001SSerapheim Dimitropoulos  * Copyright (c) 2011, 2017 by Delphix. All rights reserved.
28fa9e4066Sahrens  */
29fa9e4066Sahrens 
30fa9e4066Sahrens #ifndef _SYS_METASLAB_IMPL_H
31fa9e4066Sahrens #define	_SYS_METASLAB_IMPL_H
32fa9e4066Sahrens 
33fa9e4066Sahrens #include <sys/metaslab.h>
34fa9e4066Sahrens #include <sys/space_map.h>
350713e232SGeorge Wilson #include <sys/range_tree.h>
36fa9e4066Sahrens #include <sys/vdev.h>
37fa9e4066Sahrens #include <sys/txg.h>
38fa9e4066Sahrens #include <sys/avl.h>
39fa9e4066Sahrens 
40fa9e4066Sahrens #ifdef	__cplusplus
41fa9e4066Sahrens extern "C" {
42fa9e4066Sahrens #endif
43fa9e4066Sahrens 
448363e80aSGeorge Wilson /*
458363e80aSGeorge Wilson  * Metaslab allocation tracing record.
468363e80aSGeorge Wilson  */
478363e80aSGeorge Wilson typedef struct metaslab_alloc_trace {
488363e80aSGeorge Wilson 	list_node_t			mat_list_node;
498363e80aSGeorge Wilson 	metaslab_group_t		*mat_mg;
508363e80aSGeorge Wilson 	metaslab_t			*mat_msp;
518363e80aSGeorge Wilson 	uint64_t			mat_size;
528363e80aSGeorge Wilson 	uint64_t			mat_weight;
538363e80aSGeorge Wilson 	uint32_t			mat_dva_id;
548363e80aSGeorge Wilson 	uint64_t			mat_offset;
558363e80aSGeorge Wilson } metaslab_alloc_trace_t;
568363e80aSGeorge Wilson 
578363e80aSGeorge Wilson /*
588363e80aSGeorge Wilson  * Used by the metaslab allocation tracing facility to indicate
598363e80aSGeorge Wilson  * error conditions. These errors are stored to the offset member
608363e80aSGeorge Wilson  * of the metaslab_alloc_trace_t record and displayed by mdb.
618363e80aSGeorge Wilson  */
628363e80aSGeorge Wilson typedef enum trace_alloc_type {
638363e80aSGeorge Wilson 	TRACE_ALLOC_FAILURE	= -1ULL,
648363e80aSGeorge Wilson 	TRACE_TOO_SMALL		= -2ULL,
658363e80aSGeorge Wilson 	TRACE_FORCE_GANG	= -3ULL,
668363e80aSGeorge Wilson 	TRACE_NOT_ALLOCATABLE	= -4ULL,
678363e80aSGeorge Wilson 	TRACE_GROUP_FAILURE	= -5ULL,
688363e80aSGeorge Wilson 	TRACE_ENOSPC		= -6ULL,
698363e80aSGeorge Wilson 	TRACE_CONDENSING	= -7ULL,
708363e80aSGeorge Wilson 	TRACE_VDEV_ERROR	= -8ULL
718363e80aSGeorge Wilson } trace_alloc_type_t;
728363e80aSGeorge Wilson 
738363e80aSGeorge Wilson #define	METASLAB_WEIGHT_PRIMARY		(1ULL << 63)
748363e80aSGeorge Wilson #define	METASLAB_WEIGHT_SECONDARY	(1ULL << 62)
758363e80aSGeorge Wilson #define	METASLAB_WEIGHT_TYPE		(1ULL << 61)
768363e80aSGeorge Wilson #define	METASLAB_ACTIVE_MASK		\
778363e80aSGeorge Wilson 	(METASLAB_WEIGHT_PRIMARY | METASLAB_WEIGHT_SECONDARY)
788363e80aSGeorge Wilson 
798363e80aSGeorge Wilson /*
808363e80aSGeorge Wilson  * The metaslab weight is used to encode the amount of free space in a
818363e80aSGeorge Wilson  * metaslab, such that the "best" metaslab appears first when sorting the
828363e80aSGeorge Wilson  * metaslabs by weight. The weight (and therefore the "best" metaslab) can
838363e80aSGeorge Wilson  * be determined in two different ways: by computing a weighted sum of all
848363e80aSGeorge Wilson  * the free space in the metaslab (a space based weight) or by counting only
858363e80aSGeorge Wilson  * the free segments of the largest size (a segment based weight). We prefer
868363e80aSGeorge Wilson  * the segment based weight because it reflects how the free space is
878363e80aSGeorge Wilson  * comprised, but we cannot always use it -- legacy pools do not have the
888363e80aSGeorge Wilson  * space map histogram information necessary to determine the largest
898363e80aSGeorge Wilson  * contiguous regions. Pools that have the space map histogram determine
908363e80aSGeorge Wilson  * the segment weight by looking at each bucket in the histogram and
918363e80aSGeorge Wilson  * determining the free space whose size in bytes is in the range:
928363e80aSGeorge Wilson  *	[2^i, 2^(i+1))
938363e80aSGeorge Wilson  * We then encode the largest index, i, that contains regions into the
948363e80aSGeorge Wilson  * segment-weighted value.
958363e80aSGeorge Wilson  *
968363e80aSGeorge Wilson  * Space-based weight:
978363e80aSGeorge Wilson  *
988363e80aSGeorge Wilson  *      64      56      48      40      32      24      16      8       0
998363e80aSGeorge Wilson  *      +-------+-------+-------+-------+-------+-------+-------+-------+
1008363e80aSGeorge Wilson  *      |PS1|                   weighted-free space                     |
1018363e80aSGeorge Wilson  *      +-------+-------+-------+-------+-------+-------+-------+-------+
1028363e80aSGeorge Wilson  *
1038363e80aSGeorge Wilson  *	PS - indicates primary and secondary activation
1048363e80aSGeorge Wilson  *	space - the fragmentation-weighted space
1058363e80aSGeorge Wilson  *
1068363e80aSGeorge Wilson  * Segment-based weight:
1078363e80aSGeorge Wilson  *
1088363e80aSGeorge Wilson  *      64      56      48      40      32      24      16      8       0
1098363e80aSGeorge Wilson  *      +-------+-------+-------+-------+-------+-------+-------+-------+
1108363e80aSGeorge Wilson  *      |PS0| idx|             count of segments in region              |
1118363e80aSGeorge Wilson  *      +-------+-------+-------+-------+-------+-------+-------+-------+
1128363e80aSGeorge Wilson  *
1138363e80aSGeorge Wilson  *	PS - indicates primary and secondary activation
1148363e80aSGeorge Wilson  *	idx - index for the highest bucket in the histogram
1158363e80aSGeorge Wilson  *	count - number of segments in the specified bucket
1168363e80aSGeorge Wilson  */
1178363e80aSGeorge Wilson #define	WEIGHT_GET_ACTIVE(weight)		BF64_GET((weight), 62, 2)
1188363e80aSGeorge Wilson #define	WEIGHT_SET_ACTIVE(weight, x)		BF64_SET((weight), 62, 2, x)
1198363e80aSGeorge Wilson 
1208363e80aSGeorge Wilson #define	WEIGHT_IS_SPACEBASED(weight)		\
1218363e80aSGeorge Wilson 	((weight) == 0 || BF64_GET((weight), 61, 1))
1228363e80aSGeorge Wilson #define	WEIGHT_SET_SPACEBASED(weight)		BF64_SET((weight), 61, 1, 1)
1238363e80aSGeorge Wilson 
1248363e80aSGeorge Wilson /*
1258363e80aSGeorge Wilson  * These macros are only applicable to segment-based weighting.
1268363e80aSGeorge Wilson  */
1278363e80aSGeorge Wilson #define	WEIGHT_GET_INDEX(weight)		BF64_GET((weight), 55, 6)
1288363e80aSGeorge Wilson #define	WEIGHT_SET_INDEX(weight, x)		BF64_SET((weight), 55, 6, x)
1298363e80aSGeorge Wilson #define	WEIGHT_GET_COUNT(weight)		BF64_GET((weight), 0, 55)
1308363e80aSGeorge Wilson #define	WEIGHT_SET_COUNT(weight, x)		BF64_SET((weight), 0, 55, x)
1318363e80aSGeorge Wilson 
1322e4c9986SGeorge Wilson /*
1332e4c9986SGeorge Wilson  * A metaslab class encompasses a category of allocatable top-level vdevs.
1342e4c9986SGeorge Wilson  * Each top-level vdev is associated with a metaslab group which defines
1352e4c9986SGeorge Wilson  * the allocatable region for that vdev. Examples of these categories include
1362e4c9986SGeorge Wilson  * "normal" for data block allocations (i.e. main pool allocations) or "log"
1372e4c9986SGeorge Wilson  * for allocations designated for intent log devices (i.e. slog devices).
1382e4c9986SGeorge Wilson  * When a block allocation is requested from the SPA it is associated with a
1392e4c9986SGeorge Wilson  * metaslab_class_t, and only top-level vdevs (i.e. metaslab groups) belonging
1402e4c9986SGeorge Wilson  * to the class can be used to satisfy that request. Allocations are done
1412e4c9986SGeorge Wilson  * by traversing the metaslab groups that are linked off of the mc_rotor field.
1422e4c9986SGeorge Wilson  * This rotor points to the next metaslab group where allocations will be
1432e4c9986SGeorge Wilson  * attempted. Allocating a block is a 3 step process -- select the metaslab
1442e4c9986SGeorge Wilson  * group, select the metaslab, and then allocate the block. The metaslab
1452e4c9986SGeorge Wilson  * class defines the low-level block allocator that will be used as the
1462e4c9986SGeorge Wilson  * final step in allocation. These allocators are pluggable allowing each class
1472e4c9986SGeorge Wilson  * to use a block allocator that best suits that class.
1482e4c9986SGeorge Wilson  */
149fa9e4066Sahrens struct metaslab_class {
1500f7643c7SGeorge Wilson 	kmutex_t		mc_lock;
15188ecc943SGeorge Wilson 	spa_t			*mc_spa;
152fa9e4066Sahrens 	metaslab_group_t	*mc_rotor;
1530713e232SGeorge Wilson 	metaslab_ops_t		*mc_ops;
154b24ab676SJeff Bonwick 	uint64_t		mc_aliquot;
1550f7643c7SGeorge Wilson 
1560f7643c7SGeorge Wilson 	/*
1570f7643c7SGeorge Wilson 	 * Track the number of metaslab groups that have been initialized
1580f7643c7SGeorge Wilson 	 * and can accept allocations. An initialized metaslab group is
1590f7643c7SGeorge Wilson 	 * one has been completely added to the config (i.e. we have
1600f7643c7SGeorge Wilson 	 * updated the MOS config and the space has been added to the pool).
1610f7643c7SGeorge Wilson 	 */
1620f7643c7SGeorge Wilson 	uint64_t		mc_groups;
1630f7643c7SGeorge Wilson 
1640f7643c7SGeorge Wilson 	/*
1650f7643c7SGeorge Wilson 	 * Toggle to enable/disable the allocation throttle.
1660f7643c7SGeorge Wilson 	 */
1670f7643c7SGeorge Wilson 	boolean_t		mc_alloc_throttle_enabled;
1680f7643c7SGeorge Wilson 
1690f7643c7SGeorge Wilson 	/*
1700f7643c7SGeorge Wilson 	 * The allocation throttle works on a reservation system. Whenever
1710f7643c7SGeorge Wilson 	 * an asynchronous zio wants to perform an allocation it must
1720f7643c7SGeorge Wilson 	 * first reserve the number of blocks that it wants to allocate.
1730f7643c7SGeorge Wilson 	 * If there aren't sufficient slots available for the pending zio
1740f7643c7SGeorge Wilson 	 * then that I/O is throttled until more slots free up. The current
1750f7643c7SGeorge Wilson 	 * number of reserved allocations is maintained by the mc_alloc_slots
1760f7643c7SGeorge Wilson 	 * refcount. The mc_alloc_max_slots value determines the maximum
1770f7643c7SGeorge Wilson 	 * number of allocations that the system allows. Gang blocks are
1780f7643c7SGeorge Wilson 	 * allowed to reserve slots even if we've reached the maximum
1790f7643c7SGeorge Wilson 	 * number of allocations allowed.
1800f7643c7SGeorge Wilson 	 */
1810f7643c7SGeorge Wilson 	uint64_t		mc_alloc_max_slots;
1820f7643c7SGeorge Wilson 	refcount_t		mc_alloc_slots;
1830f7643c7SGeorge Wilson 
18422e30981SGeorge Wilson 	uint64_t		mc_alloc_groups; /* # of allocatable groups */
1850f7643c7SGeorge Wilson 
186b24ab676SJeff Bonwick 	uint64_t		mc_alloc;	/* total allocated space */
187b24ab676SJeff Bonwick 	uint64_t		mc_deferred;	/* total deferred frees */
188b24ab676SJeff Bonwick 	uint64_t		mc_space;	/* total space (alloc + free) */
189b24ab676SJeff Bonwick 	uint64_t		mc_dspace;	/* total deflated space */
1902e4c9986SGeorge Wilson 	uint64_t		mc_histogram[RANGE_TREE_HISTOGRAM_SIZE];
191fa9e4066Sahrens };
192fa9e4066Sahrens 
1932e4c9986SGeorge Wilson /*
1942e4c9986SGeorge Wilson  * Metaslab groups encapsulate all the allocatable regions (i.e. metaslabs)
1952e4c9986SGeorge Wilson  * of a top-level vdev. They are linked togther to form a circular linked
1962e4c9986SGeorge Wilson  * list and can belong to only one metaslab class. Metaslab groups may become
1972e4c9986SGeorge Wilson  * ineligible for allocations for a number of reasons such as limited free
1982e4c9986SGeorge Wilson  * space, fragmentation, or going offline. When this happens the allocator will
1992e4c9986SGeorge Wilson  * simply find the next metaslab group in the linked list and attempt
2002e4c9986SGeorge Wilson  * to allocate from that group instead.
2012e4c9986SGeorge Wilson  */
202fa9e4066Sahrens struct metaslab_group {
203fa9e4066Sahrens 	kmutex_t		mg_lock;
204fa9e4066Sahrens 	avl_tree_t		mg_metaslab_tree;
205fa9e4066Sahrens 	uint64_t		mg_aliquot;
20622e30981SGeorge Wilson 	boolean_t		mg_allocatable;		/* can we allocate? */
2070f7643c7SGeorge Wilson 
2080f7643c7SGeorge Wilson 	/*
2090f7643c7SGeorge Wilson 	 * A metaslab group is considered to be initialized only after
2100f7643c7SGeorge Wilson 	 * we have updated the MOS config and added the space to the pool.
2110f7643c7SGeorge Wilson 	 * We only allow allocation attempts to a metaslab group if it
2120f7643c7SGeorge Wilson 	 * has been initialized.
2130f7643c7SGeorge Wilson 	 */
2140f7643c7SGeorge Wilson 	boolean_t		mg_initialized;
2150f7643c7SGeorge Wilson 
21622e30981SGeorge Wilson 	uint64_t		mg_free_capacity;	/* percentage free */
217fa9e4066Sahrens 	int64_t			mg_bias;
218a1521560SJeff Bonwick 	int64_t			mg_activation_count;
219fa9e4066Sahrens 	metaslab_class_t	*mg_class;
220fa9e4066Sahrens 	vdev_t			*mg_vd;
2210713e232SGeorge Wilson 	taskq_t			*mg_taskq;
222fa9e4066Sahrens 	metaslab_group_t	*mg_prev;
223fa9e4066Sahrens 	metaslab_group_t	*mg_next;
2240f7643c7SGeorge Wilson 
2250f7643c7SGeorge Wilson 	/*
2260f7643c7SGeorge Wilson 	 * Each metaslab group can handle mg_max_alloc_queue_depth allocations
2270f7643c7SGeorge Wilson 	 * which are tracked by mg_alloc_queue_depth. It's possible for a
2280f7643c7SGeorge Wilson 	 * metaslab group to handle more allocations than its max. This
2290f7643c7SGeorge Wilson 	 * can occur when gang blocks are required or when other groups
2300f7643c7SGeorge Wilson 	 * are unable to handle their share of allocations.
2310f7643c7SGeorge Wilson 	 */
2320f7643c7SGeorge Wilson 	uint64_t		mg_max_alloc_queue_depth;
2330f7643c7SGeorge Wilson 	refcount_t		mg_alloc_queue_depth;
2340f7643c7SGeorge Wilson 
2350f7643c7SGeorge Wilson 	/*
2360f7643c7SGeorge Wilson 	 * A metalab group that can no longer allocate the minimum block
2370f7643c7SGeorge Wilson 	 * size will set mg_no_free_space. Once a metaslab group is out
2380f7643c7SGeorge Wilson 	 * of space then its share of work must be distributed to other
2390f7643c7SGeorge Wilson 	 * groups.
2400f7643c7SGeorge Wilson 	 */
2410f7643c7SGeorge Wilson 	boolean_t		mg_no_free_space;
2420f7643c7SGeorge Wilson 
2430f7643c7SGeorge Wilson 	uint64_t		mg_allocations;
2440f7643c7SGeorge Wilson 	uint64_t		mg_failed_allocations;
2452e4c9986SGeorge Wilson 	uint64_t		mg_fragmentation;
2462e4c9986SGeorge Wilson 	uint64_t		mg_histogram[RANGE_TREE_HISTOGRAM_SIZE];
247fa9e4066Sahrens };
248fa9e4066Sahrens 
249fa9e4066Sahrens /*
2500713e232SGeorge Wilson  * This value defines the number of elements in the ms_lbas array. The value
2512e4c9986SGeorge Wilson  * of 64 was chosen as it covers all power of 2 buckets up to UINT64_MAX.
2522e4c9986SGeorge Wilson  * This is the equivalent of highbit(UINT64_MAX).
2530713e232SGeorge Wilson  */
2540713e232SGeorge Wilson #define	MAX_LBAS	64
2550713e232SGeorge Wilson 
2560713e232SGeorge Wilson /*
2575f145778SMatthew Ahrens  * Each metaslab maintains a set of in-core trees to track metaslab
258*86714001SSerapheim Dimitropoulos  * operations.  The in-core free tree (ms_allocatable) contains the list of
2595f145778SMatthew Ahrens  * free segments which are eligible for allocation.  As blocks are
260*86714001SSerapheim Dimitropoulos  * allocated, the allocated segment are removed from the ms_allocatable and
261*86714001SSerapheim Dimitropoulos  * added to a per txg allocation tree (ms_allocating).  As blocks are
262*86714001SSerapheim Dimitropoulos  * freed, they are added to the free tree (ms_freeing).  These trees
2635cabbc6bSPrashanth Sreenivasa  * allow us to process all allocations and frees in syncing context
2645cabbc6bSPrashanth Sreenivasa  * where it is safe to update the on-disk space maps.  An additional set
2655cabbc6bSPrashanth Sreenivasa  * of in-core trees is maintained to track deferred frees
266*86714001SSerapheim Dimitropoulos  * (ms_defer).  Once a block is freed it will move from the
267*86714001SSerapheim Dimitropoulos  * ms_freed to the ms_defer tree.  A deferred free means that a block
2685f145778SMatthew Ahrens  * has been freed but cannot be used by the pool until TXG_DEFER_SIZE
2695f145778SMatthew Ahrens  * transactions groups later.  For example, a block that is freed in txg
2705f145778SMatthew Ahrens  * 50 will not be available for reallocation until txg 52 (50 +
2715f145778SMatthew Ahrens  * TXG_DEFER_SIZE).  This provides a safety net for uberblock rollback.
2725f145778SMatthew Ahrens  * A pool could be safely rolled back TXG_DEFERS_SIZE transactions
2735f145778SMatthew Ahrens  * groups and ensure that no block has been reallocated.
2740713e232SGeorge Wilson  *
2750713e232SGeorge Wilson  * The simplified transition diagram looks like this:
2760713e232SGeorge Wilson  *
2770713e232SGeorge Wilson  *
2780713e232SGeorge Wilson  *      ALLOCATE
2790713e232SGeorge Wilson  *         |
2800713e232SGeorge Wilson  *         V
281*86714001SSerapheim Dimitropoulos  *    free segment (ms_allocatable) -> ms_allocating[4] -> (write to space map)
2820713e232SGeorge Wilson  *         ^
283*86714001SSerapheim Dimitropoulos  *         |                        ms_freeing <--- FREE
284*86714001SSerapheim Dimitropoulos  *         |                             |
285*86714001SSerapheim Dimitropoulos  *         |                             v
286*86714001SSerapheim Dimitropoulos  *         |                         ms_freed
287*86714001SSerapheim Dimitropoulos  *         |                             |
288*86714001SSerapheim Dimitropoulos  *         +-------- ms_defer[2] <-------+-------> (write to space map)
28916a4a807SGeorge Wilson  *
2900713e232SGeorge Wilson  *
2910713e232SGeorge Wilson  * Each metaslab's space is tracked in a single space map in the MOS,
2925f145778SMatthew Ahrens  * which is only updated in syncing context.  Each time we sync a txg,
2935f145778SMatthew Ahrens  * we append the allocs and frees from that txg to the space map.  The
2945f145778SMatthew Ahrens  * pool space is only updated once all metaslabs have finished syncing.
29516a4a807SGeorge Wilson  *
2965f145778SMatthew Ahrens  * To load the in-core free tree we read the space map from disk.  This
2975f145778SMatthew Ahrens  * object contains a series of alloc and free records that are combined
2985f145778SMatthew Ahrens  * to make up the list of all free segments in this metaslab.  These
299*86714001SSerapheim Dimitropoulos  * segments are represented in-core by the ms_allocatable and are stored
300*86714001SSerapheim Dimitropoulos  * in an AVL tree.
30116a4a807SGeorge Wilson  *
3020713e232SGeorge Wilson  * As the space map grows (as a result of the appends) it will
3035f145778SMatthew Ahrens  * eventually become space-inefficient.  When the metaslab's in-core
3045f145778SMatthew Ahrens  * free tree is zfs_condense_pct/100 times the size of the minimal
3055f145778SMatthew Ahrens  * on-disk representation, we rewrite it in its minimized form.  If a
3065f145778SMatthew Ahrens  * metaslab needs to condense then we must set the ms_condensing flag to
3075f145778SMatthew Ahrens  * ensure that allocations are not performed on the metaslab that is
3085f145778SMatthew Ahrens  * being written.
309fa9e4066Sahrens  */
310fa9e4066Sahrens struct metaslab {
3110713e232SGeorge Wilson 	kmutex_t	ms_lock;
3125cabbc6bSPrashanth Sreenivasa 	kmutex_t	ms_sync_lock;
3130713e232SGeorge Wilson 	kcondvar_t	ms_load_cv;
3140713e232SGeorge Wilson 	space_map_t	*ms_sm;
3150713e232SGeorge Wilson 	uint64_t	ms_id;
3160713e232SGeorge Wilson 	uint64_t	ms_start;
3170713e232SGeorge Wilson 	uint64_t	ms_size;
3182e4c9986SGeorge Wilson 	uint64_t	ms_fragmentation;
3190713e232SGeorge Wilson 
320*86714001SSerapheim Dimitropoulos 	range_tree_t	*ms_allocating[TXG_SIZE];
321*86714001SSerapheim Dimitropoulos 	range_tree_t	*ms_allocatable;
3220713e232SGeorge Wilson 
3235f145778SMatthew Ahrens 	/*
3245f145778SMatthew Ahrens 	 * The following range trees are accessed only from syncing context.
3255f145778SMatthew Ahrens 	 * ms_free*tree only have entries while syncing, and are empty
3265f145778SMatthew Ahrens 	 * between syncs.
3275f145778SMatthew Ahrens 	 */
328*86714001SSerapheim Dimitropoulos 	range_tree_t	*ms_freeing;	/* to free this syncing txg */
329*86714001SSerapheim Dimitropoulos 	range_tree_t	*ms_freed;	/* already freed this syncing txg */
330*86714001SSerapheim Dimitropoulos 	range_tree_t	*ms_defer[TXG_DEFER_SIZE];
331*86714001SSerapheim Dimitropoulos 	range_tree_t	*ms_checkpointing; /* to add to the checkpoint */
3325f145778SMatthew Ahrens 
3330713e232SGeorge Wilson 	boolean_t	ms_condensing;	/* condensing? */
3342e4c9986SGeorge Wilson 	boolean_t	ms_condense_wanted;
335*86714001SSerapheim Dimitropoulos 	uint64_t	ms_condense_checked_txg;
3368363e80aSGeorge Wilson 
3378363e80aSGeorge Wilson 	/*
3388363e80aSGeorge Wilson 	 * We must hold both ms_lock and ms_group->mg_lock in order to
3398363e80aSGeorge Wilson 	 * modify ms_loaded.
3408363e80aSGeorge Wilson 	 */
3410713e232SGeorge Wilson 	boolean_t	ms_loaded;
3420713e232SGeorge Wilson 	boolean_t	ms_loading;
3430713e232SGeorge Wilson 
344468c413aSTim Haley 	int64_t		ms_deferspace;	/* sum of ms_defermap[] space	*/
345ecc2d604Sbonwick 	uint64_t	ms_weight;	/* weight vs. others in group	*/
3468363e80aSGeorge Wilson 	uint64_t	ms_activation_weight;	/* activation weight	*/
3478363e80aSGeorge Wilson 
3488363e80aSGeorge Wilson 	/*
3498363e80aSGeorge Wilson 	 * Track of whenever a metaslab is selected for loading or allocation.
3508363e80aSGeorge Wilson 	 * We use this value to determine how long the metaslab should
3518363e80aSGeorge Wilson 	 * stay cached.
3528363e80aSGeorge Wilson 	 */
3538363e80aSGeorge Wilson 	uint64_t	ms_selected_txg;
3548363e80aSGeorge Wilson 
3558363e80aSGeorge Wilson 	uint64_t	ms_alloc_txg;	/* last successful alloc (debug only) */
3568363e80aSGeorge Wilson 	uint64_t	ms_max_size;	/* maximum allocatable size	*/
3570713e232SGeorge Wilson 
3580713e232SGeorge Wilson 	/*
3590713e232SGeorge Wilson 	 * The metaslab block allocators can optionally use a size-ordered
3600713e232SGeorge Wilson 	 * range tree and/or an array of LBAs. Not all allocators use
361*86714001SSerapheim Dimitropoulos 	 * this functionality. The ms_allocatable_by_size should always
362*86714001SSerapheim Dimitropoulos 	 * contain the same number of segments as the ms_allocatable. The
363*86714001SSerapheim Dimitropoulos 	 * only difference is that the ms_allocatable_by_size is ordered by
364*86714001SSerapheim Dimitropoulos 	 * segment sizes.
3650713e232SGeorge Wilson 	 */
366*86714001SSerapheim Dimitropoulos 	avl_tree_t	ms_allocatable_by_size;
3670713e232SGeorge Wilson 	uint64_t	ms_lbas[MAX_LBAS];
3680713e232SGeorge Wilson 
369ecc2d604Sbonwick 	metaslab_group_t *ms_group;	/* metaslab group		*/
370ecc2d604Sbonwick 	avl_node_t	ms_group_node;	/* node in metaslab group tree	*/
371ecc2d604Sbonwick 	txg_node_t	ms_txg_node;	/* per-txg dirty metaslab links	*/
372fa9e4066Sahrens };
373fa9e4066Sahrens 
374fa9e4066Sahrens #ifdef	__cplusplus
375fa9e4066Sahrens }
376fa9e4066Sahrens #endif
377fa9e4066Sahrens 
378fa9e4066Sahrens #endif	/* _SYS_METASLAB_IMPL_H */
379