GC Tuning: NewRatio

When it comes to garbage collection tuning the first setting to be adjusted is often the heap size. This is not always the optimal choice though. If only because a bigger heap size will tend to mechanically lengthen the duration of GC pauses.

Instead of increasing the heap size it can pay to increase the size of the young generation relative to the old. That's where the NewRatio setting (i.e  ratio of the old gen space to the young gen space) comes in.

The screenshots below illustrate how GC activity differs when an application producing short-lived objects at a high frequency runs with NewRatio=2 and when it runs with NewRatio=1. Collections in the old gen disappear provided there's enough size in the young space to accomodate all the short lived objects.


NewRatio =2 (default setting on Windows 64 bits).





NewRatio =1


How to measure swap usage on Linux


On Linux (since version 2.6.14):

1- find out the pid of a process  
2- navigate to /proc/pid
3- edit the smaps file, and sum the swap value for each of the process mappings.

... or use the script found here to get the swap usage for each running process. The display below has been obtained by running that script on a Ubuntu guest OS (using Virtualbox on Windows) with base memory set at 128M.
















 All swaps values in kilobytes.