scoutfs-utils: update btree ring calc

Update the calculation of the largest number of btree blocks based on
the format.h update that provides the min free space in parent blocks
instead of the free limit for the entire block.

Signed-off-by: Zach Brown <zab@versity.com>
This commit is contained in:
Zach Brown
2017-10-11 10:52:39 -07:00
committed by Mark Fasheh
parent 362fc0ab62
commit 34fc095392
2 changed files with 16 additions and 7 deletions

View File

@@ -60,16 +60,23 @@ struct scoutfs_block_header {
/* level 0 segments can have two full keys in the value :/ */
#define SCOUTFS_BTREE_MAX_VAL_LEN 768
/*
* The min number of free bytes we must leave in a parent as we descend
* to modify. This leaves enough free bytes to insert a possibly maximal
* sized key as a seperator for a child block. Fewer bytes then this
* and split/merge might try to insert a max child item in the parent
* that wouldn't fit.
*/
#define SCOUTFS_BTREE_PARENT_MIN_FREE_BYTES \
(sizeof(struct scoutfs_btree_item_header) + \
sizeof(struct scoutfs_btree_item) + SCOUTFS_BTREE_MAX_KEY_LEN +\
sizeof(struct scoutfs_btree_ref))
/*
* A 4EB test image measured a worst case height of 17. This is plenty
* generous.
*/
#define SCOUTFS_BTREE_MAX_HEIGHT 20
/* btree blocks (beyond the first) need to be at least half full */
#define SCOUTFS_BTREE_FREE_LIMIT \
((SCOUTFS_BLOCK_SIZE - sizeof(struct scoutfs_btree_block)) / 2)
#define SCOUTFS_BTREE_BITS 8
/*

View File

@@ -68,13 +68,15 @@ static u64 calc_btree_blocks(u64 nr, u64 max_key, u64 max_val)
item_bytes = sizeof(struct scoutfs_btree_item_header) +
sizeof(struct scoutfs_btree_item) +
max_key + sizeof(struct scoutfs_btree_ref);
fanout = (SCOUTFS_BLOCK_SIZE - SCOUTFS_BTREE_FREE_LIMIT) / item_bytes;
fanout = ((SCOUTFS_BLOCK_SIZE - sizeof(struct scoutfs_btree_block) -
SCOUTFS_BTREE_PARENT_MIN_FREE_BYTES) / 2) / item_bytes;
/* figure out how many items we have to store */
item_bytes = sizeof(struct scoutfs_btree_item_header) +
sizeof(struct scoutfs_btree_item) +
max_key + max_val;
block_items = (SCOUTFS_BLOCK_SIZE - SCOUTFS_BTREE_FREE_LIMIT) / item_bytes;
block_items = ((SCOUTFS_BLOCK_SIZE -
sizeof(struct scoutfs_btree_block)) / 2) / item_bytes;
leaf_blocks = DIV_ROUND_UP(nr, block_items);
/* then calc total blocks as we grow to have enough blocks for items */