I limit my java program with -Xmx2g -Xmn1280m -Xms2g -XX:MetaspaceSize=128m -XX:MaxMetaspaceSize=152m -XX:SurvivorRatio=8 -XX:+UseConcMarkSweepGC
.
And then, I use top to show memory uesage, which shows:
Tasks: 139 total, 1 running, 138 sleeping, 0 stopped, 0 zombie
%Cpu(s): 0.5 us, 0.9 sy, 0.2 ni, 98.4 id, 0.0 wa, 0.0 hi, 0.0 si, 0.0 st
KiB Mem : 7896536 total, 2724188 free, 1870168 used, 3302180 buff/cache
KiB Swap: 0 total, 0 free, 0 used. 5756128 avail Mem
PID USER PR NI VIRT RES SHR S %CPU %MEM TIME+ COMMAND
69518 service 20 0 4089960 1.5g 16916 S 1.3 19.3 3:03.27 java
The real memory uesage is 1.5g.
But I have already set the jvm heap size.
Why this happened?
Thank you very much.
Java heap memory and stack memory are virtual memory.
VIRT is the virtual memory space: the sum of everything in the virtual memory map.
RES is the resident set size: the number of pages that are currently resident in RAM.
In short, parameters above just affects the virtual memory.