1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53
|
commit f716536100e86bb410341daf3f84cf23f4e3adc2
Author: Lukas Fittl <lukas@fittl.com>
Date: Sat Jan 9 23:42:42 2021 -0800
Add AllocSetDeleteFreeList to clean up aset.c's freelist
This frees up the memory allocated to memory contexts that are kept
for future allocations. This behaves similar to changing aset.c's
MAX_FREE_CONTEXTS to 0, but only does the cleanup when called, and
allows the freelist approach to be used during Postgres operations.
diff --git a/src/backend/utils/mmgr/aset.c b/src/backend/utils/mmgr/aset.c
index dede30dd86..16306c3216 100644
--- a/src/backend/utils/mmgr/aset.c
+++ b/src/backend/utils/mmgr/aset.c
@@ -1722,3 +1722,25 @@ AllocSetCheck(MemoryContext context)
}
#endif /* MEMORY_CONTEXT_CHECKING */
+
+void
+AllocSetDeleteFreeList(MemoryContext context)
+{
+ AllocSet set = (AllocSet) context;
+ if (set->freeListIndex >= 0)
+ {
+ AllocSetFreeList *freelist = &context_freelists[set->freeListIndex];
+
+ while (freelist->first_free != NULL)
+ {
+ AllocSetContext *oldset = freelist->first_free;
+
+ freelist->first_free = (AllocSetContext *) oldset->header.nextchild;
+ freelist->num_free--;
+
+ /* All that remains is to free the header/initial block */
+ free(oldset);
+ }
+ Assert(freelist->num_free == 0);
+ }
+}
diff --git a/src/include/utils/memutils.h b/src/include/utils/memutils.h
index cd9596ff21..fac1271673 100644
--- a/src/include/utils/memutils.h
+++ b/src/include/utils/memutils.h
@@ -114,6 +114,7 @@ extern MemoryContext AllocSetContextCreateInternal(MemoryContext parent,
Size minContextSize,
Size initBlockSize,
Size maxBlockSize);
+extern void AllocSetDeleteFreeList(MemoryContext context);
/*
* This wrapper macro exists to check for non-constant strings used as context
|