experimenting with shm_open in linux and running into problems. i'm frequently resizing a shared memory segment with ftrunc and using mmap to remap the resized segment. however, right around the 20 megabyte mark i get ENOMEM from mmap.
things i have attempted to do to resolve the issue:
first, i found out about these sysctl parameters. i reconfigured them:
kernel.shmmax = 268435456
kernel.shmall = 2097152
(shmall is specified in pages)
the issue still occurred after this. investigating the details of the resize that causes the issue revealed that the call made to ftrunc to resize the shared memory object succeeded (the corresponding file in /dev/shm had the requested new size).
documentation from here http://pubs.opengroup.org/onlinepubs/009695399/functions/mmap.html suggests three possible causes for an ENOMEM errno:
[ENOMEM] MAP_FIXED was specified, and the range [addr,addr+len) exceeds that allowed for the address space of a process; or, if MAP_FIXED was not specified and there is insufficient room in the address space to effect the mapping.
[ENOMEM] [ML] [Option Start] The mapping could not be locked in memory, if required by mlockall(), because it would require more space than the system is able to supply. [Option End]
[ENOMEM] [TYM] [Option Start] Not enough unallocated memory resources remain in the typed memory object designated by fildes to allocate len bytes. [Option End]
i am not using MAP_FIXED or locking, and the size of the image in /dev/shm suggests that the third reason is not the problem. my mmap call looks like this:
mmap(mem, length, PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0)
where mem initially is 0 and thereafter refers to the last address mmap successfully mapped.
i found information suggesting that ulimit settings could be limiting the memory mappable into a single process, but i don't think the problem was here. just in case, ulimit -a looks like this on my machine:
core file size (blocks, -c) 0
data seg size (kbytes, -d) unlimited
scheduling priority (-e) 20
file size (blocks, -f) unlimited
pending signals (-i) 16382
max locked memory (kbytes, -l) 64
max memory size (kbytes, -m) unlimited
open files (-n) 65536
pipe size (512 bytes, -p) 8
POSIX message queues (bytes, -q) 819200
real-time priority (-r) 0
stack size (kbytes, -s) 8192
cpu time (seconds, -t) unlimited
max user processes (-u) unlimited
virtual memory (kbytes, -v) unlimited
file locks (-x) unlimited
i hope this is an easy one :)