tomcat-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From David Crooke <>
Subject Re: How to allocate memory to JVM
Date Fri, 08 Nov 2002 07:57:16 GMT
Ob.Note: This is a JVM and Linux question, not a Tomcat question - there 
are more suitable lists.

Briefly, use the JVM parameters -ms and -mx to control the initial and 
maximum Java heap size. A busy JVM will take a total OS-level memory 
footprint (as shown by RSS in /usr/bin/top) of about 50-75Mb more than 
this (JVM executable, stack etc.). Memory pages are only allocated when 
used, irrespective of -ms value.

For performance tuning a dedicated Java appserver, set -mx to as much 
memory as you can comfortably allocate to heap while making sure the JVM 
process will NEVER get paged or swapped, and that you leave enough 
memory for other functions such as disk cacheing. If you're running 
Apache on the same box (we're not) then save a bit of RAM for it, etc.

A Java web application doesn't like being paged by most OS kernels; 
locality of memory references is not congruent, this ain't FORTRAN.  Set 
-ms to the same as -mx and make sure the hotspot compiler etc. is on. Be 
wary of giant heap sizes on Java 1.2 and older as large garbage 
collections can stall the VM for long periods.

Linux gives strong (in fact I think absolute) preference to process 
memory pages over disk buffer cache pages, so the JVM *will* get the 
physical RAM if it's there, if -mx is set apporpriately and if the JVM 
does not have to compete with other processes.

If -ms is less than -mx, the VM will try to garbage collect before 
extending the heap, and will extend it in little bits (e.g. 8Mb at a 
time) which is just messy. If your app has agressive cacheing, use a 
background thread to proactively manage your own cache unloading (weak 
references are, well, weak) and kick the GC up the butt every now and then.

Some real numbers: we run Sun JDK 1.2.2 with green threads, and run two 
JVM's on each box (dual Pentium 3, Linux 2.2). The boxes have 2Gb of 
physical RAM each, and we run the VM heaps with -mx of 768Mb each (total 
1.5Gb) leaving 512Mb for the OS, two JVM images / working areas, a 
couple of side processes such as sendmail, and that leaves about 150Mb 
of buffer cache. We did not ever find any of the 1.3 JVM's (IBM or Sun) 
we tested to be stable enough for long term production use - however 
Sun's 1.4.x on Linux 2.4 is looking promising. wrote:

>Hi !
>How does one allocate physical RAM to the JVM on a Linux RH box ?
>How does one change existing allocation.
>Keeping my fingers crossed.
>To unsubscribe, e-mail:   <>
>For additional commands, e-mail: <>

To unsubscribe, e-mail:   <>
For additional commands, e-mail: <>

View raw message