]> git.proxmox.com Git - mirror_zfs.git/commitdiff
Taught zdb -bb to print metadata totals
authorRich Ercolani <214141+rincebrain@users.noreply.github.com>
Mon, 24 Apr 2023 23:55:07 +0000 (19:55 -0400)
committerGitHub <noreply@github.com>
Mon, 24 Apr 2023 23:55:07 +0000 (16:55 -0700)
People often want estimates of how much of their pool is occupied
by metadata, but they end up using lots of text processing on zdb's
output to get it.

So let's just...provide it for them.

Now, zdb -bbbs will output something like:

Blocks  LSIZE   PSIZE   ASIZE     avg    comp   %Total  Type
[...]
    68  1.06M    272K    544K      8K    4.00     0.00      L6 Total
 1.71K   212M   6.85M   13.7M      8K   30.91     0.00      L5 Total
 1.71K   212M   6.85M   13.7M      8K   30.91     0.00      L4 Total
 1.73K   214M   6.92M   13.8M      8K   30.89     0.00      L3 Total
 18.7K  2.29G    111M    221M   11.8K   21.19     0.00      L2 Total
 3.56M   454G   28.4G   56.9G   16.0K   15.97     0.19      L1 Total
  308M  36.8T   28.2T   28.6T   95.1K    1.30    99.80      L0 Total
  311M  37.3T   28.3T   28.6T   94.2K    1.32   100.00  Total
 50.4M   774G    113G    291G   5.77K    6.85     0.99  Metadata Total

Reviewed-by: Tino Reichardt <milky-zfs@mcmilk.de>
Reviewed-by: Brian Behlendorf <behlendorf1@llnl.gov>
Signed-off-by: Rich Ercolani <rincebrain@gmail.com>
Closes #14746

cmd/zdb/zdb.c

index c93ed4399afd80b5039b8a29fcfcbe5e3f8498e8..64ec3eb0028c97dcd9d1aaa1071abc7fa1d4d33d 100644 (file)
@@ -6812,12 +6812,15 @@ dump_block_stats(spa_t *spa)
 
        if (dump_opt['b'] >= 2) {
                int l, t, level;
+               char csize[32], lsize[32], psize[32], asize[32];
+               char avg[32], gang[32];
                (void) printf("\nBlocks\tLSIZE\tPSIZE\tASIZE"
                    "\t  avg\t comp\t%%Total\tType\n");
 
+               zfs_blkstat_t *mdstats = umem_zalloc(sizeof (zfs_blkstat_t),
+                   UMEM_NOFAIL);
+
                for (t = 0; t <= ZDB_OT_TOTAL; t++) {
-                       char csize[32], lsize[32], psize[32], asize[32];
-                       char avg[32], gang[32];
                        const char *typename;
 
                        /* make sure nicenum has enough space */
@@ -6860,6 +6863,15 @@ dump_block_stats(spa_t *spa)
                                if (zb->zb_asize == 0)
                                        continue;
 
+                               if (level != ZB_TOTAL && t < DMU_OT_NUMTYPES &&
+                                   (level > 0 || DMU_OT_IS_METADATA(t))) {
+                                       mdstats->zb_count += zb->zb_count;
+                                       mdstats->zb_lsize += zb->zb_lsize;
+                                       mdstats->zb_psize += zb->zb_psize;
+                                       mdstats->zb_asize += zb->zb_asize;
+                                       mdstats->zb_gangs += zb->zb_gangs;
+                               }
+
                                if (dump_opt['b'] < 3 && level != ZB_TOTAL)
                                        continue;
 
@@ -6905,6 +6917,24 @@ dump_block_stats(spa_t *spa)
                                }
                        }
                }
+               zdb_nicenum(mdstats->zb_count, csize,
+                   sizeof (csize));
+               zdb_nicenum(mdstats->zb_lsize, lsize,
+                   sizeof (lsize));
+               zdb_nicenum(mdstats->zb_psize, psize,
+                   sizeof (psize));
+               zdb_nicenum(mdstats->zb_asize, asize,
+                   sizeof (asize));
+               zdb_nicenum(mdstats->zb_asize / mdstats->zb_count, avg,
+                   sizeof (avg));
+               zdb_nicenum(mdstats->zb_gangs, gang, sizeof (gang));
+
+               (void) printf("%6s\t%5s\t%5s\t%5s\t%5s"
+                   "\t%5.2f\t%6.2f\t",
+                   csize, lsize, psize, asize, avg,
+                   (double)mdstats->zb_lsize / mdstats->zb_psize,
+                   100.0 * mdstats->zb_asize / tzb->zb_asize);
+               (void) printf("%s\n", "Metadata Total");
 
                /* Output a table summarizing block sizes in the pool */
                if (dump_opt['b'] >= 2) {