1
0
mirror of https://github.com/postgres/postgres.git synced 2025-11-24 00:23:06 +03:00

Revert "Specialize MemoryContextMemAllocated()."

This reverts commit e00912e11a.
This commit is contained in:
Jeff Davis
2020-03-19 11:20:39 -07:00
parent 2247a1ea5f
commit 2fd6a44ad5
5 changed files with 28 additions and 77 deletions

View File

@@ -67,7 +67,6 @@ typedef struct SlabContext
Size fullChunkSize; /* chunk size including header and alignment */
Size blockSize; /* block size */
Size headerSize; /* allocated size of context header */
Size memAllocated; /* track memory allocated for this context */
int chunksPerBlock; /* number of chunks per block */
int minFreeChunks; /* min number of free chunks in any block */
int nblocks; /* number of blocks allocated */
@@ -133,7 +132,6 @@ static void *SlabRealloc(MemoryContext context, void *pointer, Size size);
static void SlabReset(MemoryContext context);
static void SlabDelete(MemoryContext context);
static Size SlabGetChunkSpace(MemoryContext context, void *pointer);
static Size SlabMemAllocated(MemoryContext context);
static bool SlabIsEmpty(MemoryContext context);
static void SlabStats(MemoryContext context,
MemoryStatsPrintFunc printfunc, void *passthru,
@@ -152,7 +150,6 @@ static const MemoryContextMethods SlabMethods = {
SlabReset,
SlabDelete,
SlabGetChunkSpace,
SlabMemAllocated,
SlabIsEmpty,
SlabStats
#ifdef MEMORY_CONTEXT_CHECKING
@@ -265,7 +262,6 @@ SlabContextCreate(MemoryContext parent,
slab->fullChunkSize = fullChunkSize;
slab->blockSize = blockSize;
slab->headerSize = headerSize;
slab->memAllocated = 0;
slab->chunksPerBlock = chunksPerBlock;
slab->minFreeChunks = 0;
slab->nblocks = 0;
@@ -290,17 +286,6 @@ SlabContextCreate(MemoryContext parent,
return (MemoryContext) slab;
}
/*
* All memory currently allocated for this context (including fragmentation
* and freed chunks).
*/
static Size
SlabMemAllocated(MemoryContext context)
{
SlabContext *slab = (SlabContext *) context;
return slab->memAllocated;
}
/*
* SlabReset
* Frees all memory which is allocated in the given set.
@@ -337,14 +322,14 @@ SlabReset(MemoryContext context)
#endif
free(block);
slab->nblocks--;
slab->memAllocated -= slab->blockSize;
context->mem_allocated -= slab->blockSize;
}
}
slab->minFreeChunks = 0;
Assert(slab->nblocks == 0);
Assert(slab->memAllocated == 0);
Assert(context->mem_allocated == 0);
}
/*
@@ -422,7 +407,7 @@ SlabAlloc(MemoryContext context, Size size)
slab->minFreeChunks = slab->chunksPerBlock;
slab->nblocks += 1;
slab->memAllocated += slab->blockSize;
context->mem_allocated += slab->blockSize;
}
/* grab the block from the freelist (even the new block is there) */
@@ -516,7 +501,7 @@ SlabAlloc(MemoryContext context, Size size)
SlabAllocInfo(slab, chunk);
Assert(slab->nblocks * slab->blockSize == slab->memAllocated);
Assert(slab->nblocks * slab->blockSize == context->mem_allocated);
return SlabChunkGetPointer(chunk);
}
@@ -593,13 +578,13 @@ SlabFree(MemoryContext context, void *pointer)
{
free(block);
slab->nblocks--;
slab->memAllocated -= slab->blockSize;
context->mem_allocated -= slab->blockSize;
}
else
dlist_push_head(&slab->freelist[block->nfree], &block->node);
Assert(slab->nblocks >= 0);
Assert(slab->nblocks * slab->blockSize == slab->memAllocated);
Assert(slab->nblocks * slab->blockSize == context->mem_allocated);
}
/*
@@ -819,7 +804,7 @@ SlabCheck(MemoryContext context)
}
}
Assert(slab->nblocks * slab->blockSize == slab->memAllocated);
Assert(slab->nblocks * slab->blockSize == context->mem_allocated);
}
#endif /* MEMORY_CONTEXT_CHECKING */