4 * The contents of this file are subject to the terms of the
5 * Common Development and Distribution License (the "License").
6 * You may not use this file except in compliance with the License.
8 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9 * or http://www.opensolaris.org/os/licensing.
10 * See the License for the specific language governing permissions
11 * and limitations under the License.
13 * When distributing Covered Code, include this CDDL HEADER in each
14 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15 * If applicable, add the following below this CDDL HEADER, with the
16 * fields enclosed by brackets "[]" replaced with your own identifying
17 * information: Portions Copyright [yyyy] [name of copyright owner]
22 * Copyright 2009 Sun Microsystems, Inc. All rights reserved.
23 * Use is subject to license terms.
27 * Copyright (c) 2012, 2014 by Delphix. All rights reserved.
30 #include <sys/zfs_context.h>
31 #include <sys/vdev_impl.h>
32 #include <sys/spa_impl.h>
35 #include <sys/dsl_pool.h>
37 #include <sys/spa_impl.h>
38 #include <sys/kstat.h>
44 * ZFS issues I/O operations to leaf vdevs to satisfy and complete zios. The
45 * I/O scheduler determines when and in what order those operations are
46 * issued. The I/O scheduler divides operations into five I/O classes
47 * prioritized in the following order: sync read, sync write, async read,
48 * async write, and scrub/resilver. Each queue defines the minimum and
49 * maximum number of concurrent operations that may be issued to the device.
50 * In addition, the device has an aggregate maximum. Note that the sum of the
51 * per-queue minimums must not exceed the aggregate maximum. If the
52 * sum of the per-queue maximums exceeds the aggregate maximum, then the
53 * number of active i/os may reach zfs_vdev_max_active, in which case no
54 * further i/os will be issued regardless of whether all per-queue
55 * minimums have been met.
57 * For many physical devices, throughput increases with the number of
58 * concurrent operations, but latency typically suffers. Further, physical
59 * devices typically have a limit at which more concurrent operations have no
60 * effect on throughput or can actually cause it to decrease.
62 * The scheduler selects the next operation to issue by first looking for an
63 * I/O class whose minimum has not been satisfied. Once all are satisfied and
64 * the aggregate maximum has not been hit, the scheduler looks for classes
65 * whose maximum has not been satisfied. Iteration through the I/O classes is
66 * done in the order specified above. No further operations are issued if the
67 * aggregate maximum number of concurrent operations has been hit or if there
68 * are no operations queued for an I/O class that has not hit its maximum.
69 * Every time an i/o is queued or an operation completes, the I/O scheduler
70 * looks for new operations to issue.
72 * All I/O classes have a fixed maximum number of outstanding operations
73 * except for the async write class. Asynchronous writes represent the data
74 * that is committed to stable storage during the syncing stage for
75 * transaction groups (see txg.c). Transaction groups enter the syncing state
76 * periodically so the number of queued async writes will quickly burst up and
77 * then bleed down to zero. Rather than servicing them as quickly as possible,
78 * the I/O scheduler changes the maximum number of active async write i/os
79 * according to the amount of dirty data in the pool (see dsl_pool.c). Since
80 * both throughput and latency typically increase with the number of
81 * concurrent operations issued to physical devices, reducing the burstiness
82 * in the number of concurrent operations also stabilizes the response time of
83 * operations from other -- and in particular synchronous -- queues. In broad
84 * strokes, the I/O scheduler will issue more concurrent operations from the
85 * async write queue as there's more dirty data in the pool.
89 * The number of concurrent operations issued for the async write I/O class
90 * follows a piece-wise linear function defined by a few adjustable points.
92 * | o---------| <-- zfs_vdev_async_write_max_active
99 * |------------o | | <-- zfs_vdev_async_write_min_active
100 * 0|____________^______|_________|
101 * 0% | | 100% of zfs_dirty_data_max
103 * | `-- zfs_vdev_async_write_active_max_dirty_percent
104 * `--------- zfs_vdev_async_write_active_min_dirty_percent
106 * Until the amount of dirty data exceeds a minimum percentage of the dirty
107 * data allowed in the pool, the I/O scheduler will limit the number of
108 * concurrent operations to the minimum. As that threshold is crossed, the
109 * number of concurrent operations issued increases linearly to the maximum at
110 * the specified maximum percentage of the dirty data allowed in the pool.
112 * Ideally, the amount of dirty data on a busy pool will stay in the sloped
113 * part of the function between zfs_vdev_async_write_active_min_dirty_percent
114 * and zfs_vdev_async_write_active_max_dirty_percent. If it exceeds the
115 * maximum percentage, this indicates that the rate of incoming data is
116 * greater than the rate that the backend storage can handle. In this case, we
117 * must further throttle incoming writes (see dmu_tx_delay() for details).
121 * The maximum number of i/os active to each device. Ideally, this will be >=
122 * the sum of each queue's max_active. It must be at least the sum of each
123 * queue's min_active.
125 uint32_t zfs_vdev_max_active
= 1000;
128 * Per-queue limits on the number of i/os active to each device. If the
129 * number of active i/os is < zfs_vdev_max_active, then the min_active comes
130 * into play. We will send min_active from each queue, and then select from
131 * queues in the order defined by zio_priority_t.
133 * In general, smaller max_active's will lead to lower latency of synchronous
134 * operations. Larger max_active's may lead to higher overall throughput,
135 * depending on underlying storage.
137 * The ratio of the queues' max_actives determines the balance of performance
138 * between reads, writes, and scrubs. E.g., increasing
139 * zfs_vdev_scrub_max_active will cause the scrub or resilver to complete
140 * more quickly, but reads and writes to have higher latency and lower
143 uint32_t zfs_vdev_sync_read_min_active
= 10;
144 uint32_t zfs_vdev_sync_read_max_active
= 10;
145 uint32_t zfs_vdev_sync_write_min_active
= 10;
146 uint32_t zfs_vdev_sync_write_max_active
= 10;
147 uint32_t zfs_vdev_async_read_min_active
= 1;
148 uint32_t zfs_vdev_async_read_max_active
= 3;
149 uint32_t zfs_vdev_async_write_min_active
= 1;
150 uint32_t zfs_vdev_async_write_max_active
= 10;
151 uint32_t zfs_vdev_scrub_min_active
= 1;
152 uint32_t zfs_vdev_scrub_max_active
= 2;
155 * When the pool has less than zfs_vdev_async_write_active_min_dirty_percent
156 * dirty data, use zfs_vdev_async_write_min_active. When it has more than
157 * zfs_vdev_async_write_active_max_dirty_percent, use
158 * zfs_vdev_async_write_max_active. The value is linearly interpolated
159 * between min and max.
161 int zfs_vdev_async_write_active_min_dirty_percent
= 30;
162 int zfs_vdev_async_write_active_max_dirty_percent
= 60;
165 * To reduce IOPs, we aggregate small adjacent I/Os into one large I/O.
166 * For read I/Os, we also aggregate across small adjacency gaps; for writes
167 * we include spans of optional I/Os to aid aggregation at the disk even when
168 * they aren't able to help us aggregate at this level.
170 int zfs_vdev_aggregation_limit
= SPA_OLD_MAXBLOCKSIZE
;
171 int zfs_vdev_read_gap_limit
= 32 << 10;
172 int zfs_vdev_write_gap_limit
= 4 << 10;
175 vdev_queue_offset_compare(const void *x1
, const void *x2
)
177 const zio_t
*z1
= x1
;
178 const zio_t
*z2
= x2
;
180 if (z1
->io_offset
< z2
->io_offset
)
182 if (z1
->io_offset
> z2
->io_offset
)
193 static inline avl_tree_t
*
194 vdev_queue_class_tree(vdev_queue_t
*vq
, zio_priority_t p
)
196 return (&vq
->vq_class
[p
].vqc_queued_tree
);
199 static inline avl_tree_t
*
200 vdev_queue_type_tree(vdev_queue_t
*vq
, zio_type_t t
)
202 ASSERT(t
== ZIO_TYPE_READ
|| t
== ZIO_TYPE_WRITE
);
203 if (t
== ZIO_TYPE_READ
)
204 return (&vq
->vq_read_offset_tree
);
206 return (&vq
->vq_write_offset_tree
);
210 vdev_queue_timestamp_compare(const void *x1
, const void *x2
)
212 const zio_t
*z1
= x1
;
213 const zio_t
*z2
= x2
;
215 if (z1
->io_timestamp
< z2
->io_timestamp
)
217 if (z1
->io_timestamp
> z2
->io_timestamp
)
229 vdev_queue_class_min_active(zio_priority_t p
)
232 case ZIO_PRIORITY_SYNC_READ
:
233 return (zfs_vdev_sync_read_min_active
);
234 case ZIO_PRIORITY_SYNC_WRITE
:
235 return (zfs_vdev_sync_write_min_active
);
236 case ZIO_PRIORITY_ASYNC_READ
:
237 return (zfs_vdev_async_read_min_active
);
238 case ZIO_PRIORITY_ASYNC_WRITE
:
239 return (zfs_vdev_async_write_min_active
);
240 case ZIO_PRIORITY_SCRUB
:
241 return (zfs_vdev_scrub_min_active
);
243 panic("invalid priority %u", p
);
249 vdev_queue_max_async_writes(spa_t
*spa
)
252 uint64_t dirty
= spa
->spa_dsl_pool
->dp_dirty_total
;
253 uint64_t min_bytes
= zfs_dirty_data_max
*
254 zfs_vdev_async_write_active_min_dirty_percent
/ 100;
255 uint64_t max_bytes
= zfs_dirty_data_max
*
256 zfs_vdev_async_write_active_max_dirty_percent
/ 100;
259 * Sync tasks correspond to interactive user actions. To reduce the
260 * execution time of those actions we push data out as fast as possible.
262 if (spa_has_pending_synctask(spa
)) {
263 return (zfs_vdev_async_write_max_active
);
266 if (dirty
< min_bytes
)
267 return (zfs_vdev_async_write_min_active
);
268 if (dirty
> max_bytes
)
269 return (zfs_vdev_async_write_max_active
);
272 * linear interpolation:
273 * slope = (max_writes - min_writes) / (max_bytes - min_bytes)
274 * move right by min_bytes
275 * move up by min_writes
277 writes
= (dirty
- min_bytes
) *
278 (zfs_vdev_async_write_max_active
-
279 zfs_vdev_async_write_min_active
) /
280 (max_bytes
- min_bytes
) +
281 zfs_vdev_async_write_min_active
;
282 ASSERT3U(writes
, >=, zfs_vdev_async_write_min_active
);
283 ASSERT3U(writes
, <=, zfs_vdev_async_write_max_active
);
288 vdev_queue_class_max_active(spa_t
*spa
, zio_priority_t p
)
291 case ZIO_PRIORITY_SYNC_READ
:
292 return (zfs_vdev_sync_read_max_active
);
293 case ZIO_PRIORITY_SYNC_WRITE
:
294 return (zfs_vdev_sync_write_max_active
);
295 case ZIO_PRIORITY_ASYNC_READ
:
296 return (zfs_vdev_async_read_max_active
);
297 case ZIO_PRIORITY_ASYNC_WRITE
:
298 return (vdev_queue_max_async_writes(spa
));
299 case ZIO_PRIORITY_SCRUB
:
300 return (zfs_vdev_scrub_max_active
);
302 panic("invalid priority %u", p
);
308 * Return the i/o class to issue from, or ZIO_PRIORITY_MAX_QUEUEABLE if
309 * there is no eligible class.
311 static zio_priority_t
312 vdev_queue_class_to_issue(vdev_queue_t
*vq
)
314 spa_t
*spa
= vq
->vq_vdev
->vdev_spa
;
317 if (avl_numnodes(&vq
->vq_active_tree
) >= zfs_vdev_max_active
)
318 return (ZIO_PRIORITY_NUM_QUEUEABLE
);
320 /* find a queue that has not reached its minimum # outstanding i/os */
321 for (p
= 0; p
< ZIO_PRIORITY_NUM_QUEUEABLE
; p
++) {
322 if (avl_numnodes(vdev_queue_class_tree(vq
, p
)) > 0 &&
323 vq
->vq_class
[p
].vqc_active
<
324 vdev_queue_class_min_active(p
))
329 * If we haven't found a queue, look for one that hasn't reached its
330 * maximum # outstanding i/os.
332 for (p
= 0; p
< ZIO_PRIORITY_NUM_QUEUEABLE
; p
++) {
333 if (avl_numnodes(vdev_queue_class_tree(vq
, p
)) > 0 &&
334 vq
->vq_class
[p
].vqc_active
<
335 vdev_queue_class_max_active(spa
, p
))
339 /* No eligible queued i/os */
340 return (ZIO_PRIORITY_NUM_QUEUEABLE
);
344 vdev_queue_init(vdev_t
*vd
)
346 vdev_queue_t
*vq
= &vd
->vdev_queue
;
349 mutex_init(&vq
->vq_lock
, NULL
, MUTEX_DEFAULT
, NULL
);
352 avl_create(&vq
->vq_active_tree
, vdev_queue_offset_compare
,
353 sizeof (zio_t
), offsetof(struct zio
, io_queue_node
));
354 avl_create(vdev_queue_type_tree(vq
, ZIO_TYPE_READ
),
355 vdev_queue_offset_compare
, sizeof (zio_t
),
356 offsetof(struct zio
, io_offset_node
));
357 avl_create(vdev_queue_type_tree(vq
, ZIO_TYPE_WRITE
),
358 vdev_queue_offset_compare
, sizeof (zio_t
),
359 offsetof(struct zio
, io_offset_node
));
361 for (p
= 0; p
< ZIO_PRIORITY_NUM_QUEUEABLE
; p
++) {
362 int (*compfn
) (const void *, const void *);
365 * The synchronous i/o queues are dispatched in FIFO rather
366 * than LBA order. This provides more consistent latency for
369 if (p
== ZIO_PRIORITY_SYNC_READ
|| p
== ZIO_PRIORITY_SYNC_WRITE
)
370 compfn
= vdev_queue_timestamp_compare
;
372 compfn
= vdev_queue_offset_compare
;
373 avl_create(vdev_queue_class_tree(vq
, p
), compfn
,
374 sizeof (zio_t
), offsetof(struct zio
, io_queue_node
));
379 vdev_queue_fini(vdev_t
*vd
)
381 vdev_queue_t
*vq
= &vd
->vdev_queue
;
384 for (p
= 0; p
< ZIO_PRIORITY_NUM_QUEUEABLE
; p
++)
385 avl_destroy(vdev_queue_class_tree(vq
, p
));
386 avl_destroy(&vq
->vq_active_tree
);
387 avl_destroy(vdev_queue_type_tree(vq
, ZIO_TYPE_READ
));
388 avl_destroy(vdev_queue_type_tree(vq
, ZIO_TYPE_WRITE
));
390 mutex_destroy(&vq
->vq_lock
);
394 vdev_queue_io_add(vdev_queue_t
*vq
, zio_t
*zio
)
396 spa_t
*spa
= zio
->io_spa
;
397 spa_stats_history_t
*ssh
= &spa
->spa_stats
.io_history
;
399 ASSERT3U(zio
->io_priority
, <, ZIO_PRIORITY_NUM_QUEUEABLE
);
400 avl_add(vdev_queue_class_tree(vq
, zio
->io_priority
), zio
);
401 avl_add(vdev_queue_type_tree(vq
, zio
->io_type
), zio
);
403 if (ssh
->kstat
!= NULL
) {
404 mutex_enter(&ssh
->lock
);
405 kstat_waitq_enter(ssh
->kstat
->ks_data
);
406 mutex_exit(&ssh
->lock
);
411 vdev_queue_io_remove(vdev_queue_t
*vq
, zio_t
*zio
)
413 spa_t
*spa
= zio
->io_spa
;
414 spa_stats_history_t
*ssh
= &spa
->spa_stats
.io_history
;
416 ASSERT3U(zio
->io_priority
, <, ZIO_PRIORITY_NUM_QUEUEABLE
);
417 avl_remove(vdev_queue_class_tree(vq
, zio
->io_priority
), zio
);
418 avl_remove(vdev_queue_type_tree(vq
, zio
->io_type
), zio
);
420 if (ssh
->kstat
!= NULL
) {
421 mutex_enter(&ssh
->lock
);
422 kstat_waitq_exit(ssh
->kstat
->ks_data
);
423 mutex_exit(&ssh
->lock
);
428 vdev_queue_pending_add(vdev_queue_t
*vq
, zio_t
*zio
)
430 spa_t
*spa
= zio
->io_spa
;
431 spa_stats_history_t
*ssh
= &spa
->spa_stats
.io_history
;
433 ASSERT(MUTEX_HELD(&vq
->vq_lock
));
434 ASSERT3U(zio
->io_priority
, <, ZIO_PRIORITY_NUM_QUEUEABLE
);
435 vq
->vq_class
[zio
->io_priority
].vqc_active
++;
436 avl_add(&vq
->vq_active_tree
, zio
);
438 if (ssh
->kstat
!= NULL
) {
439 mutex_enter(&ssh
->lock
);
440 kstat_runq_enter(ssh
->kstat
->ks_data
);
441 mutex_exit(&ssh
->lock
);
446 vdev_queue_pending_remove(vdev_queue_t
*vq
, zio_t
*zio
)
448 spa_t
*spa
= zio
->io_spa
;
449 spa_stats_history_t
*ssh
= &spa
->spa_stats
.io_history
;
451 ASSERT(MUTEX_HELD(&vq
->vq_lock
));
452 ASSERT3U(zio
->io_priority
, <, ZIO_PRIORITY_NUM_QUEUEABLE
);
453 vq
->vq_class
[zio
->io_priority
].vqc_active
--;
454 avl_remove(&vq
->vq_active_tree
, zio
);
456 if (ssh
->kstat
!= NULL
) {
457 kstat_io_t
*ksio
= ssh
->kstat
->ks_data
;
459 mutex_enter(&ssh
->lock
);
460 kstat_runq_exit(ksio
);
461 if (zio
->io_type
== ZIO_TYPE_READ
) {
463 ksio
->nread
+= zio
->io_size
;
464 } else if (zio
->io_type
== ZIO_TYPE_WRITE
) {
466 ksio
->nwritten
+= zio
->io_size
;
468 mutex_exit(&ssh
->lock
);
473 vdev_queue_agg_io_done(zio_t
*aio
)
475 if (aio
->io_type
== ZIO_TYPE_READ
) {
477 while ((pio
= zio_walk_parents(aio
)) != NULL
) {
478 bcopy((char *)aio
->io_data
+ (pio
->io_offset
-
479 aio
->io_offset
), pio
->io_data
, pio
->io_size
);
483 zio_buf_free(aio
->io_data
, aio
->io_size
);
487 * Compute the range spanned by two i/os, which is the endpoint of the last
488 * (lio->io_offset + lio->io_size) minus start of the first (fio->io_offset).
489 * Conveniently, the gap between fio and lio is given by -IO_SPAN(lio, fio);
490 * thus fio and lio are adjacent if and only if IO_SPAN(lio, fio) == 0.
492 #define IO_SPAN(fio, lio) ((lio)->io_offset + (lio)->io_size - (fio)->io_offset)
493 #define IO_GAP(fio, lio) (-IO_SPAN(lio, fio))
496 vdev_queue_aggregate(vdev_queue_t
*vq
, zio_t
*zio
)
498 zio_t
*first
, *last
, *aio
, *dio
, *mandatory
, *nio
;
501 boolean_t stretch
= B_FALSE
;
502 avl_tree_t
*t
= vdev_queue_type_tree(vq
, zio
->io_type
);
503 enum zio_flag flags
= zio
->io_flags
& ZIO_FLAG_AGG_INHERIT
;
505 if (zio
->io_flags
& ZIO_FLAG_DONT_AGGREGATE
)
509 * Prevent users from setting the zfs_vdev_aggregation_limit
510 * tuning larger than SPA_MAXBLOCKSIZE.
512 zfs_vdev_aggregation_limit
=
513 MIN(zfs_vdev_aggregation_limit
, SPA_MAXBLOCKSIZE
);
517 if (zio
->io_type
== ZIO_TYPE_READ
)
518 maxgap
= zfs_vdev_read_gap_limit
;
521 * We can aggregate I/Os that are sufficiently adjacent and of
522 * the same flavor, as expressed by the AGG_INHERIT flags.
523 * The latter requirement is necessary so that certain
524 * attributes of the I/O, such as whether it's a normal I/O
525 * or a scrub/resilver, can be preserved in the aggregate.
526 * We can include optional I/Os, but don't allow them
527 * to begin a range as they add no benefit in that situation.
531 * We keep track of the last non-optional I/O.
533 mandatory
= (first
->io_flags
& ZIO_FLAG_OPTIONAL
) ? NULL
: first
;
536 * Walk backwards through sufficiently contiguous I/Os
537 * recording the last non-option I/O.
539 while ((dio
= AVL_PREV(t
, first
)) != NULL
&&
540 (dio
->io_flags
& ZIO_FLAG_AGG_INHERIT
) == flags
&&
541 IO_SPAN(dio
, last
) <= zfs_vdev_aggregation_limit
&&
542 IO_GAP(dio
, first
) <= maxgap
) {
544 if (mandatory
== NULL
&& !(first
->io_flags
& ZIO_FLAG_OPTIONAL
))
549 * Skip any initial optional I/Os.
551 while ((first
->io_flags
& ZIO_FLAG_OPTIONAL
) && first
!= last
) {
552 first
= AVL_NEXT(t
, first
);
553 ASSERT(first
!= NULL
);
558 * Walk forward through sufficiently contiguous I/Os.
560 while ((dio
= AVL_NEXT(t
, last
)) != NULL
&&
561 (dio
->io_flags
& ZIO_FLAG_AGG_INHERIT
) == flags
&&
562 IO_SPAN(first
, dio
) <= zfs_vdev_aggregation_limit
&&
563 IO_GAP(last
, dio
) <= maxgap
) {
565 if (!(last
->io_flags
& ZIO_FLAG_OPTIONAL
))
570 * Now that we've established the range of the I/O aggregation
571 * we must decide what to do with trailing optional I/Os.
572 * For reads, there's nothing to do. While we are unable to
573 * aggregate further, it's possible that a trailing optional
574 * I/O would allow the underlying device to aggregate with
575 * subsequent I/Os. We must therefore determine if the next
576 * non-optional I/O is close enough to make aggregation
579 if (zio
->io_type
== ZIO_TYPE_WRITE
&& mandatory
!= NULL
) {
581 while ((dio
= AVL_NEXT(t
, nio
)) != NULL
&&
582 IO_GAP(nio
, dio
) == 0 &&
583 IO_GAP(mandatory
, dio
) <= zfs_vdev_write_gap_limit
) {
585 if (!(nio
->io_flags
& ZIO_FLAG_OPTIONAL
)) {
593 /* This may be a no-op. */
594 dio
= AVL_NEXT(t
, last
);
595 dio
->io_flags
&= ~ZIO_FLAG_OPTIONAL
;
597 while (last
!= mandatory
&& last
!= first
) {
598 ASSERT(last
->io_flags
& ZIO_FLAG_OPTIONAL
);
599 last
= AVL_PREV(t
, last
);
600 ASSERT(last
!= NULL
);
607 size
= IO_SPAN(first
, last
);
608 ASSERT3U(size
, <=, zfs_vdev_aggregation_limit
);
610 aio
= zio_vdev_delegated_io(first
->io_vd
, first
->io_offset
,
611 zio_buf_alloc(size
), size
, first
->io_type
, zio
->io_priority
,
612 flags
| ZIO_FLAG_DONT_CACHE
| ZIO_FLAG_DONT_QUEUE
,
613 vdev_queue_agg_io_done
, NULL
);
614 aio
->io_timestamp
= first
->io_timestamp
;
619 nio
= AVL_NEXT(t
, dio
);
620 ASSERT3U(dio
->io_type
, ==, aio
->io_type
);
622 if (dio
->io_flags
& ZIO_FLAG_NODATA
) {
623 ASSERT3U(dio
->io_type
, ==, ZIO_TYPE_WRITE
);
624 bzero((char *)aio
->io_data
+ (dio
->io_offset
-
625 aio
->io_offset
), dio
->io_size
);
626 } else if (dio
->io_type
== ZIO_TYPE_WRITE
) {
627 bcopy(dio
->io_data
, (char *)aio
->io_data
+
628 (dio
->io_offset
- aio
->io_offset
),
632 zio_add_child(dio
, aio
);
633 vdev_queue_io_remove(vq
, dio
);
634 zio_vdev_io_bypass(dio
);
636 } while (dio
!= last
);
642 vdev_queue_io_to_issue(vdev_queue_t
*vq
)
650 ASSERT(MUTEX_HELD(&vq
->vq_lock
));
652 p
= vdev_queue_class_to_issue(vq
);
654 if (p
== ZIO_PRIORITY_NUM_QUEUEABLE
) {
655 /* No eligible queued i/os */
660 * For LBA-ordered queues (async / scrub), issue the i/o which follows
661 * the most recently issued i/o in LBA (offset) order.
663 * For FIFO queues (sync), issue the i/o with the lowest timestamp.
665 tree
= vdev_queue_class_tree(vq
, p
);
666 vq
->vq_io_search
.io_timestamp
= 0;
667 vq
->vq_io_search
.io_offset
= vq
->vq_last_offset
+ 1;
668 VERIFY3P(avl_find(tree
, &vq
->vq_io_search
,
670 zio
= avl_nearest(tree
, idx
, AVL_AFTER
);
672 zio
= avl_first(tree
);
673 ASSERT3U(zio
->io_priority
, ==, p
);
675 aio
= vdev_queue_aggregate(vq
, zio
);
679 vdev_queue_io_remove(vq
, zio
);
682 * If the I/O is or was optional and therefore has no data, we need to
683 * simply discard it. We need to drop the vdev queue's lock to avoid a
684 * deadlock that we could encounter since this I/O will complete
687 if (zio
->io_flags
& ZIO_FLAG_NODATA
) {
688 mutex_exit(&vq
->vq_lock
);
689 zio_vdev_io_bypass(zio
);
691 mutex_enter(&vq
->vq_lock
);
695 vdev_queue_pending_add(vq
, zio
);
696 vq
->vq_last_offset
= zio
->io_offset
;
702 vdev_queue_io(zio_t
*zio
)
704 vdev_queue_t
*vq
= &zio
->io_vd
->vdev_queue
;
707 if (zio
->io_flags
& ZIO_FLAG_DONT_QUEUE
)
711 * Children i/os inherent their parent's priority, which might
712 * not match the child's i/o type. Fix it up here.
714 if (zio
->io_type
== ZIO_TYPE_READ
) {
715 if (zio
->io_priority
!= ZIO_PRIORITY_SYNC_READ
&&
716 zio
->io_priority
!= ZIO_PRIORITY_ASYNC_READ
&&
717 zio
->io_priority
!= ZIO_PRIORITY_SCRUB
)
718 zio
->io_priority
= ZIO_PRIORITY_ASYNC_READ
;
720 ASSERT(zio
->io_type
== ZIO_TYPE_WRITE
);
721 if (zio
->io_priority
!= ZIO_PRIORITY_SYNC_WRITE
&&
722 zio
->io_priority
!= ZIO_PRIORITY_ASYNC_WRITE
)
723 zio
->io_priority
= ZIO_PRIORITY_ASYNC_WRITE
;
726 zio
->io_flags
|= ZIO_FLAG_DONT_CACHE
| ZIO_FLAG_DONT_QUEUE
;
728 mutex_enter(&vq
->vq_lock
);
729 zio
->io_timestamp
= gethrtime();
730 vdev_queue_io_add(vq
, zio
);
731 nio
= vdev_queue_io_to_issue(vq
);
732 mutex_exit(&vq
->vq_lock
);
737 if (nio
->io_done
== vdev_queue_agg_io_done
) {
746 vdev_queue_io_done(zio_t
*zio
)
748 vdev_queue_t
*vq
= &zio
->io_vd
->vdev_queue
;
751 if (zio_injection_enabled
)
752 delay(SEC_TO_TICK(zio_handle_io_delay(zio
)));
754 mutex_enter(&vq
->vq_lock
);
756 vdev_queue_pending_remove(vq
, zio
);
758 zio
->io_delta
= gethrtime() - zio
->io_timestamp
;
759 vq
->vq_io_complete_ts
= gethrtime();
760 vq
->vq_io_delta_ts
= vq
->vq_io_complete_ts
- zio
->io_timestamp
;
762 while ((nio
= vdev_queue_io_to_issue(vq
)) != NULL
) {
763 mutex_exit(&vq
->vq_lock
);
764 if (nio
->io_done
== vdev_queue_agg_io_done
) {
767 zio_vdev_io_reissue(nio
);
770 mutex_enter(&vq
->vq_lock
);
773 mutex_exit(&vq
->vq_lock
);
776 #if defined(_KERNEL) && defined(HAVE_SPL)
777 module_param(zfs_vdev_aggregation_limit
, int, 0644);
778 MODULE_PARM_DESC(zfs_vdev_aggregation_limit
, "Max vdev I/O aggregation size");
780 module_param(zfs_vdev_read_gap_limit
, int, 0644);
781 MODULE_PARM_DESC(zfs_vdev_read_gap_limit
, "Aggregate read I/O over gap");
783 module_param(zfs_vdev_write_gap_limit
, int, 0644);
784 MODULE_PARM_DESC(zfs_vdev_write_gap_limit
, "Aggregate write I/O over gap");
786 module_param(zfs_vdev_max_active
, int, 0644);
787 MODULE_PARM_DESC(zfs_vdev_max_active
, "Maximum number of active I/Os per vdev");
789 module_param(zfs_vdev_async_write_active_max_dirty_percent
, int, 0644);
790 MODULE_PARM_DESC(zfs_vdev_async_write_active_max_dirty_percent
,
791 "Async write concurrency max threshold");
793 module_param(zfs_vdev_async_write_active_min_dirty_percent
, int, 0644);
794 MODULE_PARM_DESC(zfs_vdev_async_write_active_min_dirty_percent
,
795 "Async write concurrency min threshold");
797 module_param(zfs_vdev_async_read_max_active
, int, 0644);
798 MODULE_PARM_DESC(zfs_vdev_async_read_max_active
,
799 "Max active async read I/Os per vdev");
801 module_param(zfs_vdev_async_read_min_active
, int, 0644);
802 MODULE_PARM_DESC(zfs_vdev_async_read_min_active
,
803 "Min active async read I/Os per vdev");
805 module_param(zfs_vdev_async_write_max_active
, int, 0644);
806 MODULE_PARM_DESC(zfs_vdev_async_write_max_active
,
807 "Max active async write I/Os per vdev");
809 module_param(zfs_vdev_async_write_min_active
, int, 0644);
810 MODULE_PARM_DESC(zfs_vdev_async_write_min_active
,
811 "Min active async write I/Os per vdev");
813 module_param(zfs_vdev_scrub_max_active
, int, 0644);
814 MODULE_PARM_DESC(zfs_vdev_scrub_max_active
, "Max active scrub I/Os per vdev");
816 module_param(zfs_vdev_scrub_min_active
, int, 0644);
817 MODULE_PARM_DESC(zfs_vdev_scrub_min_active
, "Min active scrub I/Os per vdev");
819 module_param(zfs_vdev_sync_read_max_active
, int, 0644);
820 MODULE_PARM_DESC(zfs_vdev_sync_read_max_active
,
821 "Max active sync read I/Os per vdev");
823 module_param(zfs_vdev_sync_read_min_active
, int, 0644);
824 MODULE_PARM_DESC(zfs_vdev_sync_read_min_active
,
825 "Min active sync read I/Os per vdev");
827 module_param(zfs_vdev_sync_write_max_active
, int, 0644);
828 MODULE_PARM_DESC(zfs_vdev_sync_write_max_active
,
829 "Max active sync write I/Os per vdev");
831 module_param(zfs_vdev_sync_write_min_active
, int, 0644);
832 MODULE_PARM_DESC(zfs_vdev_sync_write_min_active
,
833 "Min active sync write I/Osper vdev");