Jvm Heap Parameters

What are the -Xms and -Xmx parameters when starting JVM?

The flag Xmx specifies the maximum memory allocation pool for a Java Virtual Machine (JVM), while Xms specifies the initial memory allocation pool.

This means that your JVM will be started with Xms amount of memory and will be able to use a maximum of Xmx amount of memory. For example, starting a JVM like below will start it with 256 MB of memory and will allow the process to use up to 2048 MB of memory:

java -Xms256m -Xmx2048m

The memory flag can also be specified in different sizes, such as kilobytes, megabytes, and so on.

-Xmx1024k
-Xmx512m
-Xmx8g

The Xms flag has no default value, and Xmx typically has a default value of 256 MB. A common use for these flags is when you encounter a java.lang.OutOfMemoryError.

When using these settings, keep in mind that these settings are for the JVM's heap, and that the JVM can and will use more memory than just the size allocated to the heap. From Oracle's documentation:

Note that the JVM uses more memory than just the heap. For example Java methods, thread stacks and native handles are allocated in memory separate from the heap, as well as JVM internal data structures.

JVM heap parameters

To summarize the information found after the link:
The JVM allocates the amount specified by -Xms but the OS usually does not allocate real pages until they are needed. So the JVM allocates virtual memory as specified by Xms but only allocates physical memory as is needed.

You can see this by using Process Explorer by Sysinternals instead of task manager on windows.

So there is a real difference between using -Xms64M and -Xms512M.
But I think the most important difference is the one you already pointed out: the garbage collector will run more often if you really need the 512MB but only started with 64MB.

Will process be allocated enough heap when no explicit parameters are specified?

Given your the available RAM on your machine, if you are running a 64-bit JVM in server mode, then yes, the heap size will be able to go up to approximately 7.5 GB.

Documentation (I highlighted the relevant parts):

Client JVM Default Initial and Maximum Heap Sizes

The default maximum heap size is half of the physical memory up to a physical memory size of 192 megabytes (MB) and otherwise one fourth of the physical memory up to a physical memory size of 1 gigabyte (GB).

Server JVM Default Initial and Maximum Heap Sizes

The default initial and maximum heap sizes work similarly on the server JVM as it does on the client JVM, except that the default values can go higher. On 32-bit JVMs, the default maximum heap size can be up to 1 GB if there is 4 GB or more of physical memory. On 64-bit JVMs, the default maximum heap size can be up to 32 GB if there is 128 GB or more of physical memory. You can always set a higher or lower initial and maximum heap by specifying those values directly; see the next section.

Again, assuming a 64-bit JVM running in server mode, the default max heap size according to the documentation will be one fourth of your total RAM. So approximately 7.5 GB in your case (1/4 of 30 GB).

If running a 32-bit JVM in server mode, you'll be capped at 1 GB. And in client mode, your max will be 256 MB.

Why are JVM memory parameters usually in multiples of 256?

It is not necessary to use a multiple of 2 for the JVM memory parameters. It is just common use for memory allocation to double the value if the old one isn't enough.

If you increase your assigned memory value in 1MB steps you will have to adjust the value several (hundred) times before the configuration matches you requirements. So it it just more comfortable to double the old value.

This relies on the fact that memory is a cheap ressource in those days.

EDIT:

As you already mentioned it is possible to assign values like 1000 MB or 381 MB. The JVM can handle every memory size that is big enough to host the permGenSpace, the stack and the heap.

Which arguments stand for what in JVM memory options?

-Xms: this option sets the initial and minimum Java heap size.

-Xmx:
This option sets the maximum Java heap size. The Java heap (the “heap”) is the part of the memory where blocks of memory are allocated to objects and freed during garbage collection.

-XX:PermSize: -XX:MaxPermSize: are used to set size for Permanent Generation. The permanent space is where are stored the class, methods, internalized strings, and similar objects used by the VM and never deallocated (hence the name).

-Xss: sets the thread stack size. Thread stacks are memory areas allocated for each Java thread for their internal use. This is where the thread stores its local execution state.

-Xns: sets the nursery size. the JRockit JVM uses a nursery when the generational garbage collection model is used, that is, when the dynamic garbage collector has determined that the generational garbage collection model should be used or when the static generational concurrent garbage collector ( -Xgc : gencon) has been selected. You can also use -Xns to set a static nursery size when running a dynamic garbage collector (-XgcPrio).

  • If you are getting java.lang.OutOfMemoryError: Java heap space than change the value of -Xmx and -Xms.

  • if you are getting java.lang.OutOfMemoryError: PermGen space than try increasing the - XX:MaxPermSize value.

  • if you are getting java.lang.StackOverflowError than try increasing the -Xss value. It may be helpful by increasing the stack size but you should have a look at your code as well.

How to run Ignite with defined JVM heap

You can use -Xms, -Xmx to set JVM memory parameters.

Here is more information: https://apacheignite.readme.io/docs/jvm-and-system-tuning
and: https://apacheignite.readme.io/docs/preparing-for-production

JDK 11 specific: https://docs.oracle.com/cd/E15523_01/web.1111/e13814/jvm_tuning.htm#PERFM160

In the Ignite logs you could see how much memory was allocated along with other parameters: look for these lines:

[IgniteKernal] Language runtime: Java Platform API Specification ver. 11 

[IgniteKernal] VM information: Java(TM) SE Runtime Environment 11.0.4+10-LTS Oracle
Corporation Java HotSpot(TM) 64-Bit Server VM 11.0.4+10-LTS

[IgniteKernal] VM total memory: 1.0GB

[IgniteKernal] VM arguments: [-Xms1g, -Xmx1g, ...

Is there any advantage in setting Xms and Xmx to the same value?

Well there are couple of things.

  1. Program will start with -Xms value and if the value is lesser it will eventually force GC to occur more frequently
  2. Once the program reaches -Xms heap, jvm request OS for additional memory and eventually grabs -Xmx that requires additional time leading to performance issue, you might as well set it to that at the beginning avoiding jvm to request additional memory.

It is very nicely answered here - https://developer.jboss.org/thread/149559?_sscc=t

What is the default max heap size (-Xmx) in Java 8?

It varies on implementation and version, but usually it depends on the VM used (e.g. client or server, see -client and -server parameters) and on your system memory.

Often for client the default value is 1/4th of your physical memory or 1GB (whichever is smaller).

Also Java configuration options (command line parameters) can be "outsourced" to environment variables including the -Xmx, which can change the default (meaning specify a new default). Specifically the JAVA_TOOL_OPTIONS environment variable is checked by all Java tools and used if exists (more details here and here).

You can run the following command to see default values:

java -XX:+PrintFlagsFinal -version

It gives you a loooong list, -Xmx is in MaxHeapSize, -Xms is in InitialHeapSize. Filter your output (e.g. |grep on linux) or save it in a file so you can search in it.



Related Topics



Leave a reply



Submit