Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit 3e70da2

Browse files
committed
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 e8a6f1f 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
1 parent e8a6f1f commit 3e70da2

File tree

2 files changed

+4
-17
lines changed

2 files changed

+4
-17
lines changed

src/include/lib/radixtree.h

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1849,21 +1849,7 @@ RT_CREATE(MemoryContext ctx)
18491849
size_class.allocsize);
18501850
}
18511851

1852-
/* By default we use the passed context for leaves. */
18531852
tree->leaf_context = ctx;
1854-
1855-
#ifndef RT_VARLEN_VALUE_SIZE
1856-
1857-
/*
1858-
* For leaves storing fixed-length values, we use a slab context to avoid
1859-
* the possibility of space wastage by power-of-2 rounding up.
1860-
*/
1861-
if (sizeof(RT_VALUE_TYPE) > sizeof(RT_PTR_ALLOC))
1862-
tree->leaf_context = SlabContextCreate(ctx,
1863-
RT_STR(RT_PREFIX) "_radix_tree leaf context",
1864-
RT_SLAB_BLOCK_SIZE(sizeof(RT_VALUE_TYPE)),
1865-
sizeof(RT_VALUE_TYPE));
1866-
#endif /* !RT_VARLEN_VALUE_SIZE */
18671853
#endif /* RT_SHMEM */
18681854

18691855
/* add root node now so that RT_SET can assume it exists */

src/test/modules/test_radixtree/test_radixtree.c

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -313,9 +313,10 @@ test_random(void)
313313
#else
314314
MemoryContext radixtree_ctx;
315315

316-
radixtree_ctx = AllocSetContextCreate(CurrentMemoryContext,
317-
"test_radix_tree",
318-
ALLOCSET_SMALL_SIZES);
316+
radixtree_ctx = SlabContextCreate(CurrentMemoryContext,
317+
"test_radix_tree",
318+
SLAB_DEFAULT_BLOCK_SIZE,
319+
sizeof(TestValueType));
319320
radixtree = rt_create(radixtree_ctx);
320321
#endif
321322

0 commit comments

Comments
 (0)