aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorHeikki Linnakangas <heikki.linnakangas@iki.fi>2014-01-29 21:33:56 +0200
committerHeikki Linnakangas <heikki.linnakangas@iki.fi>2014-01-29 21:33:56 +0200
commit699b1f40da3139def660235fa8a782ec8dd8f575 (patch)
tree434ea56ffa8a7670f190295d034b433fb322ebf0
parent626a120656a75bf4fe64b1d0d83c23cb38d3771a (diff)
downloadpostgresql-699b1f40da3139def660235fa8a782ec8dd8f575.tar.gz
postgresql-699b1f40da3139def660235fa8a782ec8dd8f575.zip
Fix thinko in huge_tlb_pages patch.
We calculated the rounded-up size for the allocation, but then failed to use the rounded-up value in the mmap() call. Oops. Also, initialize allocsize, to silence warnings seen with some compilers, as pointed out by Jeff Janes.
-rw-r--r--src/backend/port/sysv_shmem.c11
1 files changed, 7 insertions, 4 deletions
diff --git a/src/backend/port/sysv_shmem.c b/src/backend/port/sysv_shmem.c
index f7596bf6e0b..ac3a9fe3b0b 100644
--- a/src/backend/port/sysv_shmem.c
+++ b/src/backend/port/sysv_shmem.c
@@ -329,7 +329,7 @@ PGSharedMemoryIsInUse(unsigned long id1, unsigned long id2)
static void *
CreateAnonymousSegment(Size *size)
{
- Size allocsize;
+ Size allocsize = *size;
void *ptr = MAP_FAILED;
#ifndef MAP_HUGETLB
@@ -358,11 +358,10 @@ CreateAnonymousSegment(Size *size)
*/
int hugepagesize = 2 * 1024 * 1024;
- allocsize = *size;
if (allocsize % hugepagesize != 0)
allocsize += hugepagesize - (allocsize % hugepagesize);
- ptr = mmap(NULL, *size, PROT_READ | PROT_WRITE,
+ ptr = mmap(NULL, allocsize, PROT_READ | PROT_WRITE,
PG_MMAP_FLAGS | MAP_HUGETLB, -1, 0);
if (huge_tlb_pages == HUGE_TLB_TRY && ptr == MAP_FAILED)
elog(DEBUG1, "mmap with MAP_HUGETLB failed, huge pages disabled: %m");
@@ -372,8 +371,12 @@ CreateAnonymousSegment(Size *size)
if (huge_tlb_pages == HUGE_TLB_OFF ||
(huge_tlb_pages == HUGE_TLB_TRY && ptr == MAP_FAILED))
{
+ /*
+ * use the original size, not the rounded up value, when falling
+ * back to non-huge pages.
+ */
allocsize = *size;
- ptr = mmap(NULL, *size, PROT_READ | PROT_WRITE, PG_MMAP_FLAGS, -1, 0);
+ ptr = mmap(NULL, allocsize, PROT_READ | PROT_WRITE, PG_MMAP_FLAGS, -1, 0);
}
if (ptr == MAP_FAILED)