From: | Pavel Stehule <pavel(dot)stehule(at)gmail(dot)com> |
---|---|
To: | PostgreSQL Hackers <pgsql-hackers(at)postgresql(dot)org> |
Subject: | mremap and bus error |
Date: | 2010-03-31 15:05:58 |
Message-ID: | n2i162867791003310805y26290a58ga0973da506c0b27d@mail.gmail.com |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-hackers |
Hi,
I playing with mmap. I have a problem with mremap function. It
doesn't allocate correct memory. All others work well.
static void *
mmap_realloc(void *ptr, Size size)
{
Size oldsize;
void *result;
int i;
char *x;
ptr = (char *) ptr - MAXALIGN(sizeof(Size));
oldsize = *((Size *) ptr);
size = MAXALIGN(size) + MAXALIGN(sizeof(Size));
ptr = mremap(ptr, oldsize,
size,
MREMAP_MAYMOVE);
if (ptr == MAP_FAILED)
ereport(ERROR,
(errcode(ERRCODE_OUT_OF_MEMORY),
errmsg("out of memory"),
errdetail("Failed on request of size %lu.",
(unsigned long) size)));
*((Size*) ptr) = size;
result = (char *) ptr + MAXALIGN(sizeof(Size));
/* check allocated memory */
x = ptr;
fprintf(stderr, "allocated memory %ld\n", size);
for (i = 0; i < size; i++)
{
if (i > oldsize)
{
*x = 0;
}
x++;
}
fprintf(stderr, "memory checked\n");
return result;
}
log:
>>>> 1 <<<>>> 1048584
>>>> 3 <<<>>> 2097216
>>>> 3 <<<>>> 9024
allocated memory 10304
memory checked
allocated memory 11584
memory checked
allocated memory 12864
gdb
Program terminated with signal 7, Bus error.
#0 mmap_realloc (size=12864, ptr=<value optimized out>) at mmap_alloc.c:357
357 *x = 0;
Missing separate debuginfos, use: debuginfo-install glibc-2.10.2-1.x86_64
(gdb) print x
$1 = 0x7f92055df000 ""
(gdb) print i
$2 = 12289
Can somebody help me?
Regards
Pavel Stehule
From | Date | Subject | |
---|---|---|---|
Next Message | David Fetter | 2010-03-31 15:09:18 | Re: pgindent excluded files list |
Previous Message | Robert Haas | 2010-03-31 14:45:39 | Re: sorry, too many standbys already vs. MaxWalSenders vs. max_wal_senders |