]> git.ipfire.org Git - thirdparty/xfsprogs-dev.git/commitdiff
xfs_db: compute average btree height
authorDarrick J. Wong <djwong@kernel.org>
Mon, 24 Feb 2025 18:21:58 +0000 (10:21 -0800)
committerDarrick J. Wong <djwong@kernel.org>
Tue, 25 Feb 2025 17:16:00 +0000 (09:16 -0800)
Compute the btree height assuming that the blocks are 75% full.

Signed-off-by: "Darrick J. Wong" <djwong@kernel.org>
Reviewed-by: Christoph Hellwig <hch@lst.de>
db/btheight.c
man/man8/xfs_db.8

index 98165b522e4f6f9c6dc58f1faed4dd0fc9340d7e..0456af08b39edf5f432101b70381b5ef9bb29015 100644 (file)
@@ -259,6 +259,7 @@ out:
 #define REPORT_MAX     (1 << 0)
 #define REPORT_MIN     (1 << 1)
 #define REPORT_ABSMAX  (1 << 2)
+#define REPORT_AVG     (1 << 3)
 
 static void
 report_absmax(const char *tag)
@@ -317,6 +318,34 @@ _("%s: best case per %u-byte block: %u records (leaf) / %u keyptrs (node)\n"),
                calc_height(nr_records, records_per_block);
        }
 
+       if (report_what & REPORT_AVG) {
+               records_per_block[0] *= 3;
+               records_per_block[0] /= 4;
+               records_per_block[1] *= 3;
+               records_per_block[1] /= 4;
+
+               if (records_per_block[0] < 2) {
+                       fprintf(stderr,
+_("%s: cannot calculate average case scenario due to leaf geometry underflow.\n"),
+                               tag);
+                       return;
+               }
+
+               if (records_per_block[1] < 4) {
+                       fprintf(stderr,
+_("%s: cannot calculate average case scenario due to node geometry underflow.\n"),
+                               tag);
+                       return;
+               }
+
+               printf(
+_("%s: average case per %u-byte block: %u records (leaf) / %u keyptrs (node)\n"),
+                               tag, blocksize, records_per_block[0],
+                               records_per_block[1]);
+
+               calc_height(nr_records, records_per_block);
+       }
+
        if (report_what & REPORT_MIN) {
                records_per_block[0] /= 2;
                records_per_block[1] /= 2;
@@ -393,6 +422,8 @@ btheight_f(
                                report_what = REPORT_MAX;
                        else if (!strcmp(optarg, "absmax"))
                                report_what = REPORT_ABSMAX;
+                       else if (!strcmp(optarg, "avg"))
+                               report_what = REPORT_AVG;
                        else {
                                btheight_help();
                                return 0;
index 06f4464a9285968cf5658d254eba9a1688f0f785..acee900adbda505d8fe5b54c3bb195829b716d06 100644 (file)
@@ -519,7 +519,7 @@ If the cursor points at an inode, dump the extended attribute block mapping btre
 Dump all keys and pointers in intermediate btree nodes, and all records in leaf btree nodes.
 .RE
 .TP
-.BI "btheight [\-b " blksz "] [\-n " recs "] [\-w " max "|" min "|" absmax "] btree types..."
+.BI "btheight [\-b " blksz "] [\-n " recs "] [\-w " max "|" min "|" absmax "|" avg "] btree types..."
 For a given number of btree records and a btree type, report the number of
 records and blocks for each level of the btree, and the total number of blocks.
 The btree type must be given after the options.
@@ -562,6 +562,10 @@ maximally loaded.
 .B \-w min
 shows only the worst case scenario, which is when the btree blocks are
 half full.
+.TP
+.B \-w avg
+shows only the average case scenario, which is when the btree blocks are
+three quarters full.
 .RE
 .TP
 .BI "convert " "type number" " [" "type number" "] ... " type