xref: /onnv-gate/usr/src/uts/common/fs/zfs/vdev_queue.c (revision 11146:7e58f40bcb1c)
1789Sahrens /*
2789Sahrens  * CDDL HEADER START
3789Sahrens  *
4789Sahrens  * The contents of this file are subject to the terms of the
51544Seschrock  * Common Development and Distribution License (the "License").
61544Seschrock  * You may not use this file except in compliance with the License.
7789Sahrens  *
8789Sahrens  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9789Sahrens  * or http://www.opensolaris.org/os/licensing.
10789Sahrens  * See the License for the specific language governing permissions
11789Sahrens  * and limitations under the License.
12789Sahrens  *
13789Sahrens  * When distributing Covered Code, include this CDDL HEADER in each
14789Sahrens  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15789Sahrens  * If applicable, add the following below this CDDL HEADER, with the
16789Sahrens  * fields enclosed by brackets "[]" replaced with your own identifying
17789Sahrens  * information: Portions Copyright [yyyy] [name of copyright owner]
18789Sahrens  *
19789Sahrens  * CDDL HEADER END
20789Sahrens  */
21789Sahrens /*
228632SBill.Moore@Sun.COM  * Copyright 2009 Sun Microsystems, Inc.  All rights reserved.
23789Sahrens  * Use is subject to license terms.
24789Sahrens  */
25789Sahrens 
26789Sahrens #include <sys/zfs_context.h>
27789Sahrens #include <sys/vdev_impl.h>
28789Sahrens #include <sys/zio.h>
29789Sahrens #include <sys/avl.h>
30789Sahrens 
31789Sahrens /*
323059Sahrens  * These tunables are for performance analysis.
333059Sahrens  */
343059Sahrens /*
353059Sahrens  * zfs_vdev_max_pending is the maximum number of i/os concurrently
363059Sahrens  * pending to each device.  zfs_vdev_min_pending is the initial number
373059Sahrens  * of i/os pending to each device (before it starts ramping up to
383059Sahrens  * max_pending).
393059Sahrens  */
4010801SMatthew.Ahrens@Sun.COM int zfs_vdev_max_pending = 10;
413059Sahrens int zfs_vdev_min_pending = 4;
423059Sahrens 
4311066Srafael.vanoni@sun.com /* deadline = pri + ddi_get_lbolt64() >> time_shift) */
443059Sahrens int zfs_vdev_time_shift = 6;
453059Sahrens 
463059Sahrens /* exponential I/O issue ramp-up rate */
473059Sahrens int zfs_vdev_ramp_rate = 2;
483059Sahrens 
493059Sahrens /*
5010105Sadam.leventhal@sun.com  * To reduce IOPs, we aggregate small adjacent I/Os into one large I/O.
5110105Sadam.leventhal@sun.com  * For read I/Os, we also aggregate across small adjacency gaps; for writes
5210105Sadam.leventhal@sun.com  * we include spans of optional I/Os to aid aggregation at the disk even when
5310105Sadam.leventhal@sun.com  * they aren't able to help us aggregate at this level.
543059Sahrens  */
553059Sahrens int zfs_vdev_aggregation_limit = SPA_MAXBLOCKSIZE;
568692SJeff.Bonwick@Sun.COM int zfs_vdev_read_gap_limit = 32 << 10;
5710105Sadam.leventhal@sun.com int zfs_vdev_write_gap_limit = 4 << 10;
583059Sahrens 
593059Sahrens /*
60789Sahrens  * Virtual device vector for disk I/O scheduling.
61789Sahrens  */
62789Sahrens int
vdev_queue_deadline_compare(const void * x1,const void * x2)63789Sahrens vdev_queue_deadline_compare(const void *x1, const void *x2)
64789Sahrens {
65789Sahrens 	const zio_t *z1 = x1;
66789Sahrens 	const zio_t *z2 = x2;
67789Sahrens 
68789Sahrens 	if (z1->io_deadline < z2->io_deadline)
69789Sahrens 		return (-1);
70789Sahrens 	if (z1->io_deadline > z2->io_deadline)
71789Sahrens 		return (1);
72789Sahrens 
73789Sahrens 	if (z1->io_offset < z2->io_offset)
74789Sahrens 		return (-1);
75789Sahrens 	if (z1->io_offset > z2->io_offset)
76789Sahrens 		return (1);
77789Sahrens 
78789Sahrens 	if (z1 < z2)
79789Sahrens 		return (-1);
80789Sahrens 	if (z1 > z2)
81789Sahrens 		return (1);
82789Sahrens 
83789Sahrens 	return (0);
84789Sahrens }
85789Sahrens 
86789Sahrens int
vdev_queue_offset_compare(const void * x1,const void * x2)87789Sahrens vdev_queue_offset_compare(const void *x1, const void *x2)
88789Sahrens {
89789Sahrens 	const zio_t *z1 = x1;
90789Sahrens 	const zio_t *z2 = x2;
91789Sahrens 
92789Sahrens 	if (z1->io_offset < z2->io_offset)
93789Sahrens 		return (-1);
94789Sahrens 	if (z1->io_offset > z2->io_offset)
95789Sahrens 		return (1);
96789Sahrens 
97789Sahrens 	if (z1 < z2)
98789Sahrens 		return (-1);
99789Sahrens 	if (z1 > z2)
100789Sahrens 		return (1);
101789Sahrens 
102789Sahrens 	return (0);
103789Sahrens }
104789Sahrens 
105789Sahrens void
vdev_queue_init(vdev_t * vd)106789Sahrens vdev_queue_init(vdev_t *vd)
107789Sahrens {
108789Sahrens 	vdev_queue_t *vq = &vd->vdev_queue;
109789Sahrens 
110789Sahrens 	mutex_init(&vq->vq_lock, NULL, MUTEX_DEFAULT, NULL);
111789Sahrens 
112789Sahrens 	avl_create(&vq->vq_deadline_tree, vdev_queue_deadline_compare,
113789Sahrens 	    sizeof (zio_t), offsetof(struct zio, io_deadline_node));
114789Sahrens 
115789Sahrens 	avl_create(&vq->vq_read_tree, vdev_queue_offset_compare,
116789Sahrens 	    sizeof (zio_t), offsetof(struct zio, io_offset_node));
117789Sahrens 
118789Sahrens 	avl_create(&vq->vq_write_tree, vdev_queue_offset_compare,
119789Sahrens 	    sizeof (zio_t), offsetof(struct zio, io_offset_node));
120789Sahrens 
121789Sahrens 	avl_create(&vq->vq_pending_tree, vdev_queue_offset_compare,
122789Sahrens 	    sizeof (zio_t), offsetof(struct zio, io_offset_node));
123789Sahrens }
124789Sahrens 
125789Sahrens void
vdev_queue_fini(vdev_t * vd)126789Sahrens vdev_queue_fini(vdev_t *vd)
127789Sahrens {
128789Sahrens 	vdev_queue_t *vq = &vd->vdev_queue;
129789Sahrens 
130789Sahrens 	avl_destroy(&vq->vq_deadline_tree);
131789Sahrens 	avl_destroy(&vq->vq_read_tree);
132789Sahrens 	avl_destroy(&vq->vq_write_tree);
133789Sahrens 	avl_destroy(&vq->vq_pending_tree);
134789Sahrens 
135789Sahrens 	mutex_destroy(&vq->vq_lock);
136789Sahrens }
137789Sahrens 
138789Sahrens static void
vdev_queue_io_add(vdev_queue_t * vq,zio_t * zio)1391544Seschrock vdev_queue_io_add(vdev_queue_t *vq, zio_t *zio)
1401544Seschrock {
1411544Seschrock 	avl_add(&vq->vq_deadline_tree, zio);
1421544Seschrock 	avl_add(zio->io_vdev_tree, zio);
1431544Seschrock }
1441544Seschrock 
1451544Seschrock static void
vdev_queue_io_remove(vdev_queue_t * vq,zio_t * zio)1461544Seschrock vdev_queue_io_remove(vdev_queue_t *vq, zio_t *zio)
1471544Seschrock {
1481544Seschrock 	avl_remove(&vq->vq_deadline_tree, zio);
1491544Seschrock 	avl_remove(zio->io_vdev_tree, zio);
1501544Seschrock }
1511544Seschrock 
1521544Seschrock static void
vdev_queue_agg_io_done(zio_t * aio)153789Sahrens vdev_queue_agg_io_done(zio_t *aio)
154789Sahrens {
1558632SBill.Moore@Sun.COM 	zio_t *pio;
156789Sahrens 
1578632SBill.Moore@Sun.COM 	while ((pio = zio_walk_parents(aio)) != NULL)
158789Sahrens 		if (aio->io_type == ZIO_TYPE_READ)
1598632SBill.Moore@Sun.COM 			bcopy((char *)aio->io_data + (pio->io_offset -
1608632SBill.Moore@Sun.COM 			    aio->io_offset), pio->io_data, pio->io_size);
161789Sahrens 
162789Sahrens 	zio_buf_free(aio->io_data, aio->io_size);
163789Sahrens }
164789Sahrens 
1658692SJeff.Bonwick@Sun.COM /*
1668692SJeff.Bonwick@Sun.COM  * Compute the range spanned by two i/os, which is the endpoint of the last
1678692SJeff.Bonwick@Sun.COM  * (lio->io_offset + lio->io_size) minus start of the first (fio->io_offset).
1688692SJeff.Bonwick@Sun.COM  * Conveniently, the gap between fio and lio is given by -IO_SPAN(lio, fio);
1698692SJeff.Bonwick@Sun.COM  * thus fio and lio are adjacent if and only if IO_SPAN(lio, fio) == 0.
1708692SJeff.Bonwick@Sun.COM  */
1718692SJeff.Bonwick@Sun.COM #define	IO_SPAN(fio, lio) ((lio)->io_offset + (lio)->io_size - (fio)->io_offset)
1728692SJeff.Bonwick@Sun.COM #define	IO_GAP(fio, lio) (-IO_SPAN(lio, fio))
173789Sahrens 
174789Sahrens static zio_t *
vdev_queue_io_to_issue(vdev_queue_t * vq,uint64_t pending_limit)1755530Sbonwick vdev_queue_io_to_issue(vdev_queue_t *vq, uint64_t pending_limit)
176789Sahrens {
17710105Sadam.leventhal@sun.com 	zio_t *fio, *lio, *aio, *dio, *nio, *mio;
1788632SBill.Moore@Sun.COM 	avl_tree_t *t;
1798241SJeff.Bonwick@Sun.COM 	int flags;
1808692SJeff.Bonwick@Sun.COM 	uint64_t maxspan = zfs_vdev_aggregation_limit;
1818692SJeff.Bonwick@Sun.COM 	uint64_t maxgap;
18210105Sadam.leventhal@sun.com 	int stretch;
183789Sahrens 
18410105Sadam.leventhal@sun.com again:
185789Sahrens 	ASSERT(MUTEX_HELD(&vq->vq_lock));
186789Sahrens 
187789Sahrens 	if (avl_numnodes(&vq->vq_pending_tree) >= pending_limit ||
188789Sahrens 	    avl_numnodes(&vq->vq_deadline_tree) == 0)
189789Sahrens 		return (NULL);
190789Sahrens 
191789Sahrens 	fio = lio = avl_first(&vq->vq_deadline_tree);
192789Sahrens 
1938632SBill.Moore@Sun.COM 	t = fio->io_vdev_tree;
1948241SJeff.Bonwick@Sun.COM 	flags = fio->io_flags & ZIO_FLAG_AGG_INHERIT;
1958692SJeff.Bonwick@Sun.COM 	maxgap = (t == &vq->vq_read_tree) ? zfs_vdev_read_gap_limit : 0;
196789Sahrens 
1978241SJeff.Bonwick@Sun.COM 	if (!(flags & ZIO_FLAG_DONT_AGGREGATE)) {
1988241SJeff.Bonwick@Sun.COM 		/*
19910105Sadam.leventhal@sun.com 		 * We can aggregate I/Os that are sufficiently adjacent and of
20010105Sadam.leventhal@sun.com 		 * the same flavor, as expressed by the AGG_INHERIT flags.
20110105Sadam.leventhal@sun.com 		 * The latter requirement is necessary so that certain
20210105Sadam.leventhal@sun.com 		 * attributes of the I/O, such as whether it's a normal I/O
20310105Sadam.leventhal@sun.com 		 * or a scrub/resilver, can be preserved in the aggregate.
20410105Sadam.leventhal@sun.com 		 * We can include optional I/Os, but don't allow them
20510105Sadam.leventhal@sun.com 		 * to begin a range as they add no benefit in that situation.
20610105Sadam.leventhal@sun.com 		 */
20710105Sadam.leventhal@sun.com 
20810105Sadam.leventhal@sun.com 		/*
20910105Sadam.leventhal@sun.com 		 * We keep track of the last non-optional I/O.
21010105Sadam.leventhal@sun.com 		 */
21110105Sadam.leventhal@sun.com 		mio = (fio->io_flags & ZIO_FLAG_OPTIONAL) ? NULL : fio;
21210105Sadam.leventhal@sun.com 
21310105Sadam.leventhal@sun.com 		/*
21410105Sadam.leventhal@sun.com 		 * Walk backwards through sufficiently contiguous I/Os
21510105Sadam.leventhal@sun.com 		 * recording the last non-option I/O.
2168241SJeff.Bonwick@Sun.COM 		 */
2178632SBill.Moore@Sun.COM 		while ((dio = AVL_PREV(t, fio)) != NULL &&
2188241SJeff.Bonwick@Sun.COM 		    (dio->io_flags & ZIO_FLAG_AGG_INHERIT) == flags &&
21910105Sadam.leventhal@sun.com 		    IO_SPAN(dio, lio) <= maxspan &&
22010105Sadam.leventhal@sun.com 		    IO_GAP(dio, fio) <= maxgap) {
2218241SJeff.Bonwick@Sun.COM 			fio = dio;
22210105Sadam.leventhal@sun.com 			if (mio == NULL && !(fio->io_flags & ZIO_FLAG_OPTIONAL))
22310105Sadam.leventhal@sun.com 				mio = fio;
22410105Sadam.leventhal@sun.com 		}
2258692SJeff.Bonwick@Sun.COM 
22610105Sadam.leventhal@sun.com 		/*
22710105Sadam.leventhal@sun.com 		 * Skip any initial optional I/Os.
22810105Sadam.leventhal@sun.com 		 */
22910105Sadam.leventhal@sun.com 		while ((fio->io_flags & ZIO_FLAG_OPTIONAL) && fio != lio) {
23010105Sadam.leventhal@sun.com 			fio = AVL_NEXT(t, fio);
23110105Sadam.leventhal@sun.com 			ASSERT(fio != NULL);
23210105Sadam.leventhal@sun.com 		}
23310105Sadam.leventhal@sun.com 
23410105Sadam.leventhal@sun.com 		/*
23510105Sadam.leventhal@sun.com 		 * Walk forward through sufficiently contiguous I/Os.
23610105Sadam.leventhal@sun.com 		 */
2378632SBill.Moore@Sun.COM 		while ((dio = AVL_NEXT(t, lio)) != NULL &&
2388241SJeff.Bonwick@Sun.COM 		    (dio->io_flags & ZIO_FLAG_AGG_INHERIT) == flags &&
23910105Sadam.leventhal@sun.com 		    IO_SPAN(fio, dio) <= maxspan &&
24010105Sadam.leventhal@sun.com 		    IO_GAP(lio, dio) <= maxgap) {
2418241SJeff.Bonwick@Sun.COM 			lio = dio;
24210105Sadam.leventhal@sun.com 			if (!(lio->io_flags & ZIO_FLAG_OPTIONAL))
24310105Sadam.leventhal@sun.com 				mio = lio;
24410105Sadam.leventhal@sun.com 		}
24510105Sadam.leventhal@sun.com 
24610105Sadam.leventhal@sun.com 		/*
24710105Sadam.leventhal@sun.com 		 * Now that we've established the range of the I/O aggregation
24810105Sadam.leventhal@sun.com 		 * we must decide what to do with trailing optional I/Os.
24910105Sadam.leventhal@sun.com 		 * For reads, there's nothing to do. While we are unable to
25010105Sadam.leventhal@sun.com 		 * aggregate further, it's possible that a trailing optional
25110105Sadam.leventhal@sun.com 		 * I/O would allow the underlying device to aggregate with
25210105Sadam.leventhal@sun.com 		 * subsequent I/Os. We must therefore determine if the next
25310105Sadam.leventhal@sun.com 		 * non-optional I/O is close enough to make aggregation
25410105Sadam.leventhal@sun.com 		 * worthwhile.
25510105Sadam.leventhal@sun.com 		 */
25610105Sadam.leventhal@sun.com 		stretch = B_FALSE;
25710105Sadam.leventhal@sun.com 		if (t != &vq->vq_read_tree && mio != NULL) {
25810105Sadam.leventhal@sun.com 			nio = lio;
25910105Sadam.leventhal@sun.com 			while ((dio = AVL_NEXT(t, nio)) != NULL &&
26010105Sadam.leventhal@sun.com 			    IO_GAP(nio, dio) == 0 &&
26110105Sadam.leventhal@sun.com 			    IO_GAP(mio, dio) <= zfs_vdev_write_gap_limit) {
26210105Sadam.leventhal@sun.com 				nio = dio;
26310105Sadam.leventhal@sun.com 				if (!(nio->io_flags & ZIO_FLAG_OPTIONAL)) {
26410105Sadam.leventhal@sun.com 					stretch = B_TRUE;
26510105Sadam.leventhal@sun.com 					break;
26610105Sadam.leventhal@sun.com 				}
26710105Sadam.leventhal@sun.com 			}
26810105Sadam.leventhal@sun.com 		}
26910105Sadam.leventhal@sun.com 
27010105Sadam.leventhal@sun.com 		if (stretch) {
27110105Sadam.leventhal@sun.com 			/* This may be a no-op. */
27210105Sadam.leventhal@sun.com 			VERIFY((dio = AVL_NEXT(t, lio)) != NULL);
27310105Sadam.leventhal@sun.com 			dio->io_flags &= ~ZIO_FLAG_OPTIONAL;
27410105Sadam.leventhal@sun.com 		} else {
27510105Sadam.leventhal@sun.com 			while (lio != mio && lio != fio) {
27610105Sadam.leventhal@sun.com 				ASSERT(lio->io_flags & ZIO_FLAG_OPTIONAL);
27710105Sadam.leventhal@sun.com 				lio = AVL_PREV(t, lio);
27810105Sadam.leventhal@sun.com 				ASSERT(lio != NULL);
27910105Sadam.leventhal@sun.com 			}
28010105Sadam.leventhal@sun.com 		}
281789Sahrens 	}
282789Sahrens 
283789Sahrens 	if (fio != lio) {
2848692SJeff.Bonwick@Sun.COM 		uint64_t size = IO_SPAN(fio, lio);
2853059Sahrens 		ASSERT(size <= zfs_vdev_aggregation_limit);
286789Sahrens 
2877754SJeff.Bonwick@Sun.COM 		aio = zio_vdev_delegated_io(fio->io_vd, fio->io_offset,
288*11146SGeorge.Wilson@Sun.COM 		    zio_buf_alloc(size), size, fio->io_type, ZIO_PRIORITY_AGG,
2898241SJeff.Bonwick@Sun.COM 		    flags | ZIO_FLAG_DONT_CACHE | ZIO_FLAG_DONT_QUEUE,
290789Sahrens 		    vdev_queue_agg_io_done, NULL);
291789Sahrens 
2928692SJeff.Bonwick@Sun.COM 		nio = fio;
2938692SJeff.Bonwick@Sun.COM 		do {
2948692SJeff.Bonwick@Sun.COM 			dio = nio;
2958692SJeff.Bonwick@Sun.COM 			nio = AVL_NEXT(t, dio);
296789Sahrens 			ASSERT(dio->io_type == aio->io_type);
2978632SBill.Moore@Sun.COM 			ASSERT(dio->io_vdev_tree == t);
2988632SBill.Moore@Sun.COM 
29910105Sadam.leventhal@sun.com 			if (dio->io_flags & ZIO_FLAG_NODATA) {
30010105Sadam.leventhal@sun.com 				ASSERT(dio->io_type == ZIO_TYPE_WRITE);
30110105Sadam.leventhal@sun.com 				bzero((char *)aio->io_data + (dio->io_offset -
30210105Sadam.leventhal@sun.com 				    aio->io_offset), dio->io_size);
30310105Sadam.leventhal@sun.com 			} else if (dio->io_type == ZIO_TYPE_WRITE) {
3048632SBill.Moore@Sun.COM 				bcopy(dio->io_data, (char *)aio->io_data +
3058632SBill.Moore@Sun.COM 				    (dio->io_offset - aio->io_offset),
3068632SBill.Moore@Sun.COM 				    dio->io_size);
30710105Sadam.leventhal@sun.com 			}
3088632SBill.Moore@Sun.COM 
3098632SBill.Moore@Sun.COM 			zio_add_child(dio, aio);
3101544Seschrock 			vdev_queue_io_remove(vq, dio);
311789Sahrens 			zio_vdev_io_bypass(dio);
3128632SBill.Moore@Sun.COM 			zio_execute(dio);
3138692SJeff.Bonwick@Sun.COM 		} while (dio != lio);
314789Sahrens 
315789Sahrens 		avl_add(&vq->vq_pending_tree, aio);
316789Sahrens 
317789Sahrens 		return (aio);
318789Sahrens 	}
319789Sahrens 
3208632SBill.Moore@Sun.COM 	ASSERT(fio->io_vdev_tree == t);
3211544Seschrock 	vdev_queue_io_remove(vq, fio);
322789Sahrens 
32310105Sadam.leventhal@sun.com 	/*
32410105Sadam.leventhal@sun.com 	 * If the I/O is or was optional and therefore has no data, we need to
32510105Sadam.leventhal@sun.com 	 * simply discard it. We need to drop the vdev queue's lock to avoid a
32610105Sadam.leventhal@sun.com 	 * deadlock that we could encounter since this I/O will complete
32710105Sadam.leventhal@sun.com 	 * immediately.
32810105Sadam.leventhal@sun.com 	 */
32910105Sadam.leventhal@sun.com 	if (fio->io_flags & ZIO_FLAG_NODATA) {
33010105Sadam.leventhal@sun.com 		mutex_exit(&vq->vq_lock);
33110105Sadam.leventhal@sun.com 		zio_vdev_io_bypass(fio);
33210105Sadam.leventhal@sun.com 		zio_execute(fio);
33310105Sadam.leventhal@sun.com 		mutex_enter(&vq->vq_lock);
33410105Sadam.leventhal@sun.com 		goto again;
33510105Sadam.leventhal@sun.com 	}
33610105Sadam.leventhal@sun.com 
337789Sahrens 	avl_add(&vq->vq_pending_tree, fio);
338789Sahrens 
339789Sahrens 	return (fio);
340789Sahrens }
341789Sahrens 
342789Sahrens zio_t *
vdev_queue_io(zio_t * zio)343789Sahrens vdev_queue_io(zio_t *zio)
344789Sahrens {
345789Sahrens 	vdev_queue_t *vq = &zio->io_vd->vdev_queue;
346789Sahrens 	zio_t *nio;
347789Sahrens 
348789Sahrens 	ASSERT(zio->io_type == ZIO_TYPE_READ || zio->io_type == ZIO_TYPE_WRITE);
349789Sahrens 
350789Sahrens 	if (zio->io_flags & ZIO_FLAG_DONT_QUEUE)
351789Sahrens 		return (zio);
352789Sahrens 
353789Sahrens 	zio->io_flags |= ZIO_FLAG_DONT_CACHE | ZIO_FLAG_DONT_QUEUE;
354789Sahrens 
355789Sahrens 	if (zio->io_type == ZIO_TYPE_READ)
356789Sahrens 		zio->io_vdev_tree = &vq->vq_read_tree;
357789Sahrens 	else
358789Sahrens 		zio->io_vdev_tree = &vq->vq_write_tree;
359789Sahrens 
360789Sahrens 	mutex_enter(&vq->vq_lock);
361789Sahrens 
36211066Srafael.vanoni@sun.com 	zio->io_deadline = (ddi_get_lbolt64() >> zfs_vdev_time_shift) +
36311066Srafael.vanoni@sun.com 	    zio->io_priority;
364789Sahrens 
3651544Seschrock 	vdev_queue_io_add(vq, zio);
366789Sahrens 
3675530Sbonwick 	nio = vdev_queue_io_to_issue(vq, zfs_vdev_min_pending);
368789Sahrens 
369789Sahrens 	mutex_exit(&vq->vq_lock);
370789Sahrens 
3715530Sbonwick 	if (nio == NULL)
3725530Sbonwick 		return (NULL);
373789Sahrens 
3745530Sbonwick 	if (nio->io_done == vdev_queue_agg_io_done) {
3755530Sbonwick 		zio_nowait(nio);
3765530Sbonwick 		return (NULL);
3775530Sbonwick 	}
3785530Sbonwick 
3795530Sbonwick 	return (nio);
380789Sahrens }
381789Sahrens 
382789Sahrens void
vdev_queue_io_done(zio_t * zio)383789Sahrens vdev_queue_io_done(zio_t *zio)
384789Sahrens {
385789Sahrens 	vdev_queue_t *vq = &zio->io_vd->vdev_queue;
386789Sahrens 
387789Sahrens 	mutex_enter(&vq->vq_lock);
388789Sahrens 
389789Sahrens 	avl_remove(&vq->vq_pending_tree, zio);
390789Sahrens 
3917754SJeff.Bonwick@Sun.COM 	for (int i = 0; i < zfs_vdev_ramp_rate; i++) {
3927754SJeff.Bonwick@Sun.COM 		zio_t *nio = vdev_queue_io_to_issue(vq, zfs_vdev_max_pending);
393789Sahrens 		if (nio == NULL)
394789Sahrens 			break;
395789Sahrens 		mutex_exit(&vq->vq_lock);
3965530Sbonwick 		if (nio->io_done == vdev_queue_agg_io_done) {
3975530Sbonwick 			zio_nowait(nio);
3985530Sbonwick 		} else {
399789Sahrens 			zio_vdev_io_reissue(nio);
4005530Sbonwick 			zio_execute(nio);
4015530Sbonwick 		}
402789Sahrens 		mutex_enter(&vq->vq_lock);
403789Sahrens 	}
404789Sahrens 
405789Sahrens 	mutex_exit(&vq->vq_lock);
406789Sahrens }
407