Reputation: 61
I got a new VPS to run some java programs that me and some buddies have made. I start the process with a line like this:
java -Xmx512M -jar program.jar
On our old VPS, you could use the 'top' command to see how much virtual and resident memory was being used. It would use like 600-700mb of virtual memory. Now on our new VPS, with that same command, the virtual memory seems to always be an extra ~2gb over the -Xmx value. So instead of the virtual memory being around 600-700mb, it's instead 2700-3000mb.
The old VPS is running CentOS 5.7 and the new is running CentOS 6.2. Both are running JRE 1.7u3 64bit.
Why is this and how can I fix it?
edit: top
PID USER PR NI VIRT RES SHR S %CPU %MEM TIME+ COMMAND
27645 pyro 20 0 3003m 270m 10m S 5.0 1.7 1:19.18 java -Xmx512M -jar cserver.jar
another edit: I am not questioning why virtual memory is using more memory than specified in the java command line. I am questioning why it is using so much more than it used to.
Upvotes: 6
Views: 2103
Reputation: 10020
Virtual memory usage means how much address space is used and does not necessarily translate directly into RAM usage. Stack, mapped files (including binaries and libraries), etc. all contribute to virtual memory but not always to the RAM actually used. Note that your RES (resident in RAM) memory usage is a rather nice 270 MB only. On a 32-bit machine, you may run into address space limitations, so there virtual memory is a scarce resource if you get close to the 2 GB mark (the value may also be 1 GB or 3 GB depending on OS). On a 64-bit system, virtual memory (address space) is close to unlimited, so by itself, a high value need not be treated as a risk. Of course, if it is also related to actual high RAM usage or lots of mapped files which you cannot find out why are used, it's worth looking into.
Of course, JVM also has some actual overhead (in physically allocated memory), related to garbage collector's house keeping, compiler's work, native code etc., and this will also be reflected in virtual memory usage. But since the RES and SHR positions are not very high, I'd say there's no reason to panic, especially if you're 64-bit.
Upvotes: 1
Reputation: 533550
The heap is not the only thing which consumes virtual memory. Virtual memory is the amount of address space the application has rather than the amount of memory it is using (the resident is a better indicator)
Virtual memory includes all the thread stack space, direct memory and memory mapped files.
The first thing I would check is the number of threads your application uses, the more threads, the more virtual memory.
Upvotes: 4