From f8b082b5afc501050984ee58b9ea584f75bbf2ef Mon Sep 17 00:00:00 2001 From: Ivan Shapovalov Date: Tue, 10 Dec 2024 19:58:35 +0400 Subject: [PATCH] zdb: adjust block histogram binning strategy Previously, a bin included all blocks _starting_ from given size (e.g., a "4K" bin would include all blocks within the [4K; 8K) region). This is counter-intuitive and does not match the typical use-case of the block histogram (that is, to estimate disk usage considering how ZFS' block allocation works). In other words, if I'm looking at the "4K" row, I'm interested in records that _fit into_ a 4K block. Adjust the binning strategy such that a bin includes all blocks _up to_ given size, such that e.g. a "4K" bin would include all blocks within the (2K; 4K] region. Reviewed-by: Brian Behlendorf Signed-off-by: Ivan Shapovalov Closes #16999 --- cmd/zdb/zdb.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/cmd/zdb/zdb.c b/cmd/zdb/zdb.c index 62487601d..1ffb8ebc7 100644 --- a/cmd/zdb/zdb.c +++ b/cmd/zdb/zdb.c @@ -6254,7 +6254,12 @@ skipped: */ int bin; -#define BIN(size) (highbit64(size) - 1) + /* + * Binning strategy: each bin includes blocks up to and including + * the given size (excluding blocks that fit into the previous bin). + * This way, the "4K" bin includes blocks within the (2K; 4K] range. + */ +#define BIN(size) (highbit64((size) - 1)) switch (block_bin_mode) { case BIN_PSIZE: bin = BIN(BP_GET_PSIZE(bp)); break;