Skip to content

Commit

Permalink
zdb: adjust block histogram binning strategy
Browse files Browse the repository at this point in the history
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.

Signed-off-by: Ivan Shapovalov <[email protected]>
  • Loading branch information
intelfx committed Jan 28, 2025
1 parent 9328e61 commit ca4e8e8
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion cmd/zdb/zdb.c
Original file line number Diff line number Diff line change
Expand Up @@ -6139,7 +6139,12 @@ zdb_count_block(zdb_cb_t *zcb, zilog_t *zilog, const blkptr_t *bp,
*/
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;
Expand Down

0 comments on commit ca4e8e8

Please sign in to comment.