#define AREGION_INITSIZE (16 * BLOCK_ALLOCATOR_PAGES_PER_CHUNK)
#define AREGION_MAXSIZE ((64 * 1024 * 1024) / FPM_PAGE_SIZE)
-static Size aregion_private_pages_allocated = 0;
+Size aregion_private_pages_allocated = 0;
static Size aregion_private_bytes_allocated = 0;
static Size aregion_peak_private_bytes_allocated = 0;
* overhead of its own.
*/
Size
-BlockAllocatorGetChunkSpace(void *ptr)
+BlockAllocatorGetChunkSpace(AllocatorRegion *aregion, void *ptr)
{
- AllocatorRegion *region;
char *fpm_base;
BlockAllocatorSpan *span;
Size pageno;
uint16 size_class;
/* Locate the containing block. */
- region = LookupAllocatorRegion(ptr);
- fpm_base = fpm_segment_base(region->fpm);
+ fpm_base = fpm_segment_base(aregion->fpm);
pageno = fpm_pointer_to_page(fpm_base, ptr);
- span = BlockAllocatorMapGet(region->pagemap, pageno);
+ span = BlockAllocatorMapGet(aregion->pagemap, pageno);
/* Work out the size of the allocation. */
size_class = span->size_class;
#include "postgres.h"
#include "miscadmin.h"
+#include "utils/aregion.h"
#include "utils/memdebug.h"
#include "utils/memutils.h"
Assert(pointer != NULL);
Assert(pointer == (void *) MAXALIGN(pointer));
+ /*
+ * If allocator regions are in use, then this pointer might be within
+ * such a region, in which case it won't have a chunk header. So, we have
+ * to test for and handle that case first.
+ */
+ if (aregion_private_pages_allocated > 0)
+ {
+ AllocatorRegion *aregion;
+
+ aregion = LookupAllocatorRegion(pointer);
+ if (aregion != NULL)
+ return BlockAllocatorGetChunkSpace(aregion, pointer);
+ }
+
/*
* OK, it's probably safe to look at the chunk header.
*/
LogicalTapeWrite(state->tapeset, tapenum,
(void *) &tuplen, sizeof(tuplen));
- FREEMEM(state, BlockAllocatorGetChunkSpace(tuple));
+ FREEMEM(state, GetMemoryChunkSpace(tuple));
BlockAllocatorFree(tuple);
}
IndexTuple tuple;
tuple = (IndexTuple) BlockAllocatorAlloc(state->sortallocator, tuplen);
- USEMEM(state, BlockAllocatorGetChunkSpace(tuple));
+ USEMEM(state, GetMemoryChunkSpace(tuple));
LogicalTapeReadExact(state->tapeset, tapenum,
tuple, tuplen);
if (state->randomAccess) /* need trailing length word? */
extern AllocatorRegion *GetRegionForPrivateAllocation(Size npages);
extern void ReportRegionContiguousFreespace(AllocatorRegion *, Size npages);
+extern Size aregion_private_pages_allocated;
+
#endif /* AREGION_H */
#include "storage/lwlock.h"
#include "utils/relptr.h"
+struct AllocatorRegion;
typedef struct BlockAllocatorContext BlockAllocatorContext;
/* Number of pages (see FPM_PAGE_SIZE) per block-allocator chunk. */
extern void BlockAllocatorInit(MemoryContext);
extern void BlockAllocatorReset(MemoryContext);
extern void BlockAllocatorDelete(MemoryContext);
-extern Size BlockAllocatorGetChunkSpace(void *ptr); /* WRONG SIGNATURE */
+extern Size BlockAllocatorGetChunkSpace(struct AllocatorRegion *, void *ptr);
extern Size BlockAllocatorGetAllocSpace(Size size); /* EXTRA FUNCTION */
/* IS_EMPTY IS MISSING! */
/* STATS IS MISSING! */