Skip to content

Commit df2e02a

Browse files
committed
zdb: add extra -T flag to show histograms of BRT refcounts
Sponsored-by: https://despairlabs.com/sponsor/ Signed-off-by: Rob Norris <[email protected]>
1 parent e5d1f68 commit df2e02a

File tree

2 files changed

+27
-6
lines changed

2 files changed

+27
-6
lines changed

cmd/zdb/zdb.c

Lines changed: 24 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2152,14 +2152,21 @@ dump_brt(spa_t *spa)
21522152
if (dump_opt['T'] < 3)
21532153
return;
21542154

2155+
/* -TTT shows a per-vdev histograms; -TTTT shows all entries */
2156+
boolean_t do_histo = dump_opt['T'] == 3;
2157+
21552158
char dva[64];
2156-
printf("\n%-16s %-10s\n", "DVA", "REFCNT");
2159+
2160+
if (!do_histo)
2161+
printf("\n%-16s %-10s\n", "DVA", "REFCNT");
21572162

21582163
for (uint64_t vdevid = 0; vdevid < brt->brt_nvdevs; vdevid++) {
21592164
brt_vdev_t *brtvd = &brt->brt_vdevs[vdevid];
21602165
if (brtvd == NULL || !brtvd->bv_initiated)
21612166
continue;
21622167

2168+
uint64_t counts[64] = {};
2169+
21632170
zap_cursor_t zc;
21642171
zap_attribute_t *za = zap_attribute_alloc();
21652172
for (zap_cursor_init(&zc, brt->brt_mos, brtvd->bv_mos_entries);
@@ -2172,14 +2179,26 @@ dump_brt(spa_t *spa)
21722179
za->za_integer_length, za->za_num_integers,
21732180
&refcnt));
21742181

2175-
uint64_t offset = *(const uint64_t *)za->za_name;
2182+
if (do_histo)
2183+
counts[highbit64(refcnt)]++;
2184+
else {
2185+
uint64_t offset =
2186+
*(const uint64_t *)za->za_name;
21762187

2177-
snprintf(dva, sizeof (dva), "%" PRIu64 ":%llx", vdevid,
2178-
(u_longlong_t)offset);
2179-
printf("%-16s %-10llu\n", dva, (u_longlong_t)refcnt);
2188+
snprintf(dva, sizeof (dva), "%" PRIu64 ":%llx",
2189+
vdevid, (u_longlong_t)offset);
2190+
printf("%-16s %-10llu\n", dva,
2191+
(u_longlong_t)refcnt);
2192+
}
21802193
}
21812194
zap_cursor_fini(&zc);
21822195
zap_attribute_free(za);
2196+
2197+
if (do_histo) {
2198+
printf("\nBRT: vdev %" PRIu64
2199+
": DVAs with 2^n refcnts:\n", vdevid);
2200+
dump_histogram(counts, 64, 0);
2201+
}
21832202
}
21842203
}
21852204

man/man8/zdb.8

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
.\" Copyright (c) 2017 Lawrence Livermore National Security, LLC.
1515
.\" Copyright (c) 2017 Intel Corporation.
1616
.\"
17-
.Dd November 18, 2023
17+
.Dd October 27, 2024
1818
.Dt ZDB 8
1919
.Os
2020
.
@@ -408,6 +408,8 @@ blocks cloned, the space saving as a result of cloning, and the saving ratio.
408408
.It Fl TT
409409
Display the per-vdev BRT statistics, including total references.
410410
.It Fl TTT
411+
Display histograms of per-vdev BRT refcounts.
412+
.It Fl TTTT
411413
Dump the contents of the block reference tables.
412414
.It Fl u , -uberblock
413415
Display the current uberblock.

0 commit comments

Comments
 (0)