]> git.proxmox.com Git - zfsonlinux.git/blob - zfs-patches/0006-Reduce-taskq-and-context-switch-cost-of-zio-pipe.patch
update/rebase to spl-0.7.12 with patches from ZOL
[zfsonlinux.git] / zfs-patches / 0006-Reduce-taskq-and-context-switch-cost-of-zio-pipe.patch
1 From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
2 From: Matthew Ahrens <mahrens@delphix.com>
3 Date: Thu, 2 Aug 2018 15:51:45 -0700
4 Subject: [PATCH] Reduce taskq and context-switch cost of zio pipe
5
6 When doing a read from disk, ZFS creates 3 ZIO's: a zio_null(), the
7 logical zio_read(), and then a physical zio. Currently, each of these
8 results in a separate taskq_dispatch(zio_execute).
9
10 On high-read-iops workloads, this causes a significant performance
11 impact. By processing all 3 ZIO's in a single taskq entry, we reduce the
12 overhead on taskq locking and context switching. We accomplish this by
13 allowing zio_done() to return a "next zio to execute" to zio_execute().
14
15 This results in a ~12% performance increase for random reads, from
16 96,000 iops to 108,000 iops (with recordsize=8k, on SSD's).
17
18 Reviewed by: Pavel Zakharov <pavel.zakharov@delphix.com>
19 Reviewed-by: Brian Behlendorf <behlendorf1@llnl.gov>
20 Reviewed by: George Wilson <george.wilson@delphix.com>
21 Signed-off-by: Matthew Ahrens <mahrens@delphix.com>
22 External-issue: DLPX-59292
23 Requires-spl: spl-0.7-release
24 Closes #7736
25
26 (cherry-picked from behlendorf/issue-7736 496657ab3bcfeb638b1786e1759980ccfcacb08e)
27 Signed-off-by: Stoiko Ivanov <s.ivanov@proxmox.com>
28 ---
29 include/sys/zio.h | 4 +-
30 module/zfs/zio.c | 250 +++++++++++++++++++++++++++++-------------------------
31 2 files changed, 137 insertions(+), 117 deletions(-)
32
33 diff --git a/include/sys/zio.h b/include/sys/zio.h
34 index 4b0eecc2..3618912c 100644
35 --- a/include/sys/zio.h
36 +++ b/include/sys/zio.h
37 @@ -237,7 +237,7 @@ enum zio_child {
38 #define ZIO_CHILD_DDT_BIT ZIO_CHILD_BIT(ZIO_CHILD_DDT)
39 #define ZIO_CHILD_LOGICAL_BIT ZIO_CHILD_BIT(ZIO_CHILD_LOGICAL)
40 #define ZIO_CHILD_ALL_BITS \
41 - (ZIO_CHILD_VDEV_BIT | ZIO_CHILD_GANG_BIT | \
42 + (ZIO_CHILD_VDEV_BIT | ZIO_CHILD_GANG_BIT | \
43 ZIO_CHILD_DDT_BIT | ZIO_CHILD_LOGICAL_BIT)
44
45 enum zio_wait_type {
46 @@ -375,7 +375,7 @@ typedef struct zio_transform {
47 struct zio_transform *zt_next;
48 } zio_transform_t;
49
50 -typedef int zio_pipe_stage_t(zio_t *zio);
51 +typedef zio_t *zio_pipe_stage_t(zio_t *zio);
52
53 /*
54 * The io_reexecute flags are distinct from io_flags because the child must
55 diff --git a/module/zfs/zio.c b/module/zfs/zio.c
56 index 9a465e1b..b08b4747 100644
57 --- a/module/zfs/zio.c
58 +++ b/module/zfs/zio.c
59 @@ -75,9 +75,6 @@ uint64_t zio_buf_cache_frees[SPA_MAXBLOCKSIZE >> SPA_MINBLOCKSHIFT];
60
61 int zio_delay_max = ZIO_DELAY_MAX;
62
63 -#define ZIO_PIPELINE_CONTINUE 0x100
64 -#define ZIO_PIPELINE_STOP 0x101
65 -
66 #define BP_SPANB(indblkshift, level) \
67 (((uint64_t)1) << ((level) * ((indblkshift) - SPA_BLKPTRSHIFT)))
68 #define COMPARE_META_LEVEL 0x80000000ul
69 @@ -516,7 +513,8 @@ zio_wait_for_children(zio_t *zio, uint8_t childbits, enum zio_wait_type wait)
70
71 __attribute__((always_inline))
72 static inline void
73 -zio_notify_parent(zio_t *pio, zio_t *zio, enum zio_wait_type wait)
74 +zio_notify_parent(zio_t *pio, zio_t *zio, enum zio_wait_type wait,
75 + zio_t **next_to_executep)
76 {
77 uint64_t *countp = &pio->io_children[zio->io_child_type][wait];
78 int *errorp = &pio->io_child_error[zio->io_child_type];
79 @@ -535,13 +533,33 @@ zio_notify_parent(zio_t *pio, zio_t *zio, enum zio_wait_type wait)
80 ZIO_TASKQ_INTERRUPT;
81 pio->io_stall = NULL;
82 mutex_exit(&pio->io_lock);
83 +
84 /*
85 - * Dispatch the parent zio in its own taskq so that
86 - * the child can continue to make progress. This also
87 - * prevents overflowing the stack when we have deeply nested
88 - * parent-child relationships.
89 + * If we can tell the caller to execute this parent next, do
90 + * so. Otherwise dispatch the parent zio as its own task.
91 + *
92 + * Having the caller execute the parent when possible reduces
93 + * locking on the zio taskq's, reduces context switch
94 + * overhead, and has no recursion penalty. Note that one
95 + * read from disk typically causes at least 3 zio's: a
96 + * zio_null(), the logical zio_read(), and then a physical
97 + * zio. When the physical ZIO completes, we are able to call
98 + * zio_done() on all 3 of these zio's from one invocation of
99 + * zio_execute() by returning the parent back to
100 + * zio_execute(). Since the parent isn't executed until this
101 + * thread returns back to zio_execute(), the caller should do
102 + * so promptly.
103 + *
104 + * In other cases, dispatching the parent prevents
105 + * overflowing the stack when we have deeply nested
106 + * parent-child relationships, as we do with the "mega zio"
107 + * of writes for spa_sync(), and the chain of ZIL blocks.
108 */
109 - zio_taskq_dispatch(pio, type, B_FALSE);
110 + if (next_to_executep != NULL && *next_to_executep == NULL) {
111 + *next_to_executep = pio;
112 + } else {
113 + zio_taskq_dispatch(pio, type, B_FALSE);
114 + }
115 } else {
116 mutex_exit(&pio->io_lock);
117 }
118 @@ -1187,7 +1205,7 @@ zio_shrink(zio_t *zio, uint64_t size)
119 * ==========================================================================
120 */
121
122 -static int
123 +static zio_t *
124 zio_read_bp_init(zio_t *zio)
125 {
126 blkptr_t *bp = zio->io_bp;
127 @@ -1221,15 +1239,15 @@ zio_read_bp_init(zio_t *zio)
128 if (BP_GET_DEDUP(bp) && zio->io_child_type == ZIO_CHILD_LOGICAL)
129 zio->io_pipeline = ZIO_DDT_READ_PIPELINE;
130
131 - return (ZIO_PIPELINE_CONTINUE);
132 + return (zio);
133 }
134
135 -static int
136 +static zio_t *
137 zio_write_bp_init(zio_t *zio)
138 {
139
140 if (!IO_IS_ALLOCATING(zio))
141 - return (ZIO_PIPELINE_CONTINUE);
142 + return (zio);
143
144 ASSERT(zio->io_child_type != ZIO_CHILD_DDT);
145
146 @@ -1244,7 +1262,7 @@ zio_write_bp_init(zio_t *zio)
147 zio->io_pipeline = ZIO_INTERLOCK_PIPELINE;
148
149 if (BP_IS_EMBEDDED(bp))
150 - return (ZIO_PIPELINE_CONTINUE);
151 + return (zio);
152
153 /*
154 * If we've been overridden and nopwrite is set then
155 @@ -1255,13 +1273,13 @@ zio_write_bp_init(zio_t *zio)
156 ASSERT(!zp->zp_dedup);
157 ASSERT3U(BP_GET_CHECKSUM(bp), ==, zp->zp_checksum);
158 zio->io_flags |= ZIO_FLAG_NOPWRITE;
159 - return (ZIO_PIPELINE_CONTINUE);
160 + return (zio);
161 }
162
163 ASSERT(!zp->zp_nopwrite);
164
165 if (BP_IS_HOLE(bp) || !zp->zp_dedup)
166 - return (ZIO_PIPELINE_CONTINUE);
167 + return (zio);
168
169 ASSERT((zio_checksum_table[zp->zp_checksum].ci_flags &
170 ZCHECKSUM_FLAG_DEDUP) || zp->zp_dedup_verify);
171 @@ -1269,7 +1287,7 @@ zio_write_bp_init(zio_t *zio)
172 if (BP_GET_CHECKSUM(bp) == zp->zp_checksum) {
173 BP_SET_DEDUP(bp, 1);
174 zio->io_pipeline |= ZIO_STAGE_DDT_WRITE;
175 - return (ZIO_PIPELINE_CONTINUE);
176 + return (zio);
177 }
178
179 /*
180 @@ -1281,10 +1299,10 @@ zio_write_bp_init(zio_t *zio)
181 zio->io_pipeline = zio->io_orig_pipeline;
182 }
183
184 - return (ZIO_PIPELINE_CONTINUE);
185 + return (zio);
186 }
187
188 -static int
189 +static zio_t *
190 zio_write_compress(zio_t *zio)
191 {
192 spa_t *spa = zio->io_spa;
193 @@ -1303,11 +1321,11 @@ zio_write_compress(zio_t *zio)
194 */
195 if (zio_wait_for_children(zio, ZIO_CHILD_LOGICAL_BIT |
196 ZIO_CHILD_GANG_BIT, ZIO_WAIT_READY)) {
197 - return (ZIO_PIPELINE_STOP);
198 + return (NULL);
199 }
200
201 if (!IO_IS_ALLOCATING(zio))
202 - return (ZIO_PIPELINE_CONTINUE);
203 + return (zio);
204
205 if (zio->io_children_ready != NULL) {
206 /*
207 @@ -1366,7 +1384,7 @@ zio_write_compress(zio_t *zio)
208 zio->io_pipeline = ZIO_INTERLOCK_PIPELINE;
209 ASSERT(spa_feature_is_active(spa,
210 SPA_FEATURE_EMBEDDED_DATA));
211 - return (ZIO_PIPELINE_CONTINUE);
212 + return (zio);
213 } else {
214 /*
215 * Round up compressed size up to the ashift
216 @@ -1459,10 +1477,10 @@ zio_write_compress(zio_t *zio)
217 zio->io_pipeline |= ZIO_STAGE_NOP_WRITE;
218 }
219 }
220 - return (ZIO_PIPELINE_CONTINUE);
221 + return (zio);
222 }
223
224 -static int
225 +static zio_t *
226 zio_free_bp_init(zio_t *zio)
227 {
228 blkptr_t *bp = zio->io_bp;
229 @@ -1472,7 +1490,7 @@ zio_free_bp_init(zio_t *zio)
230 zio->io_pipeline = ZIO_DDT_FREE_PIPELINE;
231 }
232
233 - return (ZIO_PIPELINE_CONTINUE);
234 + return (zio);
235 }
236
237 /*
238 @@ -1541,12 +1559,12 @@ zio_taskq_member(zio_t *zio, zio_taskq_type_t q)
239 return (B_FALSE);
240 }
241
242 -static int
243 +static zio_t *
244 zio_issue_async(zio_t *zio)
245 {
246 zio_taskq_dispatch(zio, ZIO_TASKQ_ISSUE, B_FALSE);
247
248 - return (ZIO_PIPELINE_STOP);
249 + return (NULL);
250 }
251
252 void
253 @@ -1687,14 +1705,13 @@ __attribute__((always_inline))
254 static inline void
255 __zio_execute(zio_t *zio)
256 {
257 - zio->io_executor = curthread;
258 -
259 ASSERT3U(zio->io_queued_timestamp, >, 0);
260
261 while (zio->io_stage < ZIO_STAGE_DONE) {
262 enum zio_stage pipeline = zio->io_pipeline;
263 enum zio_stage stage = zio->io_stage;
264 - int rv;
265 +
266 + zio->io_executor = curthread;
267
268 ASSERT(!MUTEX_HELD(&zio->io_lock));
269 ASSERT(ISP2(stage));
270 @@ -1736,12 +1753,16 @@ __zio_execute(zio_t *zio)
271
272 zio->io_stage = stage;
273 zio->io_pipeline_trace |= zio->io_stage;
274 - rv = zio_pipeline[highbit64(stage) - 1](zio);
275
276 - if (rv == ZIO_PIPELINE_STOP)
277 - return;
278 + /*
279 + * The zio pipeline stage returns the next zio to execute
280 + * (typically the same as this one), or NULL if we should
281 + * stop.
282 + */
283 + zio = zio_pipeline[highbit64(stage) - 1](zio);
284
285 - ASSERT(rv == ZIO_PIPELINE_CONTINUE);
286 + if (zio == NULL)
287 + return;
288 }
289 }
290
291 @@ -2215,7 +2236,7 @@ zio_gang_tree_issue(zio_t *pio, zio_gang_node_t *gn, blkptr_t *bp, abd_t *data,
292 zio_nowait(zio);
293 }
294
295 -static int
296 +static zio_t *
297 zio_gang_assemble(zio_t *zio)
298 {
299 blkptr_t *bp = zio->io_bp;
300 @@ -2227,16 +2248,16 @@ zio_gang_assemble(zio_t *zio)
301
302 zio_gang_tree_assemble(zio, bp, &zio->io_gang_tree);
303
304 - return (ZIO_PIPELINE_CONTINUE);
305 + return (zio);
306 }
307
308 -static int
309 +static zio_t *
310 zio_gang_issue(zio_t *zio)
311 {
312 blkptr_t *bp = zio->io_bp;
313
314 if (zio_wait_for_children(zio, ZIO_CHILD_GANG_BIT, ZIO_WAIT_DONE)) {
315 - return (ZIO_PIPELINE_STOP);
316 + return (NULL);
317 }
318
319 ASSERT(BP_IS_GANG(bp) && zio->io_gang_leader == zio);
320 @@ -2250,7 +2271,7 @@ zio_gang_issue(zio_t *zio)
321
322 zio->io_pipeline = ZIO_INTERLOCK_PIPELINE;
323
324 - return (ZIO_PIPELINE_CONTINUE);
325 + return (zio);
326 }
327
328 static void
329 @@ -2290,7 +2311,7 @@ zio_write_gang_done(zio_t *zio)
330 abd_put(zio->io_abd);
331 }
332
333 -static int
334 +static zio_t *
335 zio_write_gang_block(zio_t *pio)
336 {
337 spa_t *spa = pio->io_spa;
338 @@ -2349,7 +2370,7 @@ zio_write_gang_block(zio_t *pio)
339 }
340
341 pio->io_error = error;
342 - return (ZIO_PIPELINE_CONTINUE);
343 + return (pio);
344 }
345
346 if (pio == gio) {
347 @@ -2423,7 +2444,7 @@ zio_write_gang_block(zio_t *pio)
348
349 zio_nowait(zio);
350
351 - return (ZIO_PIPELINE_CONTINUE);
352 + return (pio);
353 }
354
355 /*
356 @@ -2444,7 +2465,7 @@ zio_write_gang_block(zio_t *pio)
357 * used for nopwrite, assuming that the salt and the checksums
358 * themselves remain secret.
359 */
360 -static int
361 +static zio_t *
362 zio_nop_write(zio_t *zio)
363 {
364 blkptr_t *bp = zio->io_bp;
365 @@ -2471,7 +2492,7 @@ zio_nop_write(zio_t *zio)
366 BP_GET_COMPRESS(bp) != BP_GET_COMPRESS(bp_orig) ||
367 BP_GET_DEDUP(bp) != BP_GET_DEDUP(bp_orig) ||
368 zp->zp_copies != BP_GET_NDVAS(bp_orig))
369 - return (ZIO_PIPELINE_CONTINUE);
370 + return (zio);
371
372 /*
373 * If the checksums match then reset the pipeline so that we
374 @@ -2491,7 +2512,7 @@ zio_nop_write(zio_t *zio)
375 zio->io_flags |= ZIO_FLAG_NOPWRITE;
376 }
377
378 - return (ZIO_PIPELINE_CONTINUE);
379 + return (zio);
380 }
381
382 /*
383 @@ -2519,7 +2540,7 @@ zio_ddt_child_read_done(zio_t *zio)
384 mutex_exit(&pio->io_lock);
385 }
386
387 -static int
388 +static zio_t *
389 zio_ddt_read_start(zio_t *zio)
390 {
391 blkptr_t *bp = zio->io_bp;
392 @@ -2540,7 +2561,7 @@ zio_ddt_read_start(zio_t *zio)
393 zio->io_vsd = dde;
394
395 if (ddp_self == NULL)
396 - return (ZIO_PIPELINE_CONTINUE);
397 + return (zio);
398
399 for (p = 0; p < DDT_PHYS_TYPES; p++, ddp++) {
400 if (ddp->ddp_phys_birth == 0 || ddp == ddp_self)
401 @@ -2553,23 +2574,23 @@ zio_ddt_read_start(zio_t *zio)
402 zio->io_priority, ZIO_DDT_CHILD_FLAGS(zio) |
403 ZIO_FLAG_DONT_PROPAGATE, &zio->io_bookmark));
404 }
405 - return (ZIO_PIPELINE_CONTINUE);
406 + return (zio);
407 }
408
409 zio_nowait(zio_read(zio, zio->io_spa, bp,
410 zio->io_abd, zio->io_size, NULL, NULL, zio->io_priority,
411 ZIO_DDT_CHILD_FLAGS(zio), &zio->io_bookmark));
412
413 - return (ZIO_PIPELINE_CONTINUE);
414 + return (zio);
415 }
416
417 -static int
418 +static zio_t *
419 zio_ddt_read_done(zio_t *zio)
420 {
421 blkptr_t *bp = zio->io_bp;
422
423 if (zio_wait_for_children(zio, ZIO_CHILD_DDT_BIT, ZIO_WAIT_DONE)) {
424 - return (ZIO_PIPELINE_STOP);
425 + return (NULL);
426 }
427
428 ASSERT(BP_GET_DEDUP(bp));
429 @@ -2581,12 +2602,12 @@ zio_ddt_read_done(zio_t *zio)
430 ddt_entry_t *dde = zio->io_vsd;
431 if (ddt == NULL) {
432 ASSERT(spa_load_state(zio->io_spa) != SPA_LOAD_NONE);
433 - return (ZIO_PIPELINE_CONTINUE);
434 + return (zio);
435 }
436 if (dde == NULL) {
437 zio->io_stage = ZIO_STAGE_DDT_READ_START >> 1;
438 zio_taskq_dispatch(zio, ZIO_TASKQ_ISSUE, B_FALSE);
439 - return (ZIO_PIPELINE_STOP);
440 + return (NULL);
441 }
442 if (dde->dde_repair_abd != NULL) {
443 abd_copy(zio->io_abd, dde->dde_repair_abd,
444 @@ -2599,7 +2620,7 @@ zio_ddt_read_done(zio_t *zio)
445
446 ASSERT(zio->io_vsd == NULL);
447
448 - return (ZIO_PIPELINE_CONTINUE);
449 + return (zio);
450 }
451
452 static boolean_t
453 @@ -2780,7 +2801,7 @@ zio_ddt_ditto_write_done(zio_t *zio)
454 ddt_exit(ddt);
455 }
456
457 -static int
458 +static zio_t *
459 zio_ddt_write(zio_t *zio)
460 {
461 spa_t *spa = zio->io_spa;
462 @@ -2822,7 +2843,7 @@ zio_ddt_write(zio_t *zio)
463 }
464 zio->io_pipeline = ZIO_WRITE_PIPELINE;
465 ddt_exit(ddt);
466 - return (ZIO_PIPELINE_CONTINUE);
467 + return (zio);
468 }
469
470 ditto_copies = ddt_ditto_copies_needed(ddt, dde, ddp);
471 @@ -2848,7 +2869,7 @@ zio_ddt_write(zio_t *zio)
472 zio->io_bp_override = NULL;
473 BP_ZERO(bp);
474 ddt_exit(ddt);
475 - return (ZIO_PIPELINE_CONTINUE);
476 + return (zio);
477 }
478
479 dio = zio_write(zio, spa, txg, bp, zio->io_orig_abd,
480 @@ -2890,12 +2911,12 @@ zio_ddt_write(zio_t *zio)
481 if (dio)
482 zio_nowait(dio);
483
484 - return (ZIO_PIPELINE_CONTINUE);
485 + return (zio);
486 }
487
488 ddt_entry_t *freedde; /* for debugging */
489
490 -static int
491 +static zio_t *
492 zio_ddt_free(zio_t *zio)
493 {
494 spa_t *spa = zio->io_spa;
495 @@ -2916,7 +2937,7 @@ zio_ddt_free(zio_t *zio)
496 }
497 ddt_exit(ddt);
498
499 - return (ZIO_PIPELINE_CONTINUE);
500 + return (zio);
501 }
502
503 /*
504 @@ -2953,7 +2974,7 @@ zio_io_to_allocate(spa_t *spa)
505 return (zio);
506 }
507
508 -static int
509 +static zio_t *
510 zio_dva_throttle(zio_t *zio)
511 {
512 spa_t *spa = zio->io_spa;
513 @@ -2963,7 +2984,7 @@ zio_dva_throttle(zio_t *zio)
514 !spa_normal_class(zio->io_spa)->mc_alloc_throttle_enabled ||
515 zio->io_child_type == ZIO_CHILD_GANG ||
516 zio->io_flags & ZIO_FLAG_NODATA) {
517 - return (ZIO_PIPELINE_CONTINUE);
518 + return (zio);
519 }
520
521 ASSERT(zio->io_child_type > ZIO_CHILD_GANG);
522 @@ -2979,22 +3000,7 @@ zio_dva_throttle(zio_t *zio)
523 nio = zio_io_to_allocate(zio->io_spa);
524 mutex_exit(&spa->spa_alloc_lock);
525
526 - if (nio == zio)
527 - return (ZIO_PIPELINE_CONTINUE);
528 -
529 - if (nio != NULL) {
530 - ASSERT(nio->io_stage == ZIO_STAGE_DVA_THROTTLE);
531 - /*
532 - * We are passing control to a new zio so make sure that
533 - * it is processed by a different thread. We do this to
534 - * avoid stack overflows that can occur when parents are
535 - * throttled and children are making progress. We allow
536 - * it to go to the head of the taskq since it's already
537 - * been waiting.
538 - */
539 - zio_taskq_dispatch(nio, ZIO_TASKQ_ISSUE, B_TRUE);
540 - }
541 - return (ZIO_PIPELINE_STOP);
542 + return (nio);
543 }
544
545 void
546 @@ -3013,7 +3019,7 @@ zio_allocate_dispatch(spa_t *spa)
547 zio_taskq_dispatch(zio, ZIO_TASKQ_ISSUE, B_TRUE);
548 }
549
550 -static int
551 +static zio_t *
552 zio_dva_allocate(zio_t *zio)
553 {
554 spa_t *spa = zio->io_spa;
555 @@ -3054,18 +3060,18 @@ zio_dva_allocate(zio_t *zio)
556 zio->io_error = error;
557 }
558
559 - return (ZIO_PIPELINE_CONTINUE);
560 + return (zio);
561 }
562
563 -static int
564 +static zio_t *
565 zio_dva_free(zio_t *zio)
566 {
567 metaslab_free(zio->io_spa, zio->io_bp, zio->io_txg, B_FALSE);
568
569 - return (ZIO_PIPELINE_CONTINUE);
570 + return (zio);
571 }
572
573 -static int
574 +static zio_t *
575 zio_dva_claim(zio_t *zio)
576 {
577 int error;
578 @@ -3074,7 +3080,7 @@ zio_dva_claim(zio_t *zio)
579 if (error)
580 zio->io_error = error;
581
582 - return (ZIO_PIPELINE_CONTINUE);
583 + return (zio);
584 }
585
586 /*
587 @@ -3172,7 +3178,7 @@ zio_free_zil(spa_t *spa, uint64_t txg, blkptr_t *bp)
588 * force the underlying vdev layers to call either zio_execute() or
589 * zio_interrupt() to ensure that the pipeline continues with the correct I/O.
590 */
591 -static int
592 +static zio_t *
593 zio_vdev_io_start(zio_t *zio)
594 {
595 vdev_t *vd = zio->io_vd;
596 @@ -3192,7 +3198,7 @@ zio_vdev_io_start(zio_t *zio)
597 * The mirror_ops handle multiple DVAs in a single BP.
598 */
599 vdev_mirror_ops.vdev_op_io_start(zio);
600 - return (ZIO_PIPELINE_STOP);
601 + return (NULL);
602 }
603
604 ASSERT3P(zio->io_logical, !=, zio);
605 @@ -3269,31 +3275,31 @@ zio_vdev_io_start(zio_t *zio)
606 !vdev_dtl_contains(vd, DTL_PARTIAL, zio->io_txg, 1)) {
607 ASSERT(zio->io_type == ZIO_TYPE_WRITE);
608 zio_vdev_io_bypass(zio);
609 - return (ZIO_PIPELINE_CONTINUE);
610 + return (zio);
611 }
612
613 if (vd->vdev_ops->vdev_op_leaf &&
614 (zio->io_type == ZIO_TYPE_READ || zio->io_type == ZIO_TYPE_WRITE)) {
615
616 if (zio->io_type == ZIO_TYPE_READ && vdev_cache_read(zio))
617 - return (ZIO_PIPELINE_CONTINUE);
618 + return (zio);
619
620 if ((zio = vdev_queue_io(zio)) == NULL)
621 - return (ZIO_PIPELINE_STOP);
622 + return (NULL);
623
624 if (!vdev_accessible(vd, zio)) {
625 zio->io_error = SET_ERROR(ENXIO);
626 zio_interrupt(zio);
627 - return (ZIO_PIPELINE_STOP);
628 + return (NULL);
629 }
630 zio->io_delay = gethrtime();
631 }
632
633 vd->vdev_ops->vdev_op_io_start(zio);
634 - return (ZIO_PIPELINE_STOP);
635 + return (NULL);
636 }
637
638 -static int
639 +static zio_t *
640 zio_vdev_io_done(zio_t *zio)
641 {
642 vdev_t *vd = zio->io_vd;
643 @@ -3301,7 +3307,7 @@ zio_vdev_io_done(zio_t *zio)
644 boolean_t unexpected_error = B_FALSE;
645
646 if (zio_wait_for_children(zio, ZIO_CHILD_VDEV_BIT, ZIO_WAIT_DONE)) {
647 - return (ZIO_PIPELINE_STOP);
648 + return (NULL);
649 }
650
651 ASSERT(zio->io_type == ZIO_TYPE_READ || zio->io_type == ZIO_TYPE_WRITE);
652 @@ -3337,7 +3343,7 @@ zio_vdev_io_done(zio_t *zio)
653 if (unexpected_error)
654 VERIFY(vdev_probe(vd, zio) == NULL);
655
656 - return (ZIO_PIPELINE_CONTINUE);
657 + return (zio);
658 }
659
660 /*
661 @@ -3366,13 +3372,13 @@ zio_vsd_default_cksum_report(zio_t *zio, zio_cksum_report_t *zcr, void *ignored)
662 zcr->zcr_free = zio_abd_free;
663 }
664
665 -static int
666 +static zio_t *
667 zio_vdev_io_assess(zio_t *zio)
668 {
669 vdev_t *vd = zio->io_vd;
670
671 if (zio_wait_for_children(zio, ZIO_CHILD_VDEV_BIT, ZIO_WAIT_DONE)) {
672 - return (ZIO_PIPELINE_STOP);
673 + return (NULL);
674 }
675
676 if (vd == NULL && !(zio->io_flags & ZIO_FLAG_CONFIG_WRITER))
677 @@ -3402,7 +3408,7 @@ zio_vdev_io_assess(zio_t *zio)
678 zio->io_stage = ZIO_STAGE_VDEV_IO_START >> 1;
679 zio_taskq_dispatch(zio, ZIO_TASKQ_ISSUE,
680 zio_requeue_io_start_cut_in_line);
681 - return (ZIO_PIPELINE_STOP);
682 + return (NULL);
683 }
684
685 /*
686 @@ -3442,7 +3448,7 @@ zio_vdev_io_assess(zio_t *zio)
687 zio->io_physdone(zio->io_logical);
688 }
689
690 - return (ZIO_PIPELINE_CONTINUE);
691 + return (zio);
692 }
693
694 void
695 @@ -3477,7 +3483,7 @@ zio_vdev_io_bypass(zio_t *zio)
696 * Generate and verify checksums
697 * ==========================================================================
698 */
699 -static int
700 +static zio_t *
701 zio_checksum_generate(zio_t *zio)
702 {
703 blkptr_t *bp = zio->io_bp;
704 @@ -3491,7 +3497,7 @@ zio_checksum_generate(zio_t *zio)
705 checksum = zio->io_prop.zp_checksum;
706
707 if (checksum == ZIO_CHECKSUM_OFF)
708 - return (ZIO_PIPELINE_CONTINUE);
709 + return (zio);
710
711 ASSERT(checksum == ZIO_CHECKSUM_LABEL);
712 } else {
713 @@ -3505,10 +3511,10 @@ zio_checksum_generate(zio_t *zio)
714
715 zio_checksum_compute(zio, checksum, zio->io_abd, zio->io_size);
716
717 - return (ZIO_PIPELINE_CONTINUE);
718 + return (zio);
719 }
720
721 -static int
722 +static zio_t *
723 zio_checksum_verify(zio_t *zio)
724 {
725 zio_bad_cksum_t info;
726 @@ -3523,7 +3529,7 @@ zio_checksum_verify(zio_t *zio)
727 * We're either verifying a label checksum, or nothing at all.
728 */
729 if (zio->io_prop.zp_checksum == ZIO_CHECKSUM_OFF)
730 - return (ZIO_PIPELINE_CONTINUE);
731 + return (zio);
732
733 ASSERT(zio->io_prop.zp_checksum == ZIO_CHECKSUM_LABEL);
734 }
735 @@ -3538,7 +3544,7 @@ zio_checksum_verify(zio_t *zio)
736 }
737 }
738
739 - return (ZIO_PIPELINE_CONTINUE);
740 + return (zio);
741 }
742
743 /*
744 @@ -3581,7 +3587,7 @@ zio_worst_error(int e1, int e2)
745 * I/O completion
746 * ==========================================================================
747 */
748 -static int
749 +static zio_t *
750 zio_ready(zio_t *zio)
751 {
752 blkptr_t *bp = zio->io_bp;
753 @@ -3590,7 +3596,7 @@ zio_ready(zio_t *zio)
754
755 if (zio_wait_for_children(zio, ZIO_CHILD_GANG_BIT | ZIO_CHILD_DDT_BIT,
756 ZIO_WAIT_READY)) {
757 - return (ZIO_PIPELINE_STOP);
758 + return (NULL);
759 }
760
761 if (zio->io_ready) {
762 @@ -3636,7 +3642,7 @@ zio_ready(zio_t *zio)
763 */
764 for (; pio != NULL; pio = pio_next) {
765 pio_next = zio_walk_parents(zio, &zl);
766 - zio_notify_parent(pio, zio, ZIO_WAIT_READY);
767 + zio_notify_parent(pio, zio, ZIO_WAIT_READY, NULL);
768 }
769
770 if (zio->io_flags & ZIO_FLAG_NODATA) {
771 @@ -3652,7 +3658,7 @@ zio_ready(zio_t *zio)
772 zio->io_spa->spa_syncing_txg == zio->io_txg)
773 zio_handle_ignored_writes(zio);
774
775 - return (ZIO_PIPELINE_CONTINUE);
776 + return (zio);
777 }
778
779 /*
780 @@ -3716,7 +3722,7 @@ zio_dva_throttle_done(zio_t *zio)
781 zio_allocate_dispatch(zio->io_spa);
782 }
783
784 -static int
785 +static zio_t *
786 zio_done(zio_t *zio)
787 {
788 /*
789 @@ -3733,7 +3739,7 @@ zio_done(zio_t *zio)
790 * wait for them and then repeat this pipeline stage.
791 */
792 if (zio_wait_for_children(zio, ZIO_CHILD_ALL_BITS, ZIO_WAIT_DONE)) {
793 - return (ZIO_PIPELINE_STOP);
794 + return (NULL);
795 }
796
797 /*
798 @@ -3957,7 +3963,12 @@ zio_done(zio_t *zio)
799 if ((pio->io_flags & ZIO_FLAG_GODFATHER) &&
800 (zio->io_reexecute & ZIO_REEXECUTE_SUSPEND)) {
801 zio_remove_child(pio, zio, remove_zl);
802 - zio_notify_parent(pio, zio, ZIO_WAIT_DONE);
803 + /*
804 + * This is a rare code path, so we don't
805 + * bother with "next_to_execute".
806 + */
807 + zio_notify_parent(pio, zio, ZIO_WAIT_DONE,
808 + NULL);
809 }
810 }
811
812 @@ -3969,7 +3980,11 @@ zio_done(zio_t *zio)
813 */
814 ASSERT(!(zio->io_flags & ZIO_FLAG_GODFATHER));
815 zio->io_flags |= ZIO_FLAG_DONT_PROPAGATE;
816 - zio_notify_parent(pio, zio, ZIO_WAIT_DONE);
817 + /*
818 + * This is a rare code path, so we don't bother with
819 + * "next_to_execute".
820 + */
821 + zio_notify_parent(pio, zio, ZIO_WAIT_DONE, NULL);
822 } else if (zio->io_reexecute & ZIO_REEXECUTE_SUSPEND) {
823 /*
824 * We'd fail again if we reexecuted now, so suspend
825 @@ -3987,7 +4002,7 @@ zio_done(zio_t *zio)
826 (task_func_t *)zio_reexecute, zio, 0,
827 &zio->io_tqent);
828 }
829 - return (ZIO_PIPELINE_STOP);
830 + return (NULL);
831 }
832
833 ASSERT(zio->io_child_count == 0);
834 @@ -4023,12 +4038,17 @@ zio_done(zio_t *zio)
835 zio->io_state[ZIO_WAIT_DONE] = 1;
836 mutex_exit(&zio->io_lock);
837
838 + /*
839 + * We are done executing this zio. We may want to execute a parent
840 + * next. See the comment in zio_notify_parent().
841 + */
842 + zio_t *next_to_execute = NULL;
843 zl = NULL;
844 for (pio = zio_walk_parents(zio, &zl); pio != NULL; pio = pio_next) {
845 zio_link_t *remove_zl = zl;
846 pio_next = zio_walk_parents(zio, &zl);
847 zio_remove_child(pio, zio, remove_zl);
848 - zio_notify_parent(pio, zio, ZIO_WAIT_DONE);
849 + zio_notify_parent(pio, zio, ZIO_WAIT_DONE, &next_to_execute);
850 }
851
852 if (zio->io_waiter != NULL) {
853 @@ -4040,7 +4060,7 @@ zio_done(zio_t *zio)
854 zio_destroy(zio);
855 }
856
857 - return (ZIO_PIPELINE_STOP);
858 + return (next_to_execute);
859 }
860
861 /*