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, 2017 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>
36 #include <sys/metaslab_impl.h>
38 #include <sys/spa_impl.h>
39 #include <sys/kstat.h>
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.
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.
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.
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.
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.
94 * | o---------| <-- zfs_vdev_async_write_max_active
101 * |------------o | | <-- zfs_vdev_async_write_min_active
102 * 0|____________^______|_________|
103 * 0% | | 100% of zfs_dirty_data_max
105 * | `-- zfs_vdev_async_write_active_max_dirty_percent
106 * `--------- zfs_vdev_async_write_active_min_dirty_percent
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.
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).
123 * The maximum number of i/os active to each device. Ideally, this will be >=
124 * the sum of each queue's max_active. It must be at least the sum of each
125 * queue's min_active.
127 uint32_t zfs_vdev_max_active
= 1000;
130 * Per-queue limits on the number of i/os active to each device. If the
131 * number of active i/os is < zfs_vdev_max_active, then the min_active comes
132 * into play. We will send min_active from each queue, and then select from
133 * queues in the order defined by zio_priority_t.
135 * In general, smaller max_active's will lead to lower latency of synchronous
136 * operations. Larger max_active's may lead to higher overall throughput,
137 * depending on underlying storage.
139 * The ratio of the queues' max_actives determines the balance of performance
140 * between reads, writes, and scrubs. E.g., increasing
141 * zfs_vdev_scrub_max_active will cause the scrub or resilver to complete
142 * more quickly, but reads and writes to have higher latency and lower
145 uint32_t zfs_vdev_sync_read_min_active
= 10;
146 uint32_t zfs_vdev_sync_read_max_active
= 10;
147 uint32_t zfs_vdev_sync_write_min_active
= 10;
148 uint32_t zfs_vdev_sync_write_max_active
= 10;
149 uint32_t zfs_vdev_async_read_min_active
= 1;
150 uint32_t zfs_vdev_async_read_max_active
= 3;
151 uint32_t zfs_vdev_async_write_min_active
= 2;
152 uint32_t zfs_vdev_async_write_max_active
= 10;
153 uint32_t zfs_vdev_scrub_min_active
= 1;
154 uint32_t zfs_vdev_scrub_max_active
= 2;
157 * When the pool has less than zfs_vdev_async_write_active_min_dirty_percent
158 * dirty data, use zfs_vdev_async_write_min_active. When it has more than
159 * zfs_vdev_async_write_active_max_dirty_percent, use
160 * zfs_vdev_async_write_max_active. The value is linearly interpolated
161 * between min and max.
163 int zfs_vdev_async_write_active_min_dirty_percent
= 30;
164 int zfs_vdev_async_write_active_max_dirty_percent
= 60;
167 * To reduce IOPs, we aggregate small adjacent I/Os into one large I/O.
168 * For read I/Os, we also aggregate across small adjacency gaps; for writes
169 * we include spans of optional I/Os to aid aggregation at the disk even when
170 * they aren't able to help us aggregate at this level.
172 int zfs_vdev_aggregation_limit
= 1 << 20;
173 int zfs_vdev_read_gap_limit
= 32 << 10;
174 int zfs_vdev_write_gap_limit
= 4 << 10;
177 * Define the queue depth percentage for each top-level. This percentage is
178 * used in conjunction with zfs_vdev_async_max_active to determine how many
179 * allocations a specific top-level vdev should handle. Once the queue depth
180 * reaches zfs_vdev_queue_depth_pct * zfs_vdev_async_write_max_active / 100
181 * then allocator will stop allocating blocks on that top-level device.
182 * The default kernel setting is 1000% which will yield 100 allocations per
183 * device. For userland testing, the default setting is 300% which equates
184 * to 30 allocations per device.
187 int zfs_vdev_queue_depth_pct
= 1000;
189 int zfs_vdev_queue_depth_pct
= 300;
194 vdev_queue_offset_compare(const void *x1
, const void *x2
)
196 const zio_t
*z1
= (const zio_t
*)x1
;
197 const zio_t
*z2
= (const zio_t
*)x2
;
199 int cmp
= AVL_CMP(z1
->io_offset
, z2
->io_offset
);
204 return (AVL_PCMP(z1
, z2
));
207 static inline avl_tree_t
*
208 vdev_queue_class_tree(vdev_queue_t
*vq
, zio_priority_t p
)
210 return (&vq
->vq_class
[p
].vqc_queued_tree
);
213 static inline avl_tree_t
*
214 vdev_queue_type_tree(vdev_queue_t
*vq
, zio_type_t t
)
216 ASSERT(t
== ZIO_TYPE_READ
|| t
== ZIO_TYPE_WRITE
);
217 if (t
== ZIO_TYPE_READ
)
218 return (&vq
->vq_read_offset_tree
);
220 return (&vq
->vq_write_offset_tree
);
224 vdev_queue_timestamp_compare(const void *x1
, const void *x2
)
226 const zio_t
*z1
= (const zio_t
*)x1
;
227 const zio_t
*z2
= (const zio_t
*)x2
;
229 int cmp
= AVL_CMP(z1
->io_timestamp
, z2
->io_timestamp
);
234 return (AVL_PCMP(z1
, z2
));
238 vdev_queue_class_min_active(zio_priority_t p
)
241 case ZIO_PRIORITY_SYNC_READ
:
242 return (zfs_vdev_sync_read_min_active
);
243 case ZIO_PRIORITY_SYNC_WRITE
:
244 return (zfs_vdev_sync_write_min_active
);
245 case ZIO_PRIORITY_ASYNC_READ
:
246 return (zfs_vdev_async_read_min_active
);
247 case ZIO_PRIORITY_ASYNC_WRITE
:
248 return (zfs_vdev_async_write_min_active
);
249 case ZIO_PRIORITY_SCRUB
:
250 return (zfs_vdev_scrub_min_active
);
252 panic("invalid priority %u", p
);
258 vdev_queue_max_async_writes(spa_t
*spa
)
262 dsl_pool_t
*dp
= spa_get_dsl(spa
);
263 uint64_t min_bytes
= zfs_dirty_data_max
*
264 zfs_vdev_async_write_active_min_dirty_percent
/ 100;
265 uint64_t max_bytes
= zfs_dirty_data_max
*
266 zfs_vdev_async_write_active_max_dirty_percent
/ 100;
269 * Async writes may occur before the assignment of the spa's
270 * dsl_pool_t if a self-healing zio is issued prior to the
271 * completion of dmu_objset_open_impl().
274 return (zfs_vdev_async_write_max_active
);
277 * Sync tasks correspond to interactive user actions. To reduce the
278 * execution time of those actions we push data out as fast as possible.
280 if (spa_has_pending_synctask(spa
))
281 return (zfs_vdev_async_write_max_active
);
283 dirty
= dp
->dp_dirty_total
;
284 if (dirty
< min_bytes
)
285 return (zfs_vdev_async_write_min_active
);
286 if (dirty
> max_bytes
)
287 return (zfs_vdev_async_write_max_active
);
290 * linear interpolation:
291 * slope = (max_writes - min_writes) / (max_bytes - min_bytes)
292 * move right by min_bytes
293 * move up by min_writes
295 writes
= (dirty
- min_bytes
) *
296 (zfs_vdev_async_write_max_active
-
297 zfs_vdev_async_write_min_active
) /
298 (max_bytes
- min_bytes
) +
299 zfs_vdev_async_write_min_active
;
300 ASSERT3U(writes
, >=, zfs_vdev_async_write_min_active
);
301 ASSERT3U(writes
, <=, zfs_vdev_async_write_max_active
);
306 vdev_queue_class_max_active(spa_t
*spa
, zio_priority_t p
)
309 case ZIO_PRIORITY_SYNC_READ
:
310 return (zfs_vdev_sync_read_max_active
);
311 case ZIO_PRIORITY_SYNC_WRITE
:
312 return (zfs_vdev_sync_write_max_active
);
313 case ZIO_PRIORITY_ASYNC_READ
:
314 return (zfs_vdev_async_read_max_active
);
315 case ZIO_PRIORITY_ASYNC_WRITE
:
316 return (vdev_queue_max_async_writes(spa
));
317 case ZIO_PRIORITY_SCRUB
:
318 return (zfs_vdev_scrub_max_active
);
320 panic("invalid priority %u", p
);
326 * Return the i/o class to issue from, or ZIO_PRIORITY_MAX_QUEUEABLE if
327 * there is no eligible class.
329 static zio_priority_t
330 vdev_queue_class_to_issue(vdev_queue_t
*vq
)
332 spa_t
*spa
= vq
->vq_vdev
->vdev_spa
;
335 if (avl_numnodes(&vq
->vq_active_tree
) >= zfs_vdev_max_active
)
336 return (ZIO_PRIORITY_NUM_QUEUEABLE
);
338 /* find a queue that has not reached its minimum # outstanding i/os */
339 for (p
= 0; p
< ZIO_PRIORITY_NUM_QUEUEABLE
; p
++) {
340 if (avl_numnodes(vdev_queue_class_tree(vq
, p
)) > 0 &&
341 vq
->vq_class
[p
].vqc_active
<
342 vdev_queue_class_min_active(p
))
347 * If we haven't found a queue, look for one that hasn't reached its
348 * maximum # outstanding i/os.
350 for (p
= 0; p
< ZIO_PRIORITY_NUM_QUEUEABLE
; p
++) {
351 if (avl_numnodes(vdev_queue_class_tree(vq
, p
)) > 0 &&
352 vq
->vq_class
[p
].vqc_active
<
353 vdev_queue_class_max_active(spa
, p
))
357 /* No eligible queued i/os */
358 return (ZIO_PRIORITY_NUM_QUEUEABLE
);
362 vdev_queue_init(vdev_t
*vd
)
364 vdev_queue_t
*vq
= &vd
->vdev_queue
;
367 mutex_init(&vq
->vq_lock
, NULL
, MUTEX_DEFAULT
, NULL
);
369 taskq_init_ent(&vd
->vdev_queue
.vq_io_search
.io_tqent
);
371 avl_create(&vq
->vq_active_tree
, vdev_queue_offset_compare
,
372 sizeof (zio_t
), offsetof(struct zio
, io_queue_node
));
373 avl_create(vdev_queue_type_tree(vq
, ZIO_TYPE_READ
),
374 vdev_queue_offset_compare
, sizeof (zio_t
),
375 offsetof(struct zio
, io_offset_node
));
376 avl_create(vdev_queue_type_tree(vq
, ZIO_TYPE_WRITE
),
377 vdev_queue_offset_compare
, sizeof (zio_t
),
378 offsetof(struct zio
, io_offset_node
));
380 for (p
= 0; p
< ZIO_PRIORITY_NUM_QUEUEABLE
; p
++) {
381 int (*compfn
) (const void *, const void *);
384 * The synchronous i/o queues are dispatched in FIFO rather
385 * than LBA order. This provides more consistent latency for
388 if (p
== ZIO_PRIORITY_SYNC_READ
|| p
== ZIO_PRIORITY_SYNC_WRITE
)
389 compfn
= vdev_queue_timestamp_compare
;
391 compfn
= vdev_queue_offset_compare
;
392 avl_create(vdev_queue_class_tree(vq
, p
), compfn
,
393 sizeof (zio_t
), offsetof(struct zio
, io_queue_node
));
396 vq
->vq_last_offset
= 0;
400 vdev_queue_fini(vdev_t
*vd
)
402 vdev_queue_t
*vq
= &vd
->vdev_queue
;
404 for (zio_priority_t p
= 0; p
< ZIO_PRIORITY_NUM_QUEUEABLE
; p
++)
405 avl_destroy(vdev_queue_class_tree(vq
, p
));
406 avl_destroy(&vq
->vq_active_tree
);
407 avl_destroy(vdev_queue_type_tree(vq
, ZIO_TYPE_READ
));
408 avl_destroy(vdev_queue_type_tree(vq
, ZIO_TYPE_WRITE
));
410 mutex_destroy(&vq
->vq_lock
);
414 vdev_queue_io_add(vdev_queue_t
*vq
, zio_t
*zio
)
416 spa_t
*spa
= zio
->io_spa
;
417 spa_stats_history_t
*ssh
= &spa
->spa_stats
.io_history
;
419 ASSERT3U(zio
->io_priority
, <, ZIO_PRIORITY_NUM_QUEUEABLE
);
420 avl_add(vdev_queue_class_tree(vq
, zio
->io_priority
), zio
);
421 avl_add(vdev_queue_type_tree(vq
, zio
->io_type
), zio
);
423 if (ssh
->kstat
!= NULL
) {
424 mutex_enter(&ssh
->lock
);
425 kstat_waitq_enter(ssh
->kstat
->ks_data
);
426 mutex_exit(&ssh
->lock
);
431 vdev_queue_io_remove(vdev_queue_t
*vq
, zio_t
*zio
)
433 spa_t
*spa
= zio
->io_spa
;
434 spa_stats_history_t
*ssh
= &spa
->spa_stats
.io_history
;
436 ASSERT3U(zio
->io_priority
, <, ZIO_PRIORITY_NUM_QUEUEABLE
);
437 avl_remove(vdev_queue_class_tree(vq
, zio
->io_priority
), zio
);
438 avl_remove(vdev_queue_type_tree(vq
, zio
->io_type
), zio
);
440 if (ssh
->kstat
!= NULL
) {
441 mutex_enter(&ssh
->lock
);
442 kstat_waitq_exit(ssh
->kstat
->ks_data
);
443 mutex_exit(&ssh
->lock
);
448 vdev_queue_pending_add(vdev_queue_t
*vq
, zio_t
*zio
)
450 spa_t
*spa
= zio
->io_spa
;
451 spa_stats_history_t
*ssh
= &spa
->spa_stats
.io_history
;
453 ASSERT(MUTEX_HELD(&vq
->vq_lock
));
454 ASSERT3U(zio
->io_priority
, <, ZIO_PRIORITY_NUM_QUEUEABLE
);
455 vq
->vq_class
[zio
->io_priority
].vqc_active
++;
456 avl_add(&vq
->vq_active_tree
, zio
);
458 if (ssh
->kstat
!= NULL
) {
459 mutex_enter(&ssh
->lock
);
460 kstat_runq_enter(ssh
->kstat
->ks_data
);
461 mutex_exit(&ssh
->lock
);
466 vdev_queue_pending_remove(vdev_queue_t
*vq
, zio_t
*zio
)
468 spa_t
*spa
= zio
->io_spa
;
469 spa_stats_history_t
*ssh
= &spa
->spa_stats
.io_history
;
471 ASSERT(MUTEX_HELD(&vq
->vq_lock
));
472 ASSERT3U(zio
->io_priority
, <, ZIO_PRIORITY_NUM_QUEUEABLE
);
473 vq
->vq_class
[zio
->io_priority
].vqc_active
--;
474 avl_remove(&vq
->vq_active_tree
, zio
);
476 if (ssh
->kstat
!= NULL
) {
477 kstat_io_t
*ksio
= ssh
->kstat
->ks_data
;
479 mutex_enter(&ssh
->lock
);
480 kstat_runq_exit(ksio
);
481 if (zio
->io_type
== ZIO_TYPE_READ
) {
483 ksio
->nread
+= zio
->io_size
;
484 } else if (zio
->io_type
== ZIO_TYPE_WRITE
) {
486 ksio
->nwritten
+= zio
->io_size
;
488 mutex_exit(&ssh
->lock
);
493 vdev_queue_agg_io_done(zio_t
*aio
)
495 if (aio
->io_type
== ZIO_TYPE_READ
) {
497 zio_link_t
*zl
= NULL
;
498 while ((pio
= zio_walk_parents(aio
, &zl
)) != NULL
) {
499 abd_copy_off(pio
->io_abd
, aio
->io_abd
,
500 0, pio
->io_offset
- aio
->io_offset
, pio
->io_size
);
504 abd_free(aio
->io_abd
);
508 * Compute the range spanned by two i/os, which is the endpoint of the last
509 * (lio->io_offset + lio->io_size) minus start of the first (fio->io_offset).
510 * Conveniently, the gap between fio and lio is given by -IO_SPAN(lio, fio);
511 * thus fio and lio are adjacent if and only if IO_SPAN(lio, fio) == 0.
513 #define IO_SPAN(fio, lio) ((lio)->io_offset + (lio)->io_size - (fio)->io_offset)
514 #define IO_GAP(fio, lio) (-IO_SPAN(lio, fio))
517 vdev_queue_aggregate(vdev_queue_t
*vq
, zio_t
*zio
)
519 zio_t
*first
, *last
, *aio
, *dio
, *mandatory
, *nio
;
524 boolean_t stretch
= B_FALSE
;
525 avl_tree_t
*t
= vdev_queue_type_tree(vq
, zio
->io_type
);
526 enum zio_flag flags
= zio
->io_flags
& ZIO_FLAG_AGG_INHERIT
;
529 maxblocksize
= spa_maxblocksize(vq
->vq_vdev
->vdev_spa
);
530 limit
= MAX(MIN(zfs_vdev_aggregation_limit
, maxblocksize
), 0);
532 if (zio
->io_flags
& ZIO_FLAG_DONT_AGGREGATE
|| limit
== 0)
537 if (zio
->io_type
== ZIO_TYPE_READ
)
538 maxgap
= zfs_vdev_read_gap_limit
;
541 * We can aggregate I/Os that are sufficiently adjacent and of
542 * the same flavor, as expressed by the AGG_INHERIT flags.
543 * The latter requirement is necessary so that certain
544 * attributes of the I/O, such as whether it's a normal I/O
545 * or a scrub/resilver, can be preserved in the aggregate.
546 * We can include optional I/Os, but don't allow them
547 * to begin a range as they add no benefit in that situation.
551 * We keep track of the last non-optional I/O.
553 mandatory
= (first
->io_flags
& ZIO_FLAG_OPTIONAL
) ? NULL
: first
;
556 * Walk backwards through sufficiently contiguous I/Os
557 * recording the last non-optional I/O.
559 while ((dio
= AVL_PREV(t
, first
)) != NULL
&&
560 (dio
->io_flags
& ZIO_FLAG_AGG_INHERIT
) == flags
&&
561 IO_SPAN(dio
, last
) <= limit
&&
562 IO_GAP(dio
, first
) <= maxgap
) {
564 if (mandatory
== NULL
&& !(first
->io_flags
& ZIO_FLAG_OPTIONAL
))
569 * Skip any initial optional I/Os.
571 while ((first
->io_flags
& ZIO_FLAG_OPTIONAL
) && first
!= last
) {
572 first
= AVL_NEXT(t
, first
);
573 ASSERT(first
!= NULL
);
578 * Walk forward through sufficiently contiguous I/Os.
579 * The aggregation limit does not apply to optional i/os, so that
580 * we can issue contiguous writes even if they are larger than the
583 while ((dio
= AVL_NEXT(t
, last
)) != NULL
&&
584 (dio
->io_flags
& ZIO_FLAG_AGG_INHERIT
) == flags
&&
585 (IO_SPAN(first
, dio
) <= limit
||
586 (dio
->io_flags
& ZIO_FLAG_OPTIONAL
)) &&
587 IO_SPAN(first
, dio
) <= maxblocksize
&&
588 IO_GAP(last
, dio
) <= maxgap
) {
590 if (!(last
->io_flags
& ZIO_FLAG_OPTIONAL
))
595 * Now that we've established the range of the I/O aggregation
596 * we must decide what to do with trailing optional I/Os.
597 * For reads, there's nothing to do. While we are unable to
598 * aggregate further, it's possible that a trailing optional
599 * I/O would allow the underlying device to aggregate with
600 * subsequent I/Os. We must therefore determine if the next
601 * non-optional I/O is close enough to make aggregation
604 if (zio
->io_type
== ZIO_TYPE_WRITE
&& mandatory
!= NULL
) {
606 while ((dio
= AVL_NEXT(t
, nio
)) != NULL
&&
607 IO_GAP(nio
, dio
) == 0 &&
608 IO_GAP(mandatory
, dio
) <= zfs_vdev_write_gap_limit
) {
610 if (!(nio
->io_flags
& ZIO_FLAG_OPTIONAL
)) {
619 * We are going to include an optional io in our aggregated
620 * span, thus closing the write gap. Only mandatory i/os can
621 * start aggregated spans, so make sure that the next i/o
622 * after our span is mandatory.
624 dio
= AVL_NEXT(t
, last
);
625 dio
->io_flags
&= ~ZIO_FLAG_OPTIONAL
;
627 /* do not include the optional i/o */
628 while (last
!= mandatory
&& last
!= first
) {
629 ASSERT(last
->io_flags
& ZIO_FLAG_OPTIONAL
);
630 last
= AVL_PREV(t
, last
);
631 ASSERT(last
!= NULL
);
638 size
= IO_SPAN(first
, last
);
639 ASSERT3U(size
, <=, maxblocksize
);
641 abd
= abd_alloc_for_io(size
, B_TRUE
);
645 aio
= zio_vdev_delegated_io(first
->io_vd
, first
->io_offset
,
646 abd
, size
, first
->io_type
, zio
->io_priority
,
647 flags
| ZIO_FLAG_DONT_CACHE
| ZIO_FLAG_DONT_QUEUE
,
648 vdev_queue_agg_io_done
, NULL
);
649 aio
->io_timestamp
= first
->io_timestamp
;
654 nio
= AVL_NEXT(t
, dio
);
655 ASSERT3U(dio
->io_type
, ==, aio
->io_type
);
657 if (dio
->io_flags
& ZIO_FLAG_NODATA
) {
658 ASSERT3U(dio
->io_type
, ==, ZIO_TYPE_WRITE
);
659 abd_zero_off(aio
->io_abd
,
660 dio
->io_offset
- aio
->io_offset
, dio
->io_size
);
661 } else if (dio
->io_type
== ZIO_TYPE_WRITE
) {
662 abd_copy_off(aio
->io_abd
, dio
->io_abd
,
663 dio
->io_offset
- aio
->io_offset
, 0, dio
->io_size
);
666 zio_add_child(dio
, aio
);
667 vdev_queue_io_remove(vq
, dio
);
668 zio_vdev_io_bypass(dio
);
670 } while (dio
!= last
);
676 vdev_queue_io_to_issue(vdev_queue_t
*vq
)
684 ASSERT(MUTEX_HELD(&vq
->vq_lock
));
686 p
= vdev_queue_class_to_issue(vq
);
688 if (p
== ZIO_PRIORITY_NUM_QUEUEABLE
) {
689 /* No eligible queued i/os */
694 * For LBA-ordered queues (async / scrub), issue the i/o which follows
695 * the most recently issued i/o in LBA (offset) order.
697 * For FIFO queues (sync), issue the i/o with the lowest timestamp.
699 tree
= vdev_queue_class_tree(vq
, p
);
700 vq
->vq_io_search
.io_timestamp
= 0;
701 vq
->vq_io_search
.io_offset
= vq
->vq_last_offset
- 1;
702 VERIFY3P(avl_find(tree
, &vq
->vq_io_search
, &idx
), ==, NULL
);
703 zio
= avl_nearest(tree
, idx
, AVL_AFTER
);
705 zio
= avl_first(tree
);
706 ASSERT3U(zio
->io_priority
, ==, p
);
708 aio
= vdev_queue_aggregate(vq
, zio
);
712 vdev_queue_io_remove(vq
, zio
);
715 * If the I/O is or was optional and therefore has no data, we need to
716 * simply discard it. We need to drop the vdev queue's lock to avoid a
717 * deadlock that we could encounter since this I/O will complete
720 if (zio
->io_flags
& ZIO_FLAG_NODATA
) {
721 mutex_exit(&vq
->vq_lock
);
722 zio_vdev_io_bypass(zio
);
724 mutex_enter(&vq
->vq_lock
);
728 vdev_queue_pending_add(vq
, zio
);
729 vq
->vq_last_offset
= zio
->io_offset
+ zio
->io_size
;
735 vdev_queue_io(zio_t
*zio
)
737 vdev_queue_t
*vq
= &zio
->io_vd
->vdev_queue
;
740 if (zio
->io_flags
& ZIO_FLAG_DONT_QUEUE
)
744 * Children i/os inherent their parent's priority, which might
745 * not match the child's i/o type. Fix it up here.
747 if (zio
->io_type
== ZIO_TYPE_READ
) {
748 if (zio
->io_priority
!= ZIO_PRIORITY_SYNC_READ
&&
749 zio
->io_priority
!= ZIO_PRIORITY_ASYNC_READ
&&
750 zio
->io_priority
!= ZIO_PRIORITY_SCRUB
)
751 zio
->io_priority
= ZIO_PRIORITY_ASYNC_READ
;
753 ASSERT(zio
->io_type
== ZIO_TYPE_WRITE
);
754 if (zio
->io_priority
!= ZIO_PRIORITY_SYNC_WRITE
&&
755 zio
->io_priority
!= ZIO_PRIORITY_ASYNC_WRITE
)
756 zio
->io_priority
= ZIO_PRIORITY_ASYNC_WRITE
;
759 zio
->io_flags
|= ZIO_FLAG_DONT_CACHE
| ZIO_FLAG_DONT_QUEUE
;
761 mutex_enter(&vq
->vq_lock
);
762 zio
->io_timestamp
= gethrtime();
763 vdev_queue_io_add(vq
, zio
);
764 nio
= vdev_queue_io_to_issue(vq
);
765 mutex_exit(&vq
->vq_lock
);
770 if (nio
->io_done
== vdev_queue_agg_io_done
) {
779 vdev_queue_io_done(zio_t
*zio
)
781 vdev_queue_t
*vq
= &zio
->io_vd
->vdev_queue
;
784 mutex_enter(&vq
->vq_lock
);
786 vdev_queue_pending_remove(vq
, zio
);
788 zio
->io_delta
= gethrtime() - zio
->io_timestamp
;
789 vq
->vq_io_complete_ts
= gethrtime();
790 vq
->vq_io_delta_ts
= vq
->vq_io_complete_ts
- zio
->io_timestamp
;
792 while ((nio
= vdev_queue_io_to_issue(vq
)) != NULL
) {
793 mutex_exit(&vq
->vq_lock
);
794 if (nio
->io_done
== vdev_queue_agg_io_done
) {
797 zio_vdev_io_reissue(nio
);
800 mutex_enter(&vq
->vq_lock
);
803 mutex_exit(&vq
->vq_lock
);
807 * As these two methods are only used for load calculations we're not
808 * concerned if we get an incorrect value on 32bit platforms due to lack of
809 * vq_lock mutex use here, instead we prefer to keep it lock free for
813 vdev_queue_length(vdev_t
*vd
)
815 return (avl_numnodes(&vd
->vdev_queue
.vq_active_tree
));
819 vdev_queue_last_offset(vdev_t
*vd
)
821 return (vd
->vdev_queue
.vq_last_offset
);
824 #if defined(_KERNEL) && defined(HAVE_SPL)
825 module_param(zfs_vdev_aggregation_limit
, int, 0644);
826 MODULE_PARM_DESC(zfs_vdev_aggregation_limit
, "Max vdev I/O aggregation size");
828 module_param(zfs_vdev_read_gap_limit
, int, 0644);
829 MODULE_PARM_DESC(zfs_vdev_read_gap_limit
, "Aggregate read I/O over gap");
831 module_param(zfs_vdev_write_gap_limit
, int, 0644);
832 MODULE_PARM_DESC(zfs_vdev_write_gap_limit
, "Aggregate write I/O over gap");
834 module_param(zfs_vdev_max_active
, int, 0644);
835 MODULE_PARM_DESC(zfs_vdev_max_active
, "Maximum number of active I/Os per vdev");
837 module_param(zfs_vdev_async_write_active_max_dirty_percent
, int, 0644);
838 MODULE_PARM_DESC(zfs_vdev_async_write_active_max_dirty_percent
,
839 "Async write concurrency max threshold");
841 module_param(zfs_vdev_async_write_active_min_dirty_percent
, int, 0644);
842 MODULE_PARM_DESC(zfs_vdev_async_write_active_min_dirty_percent
,
843 "Async write concurrency min threshold");
845 module_param(zfs_vdev_async_read_max_active
, int, 0644);
846 MODULE_PARM_DESC(zfs_vdev_async_read_max_active
,
847 "Max active async read I/Os per vdev");
849 module_param(zfs_vdev_async_read_min_active
, int, 0644);
850 MODULE_PARM_DESC(zfs_vdev_async_read_min_active
,
851 "Min active async read I/Os per vdev");
853 module_param(zfs_vdev_async_write_max_active
, int, 0644);
854 MODULE_PARM_DESC(zfs_vdev_async_write_max_active
,
855 "Max active async write I/Os per vdev");
857 module_param(zfs_vdev_async_write_min_active
, int, 0644);
858 MODULE_PARM_DESC(zfs_vdev_async_write_min_active
,
859 "Min active async write I/Os per vdev");
861 module_param(zfs_vdev_scrub_max_active
, int, 0644);
862 MODULE_PARM_DESC(zfs_vdev_scrub_max_active
, "Max active scrub I/Os per vdev");
864 module_param(zfs_vdev_scrub_min_active
, int, 0644);
865 MODULE_PARM_DESC(zfs_vdev_scrub_min_active
, "Min active scrub I/Os per vdev");
867 module_param(zfs_vdev_sync_read_max_active
, int, 0644);
868 MODULE_PARM_DESC(zfs_vdev_sync_read_max_active
,
869 "Max active sync read I/Os per vdev");
871 module_param(zfs_vdev_sync_read_min_active
, int, 0644);
872 MODULE_PARM_DESC(zfs_vdev_sync_read_min_active
,
873 "Min active sync read I/Os per vdev");
875 module_param(zfs_vdev_sync_write_max_active
, int, 0644);
876 MODULE_PARM_DESC(zfs_vdev_sync_write_max_active
,
877 "Max active sync write I/Os per vdev");
879 module_param(zfs_vdev_sync_write_min_active
, int, 0644);
880 MODULE_PARM_DESC(zfs_vdev_sync_write_min_active
,
881 "Min active sync write I/Os per vdev");
883 module_param(zfs_vdev_queue_depth_pct
, int, 0644);
884 MODULE_PARM_DESC(zfs_vdev_queue_depth_pct
,
885 "Queue depth percentage for each top-level vdev");