Operating System - HP-UX
1847856 Members
2639 Online
104021 Solutions
New Discussion

why i cant' shmget() more then 1GB?

 
SOLVED
Go to solution
Sergey Akifiev_1
Frequent Advisor

why i cant' shmget() more then 1GB?

here is code snippet:
[... cut ...]
const size_t size = (size_t)1024*1024*1024*1+1; // 2GB + 1byte

shm_handle = shmget(IPC_PRIVATE, size, 0600);
if ( shm_handle < 0 ) {
perror("shmget()");
return 1;
}
printf("sucessfully allocated shm %dMB\n",size/1024/1024);
[... cut ...]
when i try to run prog, i get:
sergey@archer:~/work$ uname -a
HP-UX archer B.11.23 U ia64 3177107281 unlimited-user license
sergey@archer:~/work$ kctune shmmax
Tunable Value Expression Changes
shmmax 8556150784 8556150784 Immed
sergey@archer:~/work$ ./shmmem
shmget(): Not enough space

why?
8 REPLIES 8
James R. Ferguson
Acclaimed Contributor

Re: why i cant' shmget() more then 1GB?

Hi:

Perhaps (from the shmget()' manpages:

[ENOSPC] - A shared memory identifier is to be created but the system-imposed limit on the maximum number of allowed shared memory identifiers system wide would be exceeded.

Regards!

...JRF...
Solution

Re: why i cant' shmget() more then 1GB?

Have you compiled your app as 32-bit or 64-bit (I think the default is 32-bit). IIRC there's a 1GB limit on the quadrant used for shared memory on 32-bit apps. Check which this is using:

file shmmem

EL32 or ELF64?


HTH

Duncan


I am an HPE Employee
Accept or Kudo
Hein van den Heuvel
Honored Contributor

Re: why i cant' shmget() more then 1GB?


So this is a 64-bit application.

You already show shmmax having been set large enough.

What about maxdsiz_64bit and swap space?

Google for: +hpux +shmmax +64-bit ?


Nit picking...

const size_t size = (size_t)1024*1024*1024*1+1; // 2GB + 1byte

Looks like 1GB + 1 to me.

You might want to change the test to print out the MB amount rain or shine.

fwiw,
Hein.
Steven E. Protter
Exalted Contributor

Re: why i cant' shmget() more then 1GB?

Shalom,

Maybe shmmax is set to 1 GB?

SEP
Steven E Protter
Owner of ISN Corporation
http://isnamerica.com
http://hpuxconsulting.com
Sponsor: http://hpux.ws
Twitter: http://twitter.com/hpuxlinux
Founder http://newdatacloud.com
Peter Godron
Honored Contributor

Re: why i cant' shmget() more then 1GB?

Sergey,
what are your ulimit values ?
Don Morris_1
Honored Contributor

Re: why i cant' shmget() more then 1GB?

That's ENOMEM, not ENOSPC:

# cat pig2.c
#include
#include
#include
#include
#include

int
main(int argc, char *argv[])
{
int shmid;
void *shmaddr;

shmid = shmget(IPC_PRIVATE,
(size_t)((1L * 1024L * 1024L * 1024L) + 1L),
IPC_CREAT);

printf("shmget returned id: %d.\n", shmid);

if ( shmid == -1 ) {
fprintf(stderr, "shmget errno: %d.\n", errno);
perror("shmget: ");
exit(EXIT_FAILURE);
}

shmaddr = shmat(shmid, NULL, 0);

if ( shmaddr == SHM_FAILED ) {
perror("shmat: ");
exit(EXIT_FAILURE);
}

while ( shmaddr != SHM_FAILED ) {
bzero(shmaddr, (size_t)(1L * 1024L * 1024L * 1024L));
sleep(5);
}

exit(0);
}

#kctune shmmax
Tunable Value Expression Changes
shmmax 4398046511104 4398046511104 Immed

# ./pig2
shmget returned id: -1.
shmget errno: 12.
shmget: : Not enough space

And yeah -- that's because you can't create a segment larger than 1Gb in the default 32-bit address space layout. Default layout has 2Gb (on IPF) or 1.75 Gb (PA) available for shared address space, but 1Gb of that is intended for "Global" objects which must be shared across all Memory Windows clients (except those with a Private 4th Quadrant) and with 64-bit clients. That's the upper 1Gb on IPF.
That will be used when it has to be, but the lower 1Gb lives in a different address space depending on what Memory Window you're in... and as such, objects are not allowed to cross that boundary. Even for applications using an address space model where their 2nd quadrant is also shared still have discrete boundaries between each 1Gb... you can't cross them.

For >1Gb as a single segment, you need to go 64-bit. Your only alternative in 32-bit is to use multiple segments (which aren't guaranteed to be contiguous).
Emil Velez
Honored Contributor

Re: why i cant' shmget() more then 1GB?


how are you compiling the program

if you do a cc myprog.c -o myprog

you probably get a 32 bit program.. If you compile it with +DA2.0W

you will get a 64 bit executible.

Sergey Akifiev_1
Frequent Advisor

Re: why i cant' shmget() more then 1GB?

thnx for replies. the cause was 32bit binary. when rebuilding with `gcc -mlp64 shmmem.c -o shmmem' i was able to grab a 4GB shm segment.
also my simple memory grabber that doing simple malloc()'ing chubnks of 1MB was able to get around 3GB instead of 811MB in 32bit.