Java on Linux - RES vs totalMemory()
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?
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.
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.
精彩评论