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