views:

26

answers:

2

I have a Java application running on Linux with Xmx set to 1200M

When I check the process in TOP, I see numbers like: VIRT = 1412m RES = 237m SHR = 58m

Inside the Java application, I am printing the Runtime.getRuntime().totalMemory() every minute and the number there shows:

totalMemory() = 108M

Why such a big difference between the values of RES and totalMemory()?

My understanding (which could be wrong) -- totalMemory() is the memory used right now in the Heap. RES -- actual RAM memory used by the Process.

As an update: Yes, I would expect the RES > totalMemory() - but the difference here is 237MB - 108MB = 129MB. So if someone asks me, what is the maximum memory that my Java application can use, it should be 1200MB + "something" - question is how to know that "something" .. is it 150MB? 200MB? 300MB?

A: 

RES will probably include the size of the shared libraries loaded by the JVM, many of which might also be loaded for other applications (such as the C runtime library) and as such don't really count against the actual memory usage of the JVM, but are considered part of its resident memory image.

Actual interpretation of the results of ps or top are probably better directed to superuser.org or serverfault.org.

Jherico
A: 

totalMemory just is a Max heap size, the Java process contains Java heap and otherthings,for example,permanent area,so the size of RES always is biger than java heap's.

Mercy
Yes, I would expect the RES > totalMemory() - but the difference here is 237MB - 108MB = 129MB. So if someone asks me, what is the maximum memory that my Java application can use, it should be 1200MB + "something" - question is how to know that "something" .. is it 150MB? 200MB? 300MB?
sunny8107
It just can set the max size of Heap and permanent area,and it's not limited if the memnory is enough.Someting is like permanent are(can set),code generation,GC,JNI allocated memonry and so on.You can refer to here:http://www.slideshare.net/gengmao/inside-the-jvm-memory-management-and-troubleshootingIt may help you.
Mercy