Skip to content

Commit

Permalink
fix histogram median calculation (#263)
Browse files Browse the repository at this point in the history
The histogram approximate median is calculated as about double what it
should be.  When we are on the bucket that goes past the median, the
histogram is the *previous* bucket, plus part of this bucket.

Signed-off-by: Matthew Ahrens <[email protected]>
  • Loading branch information
ahrens authored Mar 9, 2021
1 parent 6630f3b commit db1b967
Show file tree
Hide file tree
Showing 9 changed files with 59 additions and 59 deletions.
2 changes: 1 addition & 1 deletion sdb/commands/zfs/histograms.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ def histogram_median(hist: drgn.Object, offset: int = 0) -> int:
for (bucket, value) in enumerate(hist):
space_in_bucket = int(value) << (bucket + offset)
if space_left <= space_in_bucket:
median = 1 << (bucket + offset)
median = 1 << (bucket + offset - 1)
#
# Size of segments may vary within one bucket thus we
# attempt to approximate the median by looking at the
Expand Down
4 changes: 2 additions & 2 deletions tests/integration/data/regression_output/zfs/spa -H
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ ADDR NAME
64.0MB: 0
128.0MB: 0
256.0MB: 15 ***************
Approx. Median: 384.0MB
Approx. Median: 192.0MB
0xffffa089413b8000 meta-domain
seg-size count
-------- -----
Expand All @@ -45,6 +45,6 @@ ADDR NAME
32.0MB: 0
64.0MB: 1 *
128.0MB: 4 ****
Approx. Median: 184.0MB
Approx. Median: 92.0MB
0xffffa08955c44000 rpool
** No histogram data available **
48 changes: 24 additions & 24 deletions tests/integration/data/regression_output/zfs/spa -mH
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ ADDR NAME
64.0MB: 0
128.0MB: 0
256.0MB: 15 ***************
Approx. Median: 384.0MB
Approx. Median: 192.0MB
ADDR STATE AUX DESCRIPTION
------------------------------------------------------------
0xffffa089486fc000 HEALTHY NONE root
Expand All @@ -50,7 +50,7 @@ ADDR NAME
64.0MB: 0
128.0MB: 0
256.0MB: 15 ***************
Approx. Median: 384.0MB
Approx. Median: 192.0MB
ADDR ID OFFSET FREE FRAG UCMU
-----------------------------------------------------------------
0xffffa0894e6e1000 0 0x0 511MB 0% 8KB
Expand All @@ -76,7 +76,7 @@ ADDR NAME
64.0MB: 0
128.0MB: 0
256.0MB: 1 *
Approx. Median: 384.0MB
Approx. Median: 192.0MB
0xffffa0894e6e4000 1 0x20000000 511MB 0% 8KB
seg-size count
-------- -----
Expand All @@ -100,7 +100,7 @@ ADDR NAME
64.0MB: 0
128.0MB: 0
256.0MB: 1 *
Approx. Median: 384.0MB
Approx. Median: 192.0MB
0xffffa0894e6e2800 2 0x40000000 511MB 0% 8KB
seg-size count
-------- -----
Expand All @@ -124,7 +124,7 @@ ADDR NAME
64.0MB: 0
128.0MB: 0
256.0MB: 1 *
Approx. Median: 384.0MB
Approx. Median: 192.0MB
0xffffa0894e6e3800 3 0x60000000 511MB 0% 8KB
seg-size count
-------- -----
Expand All @@ -148,7 +148,7 @@ ADDR NAME
64.0MB: 0
128.0MB: 0
256.0MB: 1 *
Approx. Median: 384.0MB
Approx. Median: 192.0MB
0xffffa0894e6e3000 4 0x80000000 511MB 0% 8KB
seg-size count
-------- -----
Expand All @@ -172,7 +172,7 @@ ADDR NAME
64.0MB: 0
128.0MB: 0
256.0MB: 1 *
Approx. Median: 384.0MB
Approx. Median: 192.0MB
0xffffa0894e6e4800 5 0xa0000000 511MB 0% 8KB
seg-size count
-------- -----
Expand All @@ -196,7 +196,7 @@ ADDR NAME
64.0MB: 0
128.0MB: 0
256.0MB: 1 *
Approx. Median: 384.0MB
Approx. Median: 192.0MB
0xffffa0894e6e7800 6 0xc0000000 511MB 0% 4KB
seg-size count
-------- -----
Expand All @@ -220,7 +220,7 @@ ADDR NAME
64.0MB: 0
128.0MB: 0
256.0MB: 1 *
Approx. Median: 384.0MB
Approx. Median: 192.0MB
0xffffa0894e6e2000 7 0xe0000000 511MB 0% 8KB
seg-size count
-------- -----
Expand All @@ -244,7 +244,7 @@ ADDR NAME
64.0MB: 0
128.0MB: 0
256.0MB: 1 *
Approx. Median: 384.0MB
Approx. Median: 192.0MB
0xffffa0894e637800 8 0x100000000 511MB 0% 8KB
seg-size count
-------- -----
Expand All @@ -268,7 +268,7 @@ ADDR NAME
64.0MB: 0
128.0MB: 0
256.0MB: 1 *
Approx. Median: 384.0MB
Approx. Median: 192.0MB
0xffffa0894e634800 9 0x120000000 511MB 0% 4KB
seg-size count
-------- -----
Expand All @@ -291,7 +291,7 @@ ADDR NAME
64.0MB: 0
128.0MB: 0
256.0MB: 1 *
Approx. Median: 384.0MB
Approx. Median: 192.0MB
0xffffa0894e633000 10 0x140000000 511MB 0% 4KB
seg-size count
-------- -----
Expand All @@ -314,7 +314,7 @@ ADDR NAME
64.0MB: 0
128.0MB: 0
256.0MB: 1 *
Approx. Median: 384.0MB
Approx. Median: 192.0MB
0xffffa0894e633800 11 0x160000000 509MB 0% 4KB
seg-size count
-------- -----
Expand All @@ -338,7 +338,7 @@ ADDR NAME
64.0MB: 0
128.0MB: 0
256.0MB: 1 *
Approx. Median: 384.0MB
Approx. Median: 192.0MB
0xffffa0894e632800 12 0x180000000 511MB 0% 4KB
seg-size count
-------- -----
Expand All @@ -362,7 +362,7 @@ ADDR NAME
64.0MB: 0
128.0MB: 0
256.0MB: 1 *
Approx. Median: 384.0MB
Approx. Median: 192.0MB
0xffffa0894e634000 13 0x1a0000000 511MB 0% 4KB
seg-size count
-------- -----
Expand All @@ -386,7 +386,7 @@ ADDR NAME
64.0MB: 0
128.0MB: 0
256.0MB: 1 *
Approx. Median: 384.0MB
Approx. Median: 192.0MB
0xffffa0894e631000 14 0x1c0000000 511MB 0% 4KB
seg-size count
-------- -----
Expand All @@ -410,7 +410,7 @@ ADDR NAME
64.0MB: 0
128.0MB: 0
256.0MB: 1 *
Approx. Median: 384.0MB
Approx. Median: 192.0MB
0xffffa08948af8000 HEALTHY NONE /dev/sdb1
0xffffa08949ff8000 HEALTHY NONE /dev/sdc1
0xffffa08949e58000 HEALTHY NONE /dev/sdd1
Expand Down Expand Up @@ -453,7 +453,7 @@ ADDR NAME
32.0MB: 0
64.0MB: 1 *
128.0MB: 4 ****
Approx. Median: 184.0MB
Approx. Median: 92.0MB
ADDR STATE AUX DESCRIPTION
------------------------------------------------------------
0xffffa08953aa4000 HEALTHY NONE root
Expand All @@ -478,7 +478,7 @@ ADDR NAME
32.0MB: 0
64.0MB: 1 *
128.0MB: 4 ****
Approx. Median: 184.0MB
Approx. Median: 92.0MB
ADDR ID OFFSET FREE FRAG UCMU
-----------------------------------------------------------------
0xffffa0894c701000 0 0x0 256MB 0% 0B
Expand All @@ -502,7 +502,7 @@ ADDR NAME
16.0MB: 0
32.0MB: 0
64.0MB: 1 *
Approx. Median: 95.9MB
Approx. Median: 48.0MB
0xffffa0894c700800 2 0x20000000 255MB 0% 8KB
seg-size count
-------- -----
Expand All @@ -524,7 +524,7 @@ ADDR NAME
32.0MB: 0
64.0MB: 0
128.0MB: 1 *
Approx. Median: 191.9MB
Approx. Median: 96.0MB
0xffffa0894c706000 3 0x30000000 255MB 0% 8KB
seg-size count
-------- -----
Expand All @@ -546,7 +546,7 @@ ADDR NAME
32.0MB: 0
64.0MB: 0
128.0MB: 1 *
Approx. Median: 192.0MB
Approx. Median: 96.0MB
0xffffa0894c707000 4 0x40000000 223MB 0% 4KB
seg-size count
-------- -----
Expand All @@ -568,12 +568,12 @@ ADDR NAME
32.0MB: 0
64.0MB: 0
128.0MB: 1 *
Approx. Median: 192.0MB
Approx. Median: 96.0MB
0xffffa0894c706800 5 0x50000000 255MB 0% 4KB
seg-size count
-------- -----
128.0MB: 1 *
Approx. Median: 192.0MB
Approx. Median: 96.0MB
0xffffa0894c703000 6 0x60000000 256MB 0% 0B
0xffffa0894c703800 7 0x70000000 256MB 0% 0B
0xffffa0894c705000 8 0x80000000 256MB 0% 0B
Expand Down
8 changes: 4 additions & 4 deletions tests/integration/data/regression_output/zfs/spa -vH
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ ADDR NAME
64.0MB: 0
128.0MB: 0
256.0MB: 15 ***************
Approx. Median: 384.0MB
Approx. Median: 192.0MB
ADDR STATE AUX DESCRIPTION
------------------------------------------------------------
0xffffa089486fc000 HEALTHY NONE root
Expand All @@ -50,7 +50,7 @@ ADDR NAME
64.0MB: 0
128.0MB: 0
256.0MB: 15 ***************
Approx. Median: 384.0MB
Approx. Median: 192.0MB
0xffffa08948af8000 HEALTHY NONE /dev/sdb1
0xffffa08949ff8000 HEALTHY NONE /dev/sdc1
0xffffa08949e58000 HEALTHY NONE /dev/sdd1
Expand All @@ -76,7 +76,7 @@ ADDR NAME
32.0MB: 0
64.0MB: 1 *
128.0MB: 4 ****
Approx. Median: 184.0MB
Approx. Median: 92.0MB
ADDR STATE AUX DESCRIPTION
------------------------------------------------------------
0xffffa08953aa4000 HEALTHY NONE root
Expand All @@ -101,7 +101,7 @@ ADDR NAME
32.0MB: 0
64.0MB: 1 *
128.0MB: 4 ****
Approx. Median: 184.0MB
Approx. Median: 92.0MB
0xffffa08953aac000 HEALTHY NONE /tmp/dks0
0xffffa08953ab0000 HEALTHY NONE /tmp/dks1
0xffffa08953ab4000 HEALTHY NONE /tmp/dks2
Expand Down
Loading

0 comments on commit db1b967

Please sign in to comment.