Got it

What's the difference between XMX, XMS and XSS in JVM?

Latest reply: May 11, 2022 08:44:00 7125 9 7 0 0

Hi, everyone!

Do you know the JVM options XMX and XMS? Don't worry, in this post, we can discuss the XMX, XMS and XSS.

1. What is XMX?

Xmx indicates the maximum memory size that can be occupied during program running. If the running of the program requires more memory, the OutOfMemory exception is thrown.

2. What is XMS?

Xms indicates the size of the memory occupied when the program is started. Generally, larger programs start faster but may cause the machine to slow down temporarily.

3. What is XSS?

Xss refers to setting the stack size of each thread. This depends on your program, how much memory a thread needs to occupy, how many threads may be running at the same time, etc.


By default, the unit of the preceding three parameters is the byte. You can add [k/K] or [m/M] to the end of a number to indicate KB or MB. Also, it is not possible to exceed the memory size of the machine itself, or you will wait for the machine to slow down rather than the program to slow down.

1. -XMS indicates the memory allocated during JVM startup. For example, Xms200m indicates that 200 MB is allocated.

2. -XMX indicates the maximum memory allocated during JVM running. For example, -Xms500m indicates that the JVM process can occupy a maximum of 500 MB memory. 

3. -XSS Memory size allocated to each thread started by the JVM. The default value is 256 KB in JDK1.4 and 1 MB in JDK1.5+.

Total Memory

-XMX

-XMS

-XSS

Spare Memory

JDK

Number of threads

1024M

256M

256M

256K

768M

1.4

3072

1024M

256M

256M

256K

768M

1.5

768

The table above only gives a rough estimate of the maximum number of threads that can be created in java under a given memory condition. With the increase of -Xmx, less free memory is available and fewer threads can be created. In JDK 1.4 and JDK 1.5 versions, the number of threads that can be created varies according to the memory size of each thread.

4. Common Configuration Examples

Heap Size Settings 

The maximum heap size in the JVM has three limitations: the data model (32-bit or 64-bit) of the related operating system; The available virtual memory limit of the system; The available physical memory of the system is limited to 1.5 GB to 2 GB in a 32-bit system. 64 indicates that the operating system has no memory limitation. I tested it on Windows Server 2003 with 3.5 GB physical memory and JDK 5.0. The maximum value can be set to 1478 m. 

Typical settings: 

java -Xmx3550m -Xms3550m -Xmn2g -Xss128k 

-Xmx3550m: Sets the maximum available memory of the JVM to 3550 MB.

-Xms3550m: Sets the JVM drive memory to 3550m. This value can be set to the same value as -Xmx to prevent the JVM from reallocating memory each time garbage collection is complete. 

-Xmn2g: Set the size of the young generation to 2 GB. Entire heap size = Size of the young generation + Size of the old generation + Size of the persistent generation. Persistent generation is usually fixed at 64m, so increasing the younger generation will reduce the older generation size. This value has a great impact on the system performance. Sun officially recommends that the value be 3/8 of the entire heap. 

-Xs128k: Sets the stack size of each thread. In JDK5.0 and later versions, the stack size of each thread is 1 MB. In earlier versions, the stack size of each thread is 256 KB. Adjust the memory size required by more applicable threads. Decreasing this value generates more threads under the same physical memory. However, the operating system still limits the number of threads in a process. The number of threads cannot be generated indefinitely. The empirical value ranges from 3000 to 5000.


5. java JVM Fabricator Options: Xms Xmx PermSize MaxPermSize Differences

Examples are used to illustrate the meaning: 

 1. -Xms128m 

The minimum size of the JVM Heap (heap memory) is 128 MB and the initial allocation is performed. 

2.  -Xmx512m 

The maximum size of the JVM heap memory (heap memory) is 256 MB, which is allocated on demand.

Clarification: If -Xmx is not specified to be too small, exploitation may result in a java.lang.OutOfMemory bug. This bug is caused by the fact that the JVM is not Throwable and cannot be captured by try...catch. 

PermSize and MaxPermSize indicate that the fabricator assigns memory limits to reflective things such as class things and essential things. This memory is not contained in the Heap area. 

-XX: PermSize=64MB minimum size, initial allocation.

-XX: MaxPermSize=256MB Maximum Allowable Dispatch Size, On Demand Dispatch.

If the value is too small, the following causes: java.lang.OutOfMemoryError: PermGen space.

The default value of MaxPermSize is consistent with the -server and -client option.

The default value of MaxPermSize under the -server option is 64m.

The default value of MaxPermSize is 32 m when the -client option is used.

That's all for now and will be updated in the future.

  • x
  • convention:

little_fish
Admin Created Feb 10, 2022 03:07:59

Use -Xmx to specify the maximum heap size
Use -Xms to specify the initial Java heap size
Use -Xss to set the Java thread stack size
View more
  • x
  • convention:

olive.zhao
Admin Created Aug 17, 2021 09:52:01

Thanks for your sharing!
It is very useful!
View more
  • x
  • convention:

nagu
Created Aug 17, 2021 11:41:04

Great share
View more
  • x
  • convention:

Unicef
MVE Created Aug 18, 2021 07:25:45

GOOD
View more
  • x
  • convention:

little_fish
Admin Created Dec 21, 2021 03:22:44

Very good
View more
  • x
  • convention:

Imnh
Created Dec 21, 2021 06:25:27

Good share
View more
  • x
  • convention:

little_fish
Admin Created Feb 10, 2022 03:07:59

Use -Xmx to specify the maximum heap size
Use -Xms to specify the initial Java heap size
Use -Xss to set the Java thread stack size
View more
  • x
  • convention:

Saqibaz
Created Feb 10, 2022 09:45:50

thanks for sharing
View more
  • x
  • convention:

user_4358465
Created Feb 18, 2022 15:45:22

Very helpful tutorial, thanks for sharing
View more
  • x
  • convention:

pupu.F
Created May 11, 2022 08:44:00

A good post about introduction XMS vs XMX.

View more
  • x
  • convention:

Comment

You need to log in to comment to the post Login | Register
Comment

Notice: To protect the legitimate rights and interests of you, the community, and third parties, do not release content that may bring legal risks to all parties, including but are not limited to the following:
  • Politically sensitive content
  • Content concerning pornography, gambling, and drug abuse
  • Content that may disclose or infringe upon others ' commercial secrets, intellectual properties, including trade marks, copyrights, and patents, and personal privacy
Do not share your account and password with others. All operations performed using your account will be regarded as your own actions and all consequences arising therefrom will be borne by you. For details, see " User Agreement."

My Followers

Login and enjoy all the member benefits

Login

Block
Are you sure to block this user?
Users on your blacklist cannot comment on your post,cannot mention you, cannot send you private messages.
Reminder
Please bind your phone number to obtain invitation bonus.
Information Protection Guide
Thanks for using Huawei Enterprise Support Community! We will help you learn how we collect, use, store and share your personal information and the rights you have in accordance with Privacy Policy and User Agreement.