There is a difference between -Xmx
and -Xms
. Xmx
reserves virtual memory (which you have plenty of). So for example some code like this (same numbers on Mac OSX
and a few versions of linux):
public class DeleteMe {
public static void main(String[] args) {
LockSupport.parkNanos(TimeUnit.SECONDS.toNanos(1));
System.out.println("done");
}
}
run with time java -Xmx5120g DeleteMe.java
and time java -Xmx50 DeleteMe.java
shows almost the same times. Reserving 5120 GB
and 50MB
of virtual memory has no difference, time wise.
On the other hand -Xms
commits this memory to the process, and that is more expensive. So running:
time java -Xms5120g DeleteMe.java
Shows around 9 and 10 seconds, while :
time java -Xms50m DeleteMe.java
Shows around one second only.
So yes there is some delay for those calls. Whether you can go above your physical RAM
when requesting memory, depends on the vm.overcommit_memory
flag for linux
. I do not know what settings governs this on Windows, though.
Testing your exact scenario with -Xms512g
and -Xms512m
, still reveals at least 1 second
delay in the times. As noted in the comment it is worth mentioning the -XX:+AlwaysPreTouch
flag also. It will pre-touch all committed memory, so up to -Xms
, this obviously means that with such a flag and a big size of -Xms
(as long as you have that much physical memory), start-up will be a lot slower.