From 80a4b7df2ce270034ab1d0e2346c48ea2b99d111 Mon Sep 17 00:00:00 2001 From: Zach Brown Date: Wed, 11 Oct 2017 10:37:32 -0700 Subject: [PATCH] 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 --- kmod/src/btree.c | 11 ++--------- kmod/src/format.h | 12 ++++++++++++ 2 files changed, 14 insertions(+), 9 deletions(-) diff --git a/kmod/src/btree.c b/kmod/src/btree.c index a64e6337..32421239 100644 --- a/kmod/src/btree.c +++ b/kmod/src/btree.c @@ -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); diff --git a/kmod/src/format.h b/kmod/src/format.h index 89b95ff1..9bc496b3 100644 --- a/kmod/src/format.h +++ b/kmod/src/format.h @@ -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.