ENOMEM with Plenty to Spare
Last night, something curious happened. I was working on a project after syncing in some upstream changes. Among the changes were increased parallel workers for a certain part of the code. I was running on a rather beefy server with 24 CPU cores and 128GB of RAM. (And no Sam, you can't have it.)
Almost as soon as this part of the code started running,
the program crashed with ENOMEM.
E as in error and NOMEM as in "there's no more memory."
But I was still seeing roughly half of system memory available!
Obviously the problem wasn't that I had literally run out of memory.
It turned out I was hitting a limit on the number of memory map areas.
The Linux kernel has a tunable for this: vm.max_map_count.
This is set to 65,530 per process by default.
(Aside: I'm curious why 65,530... that's suspiciously close to 2^16).
I didn't need to raise it by much, but the program I was running made liberal use of mmap,
so it end up hitting the limits on systems with a higher core count.
In the extremely unlikely event that you think you've hit something similar, you can check the current number of maps that a process holds like so:
#pid=1234
wc -l "/proc/ $ pid /maps"
Of course the process needs to be running in order for this to work, so you may want to run it in a loop running up to a crash to identify probable cause.
Some distros raise the limit above the kernel default.
You can check or set yours with the sysctl command.