Reputation: 249
We have code that needs to allocate a large amount of shared memory and would like to implement a quick, early check to determine if there is enough free to continue. I've found a number of different ways that supposedly give you information on shared memory, but all seem to have issues. Here is what I've tried so far:
ipcs -lm
On my workstation, this returns a max total shared memory of 18014398442373116 kbytes, which is absurd (~16 exabytes).
ipcs -m
If I add up all the listed segments, I get about 128 mb. Seems reasonable.
def /dev/shm
This shows a total size of 32G which seems reasonable (I have 64G of RAM), but the usage shows only 9 mb which doesn't mesh with 'ipcs -m'.
free OR /proc/meminfo
On my machine these show about 140 mb of used shared memory (more in line with 'ipcs -m'), but other machines it doesn't seem to line up and on those machines, 'man free' specifies that the shared value is obsolete and should be ignored.
I feel like I'm missing something pretty basic. Any help would be greatly appreciated.
EDIT: To give a little more information about the situation, this code runs on supercomputers where our code should be the only thing running on the compute node. Since nothing else should be allocating large chunks of memory, an up-front check seemed reasonable. The situation we typically run into is a compute node on which memory wasn't fully cleaned up from the previous job. We could just look for existing segments, but if there is enough headroom, we would like to allow the user to run even if the node isn't clean.
Upvotes: 0
Views: 1958
Reputation:
How about try it and handle the exception or failure if it doesn't succeed? Otherwise you are risking race conditions.
Upvotes: 1