Deleted Added
sdiff udiff text old ( 332547 ) new ( 339105 )
full compact
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

--- 10 unchanged lines hidden (view full) ---

19 * CDDL HEADER END
20 */
21/*
22 * Copyright 2009 Sun Microsystems, Inc. All rights reserved.
23 * Use is subject to license terms.
24 */
25
26/*
27 * Copyright (c) 2011, 2017 by Delphix. All rights reserved.
28 */
29
30#ifndef _SYS_METASLAB_IMPL_H
31#define _SYS_METASLAB_IMPL_H
32
33#include <sys/metaslab.h>
34#include <sys/space_map.h>
35#include <sys/range_tree.h>

--- 11 unchanged lines hidden (view full) ---

47typedef struct metaslab_alloc_trace {
48 list_node_t mat_list_node;
49 metaslab_group_t *mat_mg;
50 metaslab_t *mat_msp;
51 uint64_t mat_size;
52 uint64_t mat_weight;
53 uint32_t mat_dva_id;
54 uint64_t mat_offset;
55} metaslab_alloc_trace_t;
56
57/*
58 * Used by the metaslab allocation tracing facility to indicate
59 * error conditions. These errors are stored to the offset member
60 * of the metaslab_alloc_trace_t record and displayed by mdb.
61 */
62typedef enum trace_alloc_type {

--- 4 unchanged lines hidden (view full) ---

67 TRACE_GROUP_FAILURE = -5ULL,
68 TRACE_ENOSPC = -6ULL,
69 TRACE_CONDENSING = -7ULL,
70 TRACE_VDEV_ERROR = -8ULL
71} trace_alloc_type_t;
72
73#define METASLAB_WEIGHT_PRIMARY (1ULL << 63)
74#define METASLAB_WEIGHT_SECONDARY (1ULL << 62)
75#define METASLAB_WEIGHT_TYPE (1ULL << 61)
76#define METASLAB_ACTIVE_MASK \
77 (METASLAB_WEIGHT_PRIMARY | METASLAB_WEIGHT_SECONDARY)
78
79/*
80 * The metaslab weight is used to encode the amount of free space in a
81 * metaslab, such that the "best" metaslab appears first when sorting the
82 * metaslabs by weight. The weight (and therefore the "best" metaslab) can
83 * be determined in two different ways: by computing a weighted sum of all
84 * the free space in the metaslab (a space based weight) or by counting only
85 * the free segments of the largest size (a segment based weight). We prefer

--- 6 unchanged lines hidden (view full) ---

92 * [2^i, 2^(i+1))
93 * We then encode the largest index, i, that contains regions into the
94 * segment-weighted value.
95 *
96 * Space-based weight:
97 *
98 * 64 56 48 40 32 24 16 8 0
99 * +-------+-------+-------+-------+-------+-------+-------+-------+
100 * |PS1| weighted-free space |
101 * +-------+-------+-------+-------+-------+-------+-------+-------+
102 *
103 * PS - indicates primary and secondary activation
104 * space - the fragmentation-weighted space
105 *
106 * Segment-based weight:
107 *
108 * 64 56 48 40 32 24 16 8 0
109 * +-------+-------+-------+-------+-------+-------+-------+-------+
110 * |PS0| idx| count of segments in region |
111 * +-------+-------+-------+-------+-------+-------+-------+-------+
112 *
113 * PS - indicates primary and secondary activation
114 * idx - index for the highest bucket in the histogram
115 * count - number of segments in the specified bucket
116 */
117#define WEIGHT_GET_ACTIVE(weight) BF64_GET((weight), 62, 2)
118#define WEIGHT_SET_ACTIVE(weight, x) BF64_SET((weight), 62, 2, x)
119
120#define WEIGHT_IS_SPACEBASED(weight) \
121 ((weight) == 0 || BF64_GET((weight), 61, 1))
122#define WEIGHT_SET_SPACEBASED(weight) BF64_SET((weight), 61, 1, 1)
123
124/*
125 * These macros are only applicable to segment-based weighting.
126 */
127#define WEIGHT_GET_INDEX(weight) BF64_GET((weight), 55, 6)
128#define WEIGHT_SET_INDEX(weight, x) BF64_SET((weight), 55, 6, x)
129#define WEIGHT_GET_COUNT(weight) BF64_GET((weight), 0, 55)
130#define WEIGHT_SET_COUNT(weight, x) BF64_SET((weight), 0, 55, x)
131
132/*
133 * A metaslab class encompasses a category of allocatable top-level vdevs.
134 * Each top-level vdev is associated with a metaslab group which defines
135 * the allocatable region for that vdev. Examples of these categories include
136 * "normal" for data block allocations (i.e. main pool allocations) or "log"
137 * for allocations designated for intent log devices (i.e. slog devices).
138 * When a block allocation is requested from the SPA it is associated with a

--- 34 unchanged lines hidden (view full) ---

173 * If there aren't sufficient slots available for the pending zio
174 * then that I/O is throttled until more slots free up. The current
175 * number of reserved allocations is maintained by the mc_alloc_slots
176 * refcount. The mc_alloc_max_slots value determines the maximum
177 * number of allocations that the system allows. Gang blocks are
178 * allowed to reserve slots even if we've reached the maximum
179 * number of allocations allowed.
180 */
181 uint64_t mc_alloc_max_slots;
182 refcount_t mc_alloc_slots;
183
184 uint64_t mc_alloc_groups; /* # of allocatable groups */
185
186 uint64_t mc_alloc; /* total allocated space */
187 uint64_t mc_deferred; /* total deferred frees */
188 uint64_t mc_space; /* total space (alloc + free) */
189 uint64_t mc_dspace; /* total deflated space */
190 uint64_t mc_minblocksize;

--- 6 unchanged lines hidden (view full) ---

197 * list and can belong to only one metaslab class. Metaslab groups may become
198 * ineligible for allocations for a number of reasons such as limited free
199 * space, fragmentation, or going offline. When this happens the allocator will
200 * simply find the next metaslab group in the linked list and attempt
201 * to allocate from that group instead.
202 */
203struct metaslab_group {
204 kmutex_t mg_lock;
205 avl_tree_t mg_metaslab_tree;
206 uint64_t mg_aliquot;
207 boolean_t mg_allocatable; /* can we allocate? */
208
209 /*
210 * A metaslab group is considered to be initialized only after
211 * we have updated the MOS config and added the space to the pool.
212 * We only allow allocation attempts to a metaslab group if it
213 * has been initialized.
214 */
215 boolean_t mg_initialized;
216
217 uint64_t mg_free_capacity; /* percentage free */
218 int64_t mg_bias;
219 int64_t mg_activation_count;
220 metaslab_class_t *mg_class;
221 vdev_t *mg_vd;
222 taskq_t *mg_taskq;
223 metaslab_group_t *mg_prev;
224 metaslab_group_t *mg_next;
225
226 /*
227 * Each metaslab group can handle mg_max_alloc_queue_depth allocations
228 * which are tracked by mg_alloc_queue_depth. It's possible for a
229 * metaslab group to handle more allocations than its max. This
230 * can occur when gang blocks are required or when other groups
231 * are unable to handle their share of allocations.
232 */
233 uint64_t mg_max_alloc_queue_depth;
234 refcount_t mg_alloc_queue_depth;
235
236 /*
237 * A metalab group that can no longer allocate the minimum block
238 * size will set mg_no_free_space. Once a metaslab group is out
239 * of space then its share of work must be distributed to other
240 * groups.
241 */
242 boolean_t mg_no_free_space;
243

--- 108 unchanged lines hidden (view full) ---

352 * stay cached.
353 */
354 uint64_t ms_selected_txg;
355
356 uint64_t ms_alloc_txg; /* last successful alloc (debug only) */
357 uint64_t ms_max_size; /* maximum allocatable size */
358
359 /*
360 * The metaslab block allocators can optionally use a size-ordered
361 * range tree and/or an array of LBAs. Not all allocators use
362 * this functionality. The ms_allocatable_by_size should always
363 * contain the same number of segments as the ms_allocatable. The
364 * only difference is that the ms_allocatable_by_size is ordered by
365 * segment sizes.
366 */
367 avl_tree_t ms_allocatable_by_size;
368 uint64_t ms_lbas[MAX_LBAS];
369
370 metaslab_group_t *ms_group; /* metaslab group */
371 avl_node_t ms_group_node; /* node in metaslab group tree */
372 txg_node_t ms_txg_node; /* per-txg dirty metaslab links */
373};
374
375#ifdef __cplusplus
376}
377#endif
378
379#endif /* _SYS_METASLAB_IMPL_H */