scoutfs: ensure btree values end on 8-byte-alignment boundary

Round val_len up to BTREE_VALUE_ALIGN (8), to keep mid_free_len aligned.

Signed-off-by: Andy Grover <agrover@versity.com>
This commit is contained in:
Andy Grover
2020-10-14 09:23:50 -07:00
committed by Zach Brown
parent 68d7a2e2cb
commit 5e1c8586cc
2 changed files with 9 additions and 2 deletions

View File

@@ -88,7 +88,7 @@ enum {
/* total length of the value payload */
static inline unsigned int val_bytes(unsigned val_len)
{
return val_len;
return round_up(val_len, SCOUTFS_BTREE_VALUE_ALIGN);
}
/* number of bytes in a block used by an item with the given value length */
@@ -1024,6 +1024,8 @@ static void verify_btree_block(struct super_block *sb,
goto out;
}
BUILD_BUG_ON(SCOUTFS_BTREE_LEAF_ITEM_HASH_BYTES % SCOUTFS_BTREE_VALUE_ALIGN != 0);
end_off = SCOUTFS_BLOCK_LG_SIZE -
(level ? 0 : SCOUTFS_BTREE_LEAF_ITEM_HASH_BYTES);

View File

@@ -234,14 +234,19 @@ struct scoutfs_btree_block {
/* leaf blocks have a fixed size item offset hash table at the end */
} __packed;
#define SCOUTFS_BTREE_VALUE_ALIGN 8
/*
* Try to aim for a 75% load in a leaf full of items with no value.
* We'll almost never see this because most items have values and most
* blocks aren't full.
*/
#define SCOUTFS_BTREE_LEAF_ITEM_HASH_NR \
#define SCOUTFS_BTREE_LEAF_ITEM_HASH_NR_UNALIGNED \
((SCOUTFS_BLOCK_LG_SIZE - sizeof(struct scoutfs_btree_block)) / \
(sizeof(struct scoutfs_btree_item) + (sizeof(__le16))) * 100 / 75)
#define SCOUTFS_BTREE_LEAF_ITEM_HASH_NR \
(round_up(SCOUTFS_BTREE_LEAF_ITEM_HASH_NR_UNALIGNED, \
SCOUTFS_BTREE_VALUE_ALIGN))
#define SCOUTFS_BTREE_LEAF_ITEM_HASH_BYTES \
(SCOUTFS_BTREE_LEAF_ITEM_HASH_NR * sizeof(__le16))