You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cloudberry.apache.org by yj...@apache.org on 2025/01/20 04:03:05 UTC

(cloudberry) 08/25: Make slabs and generations use gp_malloc|free

This is an automated email from the ASF dual-hosted git repository.

yjhjstz pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/cloudberry.git

commit 65209eb38308e2e8b4908f2c1a3cfdbb13a71047
Author: Soumyadeep Chakraborty <so...@gmail.com>
AuthorDate: Tue Aug 15 13:43:33 2023 -0700

    Make slabs and generations use gp_malloc|free
    
    We need to call gp_malloc|free() for the newly added MemoryContext types
    instead of malloc|free(), so that we can get the VMEM reservation etc.
    
    This was missed during the 12 merge.
    
    Reviewed-by: Brent Doil <bd...@vmware.com>
---
 src/backend/utils/mmgr/generation.c | 14 +++++++-------
 src/backend/utils/mmgr/slab.c       | 12 +++++++-----
 2 files changed, 14 insertions(+), 12 deletions(-)

diff --git a/src/backend/utils/mmgr/generation.c b/src/backend/utils/mmgr/generation.c
index c5b58209dd..9662f52069 100644
--- a/src/backend/utils/mmgr/generation.c
+++ b/src/backend/utils/mmgr/generation.c
@@ -39,10 +39,10 @@
 #include "postgres.h"
 
 #include "lib/ilist.h"
+#include "utils/gp_alloc.h"
 #include "utils/memdebug.h"
 #include "utils/memutils.h"
 
-
 #define Generation_BLOCKHDRSZ	MAXALIGN(sizeof(GenerationBlock))
 #define Generation_CHUNKHDRSZ	sizeof(GenerationChunk)
 
@@ -225,7 +225,7 @@ GenerationContextCreate(MemoryContext parent,
 	 * freeing the first generation of allocations.
 	 */
 
-	set = (GenerationContext *) malloc(MAXALIGN(sizeof(GenerationContext)));
+	set = (GenerationContext *) gp_malloc(MAXALIGN(sizeof(GenerationContext)));
 	if (set == NULL)
 	{
 		MemoryContextStats(TopMemoryContext);
@@ -288,7 +288,7 @@ GenerationReset(MemoryContext context)
 		wipe_mem(block, block->blksize);
 #endif
 
-		free(block);
+		gp_free(block);
 	}
 
 	set->block = NULL;
@@ -306,7 +306,7 @@ GenerationDelete(MemoryContext context, MemoryContext parent)
 	/* Reset to release all the GenerationBlocks */
 	GenerationReset(context);
 	/* And free the context header */
-	free(context);
+	gp_free(context);
 }
 
 /*
@@ -335,7 +335,7 @@ GenerationAlloc(MemoryContext context, Size size)
 	{
 		Size		blksize = chunk_size + Generation_BLOCKHDRSZ + Generation_CHUNKHDRSZ;
 
-		block = (GenerationBlock *) malloc(blksize);
+		block = (GenerationBlock *) gp_malloc(blksize);
 		if (block == NULL)
 			return NULL;
 
@@ -389,7 +389,7 @@ GenerationAlloc(MemoryContext context, Size size)
 	{
 		Size		blksize = set->blockSize;
 
-		block = (GenerationBlock *) malloc(blksize);
+		block = (GenerationBlock *) gp_malloc(blksize);
 
 		if (block == NULL)
 			return NULL;
@@ -510,7 +510,7 @@ GenerationFree(MemoryContext context, void *pointer)
 		set->block = NULL;
 
 	context->mem_allocated -= block->blksize;
-	free(block);
+	gp_free(block);
 }
 
 /*
diff --git a/src/backend/utils/mmgr/slab.c b/src/backend/utils/mmgr/slab.c
index f553e567f8..afe7a39425 100644
--- a/src/backend/utils/mmgr/slab.c
+++ b/src/backend/utils/mmgr/slab.c
@@ -56,6 +56,8 @@
 #include "lib/ilist.h"
 #include "utils/memdebug.h"
 #include "utils/memutils.h"
+#include "utils/gp_alloc.h"
+#include "lib/ilist.h"
 
 /*
  * SlabContext is a specialized implementation of MemoryContext.
@@ -232,7 +234,7 @@ SlabContextCreate(MemoryContext parent,
 	headerSize += chunksPerBlock * sizeof(bool);
 #endif
 
-	slab = (SlabContext *) malloc(headerSize);
+	slab = (SlabContext *) gp_malloc(headerSize);
 	if (slab == NULL)
 	{
 		MemoryContextStats(TopMemoryContext);
@@ -311,7 +313,7 @@ SlabReset(MemoryContext context)
 #ifdef CLOBBER_FREED_MEMORY
 			wipe_mem(block, slab->blockSize);
 #endif
-			free(block);
+			gp_free(block);
 			slab->nblocks--;
 			context->mem_allocated -= slab->blockSize;
 		}
@@ -333,7 +335,7 @@ SlabDelete(MemoryContext context, MemoryContext parent)
 	/* Reset to release all the SlabBlocks */
 	SlabReset(context);
 	/* And free the context header */
-	free(context);
+	gp_free(context);
 }
 
 /*
@@ -368,7 +370,7 @@ SlabAlloc(MemoryContext context, Size size)
 	 */
 	if (slab->minFreeChunks == 0)
 	{
-		block = (SlabBlock *) malloc(slab->blockSize);
+		block = (SlabBlock *) gp_malloc(slab->blockSize);
 
 		if (block == NULL)
 			return NULL;
@@ -563,7 +565,7 @@ SlabFree(MemoryContext context, void *pointer)
 	/* If the block is now completely empty, free it. */
 	if (block->nfree == slab->chunksPerBlock)
 	{
-		free(block);
+		gp_free(block);
 		slab->nblocks--;
 		context->mem_allocated -= slab->blockSize;
 	}


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@cloudberry.apache.org
For additional commands, e-mail: commits-help@cloudberry.apache.org