From: Darrick J. Wong Date: Mon, 24 Feb 2025 18:21:58 +0000 (-0800) Subject: xfs_db: compute average btree height X-Git-Tag: v6.14.0~84 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=4b8d71bef9ee43316bf57b9d2b02e0c067b0d233;p=thirdparty%2Fxfsprogs-dev.git xfs_db: compute average btree height Compute the btree height assuming that the blocks are 75% full. Signed-off-by: "Darrick J. Wong" Reviewed-by: Christoph Hellwig --- diff --git a/db/btheight.c b/db/btheight.c index 98165b52..0456af08 100644 --- a/db/btheight.c +++ b/db/btheight.c @@ -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; diff --git a/man/man8/xfs_db.8 b/man/man8/xfs_db.8 index 06f4464a..acee900a 100644 --- a/man/man8/xfs_db.8 +++ b/man/man8/xfs_db.8 @@ -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