1
0
mirror of https://github.com/postgres/postgres.git synced 2025-11-19 13:42:17 +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

@@ -132,7 +132,6 @@ typedef struct AllocSetContext
Size maxBlockSize; /* maximum block size */
Size nextBlockSize; /* next block size to allocate */
Size allocChunkLimit; /* effective chunk size limit */
Size memAllocated; /* track memory allocated for this context */
AllocBlock keeper; /* keep this block over resets */
/* freelist this context could be put in, or -1 if not a candidate: */
int freeListIndex; /* index in context_freelists[], or -1 */
@@ -273,7 +272,6 @@ static void *AllocSetRealloc(MemoryContext context, void *pointer, Size size);
static void AllocSetReset(MemoryContext context);
static void AllocSetDelete(MemoryContext context);
static Size AllocSetGetChunkSpace(MemoryContext context, void *pointer);
static Size AllocSetMemAllocated(MemoryContext context);
static bool AllocSetIsEmpty(MemoryContext context);
static void AllocSetStats(MemoryContext context,
MemoryStatsPrintFunc printfunc, void *passthru,
@@ -293,7 +291,6 @@ static const MemoryContextMethods AllocSetMethods = {
AllocSetReset,
AllocSetDelete,
AllocSetGetChunkSpace,
AllocSetMemAllocated,
AllocSetIsEmpty,
AllocSetStats
#ifdef MEMORY_CONTEXT_CHECKING
@@ -467,7 +464,8 @@ AllocSetContextCreateInternal(MemoryContext parent,
parent,
name);
set->memAllocated = set->keeper->endptr - ((char *) set);
((MemoryContext) set)->mem_allocated =
set->keeper->endptr - ((char *) set);
return (MemoryContext) set;
}
@@ -557,7 +555,7 @@ AllocSetContextCreateInternal(MemoryContext parent,
parent,
name);
set->memAllocated = firstBlockSize;
((MemoryContext) set)->mem_allocated = firstBlockSize;
return (MemoryContext) set;
}
@@ -619,7 +617,7 @@ AllocSetReset(MemoryContext context)
else
{
/* Normal case, release the block */
set->memAllocated -= block->endptr - ((char*) block);
context->mem_allocated -= block->endptr - ((char*) block);
#ifdef CLOBBER_FREED_MEMORY
wipe_mem(block, block->freeptr - ((char *) block));
@@ -629,7 +627,7 @@ AllocSetReset(MemoryContext context)
block = next;
}
Assert(set->memAllocated == keepersize);
Assert(context->mem_allocated == keepersize);
/* Reset block size allocation sequence, too */
set->nextBlockSize = set->initBlockSize;
@@ -705,7 +703,7 @@ AllocSetDelete(MemoryContext context)
AllocBlock next = block->next;
if (block != set->keeper)
set->memAllocated -= block->endptr - ((char *) block);
context->mem_allocated -= block->endptr - ((char *) block);
#ifdef CLOBBER_FREED_MEMORY
wipe_mem(block, block->freeptr - ((char *) block));
@@ -717,7 +715,7 @@ AllocSetDelete(MemoryContext context)
block = next;
}
Assert(set->memAllocated == keepersize);
Assert(context->mem_allocated == keepersize);
/* Finally, free the context header, including the keeper block */
free(set);
@@ -760,7 +758,7 @@ AllocSetAlloc(MemoryContext context, Size size)
if (block == NULL)
return NULL;
set->memAllocated += blksize;
context->mem_allocated += blksize;
block->aset = set;
block->freeptr = block->endptr = ((char *) block) + blksize;
@@ -957,7 +955,7 @@ AllocSetAlloc(MemoryContext context, Size size)
if (block == NULL)
return NULL;
set->memAllocated += blksize;
context->mem_allocated += blksize;
block->aset = set;
block->freeptr = ((char *) block) + ALLOC_BLOCKHDRSZ;
@@ -1060,7 +1058,7 @@ AllocSetFree(MemoryContext context, void *pointer)
if (block->next)
block->next->prev = block->prev;
set->memAllocated -= block->endptr - ((char*) block);
context->mem_allocated -= block->endptr - ((char*) block);
#ifdef CLOBBER_FREED_MEMORY
wipe_mem(block, block->freeptr - ((char *) block));
@@ -1163,8 +1161,8 @@ AllocSetRealloc(MemoryContext context, void *pointer, Size size)
}
/* updated separately, not to underflow when (oldblksize > blksize) */
set->memAllocated -= oldblksize;
set->memAllocated += blksize;
context->mem_allocated -= oldblksize;
context->mem_allocated += blksize;
block->freeptr = block->endptr = ((char *) block) + blksize;
@@ -1339,24 +1337,6 @@ AllocSetGetChunkSpace(MemoryContext context, void *pointer)
return result;
}
/*
* All memory currently allocated for this context (including fragmentation
* and freed chunks).
*
* Allocation sizes double (up to maxBlockSize), so the current block may
* represent half of the total space allocated to the context. Subtract away
* the free space at the tail of the current block, which may never have been
* touched.
*/
static Size
AllocSetMemAllocated(MemoryContext context)
{
AllocSet set = (AllocSet) context;
AllocBlock currentBlock = set->blocks;
Size tailSpace = currentBlock->endptr - currentBlock->freeptr;
return set->memAllocated - tailSpace;
}
/*
* AllocSetIsEmpty
* Is an allocset empty of any allocated space?
@@ -1558,7 +1538,7 @@ AllocSetCheck(MemoryContext context)
name, block);
}
Assert(total_allocated == set->memAllocated);
Assert(total_allocated == context->mem_allocated);
}
#endif /* MEMORY_CONTEXT_CHECKING */