Java allocates an additional 2 GB of memory

I got a new VPS to run some java programs, which I and some buddies did. I start the process with a line like this:

java -Xmx512M -jar program.jar 

On our old VPS, you can use the "top" command to find out how much virtual and resident memory has been used. It will use as 600-700 mb virtual memory. Now on our new VPS with the same command, virtual memory will always be superfluous ~ 2gb by the value -Xmx. Thus, instead of virtual memory, about 600-700 mb instead of 2700-3000mb.

The old VPS launches CentOS 5.7, and the new CentOS 6.2. Both work on 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 don't wonder why virtual memory uses more memory than indicated on the java command line. I wonder why it uses much more than before.

+6
source share
2 answers

A heap is not the only thing that consumes virtual memory. Virtual memory is the amount of address space an application has, not the amount of memory used (resident is the best indicator)

Virtual memory includes the entire space of the thread stack, direct memory, and memory mapped files.

The first thing I would like to check is the number of threads that your application uses, the more threads, the more virtual memory.

+4
source

The use of virtual memory means how much address space is used and does not necessarily translate directly into RAM use. Stack, mapped files (including binaries and libraries), etc. Everyone contributes to virtual memory, but not always to the RAM used. Please note that using memory in RES (resident RAM) mode is quite pleasant with only 270 MB. On a 32-bit machine, you may encounter restrictions on the address space, so virtual memory is a scarce resource if you approach the 2 GB mark (the value may also be 1 GB or 3 GB depending on the OS). In a 64-bit system, virtual memory (address space) is close to unlimited, therefore, high value in itself should not be considered a risk. Of course, if it is also associated with the actual use of high RAM or a lot of displayed files that you cannot find out why use them, it is worth a look.

Of course, the JVM also has some actual overhead (in physically distributed memory) associated with storing the garbage collector, compiler operation, native code, etc., and this will also be reflected in the use of virtual memory. But since the positions of RES and SHR are not very high, I would say that there is no reason to panic, especially if you are 64-bit.

+1
source

Source: https://habr.com/ru/post/910473/


All Articles