From 69e634f94ace13b1269c8ad585807fa4aa830411 Mon Sep 17 00:00:00 2001 From: Richard Fuchs Date: Wed, 19 Mar 2025 13:13:20 -0400 Subject: [PATCH] MT#55283 store metadata head pointer Put a pointer to the shard itself in the beginning of the buffer. This facilitates quick lookup. Change-Id: I0109d77e56afac3189775dd708970288f175dfe6 --- lib/bufferpool.c | 10 +++++++++- lib/bufferpool.h | 2 +- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/lib/bufferpool.c b/lib/bufferpool.c index 71fe4c05f..12b1b9435 100644 --- a/lib/bufferpool.c +++ b/lib/bufferpool.c @@ -90,9 +90,17 @@ static struct bpool_shard *bufferpool_new_shard(struct bufferpool *bp) { struct bpool_shard *ret = g_new0(__typeof(*ret), 1); ret->bp = bp; ret->buf = buf; + ret->end = buf + BUFFERPOOL_SHARD_SIZE; + + struct bpool_shard **head = buf; + *head = ret; + + static_assert(BUFFERPOOL_ALIGN(sizeof(void *)) == BUFFERPOOL_OVERHEAD, + "wrong BUFFERPOOL_OVERHEAD size"); + buf += BUFFERPOOL_ALIGN(sizeof(void *)); + ret->empty = buf; ret->head = buf; - ret->end = buf + BUFFERPOOL_SHARD_SIZE; RWLOCK_W(&bpool_shards_lock); diff --git a/lib/bufferpool.h b/lib/bufferpool.h index 4b7251039..baa56c435 100644 --- a/lib/bufferpool.h +++ b/lib/bufferpool.h @@ -7,7 +7,7 @@ #define BUFFERPOOL_ALIGN(x) (((x + BUFFERPOOL_ALIGNMENT - 1) / BUFFERPOOL_ALIGNMENT) * BUFFERPOOL_ALIGNMENT) #define BUFFERPOOL_SHARD_SIZE (1LL<<24) // 16 MB, must be a power of two -#define BUFFERPOOL_OVERHEAD (0) // storage space not available +#define BUFFERPOOL_OVERHEAD BUFFERPOOL_ALIGN(sizeof(void *)) // storage space not available #define BUFFERPOOL_BOTTOM_MASK (BUFFERPOOL_SHARD_SIZE - 1) #define BUFFERPOOL_TOP_MASK (~BUFFERPOOL_BOTTOM_MASK)