The default configuration for shared memory on a Mac is best described as "minimal", and is the same on every Mac, regardless of the amount of total memory or the number of processors. These instructions tell you how to alter the shared memory configuation.
Last updated: 28 March 2010
A good example of how this can be useful is provided by BOINC, the Berkeley Open Infrastructure for Network Computing, which is the software used by distributed computing projects such as SETI@Home and Einstein@Home. The BOINC Core Client is the main program which manages the execution of multiple application programs for the various BOINC projects. When the Core Client starts an application process it provides configuration information and communicates commands to the application via shared memory.
On a multi-processor Mac where the BOINC Core Client is configured to keep suspended processes in memory it is possible that an application program will fail because it cannot allocate shared memory. This results in an error message that looks something like
2006-05-22 04:46:08 [Pirates@Home] Can't create shared memory: system shmget 2006-05-22 04:46:08 [Pirates@Home] Unrecoverable error for result wu_1148262635_451_0 (Couldn't start or resume: -144)The amount of shared memory available on a Mac is configured at boot time. Once the shared memory system has been initiallized it is not possible to change the shared memory configuration[1]. At present the same amount of shared memory is configured on any Mac (about 4MB), regardless of the number of processors or the amount of total memory available.
You can view the shared memory settings on your Mac by opening the Terminal application (it is in the Applications -> Utilities folder) and giving the command
sysctl -A | grep shmwhich should produce something like:
kern.sysv.shmmax: 4194304 kern.sysv.shmmin: 1 kern.sysv.shmmni: 32 kern.sysv.shmseg: 8 kern.sysv.shmall: 1024
To change the shared memory settings you need to be comfortable with creating and editing files using a text editor such as Emacs, vi, or pico. If you are not familiar with a Unix text editor then you can learn to use Emacs from this "Introduction to the Emacs Editor", which includes simple instructions for taking the Emacs tutorial.
To change the shared memory settings you also need to be able to give commands as the "root" user on your Mac. If you like, you can follow these instructions on "How to Enable the root Account on Mac OS X". However, you can also simply log in as the "Admin" user, open up the Terminal application (it is in the Applications -> Utilities folder) and giving the command:
sudo emacs /etc/sysctl.confIt is likely this file doesn't exist on your system, in which case an empty file will be created. Edit this file so that it contains the lines:
These settings increase the amount of shared memory to four (4) times the usual default.kern.sysv.shmmax=16777216 kern.sysv.shmmin=1 kern.sysv.shmmni=128 kern.sysv.shmseg=32 kern.sysv.shmall=4096
These shared memory settings will be applied the next time the computer boots. You can verify the settings after the reboot using the "sysctl -A" command demonstrated above.
Allowing an arbitrary process to share memory with any other
process on the machine would create a serious security problem.
Restrictions can be imposed on which processes can use the
shared memory segment, based on the userid and groupid of the
processes, much as is done for Unix file permissions.
See the shmget(1) man page for details [3].
Shared Memory Details
Here are what the particular shared memory kernel settings mean:
References and Resources
Copyright © 2010 by Spy Hill Research | http://www.Spy-Hill.net/~myers/help/apple/SharedMemory.html | (served by Islay.spy-hill.com) | Last modified: 28 March 2010 |