pg_buffercache: Allow huge allocations.
authorRobert Haas <rhaas@postgresql.org>
Thu, 15 Sep 2016 13:22:52 +0000 (09:22 -0400)
committerRobert Haas <rhaas@postgresql.org>
Thu, 15 Sep 2016 13:30:36 +0000 (09:30 -0400)
Otherwise, users who have configured shared_buffers >= 256GB won't
be able to use this module.  There probably aren't many of those, but
it doesn't hurt anything to fix it so that it works.

Backpatch to 9.4, where MemoryContextAllocHuge was introduced.  The
same problem exists in older branches, but there's no easy way to
fix it there.

KaiGai Kohei

contrib/pg_buffercache/pg_buffercache_pages.c

index 6622d22f5f8d3a951664d35482bde453e4942d28..0ec7a70783cc3f8eba73e9bf63008821f3636fad 100644 (file)
@@ -124,7 +124,9 @@ pg_buffercache_pages(PG_FUNCTION_ARGS)
        fctx->tupdesc = BlessTupleDesc(tupledesc);
 
        /* Allocate NBuffers worth of BufferCachePagesRec records. */
-       fctx->record = (BufferCachePagesRec *) palloc(sizeof(BufferCachePagesRec) * NBuffers);
+       fctx->record = (BufferCachePagesRec *)
+           MemoryContextAllocHuge(CurrentMemoryContext,
+                                  sizeof(BufferCachePagesRec) * NBuffers);
 
        /* Set max calls and remember the user function context. */
        funcctx->max_calls = NBuffers;