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) 2013 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>
41 * ZFS issues I/O operations to leaf vdevs to satisfy and complete zios. The
42 * I/O scheduler determines when and in what order those operations are
43 * issued. The I/O scheduler divides operations into five I/O classes
44 * prioritized in the following order: sync read, sync write, async read,
45 * async write, and scrub/resilver. Each queue defines the minimum and
46 * maximum number of concurrent operations that may be issued to the device.
47 * In addition, the device has an aggregate maximum. Note that the sum of the
48 * per-queue minimums must not exceed the aggregate maximum, and if the
49 * aggregate maximum is equal to or greater than the sum of the per-queue
50 * maximums, the per-queue minimum has no effect.
52 * For many physical devices, throughput increases with the number of
53 * concurrent operations, but latency typically suffers. Further, physical
54 * devices typically have a limit at which more concurrent operations have no
55 * effect on throughput or can actually cause it to decrease.
57 * The scheduler selects the next operation to issue by first looking for an
58 * I/O class whose minimum has not been satisfied. Once all are satisfied and
59 * the aggregate maximum has not been hit, the scheduler looks for classes
60 * whose maximum has not been satisfied. Iteration through the I/O classes is
61 * done in the order specified above. No further operations are issued if the
62 * aggregate maximum number of concurrent operations has been hit or if there
63 * are no operations queued for an I/O class that has not hit its maximum.
64 * Every time an i/o is queued or an operation completes, the I/O scheduler
65 * looks for new operations to issue.
67 * All I/O classes have a fixed maximum number of outstanding operations
68 * except for the async write class. Asynchronous writes represent the data
69 * that is committed to stable storage during the syncing stage for
70 * transaction groups (see txg.c). Transaction groups enter the syncing state
71 * periodically so the number of queued async writes will quickly burst up and
72 * then bleed down to zero. Rather than servicing them as quickly as possible,
73 * the I/O scheduler changes the maximum number of active async write i/os
74 * according to the amount of dirty data in the pool (see dsl_pool.c). Since
75 * both throughput and latency typically increase with the number of
76 * concurrent operations issued to physical devices, reducing the burstiness
77 * in the number of concurrent operations also stabilizes the response time of
78 * operations from other -- and in particular synchronous -- queues. In broad
79 * strokes, the I/O scheduler will issue more concurrent operations from the
80 * async write queue as there's more dirty data in the pool.
84 * The number of concurrent operations issued for the async write I/O class
85 * follows a piece-wise linear function defined by a few adjustable points.
87 * | o---------| <-- zfs_vdev_async_write_max_active
94 * |------------o | | <-- zfs_vdev_async_write_min_active
95 * 0|____________^______|_________|
96 * 0% | | 100% of zfs_dirty_data_max
98 * | `-- zfs_vdev_async_write_active_max_dirty_percent
99 * `--------- zfs_vdev_async_write_active_min_dirty_percent
101 * Until the amount of dirty data exceeds a minimum percentage of the dirty
102 * data allowed in the pool, the I/O scheduler will limit the number of
103 * concurrent operations to the minimum. As that threshold is crossed, the
104 * number of concurrent operations issued increases linearly to the maximum at
105 * the specified maximum percentage of the dirty data allowed in the pool.
107 * Ideally, the amount of dirty data on a busy pool will stay in the sloped
108 * part of the function between zfs_vdev_async_write_active_min_dirty_percent
109 * and zfs_vdev_async_write_active_max_dirty_percent. If it exceeds the
110 * maximum percentage, this indicates that the rate of incoming data is
111 * greater than the rate that the backend storage can handle. In this case, we
112 * must further throttle incoming writes (see dmu_tx_delay() for details).
116 * The maximum number of i/os active to each device. Ideally, this will be >=
117 * the sum of each queue's max_active. It must be at least the sum of each
118 * queue's min_active.
120 uint32_t zfs_vdev_max_active = 1000;
123 * Per-queue limits on the number of i/os active to each device. If the
124 * sum of the queue's max_active is < zfs_vdev_max_active, then the
125 * min_active comes into play. We will send min_active from each queue,
126 * and then select from queues in the order defined by zio_priority_t.
128 * In general, smaller max_active's will lead to lower latency of synchronous
129 * operations. Larger max_active's may lead to higher overall throughput,
130 * depending on underlying storage.
132 * The ratio of the queues' max_actives determines the balance of performance
133 * between reads, writes, and scrubs. E.g., increasing
134 * zfs_vdev_scrub_max_active will cause the scrub or resilver to complete
135 * more quickly, but reads and writes to have higher latency and lower
138 uint32_t zfs_vdev_sync_read_min_active = 10;
139 uint32_t zfs_vdev_sync_read_max_active = 10;
140 uint32_t zfs_vdev_sync_write_min_active = 10;
141 uint32_t zfs_vdev_sync_write_max_active = 10;
142 uint32_t zfs_vdev_async_read_min_active = 1;
143 uint32_t zfs_vdev_async_read_max_active = 3;
144 uint32_t zfs_vdev_async_write_min_active = 1;
145 uint32_t zfs_vdev_async_write_max_active = 10;
146 uint32_t zfs_vdev_scrub_min_active = 1;
147 uint32_t zfs_vdev_scrub_max_active = 2;
150 * When the pool has less than zfs_vdev_async_write_active_min_dirty_percent
151 * dirty data, use zfs_vdev_async_write_min_active. When it has more than
152 * zfs_vdev_async_write_active_max_dirty_percent, use
153 * zfs_vdev_async_write_max_active. The value is linearly interpolated
154 * between min and max.
156 int zfs_vdev_async_write_active_min_dirty_percent = 30;
157 int zfs_vdev_async_write_active_max_dirty_percent = 60;
160 * To reduce IOPs, we aggregate small adjacent I/Os into one large I/O.
161 * For read I/Os, we also aggregate across small adjacency gaps; for writes
162 * we include spans of optional I/Os to aid aggregation at the disk even when
163 * they aren't able to help us aggregate at this level.
165 int zfs_vdev_aggregation_limit = SPA_MAXBLOCKSIZE;
166 int zfs_vdev_read_gap_limit = 32 << 10;
167 int zfs_vdev_write_gap_limit = 4 << 10;
170 SYSCTL_DECL(_vfs_zfs_vdev);
171 TUNABLE_INT("vfs.zfs.vdev.max_active", &zfs_vdev_max_active);
172 SYSCTL_UINT(_vfs_zfs_vdev, OID_AUTO, max_active, CTLFLAG_RW,
173 &zfs_vdev_max_active, 0,
174 "The maximum number of i/os of all types active for each device.");
176 #define ZFS_VDEV_QUEUE_KNOB_MIN(name) \
177 TUNABLE_INT("vfs.zfs.vdev." #name "_min_active", \
178 &zfs_vdev_ ## name ## _min_active); \
179 SYSCTL_UINT(_vfs_zfs_vdev, OID_AUTO, name ## _min_active, CTLFLAG_RW, \
180 &zfs_vdev_ ## name ## _min_active, 0, \
181 "Initial number of I/O requests of type " #name \
182 " active for each device");
184 #define ZFS_VDEV_QUEUE_KNOB_MAX(name) \
185 TUNABLE_INT("vfs.zfs.vdev." #name "_max_active", \
186 &zfs_vdev_ ## name ## _max_active); \
187 SYSCTL_UINT(_vfs_zfs_vdev, OID_AUTO, name ## _max_active, CTLFLAG_RW, \
188 &zfs_vdev_ ## name ## _max_active, 0, \
189 "Maximum number of I/O requests of type " #name \
190 " active for each device");
192 ZFS_VDEV_QUEUE_KNOB_MIN(sync_read);
193 ZFS_VDEV_QUEUE_KNOB_MAX(sync_read);
194 ZFS_VDEV_QUEUE_KNOB_MIN(sync_write);
195 ZFS_VDEV_QUEUE_KNOB_MAX(sync_write);
196 ZFS_VDEV_QUEUE_KNOB_MIN(async_read);
197 ZFS_VDEV_QUEUE_KNOB_MAX(async_read);
198 ZFS_VDEV_QUEUE_KNOB_MIN(async_write);
199 ZFS_VDEV_QUEUE_KNOB_MAX(async_write);
200 ZFS_VDEV_QUEUE_KNOB_MIN(scrub);
201 ZFS_VDEV_QUEUE_KNOB_MAX(scrub);
203 #undef ZFS_VDEV_QUEUE_KNOB
205 TUNABLE_INT("vfs.zfs.vdev.aggregation_limit", &zfs_vdev_aggregation_limit);
206 SYSCTL_INT(_vfs_zfs_vdev, OID_AUTO, aggregation_limit, CTLFLAG_RW,
207 &zfs_vdev_aggregation_limit, 0,
208 "I/O requests are aggregated up to this size");
209 TUNABLE_INT("vfs.zfs.vdev.read_gap_limit", &zfs_vdev_read_gap_limit);
210 SYSCTL_INT(_vfs_zfs_vdev, OID_AUTO, read_gap_limit, CTLFLAG_RW,
211 &zfs_vdev_read_gap_limit, 0,
212 "Acceptable gap between two reads being aggregated");
213 TUNABLE_INT("vfs.zfs.vdev.write_gap_limit", &zfs_vdev_write_gap_limit);
214 SYSCTL_INT(_vfs_zfs_vdev, OID_AUTO, write_gap_limit, CTLFLAG_RW,
215 &zfs_vdev_write_gap_limit, 0,
216 "Acceptable gap between two writes being aggregated");
220 vdev_queue_offset_compare(const void *x1, const void *x2)
222 const zio_t *z1 = x1;
223 const zio_t *z2 = x2;
225 if (z1->io_offset < z2->io_offset)
227 if (z1->io_offset > z2->io_offset)
239 vdev_queue_timestamp_compare(const void *x1, const void *x2)
241 const zio_t *z1 = x1;
242 const zio_t *z2 = x2;
244 if (z1->io_timestamp < z2->io_timestamp)
246 if (z1->io_timestamp > z2->io_timestamp)
258 vdev_queue_init(vdev_t *vd)
260 vdev_queue_t *vq = &vd->vdev_queue;
262 mutex_init(&vq->vq_lock, NULL, MUTEX_DEFAULT, NULL);
265 avl_create(&vq->vq_active_tree, vdev_queue_offset_compare,
266 sizeof (zio_t), offsetof(struct zio, io_queue_node));
268 for (zio_priority_t p = 0; p < ZIO_PRIORITY_NUM_QUEUEABLE; p++) {
270 * The synchronous i/o queues are FIFO rather than LBA ordered.
271 * This provides more consistent latency for these i/os, and
272 * they tend to not be tightly clustered anyway so there is
273 * little to no throughput loss.
275 boolean_t fifo = (p == ZIO_PRIORITY_SYNC_READ ||
276 p == ZIO_PRIORITY_SYNC_WRITE);
277 avl_create(&vq->vq_class[p].vqc_queued_tree,
278 fifo ? vdev_queue_timestamp_compare :
279 vdev_queue_offset_compare,
280 sizeof (zio_t), offsetof(struct zio, io_queue_node));
285 vdev_queue_fini(vdev_t *vd)
287 vdev_queue_t *vq = &vd->vdev_queue;
289 for (zio_priority_t p = 0; p < ZIO_PRIORITY_NUM_QUEUEABLE; p++)
290 avl_destroy(&vq->vq_class[p].vqc_queued_tree);
291 avl_destroy(&vq->vq_active_tree);
293 mutex_destroy(&vq->vq_lock);
297 vdev_queue_io_add(vdev_queue_t *vq, zio_t *zio)
299 spa_t *spa = zio->io_spa;
300 ASSERT3U(zio->io_priority, <, ZIO_PRIORITY_NUM_QUEUEABLE);
301 avl_add(&vq->vq_class[zio->io_priority].vqc_queued_tree, zio);
304 mutex_enter(&spa->spa_iokstat_lock);
305 spa->spa_queue_stats[zio->io_priority].spa_queued++;
306 if (spa->spa_iokstat != NULL)
307 kstat_waitq_enter(spa->spa_iokstat->ks_data);
308 mutex_exit(&spa->spa_iokstat_lock);
313 vdev_queue_io_remove(vdev_queue_t *vq, zio_t *zio)
315 spa_t *spa = zio->io_spa;
316 ASSERT3U(zio->io_priority, <, ZIO_PRIORITY_NUM_QUEUEABLE);
317 avl_remove(&vq->vq_class[zio->io_priority].vqc_queued_tree, zio);
320 mutex_enter(&spa->spa_iokstat_lock);
321 ASSERT3U(spa->spa_queue_stats[zio->io_priority].spa_queued, >, 0);
322 spa->spa_queue_stats[zio->io_priority].spa_queued--;
323 if (spa->spa_iokstat != NULL)
324 kstat_waitq_exit(spa->spa_iokstat->ks_data);
325 mutex_exit(&spa->spa_iokstat_lock);
330 vdev_queue_pending_add(vdev_queue_t *vq, zio_t *zio)
332 spa_t *spa = zio->io_spa;
333 ASSERT(MUTEX_HELD(&vq->vq_lock));
334 ASSERT3U(zio->io_priority, <, ZIO_PRIORITY_NUM_QUEUEABLE);
335 vq->vq_class[zio->io_priority].vqc_active++;
336 avl_add(&vq->vq_active_tree, zio);
339 mutex_enter(&spa->spa_iokstat_lock);
340 spa->spa_queue_stats[zio->io_priority].spa_active++;
341 if (spa->spa_iokstat != NULL)
342 kstat_runq_enter(spa->spa_iokstat->ks_data);
343 mutex_exit(&spa->spa_iokstat_lock);
348 vdev_queue_pending_remove(vdev_queue_t *vq, zio_t *zio)
350 spa_t *spa = zio->io_spa;
351 ASSERT(MUTEX_HELD(&vq->vq_lock));
352 ASSERT3U(zio->io_priority, <, ZIO_PRIORITY_NUM_QUEUEABLE);
353 vq->vq_class[zio->io_priority].vqc_active--;
354 avl_remove(&vq->vq_active_tree, zio);
357 mutex_enter(&spa->spa_iokstat_lock);
358 ASSERT3U(spa->spa_queue_stats[zio->io_priority].spa_active, >, 0);
359 spa->spa_queue_stats[zio->io_priority].spa_active--;
360 if (spa->spa_iokstat != NULL) {
361 kstat_io_t *ksio = spa->spa_iokstat->ks_data;
363 kstat_runq_exit(spa->spa_iokstat->ks_data);
364 if (zio->io_type == ZIO_TYPE_READ) {
366 ksio->nread += zio->io_size;
367 } else if (zio->io_type == ZIO_TYPE_WRITE) {
369 ksio->nwritten += zio->io_size;
372 mutex_exit(&spa->spa_iokstat_lock);
377 vdev_queue_agg_io_done(zio_t *aio)
379 if (aio->io_type == ZIO_TYPE_READ) {
381 while ((pio = zio_walk_parents(aio)) != NULL) {
382 bcopy((char *)aio->io_data + (pio->io_offset -
383 aio->io_offset), pio->io_data, pio->io_size);
387 zio_buf_free(aio->io_data, aio->io_size);
391 vdev_queue_class_min_active(zio_priority_t p)
394 case ZIO_PRIORITY_SYNC_READ:
395 return (zfs_vdev_sync_read_min_active);
396 case ZIO_PRIORITY_SYNC_WRITE:
397 return (zfs_vdev_sync_write_min_active);
398 case ZIO_PRIORITY_ASYNC_READ:
399 return (zfs_vdev_async_read_min_active);
400 case ZIO_PRIORITY_ASYNC_WRITE:
401 return (zfs_vdev_async_write_min_active);
402 case ZIO_PRIORITY_SCRUB:
403 return (zfs_vdev_scrub_min_active);
405 panic("invalid priority %u", p);
411 vdev_queue_max_async_writes(uint64_t dirty)
414 uint64_t min_bytes = zfs_dirty_data_max *
415 zfs_vdev_async_write_active_min_dirty_percent / 100;
416 uint64_t max_bytes = zfs_dirty_data_max *
417 zfs_vdev_async_write_active_max_dirty_percent / 100;
419 if (dirty < min_bytes)
420 return (zfs_vdev_async_write_min_active);
421 if (dirty > max_bytes)
422 return (zfs_vdev_async_write_max_active);
425 * linear interpolation:
426 * slope = (max_writes - min_writes) / (max_bytes - min_bytes)
427 * move right by min_bytes
428 * move up by min_writes
430 writes = (dirty - min_bytes) *
431 (zfs_vdev_async_write_max_active -
432 zfs_vdev_async_write_min_active) /
433 (max_bytes - min_bytes) +
434 zfs_vdev_async_write_min_active;
435 ASSERT3U(writes, >=, zfs_vdev_async_write_min_active);
436 ASSERT3U(writes, <=, zfs_vdev_async_write_max_active);
441 vdev_queue_class_max_active(spa_t *spa, zio_priority_t p)
444 case ZIO_PRIORITY_SYNC_READ:
445 return (zfs_vdev_sync_read_max_active);
446 case ZIO_PRIORITY_SYNC_WRITE:
447 return (zfs_vdev_sync_write_max_active);
448 case ZIO_PRIORITY_ASYNC_READ:
449 return (zfs_vdev_async_read_max_active);
450 case ZIO_PRIORITY_ASYNC_WRITE:
451 return (vdev_queue_max_async_writes(
452 spa->spa_dsl_pool->dp_dirty_total));
453 case ZIO_PRIORITY_SCRUB:
454 return (zfs_vdev_scrub_max_active);
456 panic("invalid priority %u", p);
462 * Return the i/o class to issue from, or ZIO_PRIORITY_MAX_QUEUEABLE if
463 * there is no eligible class.
465 static zio_priority_t
466 vdev_queue_class_to_issue(vdev_queue_t *vq)
468 spa_t *spa = vq->vq_vdev->vdev_spa;
471 if (avl_numnodes(&vq->vq_active_tree) >= zfs_vdev_max_active)
472 return (ZIO_PRIORITY_NUM_QUEUEABLE);
474 /* find a queue that has not reached its minimum # outstanding i/os */
475 for (p = 0; p < ZIO_PRIORITY_NUM_QUEUEABLE; p++) {
476 if (avl_numnodes(&vq->vq_class[p].vqc_queued_tree) > 0 &&
477 vq->vq_class[p].vqc_active <
478 vdev_queue_class_min_active(p))
483 * If we haven't found a queue, look for one that hasn't reached its
484 * maximum # outstanding i/os.
486 for (p = 0; p < ZIO_PRIORITY_NUM_QUEUEABLE; p++) {
487 if (avl_numnodes(&vq->vq_class[p].vqc_queued_tree) > 0 &&
488 vq->vq_class[p].vqc_active <
489 vdev_queue_class_max_active(spa, p))
493 /* No eligible queued i/os */
494 return (ZIO_PRIORITY_NUM_QUEUEABLE);
498 * Compute the range spanned by two i/os, which is the endpoint of the last
499 * (lio->io_offset + lio->io_size) minus start of the first (fio->io_offset).
500 * Conveniently, the gap between fio and lio is given by -IO_SPAN(lio, fio);
501 * thus fio and lio are adjacent if and only if IO_SPAN(lio, fio) == 0.
503 #define IO_SPAN(fio, lio) ((lio)->io_offset + (lio)->io_size - (fio)->io_offset)
504 #define IO_GAP(fio, lio) (-IO_SPAN(lio, fio))
507 vdev_queue_aggregate(vdev_queue_t *vq, zio_t *zio)
509 zio_t *first, *last, *aio, *dio, *mandatory, *nio;
512 boolean_t stretch = B_FALSE;
513 vdev_queue_class_t *vqc = &vq->vq_class[zio->io_priority];
514 avl_tree_t *t = &vqc->vqc_queued_tree;
515 enum zio_flag flags = zio->io_flags & ZIO_FLAG_AGG_INHERIT;
517 if (zio->io_flags & ZIO_FLAG_DONT_AGGREGATE)
521 * The synchronous i/o queues are not sorted by LBA, so we can't
522 * find adjacent i/os. These i/os tend to not be tightly clustered,
523 * or too large to aggregate, so this has little impact on performance.
525 if (zio->io_priority == ZIO_PRIORITY_SYNC_READ ||
526 zio->io_priority == ZIO_PRIORITY_SYNC_WRITE)
531 if (zio->io_type == ZIO_TYPE_READ)
532 maxgap = zfs_vdev_read_gap_limit;
535 * We can aggregate I/Os that are sufficiently adjacent and of
536 * the same flavor, as expressed by the AGG_INHERIT flags.
537 * The latter requirement is necessary so that certain
538 * attributes of the I/O, such as whether it's a normal I/O
539 * or a scrub/resilver, can be preserved in the aggregate.
540 * We can include optional I/Os, but don't allow them
541 * to begin a range as they add no benefit in that situation.
545 * We keep track of the last non-optional I/O.
547 mandatory = (first->io_flags & ZIO_FLAG_OPTIONAL) ? NULL : first;
550 * Walk backwards through sufficiently contiguous I/Os
551 * recording the last non-option I/O.
553 while ((dio = AVL_PREV(t, first)) != NULL &&
554 (dio->io_flags & ZIO_FLAG_AGG_INHERIT) == flags &&
555 IO_SPAN(dio, last) <= zfs_vdev_aggregation_limit &&
556 IO_GAP(dio, first) <= maxgap) {
558 if (mandatory == NULL && !(first->io_flags & ZIO_FLAG_OPTIONAL))
563 * Skip any initial optional I/Os.
565 while ((first->io_flags & ZIO_FLAG_OPTIONAL) && first != last) {
566 first = AVL_NEXT(t, first);
567 ASSERT(first != NULL);
571 * Walk forward through sufficiently contiguous I/Os.
573 while ((dio = AVL_NEXT(t, last)) != NULL &&
574 (dio->io_flags & ZIO_FLAG_AGG_INHERIT) == flags &&
575 IO_SPAN(first, dio) <= zfs_vdev_aggregation_limit &&
576 IO_GAP(last, dio) <= maxgap) {
578 if (!(last->io_flags & ZIO_FLAG_OPTIONAL))
583 * Now that we've established the range of the I/O aggregation
584 * we must decide what to do with trailing optional I/Os.
585 * For reads, there's nothing to do. While we are unable to
586 * aggregate further, it's possible that a trailing optional
587 * I/O would allow the underlying device to aggregate with
588 * subsequent I/Os. We must therefore determine if the next
589 * non-optional I/O is close enough to make aggregation
592 if (zio->io_type == ZIO_TYPE_WRITE && mandatory != NULL) {
594 while ((dio = AVL_NEXT(t, nio)) != NULL &&
595 IO_GAP(nio, dio) == 0 &&
596 IO_GAP(mandatory, dio) <= zfs_vdev_write_gap_limit) {
598 if (!(nio->io_flags & ZIO_FLAG_OPTIONAL)) {
606 /* This may be a no-op. */
607 dio = AVL_NEXT(t, last);
608 dio->io_flags &= ~ZIO_FLAG_OPTIONAL;
610 while (last != mandatory && last != first) {
611 ASSERT(last->io_flags & ZIO_FLAG_OPTIONAL);
612 last = AVL_PREV(t, last);
613 ASSERT(last != NULL);
620 size = IO_SPAN(first, last);
621 ASSERT3U(size, <=, zfs_vdev_aggregation_limit);
623 aio = zio_vdev_delegated_io(first->io_vd, first->io_offset,
624 zio_buf_alloc(size), size, first->io_type, zio->io_priority,
625 flags | ZIO_FLAG_DONT_CACHE | ZIO_FLAG_DONT_QUEUE,
626 vdev_queue_agg_io_done, NULL);
627 aio->io_timestamp = first->io_timestamp;
632 nio = AVL_NEXT(t, dio);
633 ASSERT3U(dio->io_type, ==, aio->io_type);
635 if (dio->io_flags & ZIO_FLAG_NODATA) {
636 ASSERT3U(dio->io_type, ==, ZIO_TYPE_WRITE);
637 bzero((char *)aio->io_data + (dio->io_offset -
638 aio->io_offset), dio->io_size);
639 } else if (dio->io_type == ZIO_TYPE_WRITE) {
640 bcopy(dio->io_data, (char *)aio->io_data +
641 (dio->io_offset - aio->io_offset),
645 zio_add_child(dio, aio);
646 vdev_queue_io_remove(vq, dio);
647 zio_vdev_io_bypass(dio);
649 } while (dio != last);
655 vdev_queue_io_to_issue(vdev_queue_t *vq)
660 vdev_queue_class_t *vqc;
664 ASSERT(MUTEX_HELD(&vq->vq_lock));
666 p = vdev_queue_class_to_issue(vq);
668 if (p == ZIO_PRIORITY_NUM_QUEUEABLE) {
669 /* No eligible queued i/os */
674 * For LBA-ordered queues (async / scrub), issue the i/o which follows
675 * the most recently issued i/o in LBA (offset) order.
677 * For FIFO queues (sync), issue the i/o with the lowest timestamp.
679 vqc = &vq->vq_class[p];
680 search.io_timestamp = 0;
681 search.io_offset = vq->vq_last_offset + 1;
682 VERIFY3P(avl_find(&vqc->vqc_queued_tree, &search, &idx), ==, NULL);
683 zio = avl_nearest(&vqc->vqc_queued_tree, idx, AVL_AFTER);
685 zio = avl_first(&vqc->vqc_queued_tree);
686 ASSERT3U(zio->io_priority, ==, p);
688 aio = vdev_queue_aggregate(vq, zio);
692 vdev_queue_io_remove(vq, zio);
695 * If the I/O is or was optional and therefore has no data, we need to
696 * simply discard it. We need to drop the vdev queue's lock to avoid a
697 * deadlock that we could encounter since this I/O will complete
700 if (zio->io_flags & ZIO_FLAG_NODATA) {
701 mutex_exit(&vq->vq_lock);
702 zio_vdev_io_bypass(zio);
704 mutex_enter(&vq->vq_lock);
708 vdev_queue_pending_add(vq, zio);
709 vq->vq_last_offset = zio->io_offset;
715 vdev_queue_io(zio_t *zio)
717 vdev_queue_t *vq = &zio->io_vd->vdev_queue;
720 if (zio->io_flags & ZIO_FLAG_DONT_QUEUE)
724 * Children i/os inherent their parent's priority, which might
725 * not match the child's i/o type. Fix it up here.
727 if (zio->io_type == ZIO_TYPE_READ) {
728 if (zio->io_priority != ZIO_PRIORITY_SYNC_READ &&
729 zio->io_priority != ZIO_PRIORITY_ASYNC_READ &&
730 zio->io_priority != ZIO_PRIORITY_SCRUB)
731 zio->io_priority = ZIO_PRIORITY_ASYNC_READ;
733 ASSERT(zio->io_type == ZIO_TYPE_WRITE);
734 if (zio->io_priority != ZIO_PRIORITY_SYNC_WRITE &&
735 zio->io_priority != ZIO_PRIORITY_ASYNC_WRITE)
736 zio->io_priority = ZIO_PRIORITY_ASYNC_WRITE;
739 zio->io_flags |= ZIO_FLAG_DONT_CACHE | ZIO_FLAG_DONT_QUEUE;
741 mutex_enter(&vq->vq_lock);
742 zio->io_timestamp = gethrtime();
743 vdev_queue_io_add(vq, zio);
744 nio = vdev_queue_io_to_issue(vq);
745 mutex_exit(&vq->vq_lock);
750 if (nio->io_done == vdev_queue_agg_io_done) {
759 vdev_queue_io_done(zio_t *zio)
761 vdev_queue_t *vq = &zio->io_vd->vdev_queue;
764 if (zio_injection_enabled)
765 delay(SEC_TO_TICK(zio_handle_io_delay(zio)));
767 mutex_enter(&vq->vq_lock);
769 vdev_queue_pending_remove(vq, zio);
771 vq->vq_io_complete_ts = gethrtime();
773 while ((nio = vdev_queue_io_to_issue(vq)) != NULL) {
774 mutex_exit(&vq->vq_lock);
775 if (nio->io_done == vdev_queue_agg_io_done) {
778 zio_vdev_io_reissue(nio);
781 mutex_enter(&vq->vq_lock);
784 mutex_exit(&vq->vq_lock);