I ran into a permgen out of memory issue with one of our applications running on Tomcat/Railo and did a bit of digging around.
The main answer on the web is: Increase the size of you permgen by adding the following:
-XX:MaxPermSize=128m
However, to me this just delays the problem, particularly if you are using dynamic languages which load a lot of classes eg Railo.
So a bit of further digging found these options:
-XX:+UseConcMarkSweepGC -XX:+CMSClassUnloadingEnabled -XX:+CMSPermGenSweepingEnabled
These 3 options allow the permgen memory to be garbage collected. I tried to find a good reference link for them but couldn’t.
The final thing that I discovered was the jmap tool – which is very helpful for understanding the memory usage.
You run it as follows and it gives a great summary of the memory usage of your running jvm.
$ sudo jmap -heap 18068
Attaching to process ID 18068, please wait…
Error attaching to process: sun.jvm.hotspot.debugger.DebuggerException: Can’t attach to the process
markl@davoip:/opt/tomcat/bin$ sudo jmap -heap 18068
[sudo] password for markl:
Attaching to process ID 18068, please wait…
Debugger attached successfully.
Server compiler detected.
JVM version is 19.1-b02
using thread-local object allocation.
Parallel GC with 2 thread(s)
Heap Configuration:
MinHeapFreeRatio = 40
MaxHeapFreeRatio = 70
MaxHeapSize = 530579456 (506.0MB)
NewSize = 1048576 (1.0MB)
MaxNewSize = 4294901760 (4095.9375MB)
OldSize = 4194304 (4.0MB)
NewRatio = 2
SurvivorRatio = 8
PermSize = 16777216 (16.0MB)
MaxPermSize = 67108864 (64.0MB)
Heap Usage:
PS Young Generation
Eden Space:
capacity = 114294784 (109.0MB)
used = 54227688 (51.715553283691406MB)
free = 60067096 (57.284446716308594MB)
47.445461728157255% used
From Space:
capacity = 31260672 (29.8125MB)
used = 0 (0.0MB)
free = 31260672 (29.8125MB)
0.0% used
To Space:
capacity = 31260672 (29.8125MB)
used = 0 (0.0MB)
free = 31260672 (29.8125MB)
0.0% used
PS Old Generation
capacity = 353763328 (337.375MB)
used = 317909912 (303.1825180053711MB)
free = 35853416 (34.192481994628906MB)
89.86514057217371% used
PS Perm Generation
capacity = 46399488 (44.25MB)
used = 44117200 (42.07344055175781MB)
free = 2282288 (2.1765594482421875MB)
95.08122158589336% used
Cheers,
Mark