PostgreSQL on FreeBSD 7.0 amd64 with more than 2GB shared memory

Hell, Robert Robert.Hell at fabasoft.com
Wed Dec 10 09:06:23 PST 2008


Hi,

I'm trying to run PostgreSQL 8.3 on a FreeBSD 7.0 amd64 server with more
than 2GB shared memory. The machine has 32GB RAM installed.
After setting kern.ipc.shmmax and kern.ipc.shmall to the appropriate
values, I still had no chance to start postgres with more than 2GB of
shared memory.

I wrote a small test which does the same as postgres: shmget and shmat:
#include <sys/ipc.h>
#include <sys/shm.h>
#include <stdio.h>
#include <errno.h>

int main()
{
  int shmid, memKey = 1;
  void *memAddress;
  unsigned long size = 2147483648UL;

  shmid = shmget(memKey, size, IPC_CREAT | IPC_EXCL);
  if (shmid < 0) {
    printf("shmget failed: %d\n", errno);
    return 1;
  }

  memAddress = shmat(shmid, NULL, 0);
  if (memAddress == (void *) -1) {
    printf("shmat failed: %d\n", errno);
  }

  return 0;
}


I found out that shmget failed with ENOMEM in shmget_allocate_segment
(sysv_shm.c) because of an overflow of size (requested shared memory in
bytes):
        int i, segnum, shmid, size;
...
        size = round_page(uap->size);
        if (shm_committed + btoc(size) > shminfo.shmall) {
                return (ENOMEM);
        }

When changing size to an unsigned long shmget works - but now shmat then
fails again with ENOMEM.
Is there any easy way to use a shared memory segment which is larger
than 2GB?

Kind regards,
Robert


More information about the freebsd-questions mailing list