官网文档地址:https://docs.oracle.com/javase/8/docs/technotes/tools/unix/java.html
接录如下:
-XX:MaxHeapSize=size
Sets the maximum size (in byes) of the memory allocation pool. This value must be a multiple of 1024 and greater than 2 MB. Append the letter k or K to indicate kilobytes, m or M to indicate megabytes, g or G to indicate gigabytes. The default value is chosen at runtime based on system configuration. For server deployments, -XX:InitialHeapSize and -XX:MaxHeapSize are often set to the same value. See the section "Ergonomics" in Java SE HotSpot Virtual Machine Garbage Collection Tuning Guide at
The following examples show how to set the maximum allowed size of allocated memory to 80 MB using various units:
-XX:MaxHeapSize=83886080
-XX:MaxHeapSize=81920k
-XX:MaxHeapSize=80m
On Oracle Solaris 7 and Oracle Solaris 8 SPARC platforms, the upper limit for this value is approximately 4,000 MB minus overhead amounts. On Oracle Solaris 2.6 and x86 platforms, the upper limit is approximately 2,000 MB minus overhead amounts. On Linux platforms, the upper limit is approximately 2,000 MB minus overhead amounts.
The -XX:MaxHeapSize option is equivalent to -Xmx.
大致是这么几点:
linux操作系统上堆内存最大的设置是2个G。
-XX:MaxHeapSize 等价于 -Xmx
这个值必须是1024的倍数并且大于2 MB
不过以上似乎只是32位机器上的设置,在64位机器上堆内存将不受此限制,但在官网上没找到原话。