While looking around for information on some fairly irritating memory leaks I’ve been encountering in OS X (some common library seems to be chewing up memory, so that after a few days of running, all my apps take up enormous amounts of memory), I found this old tip regarding setting the maxvnodes parameter.
A comment attached to the tip above quotes one of Apple’s kernel developers: “Increasing the value of maxvnodes will increase the number of files that get cached in RAM. This will make subsequent access to those files much faster. But the downside is that more of your RAM will be used up for this disk caching and thus you will have less RAM available for normal application use.”
Thus, by default, Apple specify a value that is apparently a compromise for best overall performance.
That said, I increased the value to 84672, despite not having large amounts of free RAM:
sudo sysctl -w kern.maxvnodes=84672
My machine, after running for a few days without a reboot, often runs quite sluggishly, with lots of swap activity. For example, bringing up the Dashboard after not using it for a while can take a good 5-15 seconds, depending on what else is running.
After tweaking the maxvnodes value, all the widgets in Dashboard refreshed within 2 seconds (it had been a fair while since I last brought it up) – just coincidence, or did it actually make a difference?
The system does feel snappier; I can do things like start apps, bring up menus, load webpages, switch desktops and use Quicksilver without the irritating delay that I usually get. Maybe it’s all in my head, but maybe not. Worth a go!
If it does work, the command can be put into /etc/rc to be run on boot (as settings are forgotten after reboot). Instructions are outlined in the comments accompanying the tip.
[Edit]: This command might aid in establishing an optimal value:
sysctl -w kern.maxvnodes=$(echo $(sysctl -n hw.physmem) \ '33554432 / 512 * 1024 +p'|dc)
I’ve never had any problems with crashing apps but noticed that the maxvnodes value should not be set to high, depending on the amount of available RAM of course.
Crashing may be because of a damaged filesystem or cache. May be easily fixed with a program like AppleJack. http://applejack.sourceforge.net/
For 1 gig of RAM is the default ~17000 and after some experimentation I found the ideal balance between available RAM for system, apps and vnodes: 65535.
My Mac feels a lot faster even if it throws out to VM now and then, maybe because VM is faster to access than a lot of files elsewhere on the HD.