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.