aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorJohn Naylor <john.naylor@postgresql.org>2024-12-20 14:48:24 +0700
committerJohn Naylor <john.naylor@postgresql.org>2025-01-06 13:26:02 +0700
commit3e70da2781e86d07cd88f568ebeb38ddf7da8e8e (patch)
treed6805cf826387f42171b6aa16fe7a24126bec531 /src
parente8a6f1f908d03b836c8b5379b449346ad32c1ba1 (diff)
downloadpostgresql-3e70da2781e86d07cd88f568ebeb38ddf7da8e8e.tar.gz
postgresql-3e70da2781e86d07cd88f568ebeb38ddf7da8e8e.zip
Always use the caller-provided context for radix tree leaves
Previously, it would not have worked for a caller to pass a slab context, since it would have been used for other things which likely had incompatible size. In an attempt to be helpful and avoid possible space wastage due to aset's power-of-two rounding, RT_CREATE would create an additional slab context if the value type was fixed-length and larger than pointer size. The problem was, we have since added the bump context type, and the generation context was a possibility as well, so silently overriding the caller's choice may actually be worse. Commit e8a6f1f908d arranged so that the caller-provided context is used only for leaves, so it's safe for the caller to use slab here if they wish. As demonstration, use slab in one of the radix tree regression tests. Reviewed by Masahiko Sawada Discussion: https://postgr.es/m/CANWCAZZDCo4k5oURg_pPxM6+WZ1oiG=sqgjmQiELuyP0Vtrwig@mail.gmail.com
Diffstat (limited to 'src')
-rw-r--r--src/include/lib/radixtree.h14
-rw-r--r--src/test/modules/test_radixtree/test_radixtree.c7
2 files changed, 4 insertions, 17 deletions
diff --git a/src/include/lib/radixtree.h b/src/include/lib/radixtree.h
index c80817da554..f0abb0df389 100644
--- a/src/include/lib/radixtree.h
+++ b/src/include/lib/radixtree.h
@@ -1849,21 +1849,7 @@ RT_CREATE(MemoryContext ctx)
size_class.allocsize);
}
- /* By default we use the passed context for leaves. */
tree->leaf_context = ctx;
-
-#ifndef RT_VARLEN_VALUE_SIZE
-
- /*
- * For leaves storing fixed-length values, we use a slab context to avoid
- * the possibility of space wastage by power-of-2 rounding up.
- */
- if (sizeof(RT_VALUE_TYPE) > sizeof(RT_PTR_ALLOC))
- tree->leaf_context = SlabContextCreate(ctx,
- RT_STR(RT_PREFIX) "_radix_tree leaf context",
- RT_SLAB_BLOCK_SIZE(sizeof(RT_VALUE_TYPE)),
- sizeof(RT_VALUE_TYPE));
-#endif /* !RT_VARLEN_VALUE_SIZE */
#endif /* RT_SHMEM */
/* add root node now so that RT_SET can assume it exists */
diff --git a/src/test/modules/test_radixtree/test_radixtree.c b/src/test/modules/test_radixtree/test_radixtree.c
index f682bdeaa20..32de6a3123e 100644
--- a/src/test/modules/test_radixtree/test_radixtree.c
+++ b/src/test/modules/test_radixtree/test_radixtree.c
@@ -313,9 +313,10 @@ test_random(void)
#else
MemoryContext radixtree_ctx;
- radixtree_ctx = AllocSetContextCreate(CurrentMemoryContext,
- "test_radix_tree",
- ALLOCSET_SMALL_SIZES);
+ radixtree_ctx = SlabContextCreate(CurrentMemoryContext,
+ "test_radix_tree",
+ SLAB_DEFAULT_BLOCK_SIZE,
+ sizeof(TestValueType));
radixtree = rt_create(radixtree_ctx);
#endif