Skip to content

Commit 960013f

Browse files
committed
Use caller's memory context for radix tree iteration state
Typically only one iterator is present at any time, so it's overkill to devote an entire context for this. Get rid of it and use the caller's context. This is tidy-up work, so no backpatch in this form. However, a hypothetical extension to v17 that tried to start iteration from an attaching backend would result in a crash, so that'll be fixed separately in a way that doesn't change behavior in core. Patch by me, reported and reviewed by Masahiko Sawada Discussion: https://postgr.es/m/CAD21AoBB2U47V=F+wQRB1bERov_of5=BOZGaybjaV8FLQyqG3Q@mail.gmail.com
1 parent 9a8313d commit 960013f

File tree

1 file changed

+3
-12
lines changed

1 file changed

+3
-12
lines changed

src/include/lib/radixtree.h

Lines changed: 3 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -719,7 +719,6 @@ struct RT_RADIX_TREE
719719
/* leaf_context is used only for single-value leaves */
720720
MemoryContextData *leaf_context;
721721
#endif
722-
MemoryContextData *iter_context;
723722
};
724723

725724
/*
@@ -1836,14 +1835,6 @@ RT_CREATE(MemoryContext ctx)
18361835
tree = (RT_RADIX_TREE *) palloc0(sizeof(RT_RADIX_TREE));
18371836
tree->context = ctx;
18381837

1839-
/*
1840-
* Separate context for iteration in case the tree context doesn't support
1841-
* pfree
1842-
*/
1843-
tree->iter_context = AllocSetContextCreate(ctx,
1844-
RT_STR(RT_PREFIX) "_radix_tree iter context",
1845-
ALLOCSET_SMALL_SIZES);
1846-
18471838
#ifdef RT_SHMEM
18481839
tree->dsa = dsa;
18491840
dp = dsa_allocate0(dsa, sizeof(RT_RADIX_TREE_CONTROL));
@@ -2075,7 +2066,8 @@ RT_FREE(RT_RADIX_TREE * tree)
20752066
/***************** ITERATION *****************/
20762067

20772068
/*
2078-
* Create and return the iterator for the given radix tree.
2069+
* Create and return an iterator for the given radix tree
2070+
* in the caller's memory context.
20792071
*
20802072
* Taking a lock in shared mode during the iteration is the caller's
20812073
* responsibility.
@@ -2086,8 +2078,7 @@ RT_BEGIN_ITERATE(RT_RADIX_TREE * tree)
20862078
RT_ITER *iter;
20872079
RT_CHILD_PTR root;
20882080

2089-
iter = (RT_ITER *) MemoryContextAllocZero(tree->iter_context,
2090-
sizeof(RT_ITER));
2081+
iter = (RT_ITER *) palloc0(sizeof(RT_ITER));
20912082
iter->tree = tree;
20922083

20932084
Assert(RT_PTR_ALLOC_IS_VALID(tree->ctl->root));

0 commit comments

Comments
 (0)