0

I have a linux machine where I'm running a Java application. I'm running the jvm with those parameters: -Xmx27231m -Xms27231m

However when I look at htop/top. What I see for the system overall and the process specifically is that the jvm is actually not reserving the 27GB of heap I'm asking it to. What I see instead is that Virt: 32.8G RES: 15.3G SHR:16536

In all my other prod/qa/dev machines the RES reflects the exact amount (maybe a bit more) as the heap size I'm asking JVM to reserve for me. However for one particular machine this is not the case. I'm clueless of why this is happening.

I attached Java Mission Control to that process and I see that the InitialHeapSize and the MaxHeapSize actually have the correct value, however the type is not CommandLine but Ergonomic instead. I don't really know what that means.

Anyone? Thanks

Michael P
  • 2,017
  • 3
  • 25
  • 33
  • If you allocate it but aren't using it it is not necessarily the case that it will all be resident, especially if there's memory contention. The `Virt: 32.8G` indicates the memory is all there, just not all of it is swapped in. – Jim Garrison Dec 07 '17 at 23:20
  • What do you mean by swapped in? In every machine I have, the amount of memory I set for the heap, that's how much the RES shows up. and I am using this machine, there are a lot of allocations – Michael P Dec 08 '17 at 01:26
  • RES is "Resident". If there is memory contention, some of the memory that is not being currently accessed can be swapped out to disk. This is the whole point of swap space. What else is running on that system? Anything else memory intensive? – Jim Garrison Dec 08 '17 at 04:44
  • Possible duplicate of [Why does a JVM report more committed memory than the linux process resident set size?](https://stackoverflow.com/questions/31173374/why-does-a-jvm-report-more-committed-memory-than-the-linux-process-resident-set) – the8472 Dec 08 '17 at 22:40

1 Answers1

3

The JVM doesn't pretouch the pages in advance, to reduce startup time. You can however use this option to force it to.

-XX:+AlwaysPreTouch -Xmx27g -Xms27g

BTW This won't prevent the JVM releasing the memory back to the OS if it is not used (though the JVM rarely does this AFAIK), nor will it lock the heap into main memory to prevent swapping.

However for one particular machine this is not the case.

Most likely it has not had the right activity to cause the memory to be used lazily.

Peter Lawrey
  • 525,659
  • 79
  • 751
  • 1,130