From: Robert Haas Date: Tue, 13 May 2014 15:19:39 +0000 (-0400) Subject: Remove flags argument to BlockAllocatorAlloc, and other tweaks. X-Git-Url: http://git.postgresql.org/gitweb/static/close/reject?a=commitdiff_plain;h=f9881165005a76dabfa39449a4c3a0789b887a7d;p=users%2Frhaas%2Fpostgres.git Remove flags argument to BlockAllocatorAlloc, and other tweaks. --- diff --git a/src/backend/utils/mmgr/balloc.c b/src/backend/utils/mmgr/balloc.c index d155dbab7d..f501791cab 100644 --- a/src/backend/utils/mmgr/balloc.c +++ b/src/backend/utils/mmgr/balloc.c @@ -34,6 +34,7 @@ #include "postgres.h" #include "miscadmin.h" +#include "nodes/memnodes.h" #include "utils/aregion.h" typedef struct BlockAllocatorHeap BlockAllocatorHeap; @@ -158,6 +159,7 @@ struct BlockAllocatorHeap */ struct BlockAllocatorContext { + MemoryContextData header; bool private; relptr(LWLock) locks; BlockAllocatorHeap heaps[lengthof(balloc_size_classes)]; @@ -218,7 +220,7 @@ BlockAllocatorContextCreate(void) * Allocate memory. */ void * -BlockAllocatorAlloc(BlockAllocatorContext *context, Size size, int flags) +BlockAllocatorAlloc(BlockAllocatorContext *context, Size size) { AllocatorRegion *region = NULL; char *base = NULL; @@ -258,8 +260,7 @@ BlockAllocatorAlloc(BlockAllocatorContext *context, Size size, int flags) BA_SCLASS_BLOCK_OF_SPANS); if (span == NULL) { - if ((flags & SB_ALLOC_SOFT_FAIL) == 0) - BlockAllocatorMemoryError(context); + BlockAllocatorMemoryError(context); return NULL; } @@ -272,8 +273,7 @@ BlockAllocatorAlloc(BlockAllocatorContext *context, Size size, int flags) !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); @@ -325,7 +325,7 @@ BlockAllocatorAlloc(BlockAllocatorContext *context, Size size, int flags) /* 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; } diff --git a/src/backend/utils/sort/tuplesort.c b/src/backend/utils/sort/tuplesort.c index aa5f375f56..83bb97502b 100644 --- a/src/backend/utils/sort/tuplesort.c +++ b/src/backend/utils/sort/tuplesort.c @@ -3350,7 +3350,7 @@ copytup_index(Tuplesortstate *state, SortTuple *stup, void *tup) 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; @@ -3385,8 +3385,9 @@ readtup_index(Tuplesortstate *state, SortTuple *stup, 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); diff --git a/src/include/utils/balloc.h b/src/include/utils/balloc.h index 2048847a83..4fadac2333 100644 --- a/src/include/utils/balloc.h +++ b/src/include/utils/balloc.h @@ -22,17 +22,13 @@ typedef struct BlockAllocatorContext BlockAllocatorContext; /* 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. */