#include "postgres.h"
#include "miscadmin.h"
+#include "nodes/memnodes.h"
#include "utils/aregion.h"
typedef struct BlockAllocatorHeap BlockAllocatorHeap;
*/
struct BlockAllocatorContext
{
+ MemoryContextData header;
bool private;
relptr(LWLock) locks;
BlockAllocatorHeap heaps[lengthof(balloc_size_classes)];
* Allocate memory.
*/
void *
-BlockAllocatorAlloc(BlockAllocatorContext *context, Size size, int flags)
+BlockAllocatorAlloc(BlockAllocatorContext *context, Size size)
{
AllocatorRegion *region = NULL;
char *base = NULL;
BA_SCLASS_BLOCK_OF_SPANS);
if (span == NULL)
{
- if ((flags & SB_ALLOC_SOFT_FAIL) == 0)
- BlockAllocatorMemoryError(context);
+ BlockAllocatorMemoryError(context);
return NULL;
}
!FreePageManagerGet(region->fpm, npages, &first_page))
{
/* XXX. Free the span. */
- if ((flags & SB_ALLOC_SOFT_FAIL) == 0)
- BlockAllocatorMemoryError(context);
+ BlockAllocatorMemoryError(context);
return NULL;
}
ptr = fpm_page_to_pointer(fpm_segment_base(region->fpm), first_page);
/* Attempt the actual allocation. */
result = BlockAllocatorAllocGuts(base, region, context, size_class);
- if (result == NULL && (flags & SB_ALLOC_SOFT_FAIL) == 0)
+ if (result == NULL)
BlockAllocatorMemoryError(context);
return result;
}
IndexTuple newtuple;
/* copy the tuple into sort storage */
- newtuple = (IndexTuple) BlockAllocatorAlloc(state->sortallocator, tuplen, 0);
+ newtuple = (IndexTuple) BlockAllocatorAlloc(state->sortallocator, tuplen);
memcpy(newtuple, tuple, tuplen);
USEMEM(state, BlockAllocatorGetAllocSpace(tuplen));
stup->tuple = (void *) newtuple;
int tapenum, unsigned int len)
{
unsigned int tuplen = len - sizeof(unsigned int);
- IndexTuple tuple = (IndexTuple) BlockAllocatorAlloc(state->sortallocator, tuplen, 0);
+ IndexTuple tuple;
+ tuple = (IndexTuple) BlockAllocatorAlloc(state->sortallocator, tuplen);
USEMEM(state, BlockAllocatorGetChunkSpace(tuple));
LogicalTapeReadExact(state->tapeset, tapenum,
tuple, tuplen);
/* Number of pages (see FPM_PAGE_SIZE) per block-allocator chunk. */
#define BLOCK_ALLOCATOR_PAGES_PER_CHUNK 16
-/* Allocation options. */
-#define SB_ALLOC_HUGE 0x0001 /* allow >=1GB */
-#define SB_ALLOC_SOFT_FAIL 0x0002 /* return NULL if no mem */
-
/* Functions to manipulate allocators. */
extern BlockAllocatorContext *BlockAllocatorContextCreate(void);
extern void BlockAllocatorReset(BlockAllocatorContext *);
extern void BlockAllocatorDelete(BlockAllocatorContext *);
/* Functions to allocate and free memory. */
-extern void *BlockAllocatorAlloc(BlockAllocatorContext *, Size, int flags);
+extern void *BlockAllocatorAlloc(BlockAllocatorContext *, Size);
extern void BlockAllocatorFree(void *ptr);
/* Reporting functions. */