xref: /freebsd/sys/contrib/openzfs/module/zfs/vdev_queue.c (revision 90b5fc95832da64a5f56295e687379732c33718f)
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
9  * or http://www.opensolaris.org/os/licensing.
10  * See the License for the specific language governing permissions
11  * and limitations under the License.
12  *
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]
18  *
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) 2012, 2018 by Delphix. All rights reserved.
28  */
29 
30 #include <sys/zfs_context.h>
31 #include <sys/vdev_impl.h>
32 #include <sys/spa_impl.h>
33 #include <sys/zio.h>
34 #include <sys/avl.h>
35 #include <sys/dsl_pool.h>
36 #include <sys/metaslab_impl.h>
37 #include <sys/spa.h>
38 #include <sys/spa_impl.h>
39 #include <sys/kstat.h>
40 #include <sys/abd.h>
41 
42 /*
43  * ZFS I/O Scheduler
44  * ---------------
45  *
46  * ZFS issues I/O operations to leaf vdevs to satisfy and complete zios.  The
47  * I/O scheduler determines when and in what order those operations are
48  * issued.  The I/O scheduler divides operations into five I/O classes
49  * prioritized in the following order: sync read, sync write, async read,
50  * async write, and scrub/resilver.  Each queue defines the minimum and
51  * maximum number of concurrent operations that may be issued to the device.
52  * In addition, the device has an aggregate maximum. Note that the sum of the
53  * per-queue minimums must not exceed the aggregate maximum. If the
54  * sum of the per-queue maximums exceeds the aggregate maximum, then the
55  * number of active i/os may reach zfs_vdev_max_active, in which case no
56  * further i/os will be issued regardless of whether all per-queue
57  * minimums have been met.
58  *
59  * For many physical devices, throughput increases with the number of
60  * concurrent operations, but latency typically suffers. Further, physical
61  * devices typically have a limit at which more concurrent operations have no
62  * effect on throughput or can actually cause it to decrease.
63  *
64  * The scheduler selects the next operation to issue by first looking for an
65  * I/O class whose minimum has not been satisfied. Once all are satisfied and
66  * the aggregate maximum has not been hit, the scheduler looks for classes
67  * whose maximum has not been satisfied. Iteration through the I/O classes is
68  * done in the order specified above. No further operations are issued if the
69  * aggregate maximum number of concurrent operations has been hit or if there
70  * are no operations queued for an I/O class that has not hit its maximum.
71  * Every time an i/o is queued or an operation completes, the I/O scheduler
72  * looks for new operations to issue.
73  *
74  * All I/O classes have a fixed maximum number of outstanding operations
75  * except for the async write class. Asynchronous writes represent the data
76  * that is committed to stable storage during the syncing stage for
77  * transaction groups (see txg.c). Transaction groups enter the syncing state
78  * periodically so the number of queued async writes will quickly burst up and
79  * then bleed down to zero. Rather than servicing them as quickly as possible,
80  * the I/O scheduler changes the maximum number of active async write i/os
81  * according to the amount of dirty data in the pool (see dsl_pool.c). Since
82  * both throughput and latency typically increase with the number of
83  * concurrent operations issued to physical devices, reducing the burstiness
84  * in the number of concurrent operations also stabilizes the response time of
85  * operations from other -- and in particular synchronous -- queues. In broad
86  * strokes, the I/O scheduler will issue more concurrent operations from the
87  * async write queue as there's more dirty data in the pool.
88  *
89  * Async Writes
90  *
91  * The number of concurrent operations issued for the async write I/O class
92  * follows a piece-wise linear function defined by a few adjustable points.
93  *
94  *        |                   o---------| <-- zfs_vdev_async_write_max_active
95  *   ^    |                  /^         |
96  *   |    |                 / |         |
97  * active |                /  |         |
98  *  I/O   |               /   |         |
99  * count  |              /    |         |
100  *        |             /     |         |
101  *        |------------o      |         | <-- zfs_vdev_async_write_min_active
102  *       0|____________^______|_________|
103  *        0%           |      |       100% of zfs_dirty_data_max
104  *                     |      |
105  *                     |      `-- zfs_vdev_async_write_active_max_dirty_percent
106  *                     `--------- zfs_vdev_async_write_active_min_dirty_percent
107  *
108  * Until the amount of dirty data exceeds a minimum percentage of the dirty
109  * data allowed in the pool, the I/O scheduler will limit the number of
110  * concurrent operations to the minimum. As that threshold is crossed, the
111  * number of concurrent operations issued increases linearly to the maximum at
112  * the specified maximum percentage of the dirty data allowed in the pool.
113  *
114  * Ideally, the amount of dirty data on a busy pool will stay in the sloped
115  * part of the function between zfs_vdev_async_write_active_min_dirty_percent
116  * and zfs_vdev_async_write_active_max_dirty_percent. If it exceeds the
117  * maximum percentage, this indicates that the rate of incoming data is
118  * greater than the rate that the backend storage can handle. In this case, we
119  * must further throttle incoming writes (see dmu_tx_delay() for details).
120  */
121 
122 /*
123  * The maximum number of i/os active to each device.  Ideally, this will be >=
124  * the sum of each queue's max_active.
125  */
126 uint32_t zfs_vdev_max_active = 1000;
127 
128 /*
129  * Per-queue limits on the number of i/os active to each device.  If the
130  * number of active i/os is < zfs_vdev_max_active, then the min_active comes
131  * into play.  We will send min_active from each queue round-robin, and then
132  * send from queues in the order defined by zio_priority_t up to max_active.
133  * Some queues have additional mechanisms to limit number of active I/Os in
134  * addition to min_active and max_active, see below.
135  *
136  * In general, smaller max_active's will lead to lower latency of synchronous
137  * operations.  Larger max_active's may lead to higher overall throughput,
138  * depending on underlying storage.
139  *
140  * The ratio of the queues' max_actives determines the balance of performance
141  * between reads, writes, and scrubs.  E.g., increasing
142  * zfs_vdev_scrub_max_active will cause the scrub or resilver to complete
143  * more quickly, but reads and writes to have higher latency and lower
144  * throughput.
145  */
146 uint32_t zfs_vdev_sync_read_min_active = 10;
147 uint32_t zfs_vdev_sync_read_max_active = 10;
148 uint32_t zfs_vdev_sync_write_min_active = 10;
149 uint32_t zfs_vdev_sync_write_max_active = 10;
150 uint32_t zfs_vdev_async_read_min_active = 1;
151 uint32_t zfs_vdev_async_read_max_active = 3;
152 uint32_t zfs_vdev_async_write_min_active = 2;
153 uint32_t zfs_vdev_async_write_max_active = 10;
154 uint32_t zfs_vdev_scrub_min_active = 1;
155 uint32_t zfs_vdev_scrub_max_active = 3;
156 uint32_t zfs_vdev_removal_min_active = 1;
157 uint32_t zfs_vdev_removal_max_active = 2;
158 uint32_t zfs_vdev_initializing_min_active = 1;
159 uint32_t zfs_vdev_initializing_max_active = 1;
160 uint32_t zfs_vdev_trim_min_active = 1;
161 uint32_t zfs_vdev_trim_max_active = 2;
162 uint32_t zfs_vdev_rebuild_min_active = 1;
163 uint32_t zfs_vdev_rebuild_max_active = 3;
164 
165 /*
166  * When the pool has less than zfs_vdev_async_write_active_min_dirty_percent
167  * dirty data, use zfs_vdev_async_write_min_active.  When it has more than
168  * zfs_vdev_async_write_active_max_dirty_percent, use
169  * zfs_vdev_async_write_max_active. The value is linearly interpolated
170  * between min and max.
171  */
172 int zfs_vdev_async_write_active_min_dirty_percent = 30;
173 int zfs_vdev_async_write_active_max_dirty_percent = 60;
174 
175 /*
176  * For non-interactive I/O (scrub, resilver, removal, initialize and rebuild),
177  * the number of concurrently-active I/O's is limited to *_min_active, unless
178  * the vdev is "idle".  When there are no interactive I/Os active (sync or
179  * async), and zfs_vdev_nia_delay I/Os have completed since the last
180  * interactive I/O, then the vdev is considered to be "idle", and the number
181  * of concurrently-active non-interactive I/O's is increased to *_max_active.
182  */
183 uint_t zfs_vdev_nia_delay = 5;
184 
185 /*
186  * Some HDDs tend to prioritize sequential I/O so high that concurrent
187  * random I/O latency reaches several seconds.  On some HDDs it happens
188  * even if sequential I/Os are submitted one at a time, and so setting
189  * *_max_active to 1 does not help.  To prevent non-interactive I/Os, like
190  * scrub, from monopolizing the device no more than zfs_vdev_nia_credit
191  * I/Os can be sent while there are outstanding incomplete interactive
192  * I/Os.  This enforced wait ensures the HDD services the interactive I/O
193  * within a reasonable amount of time.
194  */
195 uint_t zfs_vdev_nia_credit = 5;
196 
197 /*
198  * To reduce IOPs, we aggregate small adjacent I/Os into one large I/O.
199  * For read I/Os, we also aggregate across small adjacency gaps; for writes
200  * we include spans of optional I/Os to aid aggregation at the disk even when
201  * they aren't able to help us aggregate at this level.
202  */
203 int zfs_vdev_aggregation_limit = 1 << 20;
204 int zfs_vdev_aggregation_limit_non_rotating = SPA_OLD_MAXBLOCKSIZE;
205 int zfs_vdev_read_gap_limit = 32 << 10;
206 int zfs_vdev_write_gap_limit = 4 << 10;
207 
208 /*
209  * Define the queue depth percentage for each top-level. This percentage is
210  * used in conjunction with zfs_vdev_async_max_active to determine how many
211  * allocations a specific top-level vdev should handle. Once the queue depth
212  * reaches zfs_vdev_queue_depth_pct * zfs_vdev_async_write_max_active / 100
213  * then allocator will stop allocating blocks on that top-level device.
214  * The default kernel setting is 1000% which will yield 100 allocations per
215  * device. For userland testing, the default setting is 300% which equates
216  * to 30 allocations per device.
217  */
218 #ifdef _KERNEL
219 int zfs_vdev_queue_depth_pct = 1000;
220 #else
221 int zfs_vdev_queue_depth_pct = 300;
222 #endif
223 
224 /*
225  * When performing allocations for a given metaslab, we want to make sure that
226  * there are enough IOs to aggregate together to improve throughput. We want to
227  * ensure that there are at least 128k worth of IOs that can be aggregated, and
228  * we assume that the average allocation size is 4k, so we need the queue depth
229  * to be 32 per allocator to get good aggregation of sequential writes.
230  */
231 int zfs_vdev_def_queue_depth = 32;
232 
233 /*
234  * Allow TRIM I/Os to be aggregated.  This should normally not be needed since
235  * TRIM I/O for extents up to zfs_trim_extent_bytes_max (128M) can be submitted
236  * by the TRIM code in zfs_trim.c.
237  */
238 int zfs_vdev_aggregate_trim = 0;
239 
240 static int
241 vdev_queue_offset_compare(const void *x1, const void *x2)
242 {
243 	const zio_t *z1 = (const zio_t *)x1;
244 	const zio_t *z2 = (const zio_t *)x2;
245 
246 	int cmp = TREE_CMP(z1->io_offset, z2->io_offset);
247 
248 	if (likely(cmp))
249 		return (cmp);
250 
251 	return (TREE_PCMP(z1, z2));
252 }
253 
254 static inline avl_tree_t *
255 vdev_queue_class_tree(vdev_queue_t *vq, zio_priority_t p)
256 {
257 	return (&vq->vq_class[p].vqc_queued_tree);
258 }
259 
260 static inline avl_tree_t *
261 vdev_queue_type_tree(vdev_queue_t *vq, zio_type_t t)
262 {
263 	ASSERT(t == ZIO_TYPE_READ || t == ZIO_TYPE_WRITE || t == ZIO_TYPE_TRIM);
264 	if (t == ZIO_TYPE_READ)
265 		return (&vq->vq_read_offset_tree);
266 	else if (t == ZIO_TYPE_WRITE)
267 		return (&vq->vq_write_offset_tree);
268 	else
269 		return (&vq->vq_trim_offset_tree);
270 }
271 
272 static int
273 vdev_queue_timestamp_compare(const void *x1, const void *x2)
274 {
275 	const zio_t *z1 = (const zio_t *)x1;
276 	const zio_t *z2 = (const zio_t *)x2;
277 
278 	int cmp = TREE_CMP(z1->io_timestamp, z2->io_timestamp);
279 
280 	if (likely(cmp))
281 		return (cmp);
282 
283 	return (TREE_PCMP(z1, z2));
284 }
285 
286 static int
287 vdev_queue_class_min_active(vdev_queue_t *vq, zio_priority_t p)
288 {
289 	switch (p) {
290 	case ZIO_PRIORITY_SYNC_READ:
291 		return (zfs_vdev_sync_read_min_active);
292 	case ZIO_PRIORITY_SYNC_WRITE:
293 		return (zfs_vdev_sync_write_min_active);
294 	case ZIO_PRIORITY_ASYNC_READ:
295 		return (zfs_vdev_async_read_min_active);
296 	case ZIO_PRIORITY_ASYNC_WRITE:
297 		return (zfs_vdev_async_write_min_active);
298 	case ZIO_PRIORITY_SCRUB:
299 		return (vq->vq_ia_active == 0 ? zfs_vdev_scrub_min_active :
300 		    MIN(vq->vq_nia_credit, zfs_vdev_scrub_min_active));
301 	case ZIO_PRIORITY_REMOVAL:
302 		return (vq->vq_ia_active == 0 ? zfs_vdev_removal_min_active :
303 		    MIN(vq->vq_nia_credit, zfs_vdev_removal_min_active));
304 	case ZIO_PRIORITY_INITIALIZING:
305 		return (vq->vq_ia_active == 0 ?zfs_vdev_initializing_min_active:
306 		    MIN(vq->vq_nia_credit, zfs_vdev_initializing_min_active));
307 	case ZIO_PRIORITY_TRIM:
308 		return (zfs_vdev_trim_min_active);
309 	case ZIO_PRIORITY_REBUILD:
310 		return (vq->vq_ia_active == 0 ? zfs_vdev_rebuild_min_active :
311 		    MIN(vq->vq_nia_credit, zfs_vdev_rebuild_min_active));
312 	default:
313 		panic("invalid priority %u", p);
314 		return (0);
315 	}
316 }
317 
318 static int
319 vdev_queue_max_async_writes(spa_t *spa)
320 {
321 	int writes;
322 	uint64_t dirty = 0;
323 	dsl_pool_t *dp = spa_get_dsl(spa);
324 	uint64_t min_bytes = zfs_dirty_data_max *
325 	    zfs_vdev_async_write_active_min_dirty_percent / 100;
326 	uint64_t max_bytes = zfs_dirty_data_max *
327 	    zfs_vdev_async_write_active_max_dirty_percent / 100;
328 
329 	/*
330 	 * Async writes may occur before the assignment of the spa's
331 	 * dsl_pool_t if a self-healing zio is issued prior to the
332 	 * completion of dmu_objset_open_impl().
333 	 */
334 	if (dp == NULL)
335 		return (zfs_vdev_async_write_max_active);
336 
337 	/*
338 	 * Sync tasks correspond to interactive user actions. To reduce the
339 	 * execution time of those actions we push data out as fast as possible.
340 	 */
341 	dirty = dp->dp_dirty_total;
342 	if (dirty > max_bytes || spa_has_pending_synctask(spa))
343 		return (zfs_vdev_async_write_max_active);
344 
345 	if (dirty < min_bytes)
346 		return (zfs_vdev_async_write_min_active);
347 
348 	/*
349 	 * linear interpolation:
350 	 * slope = (max_writes - min_writes) / (max_bytes - min_bytes)
351 	 * move right by min_bytes
352 	 * move up by min_writes
353 	 */
354 	writes = (dirty - min_bytes) *
355 	    (zfs_vdev_async_write_max_active -
356 	    zfs_vdev_async_write_min_active) /
357 	    (max_bytes - min_bytes) +
358 	    zfs_vdev_async_write_min_active;
359 	ASSERT3U(writes, >=, zfs_vdev_async_write_min_active);
360 	ASSERT3U(writes, <=, zfs_vdev_async_write_max_active);
361 	return (writes);
362 }
363 
364 static int
365 vdev_queue_class_max_active(spa_t *spa, vdev_queue_t *vq, zio_priority_t p)
366 {
367 	switch (p) {
368 	case ZIO_PRIORITY_SYNC_READ:
369 		return (zfs_vdev_sync_read_max_active);
370 	case ZIO_PRIORITY_SYNC_WRITE:
371 		return (zfs_vdev_sync_write_max_active);
372 	case ZIO_PRIORITY_ASYNC_READ:
373 		return (zfs_vdev_async_read_max_active);
374 	case ZIO_PRIORITY_ASYNC_WRITE:
375 		return (vdev_queue_max_async_writes(spa));
376 	case ZIO_PRIORITY_SCRUB:
377 		if (vq->vq_ia_active > 0) {
378 			return (MIN(vq->vq_nia_credit,
379 			    zfs_vdev_scrub_min_active));
380 		} else if (vq->vq_nia_credit < zfs_vdev_nia_delay)
381 			return (MAX(1, zfs_vdev_scrub_min_active));
382 		return (zfs_vdev_scrub_max_active);
383 	case ZIO_PRIORITY_REMOVAL:
384 		if (vq->vq_ia_active > 0) {
385 			return (MIN(vq->vq_nia_credit,
386 			    zfs_vdev_removal_min_active));
387 		} else if (vq->vq_nia_credit < zfs_vdev_nia_delay)
388 			return (MAX(1, zfs_vdev_removal_min_active));
389 		return (zfs_vdev_removal_max_active);
390 	case ZIO_PRIORITY_INITIALIZING:
391 		if (vq->vq_ia_active > 0) {
392 			return (MIN(vq->vq_nia_credit,
393 			    zfs_vdev_initializing_min_active));
394 		} else if (vq->vq_nia_credit < zfs_vdev_nia_delay)
395 			return (MAX(1, zfs_vdev_initializing_min_active));
396 		return (zfs_vdev_initializing_max_active);
397 	case ZIO_PRIORITY_TRIM:
398 		return (zfs_vdev_trim_max_active);
399 	case ZIO_PRIORITY_REBUILD:
400 		if (vq->vq_ia_active > 0) {
401 			return (MIN(vq->vq_nia_credit,
402 			    zfs_vdev_rebuild_min_active));
403 		} else if (vq->vq_nia_credit < zfs_vdev_nia_delay)
404 			return (MAX(1, zfs_vdev_rebuild_min_active));
405 		return (zfs_vdev_rebuild_max_active);
406 	default:
407 		panic("invalid priority %u", p);
408 		return (0);
409 	}
410 }
411 
412 /*
413  * Return the i/o class to issue from, or ZIO_PRIORITY_MAX_QUEUEABLE if
414  * there is no eligible class.
415  */
416 static zio_priority_t
417 vdev_queue_class_to_issue(vdev_queue_t *vq)
418 {
419 	spa_t *spa = vq->vq_vdev->vdev_spa;
420 	zio_priority_t p, n;
421 
422 	if (avl_numnodes(&vq->vq_active_tree) >= zfs_vdev_max_active)
423 		return (ZIO_PRIORITY_NUM_QUEUEABLE);
424 
425 	/*
426 	 * Find a queue that has not reached its minimum # outstanding i/os.
427 	 * Do round-robin to reduce starvation due to zfs_vdev_max_active
428 	 * and vq_nia_credit limits.
429 	 */
430 	for (n = 0; n < ZIO_PRIORITY_NUM_QUEUEABLE; n++) {
431 		p = (vq->vq_last_prio + n + 1) % ZIO_PRIORITY_NUM_QUEUEABLE;
432 		if (avl_numnodes(vdev_queue_class_tree(vq, p)) > 0 &&
433 		    vq->vq_class[p].vqc_active <
434 		    vdev_queue_class_min_active(vq, p)) {
435 			vq->vq_last_prio = p;
436 			return (p);
437 		}
438 	}
439 
440 	/*
441 	 * If we haven't found a queue, look for one that hasn't reached its
442 	 * maximum # outstanding i/os.
443 	 */
444 	for (p = 0; p < ZIO_PRIORITY_NUM_QUEUEABLE; p++) {
445 		if (avl_numnodes(vdev_queue_class_tree(vq, p)) > 0 &&
446 		    vq->vq_class[p].vqc_active <
447 		    vdev_queue_class_max_active(spa, vq, p)) {
448 			vq->vq_last_prio = p;
449 			return (p);
450 		}
451 	}
452 
453 	/* No eligible queued i/os */
454 	return (ZIO_PRIORITY_NUM_QUEUEABLE);
455 }
456 
457 void
458 vdev_queue_init(vdev_t *vd)
459 {
460 	vdev_queue_t *vq = &vd->vdev_queue;
461 	zio_priority_t p;
462 
463 	mutex_init(&vq->vq_lock, NULL, MUTEX_DEFAULT, NULL);
464 	vq->vq_vdev = vd;
465 	taskq_init_ent(&vd->vdev_queue.vq_io_search.io_tqent);
466 
467 	avl_create(&vq->vq_active_tree, vdev_queue_offset_compare,
468 	    sizeof (zio_t), offsetof(struct zio, io_queue_node));
469 	avl_create(vdev_queue_type_tree(vq, ZIO_TYPE_READ),
470 	    vdev_queue_offset_compare, sizeof (zio_t),
471 	    offsetof(struct zio, io_offset_node));
472 	avl_create(vdev_queue_type_tree(vq, ZIO_TYPE_WRITE),
473 	    vdev_queue_offset_compare, sizeof (zio_t),
474 	    offsetof(struct zio, io_offset_node));
475 	avl_create(vdev_queue_type_tree(vq, ZIO_TYPE_TRIM),
476 	    vdev_queue_offset_compare, sizeof (zio_t),
477 	    offsetof(struct zio, io_offset_node));
478 
479 	for (p = 0; p < ZIO_PRIORITY_NUM_QUEUEABLE; p++) {
480 		int (*compfn) (const void *, const void *);
481 
482 		/*
483 		 * The synchronous/trim i/o queues are dispatched in FIFO rather
484 		 * than LBA order. This provides more consistent latency for
485 		 * these i/os.
486 		 */
487 		if (p == ZIO_PRIORITY_SYNC_READ ||
488 		    p == ZIO_PRIORITY_SYNC_WRITE ||
489 		    p == ZIO_PRIORITY_TRIM) {
490 			compfn = vdev_queue_timestamp_compare;
491 		} else {
492 			compfn = vdev_queue_offset_compare;
493 		}
494 		avl_create(vdev_queue_class_tree(vq, p), compfn,
495 		    sizeof (zio_t), offsetof(struct zio, io_queue_node));
496 	}
497 
498 	vq->vq_last_offset = 0;
499 }
500 
501 void
502 vdev_queue_fini(vdev_t *vd)
503 {
504 	vdev_queue_t *vq = &vd->vdev_queue;
505 
506 	for (zio_priority_t p = 0; p < ZIO_PRIORITY_NUM_QUEUEABLE; p++)
507 		avl_destroy(vdev_queue_class_tree(vq, p));
508 	avl_destroy(&vq->vq_active_tree);
509 	avl_destroy(vdev_queue_type_tree(vq, ZIO_TYPE_READ));
510 	avl_destroy(vdev_queue_type_tree(vq, ZIO_TYPE_WRITE));
511 	avl_destroy(vdev_queue_type_tree(vq, ZIO_TYPE_TRIM));
512 
513 	mutex_destroy(&vq->vq_lock);
514 }
515 
516 static void
517 vdev_queue_io_add(vdev_queue_t *vq, zio_t *zio)
518 {
519 	spa_t *spa = zio->io_spa;
520 	spa_history_kstat_t *shk = &spa->spa_stats.io_history;
521 
522 	ASSERT3U(zio->io_priority, <, ZIO_PRIORITY_NUM_QUEUEABLE);
523 	avl_add(vdev_queue_class_tree(vq, zio->io_priority), zio);
524 	avl_add(vdev_queue_type_tree(vq, zio->io_type), zio);
525 
526 	if (shk->kstat != NULL) {
527 		mutex_enter(&shk->lock);
528 		kstat_waitq_enter(shk->kstat->ks_data);
529 		mutex_exit(&shk->lock);
530 	}
531 }
532 
533 static void
534 vdev_queue_io_remove(vdev_queue_t *vq, zio_t *zio)
535 {
536 	spa_t *spa = zio->io_spa;
537 	spa_history_kstat_t *shk = &spa->spa_stats.io_history;
538 
539 	ASSERT3U(zio->io_priority, <, ZIO_PRIORITY_NUM_QUEUEABLE);
540 	avl_remove(vdev_queue_class_tree(vq, zio->io_priority), zio);
541 	avl_remove(vdev_queue_type_tree(vq, zio->io_type), zio);
542 
543 	if (shk->kstat != NULL) {
544 		mutex_enter(&shk->lock);
545 		kstat_waitq_exit(shk->kstat->ks_data);
546 		mutex_exit(&shk->lock);
547 	}
548 }
549 
550 static boolean_t
551 vdev_queue_is_interactive(zio_priority_t p)
552 {
553 	switch (p) {
554 	case ZIO_PRIORITY_SCRUB:
555 	case ZIO_PRIORITY_REMOVAL:
556 	case ZIO_PRIORITY_INITIALIZING:
557 	case ZIO_PRIORITY_REBUILD:
558 		return (B_FALSE);
559 	default:
560 		return (B_TRUE);
561 	}
562 }
563 
564 static void
565 vdev_queue_pending_add(vdev_queue_t *vq, zio_t *zio)
566 {
567 	spa_t *spa = zio->io_spa;
568 	spa_history_kstat_t *shk = &spa->spa_stats.io_history;
569 
570 	ASSERT(MUTEX_HELD(&vq->vq_lock));
571 	ASSERT3U(zio->io_priority, <, ZIO_PRIORITY_NUM_QUEUEABLE);
572 	vq->vq_class[zio->io_priority].vqc_active++;
573 	if (vdev_queue_is_interactive(zio->io_priority)) {
574 		if (++vq->vq_ia_active == 1)
575 			vq->vq_nia_credit = 1;
576 	} else if (vq->vq_ia_active > 0) {
577 		vq->vq_nia_credit--;
578 	}
579 	avl_add(&vq->vq_active_tree, zio);
580 
581 	if (shk->kstat != NULL) {
582 		mutex_enter(&shk->lock);
583 		kstat_runq_enter(shk->kstat->ks_data);
584 		mutex_exit(&shk->lock);
585 	}
586 }
587 
588 static void
589 vdev_queue_pending_remove(vdev_queue_t *vq, zio_t *zio)
590 {
591 	spa_t *spa = zio->io_spa;
592 	spa_history_kstat_t *shk = &spa->spa_stats.io_history;
593 
594 	ASSERT(MUTEX_HELD(&vq->vq_lock));
595 	ASSERT3U(zio->io_priority, <, ZIO_PRIORITY_NUM_QUEUEABLE);
596 	vq->vq_class[zio->io_priority].vqc_active--;
597 	if (vdev_queue_is_interactive(zio->io_priority)) {
598 		if (--vq->vq_ia_active == 0)
599 			vq->vq_nia_credit = 0;
600 		else
601 			vq->vq_nia_credit = zfs_vdev_nia_credit;
602 	} else if (vq->vq_ia_active == 0)
603 		vq->vq_nia_credit++;
604 	avl_remove(&vq->vq_active_tree, zio);
605 
606 	if (shk->kstat != NULL) {
607 		kstat_io_t *ksio = shk->kstat->ks_data;
608 
609 		mutex_enter(&shk->lock);
610 		kstat_runq_exit(ksio);
611 		if (zio->io_type == ZIO_TYPE_READ) {
612 			ksio->reads++;
613 			ksio->nread += zio->io_size;
614 		} else if (zio->io_type == ZIO_TYPE_WRITE) {
615 			ksio->writes++;
616 			ksio->nwritten += zio->io_size;
617 		}
618 		mutex_exit(&shk->lock);
619 	}
620 }
621 
622 static void
623 vdev_queue_agg_io_done(zio_t *aio)
624 {
625 	abd_free(aio->io_abd);
626 }
627 
628 /*
629  * Compute the range spanned by two i/os, which is the endpoint of the last
630  * (lio->io_offset + lio->io_size) minus start of the first (fio->io_offset).
631  * Conveniently, the gap between fio and lio is given by -IO_SPAN(lio, fio);
632  * thus fio and lio are adjacent if and only if IO_SPAN(lio, fio) == 0.
633  */
634 #define	IO_SPAN(fio, lio) ((lio)->io_offset + (lio)->io_size - (fio)->io_offset)
635 #define	IO_GAP(fio, lio) (-IO_SPAN(lio, fio))
636 
637 /*
638  * Sufficiently adjacent io_offset's in ZIOs will be aggregated. We do this
639  * by creating a gang ABD from the adjacent ZIOs io_abd's. By using
640  * a gang ABD we avoid doing memory copies to and from the parent,
641  * child ZIOs. The gang ABD also accounts for gaps between adjacent
642  * io_offsets by simply getting the zero ABD for writes or allocating
643  * a new ABD for reads and placing them in the gang ABD as well.
644  */
645 static zio_t *
646 vdev_queue_aggregate(vdev_queue_t *vq, zio_t *zio)
647 {
648 	zio_t *first, *last, *aio, *dio, *mandatory, *nio;
649 	zio_link_t *zl = NULL;
650 	uint64_t maxgap = 0;
651 	uint64_t size;
652 	uint64_t limit;
653 	int maxblocksize;
654 	boolean_t stretch = B_FALSE;
655 	avl_tree_t *t = vdev_queue_type_tree(vq, zio->io_type);
656 	enum zio_flag flags = zio->io_flags & ZIO_FLAG_AGG_INHERIT;
657 	uint64_t next_offset;
658 	abd_t *abd;
659 
660 	maxblocksize = spa_maxblocksize(vq->vq_vdev->vdev_spa);
661 	if (vq->vq_vdev->vdev_nonrot)
662 		limit = zfs_vdev_aggregation_limit_non_rotating;
663 	else
664 		limit = zfs_vdev_aggregation_limit;
665 	limit = MAX(MIN(limit, maxblocksize), 0);
666 
667 	if (zio->io_flags & ZIO_FLAG_DONT_AGGREGATE || limit == 0)
668 		return (NULL);
669 
670 	/*
671 	 * While TRIM commands could be aggregated based on offset this
672 	 * behavior is disabled until it's determined to be beneficial.
673 	 */
674 	if (zio->io_type == ZIO_TYPE_TRIM && !zfs_vdev_aggregate_trim)
675 		return (NULL);
676 
677 	/*
678 	 * I/Os to distributed spares are directly dispatched to the dRAID
679 	 * leaf vdevs for aggregation.  See the comment at the end of the
680 	 * zio_vdev_io_start() function.
681 	 */
682 	ASSERT(vq->vq_vdev->vdev_ops != &vdev_draid_spare_ops);
683 
684 	first = last = zio;
685 
686 	if (zio->io_type == ZIO_TYPE_READ)
687 		maxgap = zfs_vdev_read_gap_limit;
688 
689 	/*
690 	 * We can aggregate I/Os that are sufficiently adjacent and of
691 	 * the same flavor, as expressed by the AGG_INHERIT flags.
692 	 * The latter requirement is necessary so that certain
693 	 * attributes of the I/O, such as whether it's a normal I/O
694 	 * or a scrub/resilver, can be preserved in the aggregate.
695 	 * We can include optional I/Os, but don't allow them
696 	 * to begin a range as they add no benefit in that situation.
697 	 */
698 
699 	/*
700 	 * We keep track of the last non-optional I/O.
701 	 */
702 	mandatory = (first->io_flags & ZIO_FLAG_OPTIONAL) ? NULL : first;
703 
704 	/*
705 	 * Walk backwards through sufficiently contiguous I/Os
706 	 * recording the last non-optional I/O.
707 	 */
708 	while ((dio = AVL_PREV(t, first)) != NULL &&
709 	    (dio->io_flags & ZIO_FLAG_AGG_INHERIT) == flags &&
710 	    IO_SPAN(dio, last) <= limit &&
711 	    IO_GAP(dio, first) <= maxgap &&
712 	    dio->io_type == zio->io_type) {
713 		first = dio;
714 		if (mandatory == NULL && !(first->io_flags & ZIO_FLAG_OPTIONAL))
715 			mandatory = first;
716 	}
717 
718 	/*
719 	 * Skip any initial optional I/Os.
720 	 */
721 	while ((first->io_flags & ZIO_FLAG_OPTIONAL) && first != last) {
722 		first = AVL_NEXT(t, first);
723 		ASSERT(first != NULL);
724 	}
725 
726 
727 	/*
728 	 * Walk forward through sufficiently contiguous I/Os.
729 	 * The aggregation limit does not apply to optional i/os, so that
730 	 * we can issue contiguous writes even if they are larger than the
731 	 * aggregation limit.
732 	 */
733 	while ((dio = AVL_NEXT(t, last)) != NULL &&
734 	    (dio->io_flags & ZIO_FLAG_AGG_INHERIT) == flags &&
735 	    (IO_SPAN(first, dio) <= limit ||
736 	    (dio->io_flags & ZIO_FLAG_OPTIONAL)) &&
737 	    IO_SPAN(first, dio) <= maxblocksize &&
738 	    IO_GAP(last, dio) <= maxgap &&
739 	    dio->io_type == zio->io_type) {
740 		last = dio;
741 		if (!(last->io_flags & ZIO_FLAG_OPTIONAL))
742 			mandatory = last;
743 	}
744 
745 	/*
746 	 * Now that we've established the range of the I/O aggregation
747 	 * we must decide what to do with trailing optional I/Os.
748 	 * For reads, there's nothing to do. While we are unable to
749 	 * aggregate further, it's possible that a trailing optional
750 	 * I/O would allow the underlying device to aggregate with
751 	 * subsequent I/Os. We must therefore determine if the next
752 	 * non-optional I/O is close enough to make aggregation
753 	 * worthwhile.
754 	 */
755 	if (zio->io_type == ZIO_TYPE_WRITE && mandatory != NULL) {
756 		zio_t *nio = last;
757 		while ((dio = AVL_NEXT(t, nio)) != NULL &&
758 		    IO_GAP(nio, dio) == 0 &&
759 		    IO_GAP(mandatory, dio) <= zfs_vdev_write_gap_limit) {
760 			nio = dio;
761 			if (!(nio->io_flags & ZIO_FLAG_OPTIONAL)) {
762 				stretch = B_TRUE;
763 				break;
764 			}
765 		}
766 	}
767 
768 	if (stretch) {
769 		/*
770 		 * We are going to include an optional io in our aggregated
771 		 * span, thus closing the write gap.  Only mandatory i/os can
772 		 * start aggregated spans, so make sure that the next i/o
773 		 * after our span is mandatory.
774 		 */
775 		dio = AVL_NEXT(t, last);
776 		dio->io_flags &= ~ZIO_FLAG_OPTIONAL;
777 	} else {
778 		/* do not include the optional i/o */
779 		while (last != mandatory && last != first) {
780 			ASSERT(last->io_flags & ZIO_FLAG_OPTIONAL);
781 			last = AVL_PREV(t, last);
782 			ASSERT(last != NULL);
783 		}
784 	}
785 
786 	if (first == last)
787 		return (NULL);
788 
789 	size = IO_SPAN(first, last);
790 	ASSERT3U(size, <=, maxblocksize);
791 
792 	abd = abd_alloc_gang_abd();
793 	if (abd == NULL)
794 		return (NULL);
795 
796 	aio = zio_vdev_delegated_io(first->io_vd, first->io_offset,
797 	    abd, size, first->io_type, zio->io_priority,
798 	    flags | ZIO_FLAG_DONT_CACHE | ZIO_FLAG_DONT_QUEUE,
799 	    vdev_queue_agg_io_done, NULL);
800 	aio->io_timestamp = first->io_timestamp;
801 
802 	nio = first;
803 	next_offset = first->io_offset;
804 	do {
805 		dio = nio;
806 		nio = AVL_NEXT(t, dio);
807 		zio_add_child(dio, aio);
808 		vdev_queue_io_remove(vq, dio);
809 
810 		if (dio->io_offset != next_offset) {
811 			/* allocate a buffer for a read gap */
812 			ASSERT3U(dio->io_type, ==, ZIO_TYPE_READ);
813 			ASSERT3U(dio->io_offset, >, next_offset);
814 			abd = abd_alloc_for_io(
815 			    dio->io_offset - next_offset, B_TRUE);
816 			abd_gang_add(aio->io_abd, abd, B_TRUE);
817 		}
818 		if (dio->io_abd &&
819 		    (dio->io_size != abd_get_size(dio->io_abd))) {
820 			/* abd size not the same as IO size */
821 			ASSERT3U(abd_get_size(dio->io_abd), >, dio->io_size);
822 			abd = abd_get_offset_size(dio->io_abd, 0, dio->io_size);
823 			abd_gang_add(aio->io_abd, abd, B_TRUE);
824 		} else {
825 			if (dio->io_flags & ZIO_FLAG_NODATA) {
826 				/* allocate a buffer for a write gap */
827 				ASSERT3U(dio->io_type, ==, ZIO_TYPE_WRITE);
828 				ASSERT3P(dio->io_abd, ==, NULL);
829 				abd_gang_add(aio->io_abd,
830 				    abd_get_zeros(dio->io_size), B_TRUE);
831 			} else {
832 				/*
833 				 * We pass B_FALSE to abd_gang_add()
834 				 * because we did not allocate a new
835 				 * ABD, so it is assumed the caller
836 				 * will free this ABD.
837 				 */
838 				abd_gang_add(aio->io_abd, dio->io_abd,
839 				    B_FALSE);
840 			}
841 		}
842 		next_offset = dio->io_offset + dio->io_size;
843 	} while (dio != last);
844 	ASSERT3U(abd_get_size(aio->io_abd), ==, aio->io_size);
845 
846 	/*
847 	 * We need to drop the vdev queue's lock during zio_execute() to
848 	 * avoid a deadlock that we could encounter due to lock order
849 	 * reversal between vq_lock and io_lock in zio_change_priority().
850 	 */
851 	mutex_exit(&vq->vq_lock);
852 	while ((dio = zio_walk_parents(aio, &zl)) != NULL) {
853 		ASSERT3U(dio->io_type, ==, aio->io_type);
854 
855 		zio_vdev_io_bypass(dio);
856 		zio_execute(dio);
857 	}
858 	mutex_enter(&vq->vq_lock);
859 
860 	return (aio);
861 }
862 
863 static zio_t *
864 vdev_queue_io_to_issue(vdev_queue_t *vq)
865 {
866 	zio_t *zio, *aio;
867 	zio_priority_t p;
868 	avl_index_t idx;
869 	avl_tree_t *tree;
870 
871 again:
872 	ASSERT(MUTEX_HELD(&vq->vq_lock));
873 
874 	p = vdev_queue_class_to_issue(vq);
875 
876 	if (p == ZIO_PRIORITY_NUM_QUEUEABLE) {
877 		/* No eligible queued i/os */
878 		return (NULL);
879 	}
880 
881 	/*
882 	 * For LBA-ordered queues (async / scrub / initializing), issue the
883 	 * i/o which follows the most recently issued i/o in LBA (offset) order.
884 	 *
885 	 * For FIFO queues (sync/trim), issue the i/o with the lowest timestamp.
886 	 */
887 	tree = vdev_queue_class_tree(vq, p);
888 	vq->vq_io_search.io_timestamp = 0;
889 	vq->vq_io_search.io_offset = vq->vq_last_offset - 1;
890 	VERIFY3P(avl_find(tree, &vq->vq_io_search, &idx), ==, NULL);
891 	zio = avl_nearest(tree, idx, AVL_AFTER);
892 	if (zio == NULL)
893 		zio = avl_first(tree);
894 	ASSERT3U(zio->io_priority, ==, p);
895 
896 	aio = vdev_queue_aggregate(vq, zio);
897 	if (aio != NULL)
898 		zio = aio;
899 	else
900 		vdev_queue_io_remove(vq, zio);
901 
902 	/*
903 	 * If the I/O is or was optional and therefore has no data, we need to
904 	 * simply discard it. We need to drop the vdev queue's lock to avoid a
905 	 * deadlock that we could encounter since this I/O will complete
906 	 * immediately.
907 	 */
908 	if (zio->io_flags & ZIO_FLAG_NODATA) {
909 		mutex_exit(&vq->vq_lock);
910 		zio_vdev_io_bypass(zio);
911 		zio_execute(zio);
912 		mutex_enter(&vq->vq_lock);
913 		goto again;
914 	}
915 
916 	vdev_queue_pending_add(vq, zio);
917 	vq->vq_last_offset = zio->io_offset + zio->io_size;
918 
919 	return (zio);
920 }
921 
922 zio_t *
923 vdev_queue_io(zio_t *zio)
924 {
925 	vdev_queue_t *vq = &zio->io_vd->vdev_queue;
926 	zio_t *nio;
927 
928 	if (zio->io_flags & ZIO_FLAG_DONT_QUEUE)
929 		return (zio);
930 
931 	/*
932 	 * Children i/os inherent their parent's priority, which might
933 	 * not match the child's i/o type.  Fix it up here.
934 	 */
935 	if (zio->io_type == ZIO_TYPE_READ) {
936 		ASSERT(zio->io_priority != ZIO_PRIORITY_TRIM);
937 
938 		if (zio->io_priority != ZIO_PRIORITY_SYNC_READ &&
939 		    zio->io_priority != ZIO_PRIORITY_ASYNC_READ &&
940 		    zio->io_priority != ZIO_PRIORITY_SCRUB &&
941 		    zio->io_priority != ZIO_PRIORITY_REMOVAL &&
942 		    zio->io_priority != ZIO_PRIORITY_INITIALIZING &&
943 		    zio->io_priority != ZIO_PRIORITY_REBUILD) {
944 			zio->io_priority = ZIO_PRIORITY_ASYNC_READ;
945 		}
946 	} else if (zio->io_type == ZIO_TYPE_WRITE) {
947 		ASSERT(zio->io_priority != ZIO_PRIORITY_TRIM);
948 
949 		if (zio->io_priority != ZIO_PRIORITY_SYNC_WRITE &&
950 		    zio->io_priority != ZIO_PRIORITY_ASYNC_WRITE &&
951 		    zio->io_priority != ZIO_PRIORITY_REMOVAL &&
952 		    zio->io_priority != ZIO_PRIORITY_INITIALIZING &&
953 		    zio->io_priority != ZIO_PRIORITY_REBUILD) {
954 			zio->io_priority = ZIO_PRIORITY_ASYNC_WRITE;
955 		}
956 	} else {
957 		ASSERT(zio->io_type == ZIO_TYPE_TRIM);
958 		ASSERT(zio->io_priority == ZIO_PRIORITY_TRIM);
959 	}
960 
961 	zio->io_flags |= ZIO_FLAG_DONT_CACHE | ZIO_FLAG_DONT_QUEUE;
962 
963 	mutex_enter(&vq->vq_lock);
964 	zio->io_timestamp = gethrtime();
965 	vdev_queue_io_add(vq, zio);
966 	nio = vdev_queue_io_to_issue(vq);
967 	mutex_exit(&vq->vq_lock);
968 
969 	if (nio == NULL)
970 		return (NULL);
971 
972 	if (nio->io_done == vdev_queue_agg_io_done) {
973 		zio_nowait(nio);
974 		return (NULL);
975 	}
976 
977 	return (nio);
978 }
979 
980 void
981 vdev_queue_io_done(zio_t *zio)
982 {
983 	vdev_queue_t *vq = &zio->io_vd->vdev_queue;
984 	zio_t *nio;
985 
986 	mutex_enter(&vq->vq_lock);
987 
988 	vdev_queue_pending_remove(vq, zio);
989 
990 	zio->io_delta = gethrtime() - zio->io_timestamp;
991 	vq->vq_io_complete_ts = gethrtime();
992 	vq->vq_io_delta_ts = vq->vq_io_complete_ts - zio->io_timestamp;
993 
994 	while ((nio = vdev_queue_io_to_issue(vq)) != NULL) {
995 		mutex_exit(&vq->vq_lock);
996 		if (nio->io_done == vdev_queue_agg_io_done) {
997 			zio_nowait(nio);
998 		} else {
999 			zio_vdev_io_reissue(nio);
1000 			zio_execute(nio);
1001 		}
1002 		mutex_enter(&vq->vq_lock);
1003 	}
1004 
1005 	mutex_exit(&vq->vq_lock);
1006 }
1007 
1008 void
1009 vdev_queue_change_io_priority(zio_t *zio, zio_priority_t priority)
1010 {
1011 	vdev_queue_t *vq = &zio->io_vd->vdev_queue;
1012 	avl_tree_t *tree;
1013 
1014 	/*
1015 	 * ZIO_PRIORITY_NOW is used by the vdev cache code and the aggregate zio
1016 	 * code to issue IOs without adding them to the vdev queue. In this
1017 	 * case, the zio is already going to be issued as quickly as possible
1018 	 * and so it doesn't need any reprioritization to help.
1019 	 */
1020 	if (zio->io_priority == ZIO_PRIORITY_NOW)
1021 		return;
1022 
1023 	ASSERT3U(zio->io_priority, <, ZIO_PRIORITY_NUM_QUEUEABLE);
1024 	ASSERT3U(priority, <, ZIO_PRIORITY_NUM_QUEUEABLE);
1025 
1026 	if (zio->io_type == ZIO_TYPE_READ) {
1027 		if (priority != ZIO_PRIORITY_SYNC_READ &&
1028 		    priority != ZIO_PRIORITY_ASYNC_READ &&
1029 		    priority != ZIO_PRIORITY_SCRUB)
1030 			priority = ZIO_PRIORITY_ASYNC_READ;
1031 	} else {
1032 		ASSERT(zio->io_type == ZIO_TYPE_WRITE);
1033 		if (priority != ZIO_PRIORITY_SYNC_WRITE &&
1034 		    priority != ZIO_PRIORITY_ASYNC_WRITE)
1035 			priority = ZIO_PRIORITY_ASYNC_WRITE;
1036 	}
1037 
1038 	mutex_enter(&vq->vq_lock);
1039 
1040 	/*
1041 	 * If the zio is in none of the queues we can simply change
1042 	 * the priority. If the zio is waiting to be submitted we must
1043 	 * remove it from the queue and re-insert it with the new priority.
1044 	 * Otherwise, the zio is currently active and we cannot change its
1045 	 * priority.
1046 	 */
1047 	tree = vdev_queue_class_tree(vq, zio->io_priority);
1048 	if (avl_find(tree, zio, NULL) == zio) {
1049 		avl_remove(vdev_queue_class_tree(vq, zio->io_priority), zio);
1050 		zio->io_priority = priority;
1051 		avl_add(vdev_queue_class_tree(vq, zio->io_priority), zio);
1052 	} else if (avl_find(&vq->vq_active_tree, zio, NULL) != zio) {
1053 		zio->io_priority = priority;
1054 	}
1055 
1056 	mutex_exit(&vq->vq_lock);
1057 }
1058 
1059 /*
1060  * As these two methods are only used for load calculations we're not
1061  * concerned if we get an incorrect value on 32bit platforms due to lack of
1062  * vq_lock mutex use here, instead we prefer to keep it lock free for
1063  * performance.
1064  */
1065 int
1066 vdev_queue_length(vdev_t *vd)
1067 {
1068 	return (avl_numnodes(&vd->vdev_queue.vq_active_tree));
1069 }
1070 
1071 uint64_t
1072 vdev_queue_last_offset(vdev_t *vd)
1073 {
1074 	return (vd->vdev_queue.vq_last_offset);
1075 }
1076 
1077 /* BEGIN CSTYLED */
1078 ZFS_MODULE_PARAM(zfs_vdev, zfs_vdev_, aggregation_limit, INT, ZMOD_RW,
1079 	"Max vdev I/O aggregation size");
1080 
1081 ZFS_MODULE_PARAM(zfs_vdev, zfs_vdev_, aggregation_limit_non_rotating, INT, ZMOD_RW,
1082 	"Max vdev I/O aggregation size for non-rotating media");
1083 
1084 ZFS_MODULE_PARAM(zfs_vdev, zfs_vdev_, aggregate_trim, INT, ZMOD_RW,
1085 	"Allow TRIM I/O to be aggregated");
1086 
1087 ZFS_MODULE_PARAM(zfs_vdev, zfs_vdev_, read_gap_limit, INT, ZMOD_RW,
1088 	"Aggregate read I/O over gap");
1089 
1090 ZFS_MODULE_PARAM(zfs_vdev, zfs_vdev_, write_gap_limit, INT, ZMOD_RW,
1091 	"Aggregate write I/O over gap");
1092 
1093 ZFS_MODULE_PARAM(zfs_vdev, zfs_vdev_, max_active, INT, ZMOD_RW,
1094 	"Maximum number of active I/Os per vdev");
1095 
1096 ZFS_MODULE_PARAM(zfs_vdev, zfs_vdev_, async_write_active_max_dirty_percent, INT, ZMOD_RW,
1097 	"Async write concurrency max threshold");
1098 
1099 ZFS_MODULE_PARAM(zfs_vdev, zfs_vdev_, async_write_active_min_dirty_percent, INT, ZMOD_RW,
1100 	"Async write concurrency min threshold");
1101 
1102 ZFS_MODULE_PARAM(zfs_vdev, zfs_vdev_, async_read_max_active, INT, ZMOD_RW,
1103 	"Max active async read I/Os per vdev");
1104 
1105 ZFS_MODULE_PARAM(zfs_vdev, zfs_vdev_, async_read_min_active, INT, ZMOD_RW,
1106 	"Min active async read I/Os per vdev");
1107 
1108 ZFS_MODULE_PARAM(zfs_vdev, zfs_vdev_, async_write_max_active, INT, ZMOD_RW,
1109 	"Max active async write I/Os per vdev");
1110 
1111 ZFS_MODULE_PARAM(zfs_vdev, zfs_vdev_, async_write_min_active, INT, ZMOD_RW,
1112 	"Min active async write I/Os per vdev");
1113 
1114 ZFS_MODULE_PARAM(zfs_vdev, zfs_vdev_, initializing_max_active, INT, ZMOD_RW,
1115 	"Max active initializing I/Os per vdev");
1116 
1117 ZFS_MODULE_PARAM(zfs_vdev, zfs_vdev_, initializing_min_active, INT, ZMOD_RW,
1118 	"Min active initializing I/Os per vdev");
1119 
1120 ZFS_MODULE_PARAM(zfs_vdev, zfs_vdev_, removal_max_active, INT, ZMOD_RW,
1121 	"Max active removal I/Os per vdev");
1122 
1123 ZFS_MODULE_PARAM(zfs_vdev, zfs_vdev_, removal_min_active, INT, ZMOD_RW,
1124 	"Min active removal I/Os per vdev");
1125 
1126 ZFS_MODULE_PARAM(zfs_vdev, zfs_vdev_, scrub_max_active, INT, ZMOD_RW,
1127 	"Max active scrub I/Os per vdev");
1128 
1129 ZFS_MODULE_PARAM(zfs_vdev, zfs_vdev_, scrub_min_active, INT, ZMOD_RW,
1130 	"Min active scrub I/Os per vdev");
1131 
1132 ZFS_MODULE_PARAM(zfs_vdev, zfs_vdev_, sync_read_max_active, INT, ZMOD_RW,
1133 	"Max active sync read I/Os per vdev");
1134 
1135 ZFS_MODULE_PARAM(zfs_vdev, zfs_vdev_, sync_read_min_active, INT, ZMOD_RW,
1136 	"Min active sync read I/Os per vdev");
1137 
1138 ZFS_MODULE_PARAM(zfs_vdev, zfs_vdev_, sync_write_max_active, INT, ZMOD_RW,
1139 	"Max active sync write I/Os per vdev");
1140 
1141 ZFS_MODULE_PARAM(zfs_vdev, zfs_vdev_, sync_write_min_active, INT, ZMOD_RW,
1142 	"Min active sync write I/Os per vdev");
1143 
1144 ZFS_MODULE_PARAM(zfs_vdev, zfs_vdev_, trim_max_active, INT, ZMOD_RW,
1145 	"Max active trim/discard I/Os per vdev");
1146 
1147 ZFS_MODULE_PARAM(zfs_vdev, zfs_vdev_, trim_min_active, INT, ZMOD_RW,
1148 	"Min active trim/discard I/Os per vdev");
1149 
1150 ZFS_MODULE_PARAM(zfs_vdev, zfs_vdev_, rebuild_max_active, INT, ZMOD_RW,
1151 	"Max active rebuild I/Os per vdev");
1152 
1153 ZFS_MODULE_PARAM(zfs_vdev, zfs_vdev_, rebuild_min_active, INT, ZMOD_RW,
1154 	"Min active rebuild I/Os per vdev");
1155 
1156 ZFS_MODULE_PARAM(zfs_vdev, zfs_vdev_, nia_credit, INT, ZMOD_RW,
1157 	"Number of non-interactive I/Os to allow in sequence");
1158 
1159 ZFS_MODULE_PARAM(zfs_vdev, zfs_vdev_, nia_delay, INT, ZMOD_RW,
1160 	"Number of non-interactive I/Os before _max_active");
1161 
1162 ZFS_MODULE_PARAM(zfs_vdev, zfs_vdev_, queue_depth_pct, INT, ZMOD_RW,
1163 	"Queue depth percentage for each top-level vdev");
1164 /* END CSTYLED */
1165