mirror of
https://github.com/versity/scoutfs.git
synced 2026-01-08 04:55:21 +00:00
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:
@@ -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);
|
||||
|
||||
|
||||
@@ -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))
|
||||
|
||||
|
||||
Reference in New Issue
Block a user