I have questions about some strange behavior I am seeing with Java 5.0 on Linux.
First here is the environment:
Code:
[~]:> uname -a
Linux xxxxxxxxxx 2.4.21-47.ELsmp #1 SMP Wed Jul 5 20:38:41 EDT 2006 i686 i686 i386 GNU/Linux
[~]:> java -version
java version "1.5.0_12"
Java(TM) 2 Runtime Environment, Standard Edition (build 1.5.0_12-b04)
Java HotSpot(TM) Server VM (build 1.5.0_12-b04, mixed mode)
I wrote a very simple java program that just starts up and sleeps.
Wait.java:
Code:
import java.lang.*;
public class Wait{
public static void main(String args[]) throws Throwable{
Thread.sleep(100000);
}
}
I run the program with no memory arguments:
Code:
[~]:> java -classpath . Wait &
[1] 30841
[~]:> pmap 30841 | tail -1
mapped: 1220332K writeable/private: 1160336K shared: 49468K
Note that pmap is showing me that it is using over 1 gig of memory. The java documentation says that if I don't specify a max heap size that the Max heap is 64 Megs. 1 gig of memory for a 64 Meg heap is a lot of overhead.
Top however, seems to be showing me that I am only using 10 megs.
Code:
[~]:> top -bp 30841
08:44:00 up 187 days, 14:20, 12 users, load average: 0.38, 0.69, 0.37
1 processes: 1 sleeping, 0 running, 0 zombie, 0 stopped
CPU states: cpu user nice system irq softirq iowait idle
total 13.6% 0.0% 3.9% 0.0% 0.0% 7.0% 75.3%
cpu00 16.9% 0.0% 3.7% 0.0% 0.0% 5.6% 73.5%
cpu01 11.2% 0.0% 2.8% 0.0% 0.0% 8.4% 77.5%
cpu02 11.2% 0.0% 2.8% 0.0% 0.0% 6.5% 79.4%
cpu03 15.0% 0.0% 6.6% 0.0% 0.0% 7.5% 70.7%
Mem: 4101252k av, 3859028k used, 242224k free, 0k shrd, 145796k buff
2619760k actv, 545440k in_d, 65836k in_c
Swap: 2048184k av, 594480k used, 1453704k free 1726032k cached
PID USER PRI NI SIZE RSS SHARE STAT %CPU %MEM TIME CPU COMMAND
30841 xxxxxxx 21 0 10336 10M 6408 S 0.0 0.2 0:00 0 java
Now I run the program with a 64 meg min and max heap.
Code:
[~]:> java -classpath . -Xms64m -Xmx64m Wait &
[2] 30894
Then run pmap.
Code:
[~]:> pmap 30894 | tail -1
mapped: 256276K writeable/private: 196280K shared: 49468K
So it looks like it is using 196 megs. Which is fine because I know that there is overhead on top of the actual Heap size.
Then I run top on the process:
Code:
[~]:> top -bp 30894
08:45:13 up 187 days, 14:21, 12 users, load average: 0.26, 0.58, 0.36
1 processes: 1 sleeping, 0 running, 0 zombie, 0 stopped
CPU states: cpu user nice system irq softirq iowait idle
total 8.4% 0.0% 0.4% 0.2% 0.2% 7.4% 83.1%
cpu00 8.4% 0.0% 0.0% 0.9% 0.0% 6.5% 84.1%
cpu01 7.4% 0.0% 0.0% 0.0% 0.9% 7.4% 84.1%
cpu02 4.6% 0.0% 0.0% 0.0% 0.0% 8.4% 86.9%
cpu03 13.0% 0.0% 1.8% 0.0% 0.0% 7.4% 77.5%
Mem: 4101252k av, 3904008k used, 197244k free, 0k shrd, 146224k buff
2657632k actv, 549712k in_d, 65836k in_c
Swap: 2048184k av, 594480k used, 1453704k free 1731604k cached
PID USER PRI NI SIZE RSS SHARE STAT %CPU %MEM TIME CPU COMMAND
30894 xxxxxxx 21 0 10340 10M 6408 S 0.0 0.2 0:00 3 java
And it shows me that I am using 10 megs.
So what is going on here?
1) Why is top and pmap showing different values between the SIZE (top) and the writeable/private (pmap) ?
2) if the value in pmap is correct, why if I don't specify the max heap is it not taking the document default value?:
From the Java documentation:
Quote:
|
-Xmxn Specify the maximum size, in bytes, of the memory allocation pool. This value must a multiple of 1024 greater than 2MB. Append the letter k or K to indicate kilobytes, or m or M to indicate megabytes. The default value is 64MB.
|