Forum Moderators: bakedjake
Kaled.
Thanks in advance.
yes, it is a linux system and i want to display used and left out shared memory.
Not sure what "left out" shared memory is...
Shared memory is, just... memory.
It's a chunk of memory that can be shared by multiple processes. An application acquires shared memory by making a system call similar to what it would make to acquire conventional memory. The only difference is that each chunk of shared memory has a name (or "key") and it's possible for another application to map the same shared memory, by referencing the key.
On modern operating systems, there's no specific shared-memory "pool". (Older versions of Windows had a limited pool of shared memory.) Any memory can be made into shared memory - it's just a matter of the OS flipping some bits that make it available to map-in to other processes. So, it's not a limited resource that is easily depleted. That is, it's no more precious than "normal" memory.
Under Linux, shared memory is backed by the swap partition. (As is "normal" memory.)
I doubt there's really much reason to monitor shared memory, outside of curiosity.
Note that it's fairly difficult to interpret Linux memory statistics. A casual observation will suggest that almost all Linux systems are deficient of free memory. This is because the OS tries to allocate any unused memory to cache and tmpfs. When memory is needed for other purposes, it's withdrawn from these uses.
As I suggested before, "ipcs -m" will display the shared-memory segments currently in use.
Perhaps this will help you debug your application.
Still not sure what you mean by "used or left out".
The OS doesn't know how much of a shared-memory segment has been "used". Your app makes a call, say, asking for a shared-memory segment of 10,000 bytes. At some point you tell the OS you are done, and it takes the memory back. But the OS has no idea if you've stuffed 1 byte, 5000, or 10,000 into the memory.
Should you attempt to write outside of an allocated memory segment (e.g. in the above example, to byte 10,001) you will get a segmentation violation.
You *are* giving the shared memory segments back eventually, right? ;)
It's unclear to me if you've written this application yourself, or if it is a software package you've obtained. If it's a software package that you didn't write yourself, you're probably best off seeking help from any support resources that application has. Sounds more to me like a buggy program than an actual OS problem.
Now, there are some limits placed on shared memory segment size, number of shared memory segments, etc. This varies from system to system. There are a number of kernel variables that you can view to determine the limits on your system. You can "cat" the variable numbers in /proc/sys/kernel. For example, to view the maximum size of a shared-memory segment:
cat /proc/sys/kernel/shmmax
Here are the values on my Fedora Core 6 system:
shmmax - max size of a shared-memory segment: 33554432
shmall - total shared memory avail: 2097152
shmseg - max # of shared memory segs per process: (doesn't exist in FC6)
shmmni - max # of shared memory segs system-wide: 4096
Note my previous caveat about interpreting "available memory" statistics in Linux. They aren't really meaningful, as you need to add the memory being used for disk caching and tmpfs to any "available" feature.
I'm thinking your app may be running afoul of the max number of shared memory segments system-wide - especially if it isn't giving them back when it is done!