From 79616ca27e945afe73d4f8e69216d364972b361e Mon Sep 17 00:00:00 2001 From: John Naylor Date: Fri, 19 Jan 2024 18:08:04 +0700 Subject: [PATCH v51] Put shared radix tree for tidstore in its own translation unit The point is to test global functions with the template, but it could be useful for keeping related code together in cache. --- src/backend/access/common/meson.build | 1 + src/backend/access/common/tidstore.c | 23 ++----------------- src/backend/access/common/tidstore_internal.h | 23 +++++++++++++++++++ src/backend/access/common/tidstore_shmem.c | 16 +++++++++++++ src/include/lib/radixtree.h | 1 + 5 files changed, 43 insertions(+), 21 deletions(-) create mode 100644 src/backend/access/common/tidstore_internal.h create mode 100644 src/backend/access/common/tidstore_shmem.c diff --git a/src/backend/access/common/meson.build b/src/backend/access/common/meson.build index a02397855e..32caa148de 100644 --- a/src/backend/access/common/meson.build +++ b/src/backend/access/common/meson.build @@ -16,6 +16,7 @@ backend_sources += files( 'toast_compression.c', 'toast_internals.c', 'tidstore.c', + 'tidstore_shmem.c', 'tupconvert.c', 'tupdesc.c', ) diff --git a/src/backend/access/common/tidstore.c b/src/backend/access/common/tidstore.c index 272910f77e..0c1ae8d305 100644 --- a/src/backend/access/common/tidstore.c +++ b/src/backend/access/common/tidstore.c @@ -21,9 +21,10 @@ */ #include "postgres.h" +#include "tidstore_internal.h" + #include "access/tidstore.h" #include "miscadmin.h" -#include "nodes/bitmapset.h" #include "port/pg_bitutils.h" #include "storage/lwlock.h" #include "utils/dsa.h" @@ -33,18 +34,6 @@ #define WORDNUM(x) ((x) / BITS_PER_BITMAPWORD) #define BITNUM(x) ((x) % BITS_PER_BITMAPWORD) -/* number of active words for a page: */ -#define WORDS_PER_PAGE(n) ((n) / BITS_PER_BITMAPWORD + 1) - -typedef struct BlocktableEntry -{ - uint16 nwords; - bitmapword words[FLEXIBLE_ARRAY_MEMBER]; -} BlocktableEntry; -#define MaxBlocktableEntrySize \ - offsetof(BlocktableEntry, words) + \ - (sizeof(bitmapword) * WORDS_PER_PAGE(MaxOffsetNumber)) - /* A magic value used to identify our TidStores. */ #define TIDSTORE_MAGIC 0x826f6a10 @@ -56,14 +45,6 @@ typedef struct BlocktableEntry #define RT_VARLEN_VALUE #include "lib/radixtree.h" -#define RT_PREFIX shared_rt -#define RT_SHMEM -#define RT_SCOPE static -#define RT_DECLARE -#define RT_DEFINE -#define RT_VALUE_TYPE BlocktableEntry -#define RT_VARLEN_VALUE -#include "lib/radixtree.h" /* The control object for a TidStore */ typedef struct TidStoreControl diff --git a/src/backend/access/common/tidstore_internal.h b/src/backend/access/common/tidstore_internal.h new file mode 100644 index 0000000000..abb2f46b37 --- /dev/null +++ b/src/backend/access/common/tidstore_internal.h @@ -0,0 +1,23 @@ +#include "nodes/bitmapset.h" + +/* number of active words for a page: */ +#define WORDS_PER_PAGE(n) ((n) / BITS_PER_BITMAPWORD + 1) + +typedef struct BlocktableEntry +{ + uint16 nwords; + bitmapword words[FLEXIBLE_ARRAY_MEMBER]; +} BlocktableEntry; +#define MaxBlocktableEntrySize \ + offsetof(BlocktableEntry, words) + \ + (sizeof(bitmapword) * WORDS_PER_PAGE(MaxOffsetNumber)) + + +#define RT_PREFIX shared_rt +#define RT_SHMEM +#define RT_SCOPE extern +#define RT_DECLARE +#define RT_VALUE_TYPE BlocktableEntry +#define RT_VARLEN_VALUE +#include "lib/radixtree.h" + diff --git a/src/backend/access/common/tidstore_shmem.c b/src/backend/access/common/tidstore_shmem.c new file mode 100644 index 0000000000..50bd422b41 --- /dev/null +++ b/src/backend/access/common/tidstore_shmem.c @@ -0,0 +1,16 @@ +#include "postgres.h" + +#include "tidstore_internal.h" + +#include "storage/lwlock.h" +#include "utils/dsa.h" + + +#define RT_PREFIX shared_rt +#define RT_SHMEM +#define RT_SCOPE extern +#define RT_DEFINE +#define RT_VALUE_TYPE BlocktableEntry +#define RT_VARLEN_VALUE +#include "lib/radixtree.h" + diff --git a/src/include/lib/radixtree.h b/src/include/lib/radixtree.h index aca9984ecb..90152496c9 100644 --- a/src/include/lib/radixtree.h +++ b/src/include/lib/radixtree.h @@ -2817,6 +2817,7 @@ RT_DUMP_NODE(RT_NODE * node) /* undefine external parameters, so next radix tree can be defined */ #undef RT_PREFIX +#undef RT_SHMEM #undef RT_SCOPE #undef RT_DECLARE #undef RT_DEFINE -- 2.43.0