Print this page
NEX-13140 DVA-throttle support for special-class
Reviewed by: Sanjay Nadkarni <sanjay.nadkarni@nexenta.com>
Reviewed by: Saso Kiselkov <saso.kiselkov@nexenta.com>
Reviewed by: Yuri Pankov <yuri.pankov@nexenta.com>
NEX-4620 ZFS autotrim triggering is unreliable
NEX-4622 On-demand TRIM code illogically enumerates metaslabs via mg_ms_tree
Reviewed by: Josef 'Jeff' Sipek <josef.sipek@nexenta.com>
Reviewed by: Hans Rosenfeld <hans.rosenfeld@nexenta.com>
NEX-3984 On-demand TRIM
Reviewed by: Alek Pinchuk <alek@nexenta.com>
Reviewed by: Josef 'Jeff' Sipek <josef.sipek@nexenta.com>
Conflicts:
usr/src/common/zfs/zpool_prop.c
usr/src/uts/common/sys/fs/zfs.h
NEX-3508 CLONE - Port NEX-2946 Add UNMAP/TRIM functionality to ZFS and illumos
Reviewed by: Josef Sipek <josef.sipek@nexenta.com>
Reviewed by: Alek Pinchuk <alek.pinchuk@nexenta.com>
Conflicts:
usr/src/uts/common/io/scsi/targets/sd.c
usr/src/uts/common/sys/scsi/targets/sddef.h
| Split |
Close |
| Expand all |
| Collapse all |
--- old/usr/src/uts/common/fs/zfs/sys/metaslab_impl.h
+++ new/usr/src/uts/common/fs/zfs/sys/metaslab_impl.h
1 1 /*
2 2 * CDDL HEADER START
3 3 *
4 4 * The contents of this file are subject to the terms of the
5 5 * Common Development and Distribution License (the "License").
6 6 * You may not use this file except in compliance with the License.
7 7 *
8 8 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9 9 * or http://www.opensolaris.org/os/licensing.
10 10 * See the License for the specific language governing permissions
11 11 * and limitations under the License.
12 12 *
13 13 * When distributing Covered Code, include this CDDL HEADER in each
14 14 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15 15 * If applicable, add the following below this CDDL HEADER, with the
16 16 * fields enclosed by brackets "[]" replaced with your own identifying
17 17 * information: Portions Copyright [yyyy] [name of copyright owner]
|
↓ open down ↓ |
17 lines elided |
↑ open up ↑ |
18 18 *
19 19 * CDDL HEADER END
20 20 */
21 21 /*
22 22 * Copyright 2009 Sun Microsystems, Inc. All rights reserved.
23 23 * Use is subject to license terms.
24 24 */
25 25
26 26 /*
27 27 * Copyright (c) 2011, 2015 by Delphix. All rights reserved.
28 + * Copyright 2017 Nexenta Systems, Inc. All rights reserved.
28 29 */
29 30
30 31 #ifndef _SYS_METASLAB_IMPL_H
31 32 #define _SYS_METASLAB_IMPL_H
32 33
33 34 #include <sys/metaslab.h>
34 35 #include <sys/space_map.h>
35 36 #include <sys/range_tree.h>
36 37 #include <sys/vdev.h>
37 38 #include <sys/txg.h>
38 39 #include <sys/avl.h>
39 40
40 41 #ifdef __cplusplus
41 42 extern "C" {
42 43 #endif
43 44
44 45 /*
45 46 * Metaslab allocation tracing record.
46 47 */
47 48 typedef struct metaslab_alloc_trace {
48 49 list_node_t mat_list_node;
49 50 metaslab_group_t *mat_mg;
50 51 metaslab_t *mat_msp;
51 52 uint64_t mat_size;
52 53 uint64_t mat_weight;
53 54 uint32_t mat_dva_id;
54 55 uint64_t mat_offset;
55 56 } metaslab_alloc_trace_t;
56 57
57 58 /*
58 59 * Used by the metaslab allocation tracing facility to indicate
59 60 * error conditions. These errors are stored to the offset member
60 61 * of the metaslab_alloc_trace_t record and displayed by mdb.
61 62 */
62 63 typedef enum trace_alloc_type {
63 64 TRACE_ALLOC_FAILURE = -1ULL,
64 65 TRACE_TOO_SMALL = -2ULL,
65 66 TRACE_FORCE_GANG = -3ULL,
66 67 TRACE_NOT_ALLOCATABLE = -4ULL,
67 68 TRACE_GROUP_FAILURE = -5ULL,
68 69 TRACE_ENOSPC = -6ULL,
69 70 TRACE_CONDENSING = -7ULL,
70 71 TRACE_VDEV_ERROR = -8ULL
71 72 } trace_alloc_type_t;
72 73
73 74 #define METASLAB_WEIGHT_PRIMARY (1ULL << 63)
74 75 #define METASLAB_WEIGHT_SECONDARY (1ULL << 62)
75 76 #define METASLAB_WEIGHT_TYPE (1ULL << 61)
76 77 #define METASLAB_ACTIVE_MASK \
77 78 (METASLAB_WEIGHT_PRIMARY | METASLAB_WEIGHT_SECONDARY)
78 79
79 80 /*
80 81 * The metaslab weight is used to encode the amount of free space in a
81 82 * metaslab, such that the "best" metaslab appears first when sorting the
82 83 * metaslabs by weight. The weight (and therefore the "best" metaslab) can
83 84 * be determined in two different ways: by computing a weighted sum of all
84 85 * the free space in the metaslab (a space based weight) or by counting only
85 86 * the free segments of the largest size (a segment based weight). We prefer
86 87 * the segment based weight because it reflects how the free space is
87 88 * comprised, but we cannot always use it -- legacy pools do not have the
88 89 * space map histogram information necessary to determine the largest
89 90 * contiguous regions. Pools that have the space map histogram determine
90 91 * the segment weight by looking at each bucket in the histogram and
91 92 * determining the free space whose size in bytes is in the range:
92 93 * [2^i, 2^(i+1))
93 94 * We then encode the largest index, i, that contains regions into the
94 95 * segment-weighted value.
95 96 *
96 97 * Space-based weight:
97 98 *
98 99 * 64 56 48 40 32 24 16 8 0
99 100 * +-------+-------+-------+-------+-------+-------+-------+-------+
100 101 * |PS1| weighted-free space |
101 102 * +-------+-------+-------+-------+-------+-------+-------+-------+
102 103 *
103 104 * PS - indicates primary and secondary activation
104 105 * space - the fragmentation-weighted space
105 106 *
106 107 * Segment-based weight:
107 108 *
108 109 * 64 56 48 40 32 24 16 8 0
109 110 * +-------+-------+-------+-------+-------+-------+-------+-------+
110 111 * |PS0| idx| count of segments in region |
111 112 * +-------+-------+-------+-------+-------+-------+-------+-------+
112 113 *
113 114 * PS - indicates primary and secondary activation
114 115 * idx - index for the highest bucket in the histogram
115 116 * count - number of segments in the specified bucket
116 117 */
117 118 #define WEIGHT_GET_ACTIVE(weight) BF64_GET((weight), 62, 2)
118 119 #define WEIGHT_SET_ACTIVE(weight, x) BF64_SET((weight), 62, 2, x)
119 120
120 121 #define WEIGHT_IS_SPACEBASED(weight) \
121 122 ((weight) == 0 || BF64_GET((weight), 61, 1))
122 123 #define WEIGHT_SET_SPACEBASED(weight) BF64_SET((weight), 61, 1, 1)
123 124
124 125 /*
125 126 * These macros are only applicable to segment-based weighting.
126 127 */
127 128 #define WEIGHT_GET_INDEX(weight) BF64_GET((weight), 55, 6)
128 129 #define WEIGHT_SET_INDEX(weight, x) BF64_SET((weight), 55, 6, x)
129 130 #define WEIGHT_GET_COUNT(weight) BF64_GET((weight), 0, 55)
130 131 #define WEIGHT_SET_COUNT(weight, x) BF64_SET((weight), 0, 55, x)
131 132
132 133 /*
133 134 * A metaslab class encompasses a category of allocatable top-level vdevs.
134 135 * Each top-level vdev is associated with a metaslab group which defines
135 136 * the allocatable region for that vdev. Examples of these categories include
136 137 * "normal" for data block allocations (i.e. main pool allocations) or "log"
137 138 * for allocations designated for intent log devices (i.e. slog devices).
138 139 * When a block allocation is requested from the SPA it is associated with a
139 140 * metaslab_class_t, and only top-level vdevs (i.e. metaslab groups) belonging
140 141 * to the class can be used to satisfy that request. Allocations are done
141 142 * by traversing the metaslab groups that are linked off of the mc_rotor field.
142 143 * This rotor points to the next metaslab group where allocations will be
143 144 * attempted. Allocating a block is a 3 step process -- select the metaslab
144 145 * group, select the metaslab, and then allocate the block. The metaslab
145 146 * class defines the low-level block allocator that will be used as the
146 147 * final step in allocation. These allocators are pluggable allowing each class
147 148 * to use a block allocator that best suits that class.
148 149 */
149 150 struct metaslab_class {
150 151 kmutex_t mc_lock;
151 152 spa_t *mc_spa;
152 153 metaslab_group_t *mc_rotor;
153 154 metaslab_ops_t *mc_ops;
154 155 uint64_t mc_aliquot;
155 156
156 157 /*
157 158 * Track the number of metaslab groups that have been initialized
158 159 * and can accept allocations. An initialized metaslab group is
159 160 * one has been completely added to the config (i.e. we have
160 161 * updated the MOS config and the space has been added to the pool).
161 162 */
162 163 uint64_t mc_groups;
163 164
164 165 /*
165 166 * Toggle to enable/disable the allocation throttle.
166 167 */
167 168 boolean_t mc_alloc_throttle_enabled;
168 169
169 170 /*
170 171 * The allocation throttle works on a reservation system. Whenever
171 172 * an asynchronous zio wants to perform an allocation it must
172 173 * first reserve the number of blocks that it wants to allocate.
173 174 * If there aren't sufficient slots available for the pending zio
174 175 * then that I/O is throttled until more slots free up. The current
175 176 * number of reserved allocations is maintained by the mc_alloc_slots
176 177 * refcount. The mc_alloc_max_slots value determines the maximum
177 178 * number of allocations that the system allows. Gang blocks are
178 179 * allowed to reserve slots even if we've reached the maximum
179 180 * number of allocations allowed.
180 181 */
|
↓ open down ↓ |
143 lines elided |
↑ open up ↑ |
181 182 uint64_t mc_alloc_max_slots;
182 183 refcount_t mc_alloc_slots;
183 184
184 185 uint64_t mc_alloc_groups; /* # of allocatable groups */
185 186
186 187 uint64_t mc_alloc; /* total allocated space */
187 188 uint64_t mc_deferred; /* total deferred frees */
188 189 uint64_t mc_space; /* total space (alloc + free) */
189 190 uint64_t mc_dspace; /* total deflated space */
190 191 uint64_t mc_histogram[RANGE_TREE_HISTOGRAM_SIZE];
192 +
193 + kmutex_t mc_alloc_lock;
194 + avl_tree_t mc_alloc_tree;
191 195 };
192 196
193 197 /*
194 198 * Metaslab groups encapsulate all the allocatable regions (i.e. metaslabs)
195 199 * of a top-level vdev. They are linked togther to form a circular linked
196 200 * list and can belong to only one metaslab class. Metaslab groups may become
197 201 * ineligible for allocations for a number of reasons such as limited free
198 202 * space, fragmentation, or going offline. When this happens the allocator will
199 203 * simply find the next metaslab group in the linked list and attempt
200 204 * to allocate from that group instead.
201 205 */
202 206 struct metaslab_group {
203 207 kmutex_t mg_lock;
204 208 avl_tree_t mg_metaslab_tree;
205 209 uint64_t mg_aliquot;
206 210 boolean_t mg_allocatable; /* can we allocate? */
207 211
208 212 /*
209 213 * A metaslab group is considered to be initialized only after
210 214 * we have updated the MOS config and added the space to the pool.
211 215 * We only allow allocation attempts to a metaslab group if it
212 216 * has been initialized.
213 217 */
214 218 boolean_t mg_initialized;
215 219
216 220 uint64_t mg_free_capacity; /* percentage free */
217 221 int64_t mg_bias;
218 222 int64_t mg_activation_count;
219 223 metaslab_class_t *mg_class;
220 224 vdev_t *mg_vd;
221 225 taskq_t *mg_taskq;
222 226 metaslab_group_t *mg_prev;
223 227 metaslab_group_t *mg_next;
224 228
225 229 /*
226 230 * Each metaslab group can handle mg_max_alloc_queue_depth allocations
227 231 * which are tracked by mg_alloc_queue_depth. It's possible for a
228 232 * metaslab group to handle more allocations than its max. This
229 233 * can occur when gang blocks are required or when other groups
230 234 * are unable to handle their share of allocations.
231 235 */
232 236 uint64_t mg_max_alloc_queue_depth;
233 237 refcount_t mg_alloc_queue_depth;
234 238
235 239 /*
236 240 * A metalab group that can no longer allocate the minimum block
237 241 * size will set mg_no_free_space. Once a metaslab group is out
238 242 * of space then its share of work must be distributed to other
|
↓ open down ↓ |
38 lines elided |
↑ open up ↑ |
239 243 * groups.
240 244 */
241 245 boolean_t mg_no_free_space;
242 246
243 247 uint64_t mg_allocations;
244 248 uint64_t mg_failed_allocations;
245 249 uint64_t mg_fragmentation;
246 250 uint64_t mg_histogram[RANGE_TREE_HISTOGRAM_SIZE];
247 251 };
248 252
253 +typedef struct {
254 + uint64_t ts_birth; /* TXG at which this trimset starts */
255 + range_tree_t *ts_tree; /* tree of extents in the trimset */
256 +} metaslab_trimset_t;
257 +
249 258 /*
250 259 * This value defines the number of elements in the ms_lbas array. The value
251 260 * of 64 was chosen as it covers all power of 2 buckets up to UINT64_MAX.
252 261 * This is the equivalent of highbit(UINT64_MAX).
253 262 */
254 263 #define MAX_LBAS 64
255 264
256 265 /*
257 266 * Each metaslab maintains a set of in-core trees to track metaslab
258 267 * operations. The in-core free tree (ms_tree) contains the list of
259 268 * free segments which are eligible for allocation. As blocks are
260 - * allocated, the allocated segment are removed from the ms_tree and
261 - * added to a per txg allocation tree (ms_alloctree). As blocks are
262 - * freed, they are added to the free tree (ms_freeingtree). These trees
263 - * allow us to process all allocations and frees in syncing context
264 - * where it is safe to update the on-disk space maps. An additional set
265 - * of in-core trees is maintained to track deferred frees
266 - * (ms_defertree). Once a block is freed it will move from the
269 + * allocated, the allocated segments are removed from the ms_tree and
270 + * added to a per txg allocation tree (ms_alloctree). This allows us to
271 + * process all allocations in syncing context where it is safe to update
272 + * the on-disk space maps. Frees are also processed in syncing context.
273 + * Most frees are generated from syncing context, and those that are not
274 + * are held in the spa_free_bplist for processing in syncing context.
275 + * An additional set of in-core trees is maintained to track deferred
276 + * frees (ms_defertree). Once a block is freed it will move from the
267 277 * ms_freedtree to the ms_defertree. A deferred free means that a block
268 278 * has been freed but cannot be used by the pool until TXG_DEFER_SIZE
269 279 * transactions groups later. For example, a block that is freed in txg
270 280 * 50 will not be available for reallocation until txg 52 (50 +
271 281 * TXG_DEFER_SIZE). This provides a safety net for uberblock rollback.
272 282 * A pool could be safely rolled back TXG_DEFERS_SIZE transactions
273 283 * groups and ensure that no block has been reallocated.
274 284 *
275 285 * The simplified transition diagram looks like this:
276 286 *
277 287 *
278 288 * ALLOCATE
279 289 * |
280 290 * V
281 291 * free segment (ms_tree) -----> ms_alloctree[4] ----> (write to space map)
282 292 * ^
283 293 * | ms_freeingtree <--- FREE
284 294 * | |
285 295 * | v
286 296 * | ms_freedtree
287 297 * | |
288 298 * +-------- ms_defertree[2] <-------+---------> (write to space map)
289 299 *
290 300 *
291 301 * Each metaslab's space is tracked in a single space map in the MOS,
292 302 * which is only updated in syncing context. Each time we sync a txg,
293 303 * we append the allocs and frees from that txg to the space map. The
294 304 * pool space is only updated once all metaslabs have finished syncing.
295 305 *
296 306 * To load the in-core free tree we read the space map from disk. This
297 307 * object contains a series of alloc and free records that are combined
298 308 * to make up the list of all free segments in this metaslab. These
299 309 * segments are represented in-core by the ms_tree and are stored in an
300 310 * AVL tree.
301 311 *
|
↓ open down ↓ |
25 lines elided |
↑ open up ↑ |
302 312 * As the space map grows (as a result of the appends) it will
303 313 * eventually become space-inefficient. When the metaslab's in-core
304 314 * free tree is zfs_condense_pct/100 times the size of the minimal
305 315 * on-disk representation, we rewrite it in its minimized form. If a
306 316 * metaslab needs to condense then we must set the ms_condensing flag to
307 317 * ensure that allocations are not performed on the metaslab that is
308 318 * being written.
309 319 */
310 320 struct metaslab {
311 321 kmutex_t ms_lock;
312 - kmutex_t ms_sync_lock;
313 322 kcondvar_t ms_load_cv;
314 323 space_map_t *ms_sm;
315 324 uint64_t ms_id;
316 325 uint64_t ms_start;
317 326 uint64_t ms_size;
318 327 uint64_t ms_fragmentation;
319 328
320 329 range_tree_t *ms_alloctree[TXG_SIZE];
321 330 range_tree_t *ms_tree;
322 331
332 + metaslab_trimset_t *ms_cur_ts; /* currently prepared trims */
333 + metaslab_trimset_t *ms_prev_ts; /* previous (aging) trims */
334 + kcondvar_t ms_trim_cv;
335 + metaslab_trimset_t *ms_trimming_ts;
336 +
323 337 /*
324 338 * The following range trees are accessed only from syncing context.
325 339 * ms_free*tree only have entries while syncing, and are empty
326 340 * between syncs.
327 341 */
328 342 range_tree_t *ms_freeingtree; /* to free this syncing txg */
329 343 range_tree_t *ms_freedtree; /* already freed this syncing txg */
330 344 range_tree_t *ms_defertree[TXG_DEFER_SIZE];
331 345
332 346 boolean_t ms_condensing; /* condensing? */
333 347 boolean_t ms_condense_wanted;
334 348
335 349 /*
336 350 * We must hold both ms_lock and ms_group->mg_lock in order to
337 351 * modify ms_loaded.
338 352 */
339 353 boolean_t ms_loaded;
340 354 boolean_t ms_loading;
341 355
342 356 int64_t ms_deferspace; /* sum of ms_defermap[] space */
343 357 uint64_t ms_weight; /* weight vs. others in group */
344 358 uint64_t ms_activation_weight; /* activation weight */
345 359
346 360 /*
347 361 * Track of whenever a metaslab is selected for loading or allocation.
348 362 * We use this value to determine how long the metaslab should
349 363 * stay cached.
350 364 */
351 365 uint64_t ms_selected_txg;
352 366
353 367 uint64_t ms_alloc_txg; /* last successful alloc (debug only) */
354 368 uint64_t ms_max_size; /* maximum allocatable size */
355 369
356 370 /*
357 371 * The metaslab block allocators can optionally use a size-ordered
358 372 * range tree and/or an array of LBAs. Not all allocators use
359 373 * this functionality. The ms_size_tree should always contain the
360 374 * same number of segments as the ms_tree. The only difference
361 375 * is that the ms_size_tree is ordered by segment sizes.
362 376 */
363 377 avl_tree_t ms_size_tree;
364 378 uint64_t ms_lbas[MAX_LBAS];
365 379
366 380 metaslab_group_t *ms_group; /* metaslab group */
367 381 avl_node_t ms_group_node; /* node in metaslab group tree */
368 382 txg_node_t ms_txg_node; /* per-txg dirty metaslab links */
369 383 };
370 384
371 385 #ifdef __cplusplus
372 386 }
373 387 #endif
374 388
375 389 #endif /* _SYS_METASLAB_IMPL_H */
|
↓ open down ↓ |
43 lines elided |
↑ open up ↑ |
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX