Skip to content

Commit 4f789ad

Browse files
committed
zinject: separate match counts for delay injections
It turns out we can count a matching delay injection handler earlier, by counting it once we decide its worth considering if it has a spare lane for this IO. With that in hand, it becomes useful to show separate match and inject counts, as well as the frequency, so update the output and the test to show all that. Sponsored-by: Klara, Inc. Sponsored-by: Wasabi Technology, Inc. Suggested-by: Alexander Motin <[email protected]> Signed-off-by: Rob Norris <[email protected]>
1 parent 29d30f2 commit 4f789ad

File tree

3 files changed

+27
-20
lines changed

3 files changed

+27
-20
lines changed

cmd/zinject/zinject.c

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -484,19 +484,25 @@ print_delay_handler(int id, const char *pool, zinject_record_t *record,
484484
return (0);
485485

486486
if (*count == 0) {
487-
(void) printf("%3s %-15s %-15s %-15s %-16s %-6s\n",
488-
"ID", "POOL", "DELAY (ms)", "LANES", "GUID", "INJECT");
489-
(void) printf("--- --------------- --------------- "
490-
"--------------- ---------------- ------\n");
487+
(void) printf("%3s %-15s %-16s %-10s %-5s %-9s "
488+
"%-6s %-6s\n",
489+
"ID", "POOL", "GUID", "DELAY (ms)", "LANES", "FREQ",
490+
"MATCH", "INJECT");
491+
(void) printf("--- --------------- ---------------- "
492+
"---------- ----- --------- "
493+
"------ ------\n");
491494
}
492495

493496
*count += 1;
494497

495-
(void) printf("%3d %-15s %-15llu %-15llu %llx %6lu\n", id, pool,
498+
double freq = record->zi_freq == 0 ? 100.0f :
499+
(((double)record->zi_freq) / ZI_PERCENTAGE_MAX) * 100.0f;
500+
501+
(void) printf("%3d %-15s %llx %10llu %5llu %8.4f%% "
502+
"%6lu %6lu\n", id, pool, (u_longlong_t)record->zi_guid,
496503
(u_longlong_t)NSEC2MSEC(record->zi_timer),
497504
(u_longlong_t)record->zi_nlanes,
498-
(u_longlong_t)record->zi_guid,
499-
record->zi_inject_count);
505+
freq, record->zi_match_count, record->zi_inject_count);
500506

501507
return (0);
502508
}

module/zfs/zio_inject.c

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -631,9 +631,6 @@ zio_handle_io_delay(zio_t *zio)
631631
if (handler->zi_record.zi_cmd != ZINJECT_DELAY_IO)
632632
continue;
633633

634-
if (!freq_triggered(handler->zi_record.zi_freq))
635-
continue;
636-
637634
if (vd->vdev_guid != handler->zi_record.zi_guid)
638635
continue;
639636

@@ -658,6 +655,12 @@ zio_handle_io_delay(zio_t *zio)
658655
ASSERT3U(handler->zi_record.zi_nlanes, >,
659656
handler->zi_next_lane);
660657

658+
handler->zi_record.zi_match_count++;
659+
660+
/* Limit the use of this handler if requested */
661+
if (!freq_triggered(handler->zi_record.zi_freq))
662+
continue;
663+
661664
/*
662665
* We want to issue this IO to the lane that will become
663666
* idle the soonest, so we compare the soonest this
@@ -730,7 +733,6 @@ zio_handle_io_delay(zio_t *zio)
730733
min_handler->zi_next_lane = (min_handler->zi_next_lane + 1) %
731734
min_handler->zi_record.zi_nlanes;
732735

733-
min_handler->zi_record.zi_match_count++;
734736
min_handler->zi_record.zi_inject_count++;
735737

736738
}

tests/zfs-tests/tests/functional/cli_root/zinject/zinject_counts.ksh

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -112,20 +112,19 @@ function test_object_injection
112112
done
113113
}
114114

115-
# Test delay injections, bu injecting delays and writing. Note that there
116-
# is no frequency option for these, and match counts are not reqported, so
117-
# we only look for the inject count in the last column.
115+
# Test delay injections, bu injecting delays and writing
118116
function test_delay_injection
119117
{
120-
log_must zinject -d $DISK1 -D 50:1 $TESTPOOL
118+
for freq in 100 50 ; do
119+
log_must zinject -d $DISK1 -D 50:1 $TESTPOOL
121120

122-
log_must dd if=/dev/urandom of=/$TESTPOOL/file bs=1M count=1
123-
zpool sync
121+
log_must dd if=/dev/urandom of=/$TESTPOOL/file bs=1M count=1
122+
zpool sync
124123

125-
typeset -i match=($(zinject | grep -oE ' [0-9]+$'))
126-
log_must test $match -gt 0
124+
log_must check_count_freq $freq
127125

128-
log_must zinject -c all
126+
log_must zinject -c all
127+
done
129128
}
130129

131130
# Disable cache, to ensure reads induce IO

0 commit comments

Comments
 (0)