Remove flags argument to BlockAllocatorAlloc, and other tweaks.
authorRobert Haas <rhaas@postgresql.org>
Tue, 13 May 2014 15:19:39 +0000 (11:19 -0400)
committerRobert Haas <rhaas@postgresql.org>
Tue, 13 May 2014 15:19:39 +0000 (11:19 -0400)
src/backend/utils/mmgr/balloc.c
src/backend/utils/sort/tuplesort.c
src/include/utils/balloc.h

index d155dbab7d29ed84a69f125c26e7953b5f286abc..f501791caba1bc02cc7145e069fe6ad4a19b4b21 100644 (file)
@@ -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;          
 }
index aa5f375f56d684847cd4412d29a97cd6b7a03663..83bb97502b56f38e4d2eb696b4c332bc1b979fe2 100644 (file)
@@ -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);
index 2048847a8315c96f3032ed95d32da55f11e82fd5..4fadac2333cd93308dcd53877d39e488a1b7ad62 100644 (file)
@@ -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. */