scoutfs: move btree parent min to format.h

mkfs needs to know the size of the largest btree when figuring out how
big to make the ring.  It needs to know how few items we can have in
parent blocks and to know that it needs to know how empty the blocks can
get.

Signed-off-by: Zach Brown <zab@versity.com>
This commit is contained in:
Zach Brown
2017-10-11 10:37:32 -07:00
committed by Mark Fasheh
parent 8bbb859f0c
commit 80a4b7df2c
2 changed files with 14 additions and 9 deletions

View File

@@ -169,13 +169,6 @@ static inline unsigned int all_len_bytes(unsigned key_len, unsigned val_len)
len_bytes(key_len, val_len);
}
/* number of bytes needed to insert potentially max size child item */
static inline unsigned int parent_min_free_bytes(void)
{
return all_len_bytes(SCOUTFS_BTREE_MAX_KEY_LEN,
sizeof(struct scoutfs_btree_ref));
}
/*
* The minimum number of bytes we allow in a block. During descent to
* modify if we see a block with fewer used bytes then we'll try to
@@ -196,7 +189,7 @@ static inline unsigned int parent_min_free_bytes(void)
static inline unsigned int min_used_bytes(void)
{
return (SCOUTFS_BLOCK_SIZE - sizeof(struct scoutfs_btree_block) -
parent_min_free_bytes()) / 2;
SCOUTFS_BTREE_PARENT_MIN_FREE_BYTES) / 2;
}
/* total block bytes used by an existing item */
@@ -986,7 +979,7 @@ static int try_split(struct super_block *sb, struct scoutfs_btree_root *root,
int ret;
if (right->level)
all_bytes = parent_min_free_bytes();
all_bytes = SCOUTFS_BTREE_PARENT_MIN_FREE_BYTES;
else
all_bytes = all_len_bytes(key_len, val_len);

View File

@@ -60,6 +60,18 @@ 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.