mremap and bus error

Поиск
Список
Период
Сортировка
От Pavel Stehule
Тема mremap and bus error
Дата
Msg-id n2i162867791003310805y26290a58ga0973da506c0b27d@mail.gmail.com
обсуждение исходный текст
Ответы Re: mremap and bus error  (Robert Haas <robertmhaas@gmail.com>)
Список 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,
"memorychecked\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


В списке pgsql-hackers по дате отправления:

Предыдущее
От: Robert Haas
Дата:
Сообщение: Re: sorry, too many standbys already vs. MaxWalSenders vs. max_wal_senders
Следующее
От: David Fetter
Дата:
Сообщение: Re: pgindent excluded files list