Submit Hint Search The Forums LinksStatsPollsHeadlinesRSS
14,000 hints and counting!

Tuning maxvnodes for better system peformance System
I have been using this hint for about a week or two, and believe it's ready for "prime time" on OSX Hints. Credit goes to Charles Richmond, as posted in his Tuning maxvnodes for better performance topic on the Apple Discussions boards.

[robg adds: I have not tested this one myself...]
    •    
  • Currently 3.00 / 5
  You rated: 4 / 5 (5 votes cast)
 
[24,507 views]  

Tuning maxvnodes for better system peformance | 24 comments | Create New Account
Click here to return to the 'Tuning maxvnodes for better system peformance' hint
The following comments are owned by whoever posted them. This site is not responsible for what they say.
Tuning maxvnodes for better system peformance
Authored by: zedwards on Jul 16, '03 11:33:45AM

Wow....this works. I am looking at top running, and it seems that the ram isnt stuck and the pageouts are low.



[ Reply to This | # ]
Tuning maxvnodes for better system peformance
Authored by: youcanrunnaked on Jul 16, '03 02:53:30PM

After adding more RAM, this is the single biggest improvement you can make to system performance. If you have more than 500 megs of RAM, try tuning the kernel per this hint. It really works.



[ Reply to This | # ]
Please Explain
Authored by: SOX on Jul 16, '03 03:32:27PM

could some one explain
1) what the problem this addresses and how to see if you have such a problem.
2) what this is doing.



[ Reply to This | # ]
Please Explain
Authored by: youcanrunnaked on Jul 16, '03 11:51:15PM

Read the thread in the Aplle Discussions. It is all laid out there.



[ Reply to This | # ]
Tuning maxvnodes for better system peformance
Authored by: gxw on Jul 17, '03 12:52:05AM

Here's some more info about this from this site:
http://www.netbsd.org/Documentation/tune/5.html

<fair use>
UBC and sysctl (top)

From what I have gathered on a variety of lists, the most commonly "tweaked" part of the system via sysctl is the Unified Buffer Cache (UBC). In a really great email a developer made some excellent recommendations for tuning a system with UBC, this section will peruse that for the example.

Following along with the maxfiles example above, even though there can now be a larger amount of open files, there still may be more that can be done to make the system run faster. Since more files can be opened, it stands to reason that it would be good if the caching were optimized as well. In the case of this machine, there is a decent amount of RAM (256MB) that despite a lot of low level activity (such as editing and small compiles) is not being utilized to its full potential. This means that the buffer cache could probably be expanded, thereby making performance better since more would be in the cache versus rereading from disk. Now, a word of warning, it is of course possible to raise the size to a point where getting a cache hit is taking too long, but as has been well documented, that number seems to be fairly high [1]. So what is the parameter? It is kern.maxvnodes and in the case of this machine, 38k was used which gave a pretty decent performance boost. In general, it has been seen that a kern.maxvnodes operates well when the size is set to between 1/6 to 1/4 of the amount of RAM (depending on what the system is being used for).
</fair use>



[ Reply to This | # ]
Be VERY careful with dynamic_pager custom settings...
Authored by: kupietz on Sep 22, '08 01:20:10PM

Here's a good way to get your computer to sporadically slow to a crawl and then freeze completely, with no beachball cursor, no diagnostic information written to any log file, and with the mouse still responsive, but no way to break the freeze besides a forced reboot: (tested in 10.4.11)

/sbin/dynamic_pager ${encryptswap} -H 1024 -L 8001025 -S 80000000 -F ${swapdir}/swapfile

Can you see what's wrong? -L is 8,001,025 but -S is 80,000,000 (there's an extra 0.) So double check those numbers. It's a *very* odd and tricky problem to troubleshoot. The only indicator you get of the problem is a very brief warning buried in the output when you do a verbose boot.



[ Reply to This | # ]
This hint works!
Authored by: gxw on Jul 17, '03 10:49:57PM

eMac 800Mhz with 512 meg of RAM.
before = 8990 vnodes in use - 9009 maximum
After = 9181 in use 363036 max (Used the smallest # from the tech forum).

My system is running really snappy now. Used to get 4 dock bounces
upon starting iTunes or Mozilla. Now I only get one icon bounce.
Sweet.



[ Reply to This | # ]
Tuning maxvnodes for better system peformance
Authored by: bluehz on Jul 18, '03 10:59:27AM
Something doesn't jive here though. I am a prime candidate for this - with over 1.2G of RAM. Following the info at the discussions, I tested to see if it would be beneficial using these commands:

First to see if the change will be beneficial, wait unto your system is being sluggish and in a terminal window do the following commands: pstat -T sysctl kern.maxvnodes
The numbers came up almost identical - I think a difference of 1. So I hardwired the tuning to the /etc/rc as explained and then rebooted.

Running the test after rebooting and enabling this hack I get:

% pstat -T
86714 vnodes
swapmode is not (yet) available under Mach
% sysctl kern.maxvnodes
kern.maxvnodes = 86720

WOW!... a difference of 6... is that supposed to be good??? I personally have not really noticed any performance increase either.

[ Reply to This | # ]

Tuning maxvnodes for better system peformance
Authored by: bdm on Jul 19, '03 12:24:01AM

I'm also suspicious about this hint. It seems to me that unless you are doing something that requires an extremely large number of files open at once (or open repeatedly), a very large value of maxvnodes is not going to help. It can even hurt as the ram used to hold all those vnodes could be put to other use.

Brendan.



[ Reply to This | # ]
Tuning maxvnodes for better system peformance
Authored by: mlaster on Mar 28, '04 08:20:48AM

I'm a bit suspicious of this too. I've tried it out and from everything I can tell, the number of vnodes in use will never shrink significantly. I think I only saw vnode shrinkage when I actually deleted recently touched files.
Being that is never shrinks, any system with any maxvnodes setting will eventually hit the 99% usage mark, making this a useless metric for determining that your maxvnodes amount is too low.

Also, I've been searching the web, and I still haven't found a clear definition of exactly what a vnode is cachine? Is it just filesystem metadata, or does this somehow factor into caching the file contents as well? Does a 6 gig file still take only one vnode slot when it is cached?

How do we measure the effectiveness of the unified buffer cache? Is that
what the hit_rate value is in vm_stat?

Does increasing the maxvnodes help better utilize unused RAM? I looked
at our CVS server and it is hardly using it's RAM and could maybe take advantage of this. The machine has 1.5 gig of RAM and 1.1 gig of it is still free after 18 days of uptime. I suspect that if OS X hasn't utilized it after 2 weeks, it's not likely to start using it soon. It would probably better be used for disk caching.

If sure would be nice if Apple would document the low levels of the system a bit better :-)



[ Reply to This | # ]
A little convenient script to calculate the percentage of vnodes used
Authored by: sx1 on Jul 19, '03 04:21:09AM

The maxvnodes tip is useful but it's all in the fine tuning. Here's a little script that calculates how many vnodes are used as a percentage of the maximum vnodes. I put it in /usr/local/bin/vnodeusage. I found it invaluable when tweaking the maxvnodes value.

#!/bin/tcsh
# returns the percentage of vnodes used

set vnodesused=`pstat -T | grep vnodes | sed 's/vnodes//' `
set vnodesmax=`sysctl kern.maxvnodes | sed 's/kern.maxvnodes = //'`

set result=`expr $vnodesused \* 100 / $vnodesmax`
echo "${result}% used"

Enjoy!



[ Reply to This | # ]
sh version
Authored by: gatorparrots on Jul 20, '03 01:40:07AM
Here's an sh version (repeat after me: I will not script in tcsh, I will not script in tcsh...) that uses awk instead of sed:
#!/bin/sh
# returns percentage of maxvnodes used
vnodes=$(pstat -T |awk '/vnodes/ {print $1}')
maxvnodes=$(sysctl kern.maxvnodes | awk '{print $3}')
echo "$(expr $vnodes \* 100 / $maxvnodes)% used"


[ Reply to This | # ]
A little convenient script to calculate the percentage of vnodes used
Authored by: tegbains on Jul 20, '03 07:19:04PM

There is a mistake on the second to last line:

It was: set result=`expr $vnodesused * 100 / $vnodesmax`

But should be: set result=`expr $vnodesused \* 100 / $vnodesmax`

Corrected code is below:
__

#!/bin/tcsh
# returns the percentage of vnodes used

set vnodesused=`pstat -T | grep vnodes | sed 's/vnodes//' `
set vnodesmax=`sysctl kern.maxvnodes | sed 's/kern.maxvnodes = //'`

set result=`expr $vnodesused \* 100 / $vnodesmax`
echo "${result}% used"

___

---
___
Teg Bains



[ Reply to This | # ]
Tuning dynamic_pager so unused swapfiles dissapear
Authored by: carsten on Jul 19, '03 09:18:54AM

Nice tip! I couldn't get the script to work, I get

I have 768 Mb RAM, and my vnodesused=13101, vnodesmax=13104. As soon as I increased kern.maxvnodes=51904 the system started using it, already at 13431 vnodes used in only a couple minutes of running.

Well Mac OS X doesn't use sysctl for virtual memory so the sysctl entries: vm.{anon,exec,file}{min,max} (referenced in a link to an email in the page referenced above).

I made the following changes to my /etc/rc file:


dynamic_pager -H 35000000 -L 80000000 -S 40000000 -F ${swapdir}/swapfile

In case you want to go back, the original statement was:


dynamic_pager -H 40000000 -L 160000000 -S 80000000 -F ${swapdir}/swapfile

For a while I tried cutting the swap file sizes in half, because the swapfiles never EVER seemed to dissapear from my /var/vm, however it did not seem to make any difference at all:


dynamic_pager -H 20000000 -L 80000000 -S 40000000 -F ${swapdir}/swapfile

By lowering the "highwater mark" to 35000000 from 40000000, now my swapfiles are disappearing once in a while. Most noticeably when I run classic, look in /private/var/vm, then stop Classic. Look in /private/var/vm again. Tada!

Note that Apple's dynamic_pager is very poorly documented and I just got lucky with my choice of numbers. Being a crucial component of the OS, dynamic_pager really needs some comprehensive documentation!

[ Reply to This | # ]

Tuning maxvnodes for better system peformance
Authored by: carsten on Jul 19, '03 09:33:18AM
Oops, I meant to say in my last message:

I couldn't get the script to work, it always says "expr: syntax error". So I just added this before the expr line:


echo "vnodesused=${vnodesused}"
echo "vnodesmax=${vnodesmax}"


[ Reply to This | # ]
syntax errror
Authored by: nicola on Jul 19, '03 10:36:30AM

Just add a backslash before the '*' in the expression.



[ Reply to This | # ]
Tuning maxvnodes for better system peformance
Authored by: david-bo on Jul 20, '03 03:58:43PM

On my PBG3 with 384MB I get 99% when I run this script and only have a few (less than 10) programs open. This seems completely unreasonable?

---
http://www.google.com/search?as_q=%22Authored+by%3A+david-bo%22&num=10&hl=en&ie=ISO-8859-1&btnG=



[ Reply to This | # ]
Tuning maxvnodes for better system peformance
Authored by: zedwards on Oct 04, '03 08:32:01PM

OK, Apple seemed to pull this or it is lost somewhere in the discussions. Does anyone have the text from this article? I posted only the link and not the instructions.



[ Reply to This | # ]
Apple thinks secret, but the net never forgets...
Authored by: voldenuit on Oct 05, '03 05:26:47AM

As I saw this coming, I kept a local copy, no idea how much of the thread will fit in one comment, here we go, there were more messages in the thread but nothing really brilliant as far as I remember :

Discussions >Mac OS X >Getting Started and General Use >Using Mac OS X >Tuning maxvnodes for better performance

Topic: Tuning maxvnodes for better performance
Outline
Charles Richmond
Original Message
(Posted Jul 1, 03 5:41 am)
***

Posts: 783
Powerbook G4 17
Mac OS X (10.2.x)
+30 yrs S/W, O/S & H/W design
If you are seeing too many spinning beachballs or your system seems to get slower and slower and only a reboot fixes it. (or MacJanitor or running the Weekly script) If you have already added RAM then tuning the kernel parameter maxvnodes may help. If you are running on less than 512M do not do this. Buy RAM instead. If you have less than 1G RAM then instead of 84672 use 51904 instead of 84672 and use 36032 instead of 68800. If you are confused by this post, do not do anything until you fully understand the edits that you will be doing.
The following instructions must be followed exactly! A typo could interfere with the efficiency of your system. Use cut/paste or type very carefully and slowly in your text editor. When editing /etc/rc make a backup copy first by:
sudo cp /etc/rc /etc/rc.bck
First to see if the change will be beneficial, wait unto your system is being sluggish and in a terminal window do the following commands:
pstat -T
sysctl kern.maxvnodes
If the numbers are close then you likely will benefit from increasing the maximum number of vnodes by tuning.
To try the tuning change without making it permanent:
sudo sysctl -w kern.maxvnodes=84672
Run with this for awhile, but if you reboot it will be gone. Lets see if things get better. If you want it to survive a reboot then add similar lines to /etc/rc just below where is says, ConsoleMessage "Starting virtual memory"
## by cmr (put your initials if you like)
/usr/sbin/sysctl -w kern.maxvnodes=68800
## end cmr
So the finished area will look like:
##
# Start the virtual memory system.
##
ConsoleMessage "Starting virtual memory"
## by cmr
/usr/sbin/sysctl -w kern.maxvnodes=68800
## end cmr
swapdir=/private/var/vm
if [ "${netboot}" = "1" ]; then
    sh /etc/rc.netboot setup_vm ${swapdir}
fi
Even though the number '68800' is used above after a reboot the value of maxvnodes will go to 84672 because the SystemStart adds 512*(number of 32M segments of RAM - 1) to the number we set. If it doesn't make sense, don't worry about it :) An even higher number is working fine on my machine.
Hope this is Helpful

Messages 51 - 57 of 57    Previous  |  View All
Charles Richmond
RE(1): RE: Tuning maxvnodes for better performance
(msg # 11.1 : Posted Jul 11, 03 5:27 am)
*

 
Posts: 783
Powerbook G4 17
Mac OS X (10.2.x)
+30 yrs S/W, O/S & H/W design
Think you could write this into an Applescript?
It would be a fairly complex script as there are a lot of decisions to be made.
1. Is `sysctl kern.maxvnodes` *close to* `pstat -T`
 no == forget it
yes == how much RAM in the system
<512M == forget it
  other amounts -- assign values and edit file...
But I have an idea for a scriptable solution... let me try it out and get back to you.
In the meantime, if you have any applescript examples that modify the contents of text files, it might help me to look at them.

a brody
(Helper )
RE(2): RE: Tuning maxvnodes for better performance
(msg # 11.1.1 : Posted Jul 11, 03 7:36 pm)
*

 
Posts: 6732
iMac G4/800 Superdrive
Mac OS X (10.2.x)
http://www.macm aps.com Olympus C-700, iPod 20
You could probably tell the terminal to cat two files together using Applescript!
http://ftp.crihan.fr/mirrors/ftp.redhat.com/redhat/linux/8.0/en/doc/RH-DOCS/rhl-gsg-en-8.0/s1-navigating-usingcat.html
explains how to use cat to concatenate two files together.
As for individual line editing through Applescript that's beyond what I know.

Charles Richmond
RE(3): RE: Tuning maxvnodes for better performance
(msg # 11.1.1.1 : Posted Jul 11, 03 9:35 pm)
*

 
Posts: 783
Powerbook G4 17
Mac OS X (10.2.x)
+30 yrs S/W, O/S & H/W design
For what I have in mind, con cat tenating 2 files won't do it. I can do it with UNIX scripting languages like perl or bython or with a hybrid like sed.... I'll think on it and put it on one of my web sites.

P T Withington
RE: Tuning maxvnodes for better performance
(msg # 12. : Posted Jul 16, 03 1:59 pm)
*

 
Posts: 8
Just curious, how did you come up with the numbers you suggest?

Charles Richmond
RE(1): RE: Tuning maxvnodes for better performance
(msg # 12.1 : Posted Jul 16, 03 4:26 pm)
*

 
Posts: 783
Powerbook G4 17
Mac OS X (10.2.x)
+30 yrs S/W, O/S & H/W design
Just curious, how did you come up with the numbers you suggest?
Empirically :) I was helping someone who had a really bad case of vnode starvation and trying to balance the really big values suggested for the various other BSDs with Apple's really low numbers. I tried to err on the side of caution by using smaller numbers than the BSDs were suggesting. Then I ran with the higest values for a couple of weeks to verify with my own system.

andre santos1
RE: Tuning maxvnodes for better performance
(msg # 13. : Posted Jul 16, 03 4:05 pm)
*

 
Posts: 10
iMac G3 700 CDRW
Mac OS X (10.2.x)
512 RAM
Hi Charles !
look at this : pstat -T
223/12288 files
   5519 vnodes
swapmode is not (yet) available under Mach
 andreluiz% sysctl kern.maxvnodes
kern.maxvnodes = 9008
What do you thing about ? Do i need the tuning or not ? If yes , what values ? Thanks for all help

Charles Richmond
RE(1): RE: Tuning maxvnodes for better performance
(msg # 13.1 : Posted Jul 16, 03 4:36 pm)
*

 
Posts: 783
Powerbook G4 17
Mac OS X (10.2.x)
+30 yrs S/W, O/S & H/W design
What do you thing about ? Do i need the tuning or not ? If yes , what values ? Thanks for all help
No you are only using 61% of your available vnodes. But if that was when your system was lightly loaded, then do the pstat command when the system is sluggish and see what you get. From the look of things, you have 512M RAM so you could use the smaller set of numbers that I give in the first post.



[ Reply to This | # ]
Apple thinks secret, but the net never forgets...
Authored by: Cecily on Nov 14, '03 11:28:24AM

Silly question, quite probably - but my rc file doesn't contain the line ConsoleMessage "Starting virtual memory" - it says echo "Starting Virtual Memory" (I'm running Panther). Is it safe to add the extra lines to the rc file just before this line?



[ Reply to This | # ]
Apple thinks secret, but the net never forgets...
Authored by: bluehz on Nov 14, '03 08:54:23PM

Works just fine in Panther. I say "works" meaning it causes no ill effects. Whether it actually does anything is anyones guess. Just a note though - if you are running the default crontasks for os x that run at 3am or so - all bets are off. This process completely whacks out maxvnodes and when you get up in the morning it is ALWAYS at 100%. I guess I shouldn't say "whacks out" what I mean is - it completely obliterates any maxvnodes tuning you have done. Something about touching/accessing hundreds of files so I've read.



[ Reply to This | # ]
pstat -T = 51883 vnodes
Authored by: kupietz on Mar 16, '04 07:41:10PM
I can confirm this. Don't know which script causes this, but I just entered the maxvnodes adjustment, then ran all 3 (daily, weekly, monthly) and now I get:
Mike-Kupietzs-Computer:~ Kupietz$ pstat -T
612/12288 files
  51883 vnodes
swapmode is not (yet) available under Mach
Mike-Kupietzs-Computer:~ Kupietz$ sysctl kern.maxvnodes
kern.maxvnodes = 51904
So... does someone more knowledgable want to comment on what this might mean in terms of performance?

[ Reply to This | # ]
advice from an Apple kernel developer
Authored by: hayne on Dec 08, '04 01:57:38PM
I found the following discussion in the archives of the Darwin development email list:
http://lists.apple.com/archives/darwin-development/2002/Aug/msg00441.html
The writer is/was apparently one of Apple's kernel developers and so presumably knows what he/she is talking about.

Summary:
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. Therefore you should only consider increasing maxvnodes if you always have lots of "free memory" as shown in 'top' or "Activity Monitor", and if you hardly ever get pageouts (also shown in 'top' or "Activity Monitor").

The default value is a compromise that is expected to result in the best overall performance for people using OS X as a "desktop OS" - i.e. for running GUI applications, etc.
If you are running OS X primarily for use as a server, or if your usage differs significantly from the norm, you might find it useful to tune the maxvnodes number. But only if you have a lot more RAM than is needed for the apps you run!

[ Reply to This | # ]

Tuning maxvnodes for better system peformance
Authored by: dylanjames on Sep 30, '05 01:11:25PM

Well, it would appear that in the Tiger update, Apple has removed "pstat"... is there another way of discerning the state of the inode cache?



[ Reply to This | # ]