aboutsummaryrefslogtreecommitdiff
path: root/src/backend/access
diff options
context:
space:
mode:
authorJohn Naylor <john.naylor@postgresql.org>2024-12-20 13:04:18 +0700
committerJohn Naylor <john.naylor@postgresql.org>2025-01-06 11:21:21 +0700
commite8a6f1f908d03b836c8b5379b449346ad32c1ba1 (patch)
tree56157ad37ff6fc3c4598ecc263040208473cdeec /src/backend/access
parent960013f2a1f9e51aad85c91aceeb442508be6032 (diff)
downloadpostgresql-e8a6f1f908d03b836c8b5379b449346ad32c1ba1.tar.gz
postgresql-e8a6f1f908d03b836c8b5379b449346ad32c1ba1.zip
Get rid of radix tree's general purpose memory context
Previously, this was notionally used only for the entry point of the tree and as a convenient parent for other contexts. For shared memory, the creator previously allocated the entry point in this context, but attaching backends didn't have access to that, so they just used the caller's context. For the sake of consistency, allocate every instance of an entry point in the caller's context. For local memory, allocate the control object in the caller's context as well. This commit also makes the "leaf context" the notional parent of the child contexts used for nodes, so it's a bit of a misnomer, but a future commit will make the node contexts independent rather than children, so leave it this way for now to avoid code churn. The memory context parameter for RT_CREATE is now unused in the case of shared memory, so remove it and adjust callers to match. In passing, remove unused "context" member from struct TidStore, which seems to have been an oversight. Reviewed by Masahiko Sawada Discussion: https://postgr.es/m/CANWCAZZDCo4k5oURg_pPxM6+WZ1oiG=sqgjmQiELuyP0Vtrwig@mail.gmail.com
Diffstat (limited to 'src/backend/access')
-rw-r--r--src/backend/access/common/tidstore.c26
1 files changed, 9 insertions, 17 deletions
diff --git a/src/backend/access/common/tidstore.c b/src/backend/access/common/tidstore.c
index 27f20cf1972..5bd75fb499c 100644
--- a/src/backend/access/common/tidstore.c
+++ b/src/backend/access/common/tidstore.c
@@ -113,10 +113,10 @@ typedef struct BlocktableEntry
/* Per-backend state for a TidStore */
struct TidStore
{
- /* MemoryContext where the TidStore is allocated */
- MemoryContext context;
-
- /* MemoryContext that the radix tree uses */
+ /*
+ * MemoryContext for the radix tree when using local memory, NULL for
+ * shared memory
+ */
MemoryContext rt_context;
/* Storage for TIDs. Use either one depending on TidStoreIsShared() */
@@ -167,7 +167,6 @@ TidStoreCreateLocal(size_t max_bytes, bool insert_only)
size_t maxBlockSize = ALLOCSET_DEFAULT_MAXSIZE;
ts = palloc0(sizeof(TidStore));
- ts->context = CurrentMemoryContext;
/* choose the maxBlockSize to be no larger than 1/16 of max_bytes */
while (16 * maxBlockSize > max_bytes)
@@ -201,8 +200,7 @@ TidStoreCreateLocal(size_t max_bytes, bool insert_only)
/*
* Similar to TidStoreCreateLocal() but create a shared TidStore on a
- * DSA area. The TID storage will live in the DSA area, and the memory
- * context rt_context will have only meta data of the radix tree.
+ * DSA area.
*
* The returned object is allocated in backend-local memory.
*/
@@ -215,11 +213,6 @@ TidStoreCreateShared(size_t max_bytes, int tranche_id)
size_t dsa_max_size = DSA_MAX_SEGMENT_SIZE;
ts = palloc0(sizeof(TidStore));
- ts->context = CurrentMemoryContext;
-
- ts->rt_context = AllocSetContextCreate(CurrentMemoryContext,
- "TID storage meta data",
- ALLOCSET_SMALL_SIZES);
/*
* Choose the initial and maximum DSA segment sizes to be no longer than
@@ -235,8 +228,7 @@ TidStoreCreateShared(size_t max_bytes, int tranche_id)
dsa_init_size = dsa_max_size;
area = dsa_create_ext(tranche_id, dsa_init_size, dsa_max_size);
- ts->tree.shared = shared_ts_create(ts->rt_context, area,
- tranche_id);
+ ts->tree.shared = shared_ts_create(area, tranche_id);
ts->area = area;
return ts;
@@ -328,13 +320,13 @@ TidStoreDestroy(TidStore *ts)
if (TidStoreIsShared(ts))
{
shared_ts_free(ts->tree.shared);
-
dsa_detach(ts->area);
}
else
+ {
local_ts_free(ts->tree.local);
-
- MemoryContextDelete(ts->rt_context);
+ MemoryContextDelete(ts->rt_context);
+ }
pfree(ts);
}