Categories
Mac OS X OS

Tweaking Mac OS X Sysctl Values

Now that my PowerBook is back I’ve done a fresh install of Mac OS X. Along with restoring all of my data and applications I’ve been tweaking a few settings. In the past I’ve edited /etc/rc to adjust sysctl values. It turns out that Mac OS X (at least as of 10.3.4) supports using /etc/sysctl.conf to set sysctl values. Here’s what my /etc/sysctl.conf looks like:

kern.sysv.shmmax=167772160
kern.sysv.shmmin=1
kern.sysv.shmmni=64
kern.sysv.shmseg=16
kern.sysv.shmall=65536
kern.maxproc=2048
kern.maxprocperuid=512

Update (8:42am 7 Jul 04): Hmmm, even though there is clearly code in /etc/rc to set sysctl values from /etc/sysctl.conf they don’t appear to actually change the values. I guess for now I’ll be putting these values directly into /etc/rc again. If anyone has more info on this please leave a comment.

13 replies on “Tweaking Mac OS X Sysctl Values”

I’ve the same problem to configure the shmmax parameter

a /etc/rc modification works, a /etc/sysctl.conf modification doesn’t.

worth, after a reboot with sysctl -a, I check that the new value is 16Mb (old 4Mb) but in my program, shmget failed with ENOMEM errno if I try to get more than 4Mb of share memory

any idee ?

$ vi /System/Library/StartupItems/SystemTuning/SystemTuning

# you should be able to increase shared mem here, by increasing
# the “4194304” value

sysctl -w kern.sysv.shmmax=4194304

sorry, you probably already knew this, but OSX 10.3 (panther) does not have any parameters defined in this file:

$ ls /System/Library/StartupItems/SystemTuning/SystemTuning

this file was used in previous versions of OSX; as you already stated, now these parameters are in /etc/rc

had the same problem with values in sysctl.conf not taking effect — until what you said caused me to look at /etc/rc. I then looked closely at my sysctl.conf, and I realized it had what turns out to be a syntax error — whitespace!

I set the following:

net.inet.tcp.keepidle=2160

but I had originally written it with a space on either side of the equals sign. Without the spaces, it loads at startup!

Make sure that’s not your issue too…

I’m on 10.3.7 btw.

herve – make sure you adjusted SHMALL to match the adjustment you made to SHMMAX. SHMALL is the total amount of shared memory available, SHMMAX is maximum size of a shared memory segment.

On Panther (10.3.x) set your SHMALL to:

{VALUE of SHMMAX} / 4096

4096 is the default page size in 10.3.x. So, for example, your SHMMAX is 134217728 (128MB), you would set SHMALL to 32768.

Hmm, putting together rhumgod’s and jfw’s comments, I set /etc/sysctl.conf to:

kern.sysv.shmmax=134217728
kern.sysv.shmmin=1
kern.sysv.shmmni=32
kern.sysv.shmseg=8
kern.sysv.shmall=32768

However, the settings are not applied once I reboot (e.g., ‘sysctl kern.sysv.shmmax’ shows the default 4194304 instead of my value. Is this an Apple bug, or am I still missing something?

The reason why those changes in sysctl.conf do not take effect is because those particular parameters can only be set once. Future modifications to the values are ignored.

That said, if you remove the settings from /etc/rc, then the change in /etc/sysctl.conf should take effect.

Turns out that when you set the last of the 5 shm values, the shared memory becomes “initialized” by a call to shminit(). After that, it simply ignores any subsequent changes until the system restarts.

If you edit /etc/sysctl.conf, as you are supposed to, unless you set all 5, your changes will be overwritten by the subsequent code in /etc/rc that sets the default values. So the solution is to not just add the shmmax and shmall that you want, but the other three also, so that shminit() gets called, locking the values in place.

Thanks to all from me, too. dmc – your last comment was especially helpful. After (only some) aggravation, I was able to successfull change shmmax, etc on 10.3 and 10.4

I think that shmall should actually be set to (shmmax / pagesize) * shmmni instead. That lets you have the maximum number of shared memory ids worth of shared memory counted in pages… I could be mistaken however, I’m not a shared memory guru.

Hi. I’ve read all of your correspondence, but I still can not work this out….
Here’s what happens.

Yukies-iBook:/etc yukie$ sudo sysctl -w kern.sysv.shmmax=20971520 kern.sysv.shmmin=1 kern.sysv.shmmni=32 kern.sysv.shmseg=8 kern.sysv.shmall=5120
Password:
kern.sysv.shmmax: 4194304 -> 4194304
kern.sysv.shmmin: 1 -> 1
kern.sysv.shmmni: 32 -> 32
kern.sysv.shmseg: 8 -> 8
kern.sysv.shmall: 1024 -> 1024

I can’t even change these values …. A little help??

Leave a Reply

Your email address will not be published. Required fields are marked *