Unless the initial and maximum heap sizes are specified on the command line, they are calculated based on the amount of memory on the machine.
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:
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
What system configuration settings influence the default value?
You can specify the initial and maximum heap sizes using the flags -Xms (initial heap size) and -Xmx (maximum heap size). If you know how much heap your application needs to work well, you can set -Xms and -Xmx to the same value
A number of parameters affect generation size. The following diagram illustrates the difference between committed space and virtual space in the heap. At initialization of the virtual machine, the entire space for the heap is reserved. The size of the space reserved can be specified with the -Xmx option. If the value of the -Xms parameter is smaller than the value of the -Xmx parameter, not all of the space that is reserved is immediately committed to the virtual machine. The uncommitted space is labeled "virtual" in this figure. The different parts of the heap (permanent generation, tenured generation and young generation) can grow to the limit of the virtual space as needed.
By default, the virtual machine grows or shrinks the heap at each collection to try to keep the proportion of free space to live objects at each collection within a specific range. This target range is set as a percentage by the parameters -XX:MinHeapFreeRatio=<minimum> and -XX:MaxHeapFreeRatio=<maximum>, and the total size is bounded below by -Xms<min> and above by -Xmx<max>.
Parameter Default Value
MinHeapFreeRatio 40
MaxHeapFreeRatio 70
-Xms 3670k
-Xmx 64m
Default values of heap size parameters on 64-bit systems have been scaled up by approximately 30%. This increase is meant to compensate for the larger size of objects on a 64-bit system.
With these parameters, if the percent of free space in a generation falls below 40%, the generation will be expanded to maintain 40% free space, up to the maximum allowed size of the generation. Similarly, if the free space exceeds 70%, the generation will be contracted so that only 70% of the space is free, subject to the minimum size of the generation.
Large server applications often experience two problems with these defaults. One is slow startup, because the initial heap is small and must be resized over many major collections. A more pressing problem is that the default maximum heap size is unreasonably small for most server applications. The rules of thumb for server applications are:
Unless you have problems with pauses, try granting as much memory as
possible to the virtual machine. The default size (64MB) is often too
small.
Setting -Xms and -Xmx to the same value increases predictability by
removing the most important sizing decision from the virtual machine.
However, the virtual machine is then unable to compensate if you make
a poor choice.
In general, increase the memory as you increase the number of
processors, since allocation can be parallelized.
Larger of 1/64th of the machine's physical memory on the machine or some
reasonable minimum. Before J2SE 5.0,
the default initial heap size was a
reasonable minimum, which varies by
platform. You can override this
default using the -Xms command-line
option.
maximum heap size:
Smaller of 1/4th of the physical memory or 1GB. Before J2SE 5.0, the
default maximum heap size was 64MB.
You can override this default using
the -Xmx command-line option.
In the J2SE platform version 5.0 a
class of machine referred to as a
server-class machine has been defined
as a machine with
2 or more physical processors
2 or more Gbytes of physical memory
with the exception of 32 bit platforms
running a version of the Windows
operating system. On all other
platforms the default values are the
same as the default values for version
1.4.2.
In the J2SE platform version 1.4.2 by
default the following selections were
made
Java 8 takes more than 1/64th of your physical memory for your Xmssize (Minimum HeapSize) and less than 1/4th of your physical memory for your -Xmxsize (Maximum HeapSize).
that can be used to size the heap as a percentage of the usable physical RAM. (which is same as the RAM installed less what the kernel uses).
See Release Notes for Java8 u191 for more information. Note that the options are mentioned under a Docker heading but in fact they apply whether you are in Docker environment or in a traditional environment.
The default value for MaxRAMPercentage is 25%. This is extremely conservative.
My own rule: If your host is more or less dedicated to running the given java application, then you can without problems increase dramatically. If you are on Linux, only running standard daemons and have installed RAM from somewhere around 1 Gb and up then I wouldn't hesitate to use 75% for the JVM's heap. Again, remember that this is 75% of the RAM available, not the RAM installed. What is left is the other user land processes that may be running on the host and the other types of memory that the JVM needs (eg for stack). All together, this will typically fit nicely in the 25% that is left. Obviously, with even more installed RAM the 75% is a safer and safer bet. (I wish the JDK folks had implemented an option where you could specify a ladder)
Setting the MaxRAMPercentage option look like this:
java -XX:MaxRAMPercentage=75.0 ....
Note that these percentage values are of 'double' type and therefore you must specify them with a decimal dot. You get a somewhat odd error if you use "75" instead of "75.0".
Ernesto is right. According to the link he posted [1]:
Updated Client JVM heap configuration
In the Client JVM...
The default maximum heap size is half of the physical memory up to a physical memory size of 192 megabytes and otherwise one fourth of the physical memory up to a physical memory size of 1 gigabyte.
For example, if your machine has 128 megabytes of physical memory, then the maximum heap size is 64 megabytes, and greater than or equal to 1 gigabyte of physical memory results in a maximum heap size of 256 megabytes.
The maximum heap size is not actually used by the JVM unless your program creates enough objects to require it. A much smaller amount, termed the initial heap size, is allocated during JVM initialization. ...
...
Server JVM heap configuration ergonomics are now the same as the Client, except that the default maximum heap size for 32-bit JVMs is 1 gigabyte, corresponding to a physical memory size of 4 gigabytes, and for 64-bit JVMs is 32 gigabytes, corresponding to a physical memory size of 128 gigabytes.
发布评论
评论(10)
请查看文档 页面
客户端 JVM 默认初始和最大堆大小:
默认最大堆大小是物理内存的一半,最多为 192 兆字节 (MB),否则为物理内存的四分之一,最多为物理内存大小1 吉字节 (GB)。
服务器 JVM 默认初始和最大堆大小:
在 32 位 JVM 上,如果有 4 GB 或更多物理内存,默认最大堆大小可达 1 GB。 在 64 位 JVM 上,如果有 128 GB 或更多物理内存,默认最大堆大小可达 32 GB
您可以使用标志 -Xms(初始堆大小)和 -Xmx 指定初始堆大小和最大堆大小(最大堆大小)。如果您知道应用程序需要多少堆才能正常运行,则可以将 -Xms 和 -Xmx 设置为相同的值
Have a look at the documentation page
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:
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 specify the initial and maximum heap sizes using the flags -Xms (initial heap size) and -Xmx (maximum heap size). If you know how much heap your application needs to work well, you can set -Xms and -Xmx to the same value
许多参数会影响生成大小。下图说明了堆中提交空间和虚拟空间之间的区别。在虚拟机初始化时,堆的整个空间都被保留。保留空间的大小可以使用
-Xmx
选项指定。如果-Xms
参数的值小于-Xmx
参数的值,则并非所有保留的空间都会立即提交给虚拟机。未提交的空间在此图中标记为“虚拟”。堆的不同部分(永久代、终身代和年轻代)可以根据需要增长到虚拟空间的极限。情况下,虚拟机会在每个集合中增大或缩小堆,以尝试将每个集合中的可用空间与活动对象的比例保持在特定范围内。该目标范围由参数 -
XX:MinHeapFreeRatio=
和-XX:MaxHeapFreeRatio=
设置为百分比,总大小为下面以-Xms
为界,上面以-Xmx
为界。参数默认值
MinHeapFreeRatio 40
MaxHeapFreeRatio 70
-Xms 3670k
-Xmx 64m
64 位系统上堆大小参数的默认值已扩大约 30%。这种增加是为了补偿 64 位系统上较大的对象大小。
使用这些参数,如果一代中的可用空间百分比低于 40%,则该代将扩展以保持 40% 的可用空间,直至该代允许的最大大小。同样,如果可用空间超过 70%,则将收缩该代,以便只有 70% 的空间是可用的,但须遵守该代的最小大小。
大型服务器应用程序通常会遇到这些默认值的两个问题。一是启动缓慢,因为初始堆很小,必须在许多主要集合上调整大小。更紧迫的问题是,对于大多数服务器应用程序来说,默认的最大堆大小过小。服务器应用程序的经验法则是:
可以到虚拟机。默认大小 (64MB) 通常太大
小的。
从虚拟机中删除最重要的大小决策。
但是,如果您执行以下操作,虚拟机将无法进行补偿
一个糟糕的选择。
一般来说,随着数量的增加,内存也随之增加。
处理器,因为分配可以并行化。
这里有完整文章< /p>
A number of parameters affect generation size. The following diagram illustrates the difference between committed space and virtual space in the heap. At initialization of the virtual machine, the entire space for the heap is reserved. The size of the space reserved can be specified with the
-Xmx
option. If the value of the-Xms
parameter is smaller than the value of the-Xmx
parameter, not all of the space that is reserved is immediately committed to the virtual machine. The uncommitted space is labeled "virtual" in this figure. The different parts of the heap (permanent generation, tenured generation and young generation) can grow to the limit of the virtual space as needed.By default, the virtual machine grows or shrinks the heap at each collection to try to keep the proportion of free space to live objects at each collection within a specific range. This target range is set as a percentage by the parameters -
XX:MinHeapFreeRatio=<minimum>
and-XX:MaxHeapFreeRatio=<maximum>
, and the total size is bounded below by-Xms<min>
and above by-Xmx<max>
.Parameter Default Value
MinHeapFreeRatio 40
MaxHeapFreeRatio 70
-Xms 3670k
-Xmx 64m
Default values of heap size parameters on 64-bit systems have been scaled up by approximately 30%. This increase is meant to compensate for the larger size of objects on a 64-bit system.
With these parameters, if the percent of free space in a generation falls below 40%, the generation will be expanded to maintain 40% free space, up to the maximum allowed size of the generation. Similarly, if the free space exceeds 70%, the generation will be contracted so that only 70% of the space is free, subject to the minimum size of the generation.
Large server applications often experience two problems with these defaults. One is slow startup, because the initial heap is small and must be resized over many major collections. A more pressing problem is that the default maximum heap size is unreasonably small for most server applications. The rules of thumb for server applications are:
possible to the virtual machine. The default size (64MB) is often too
small.
removing the most important sizing decision from the virtual machine.
However, the virtual machine is then unable to compensate if you make
a poor choice.
In general, increase the memory as you increase the number of
processors, since allocation can be parallelized.
There is the full article
在 Windows 上,您可以使用以下命令来查找运行应用程序的系统上的默认值。
查找选项
MaxHeapSize
(对于-Xmx
)和InitialHeapSize
对于-Xms
。在 Unix/Linux 系统上,您可以这样做
,我相信结果输出以字节为单位。
On Windows, you can use the following command to find out the defaults on the system where your applications runs.
Look for the options
MaxHeapSize
(for-Xmx
) andInitialHeapSize
for-Xms
.On a Unix/Linux system, you can do
I believe the resulting output is in bytes.
对于 Java SE 5:根据 垃圾收集器人体工程学 [甲骨文]:
更新:
正如 Tom Anderson 在评论中指出的,以上内容适用于服务器级计算机。来自5.0 JavaTM 虚拟机中的人体工程学:
For Java SE 5: According to Garbage Collector Ergonomics [Oracle]:
UPDATE:
As pointed out by Tom Anderson in his comment, the above is for server-class machines. From Ergonomics in the 5.0 JavaTM Virtual Machine:
Java 8 的 Xmssize(最小堆大小)占用超过 1/64 物理内存,但少于 1/4 物理内存为您的 -Xmxsize(最大堆大小)。
您可以通过以下方式检查默认 Java 堆大小:
在 Windows 中:
在 Linux 中:
机器的物理内存和内存Java 版本。
Java 8 takes more than 1/64th of your physical memory for your Xmssize (Minimum HeapSize) and less than 1/4th of your physical memory for your -Xmxsize (Maximum HeapSize).
You can check the default Java heap size by:
In Windows:
In Linux:
The machine's physical memory & Java version.
这在 Java 6 update 18 中进行了更改。
假设我们有超过 1 GB 的物理内存(现在很常见),它始终是服务器虚拟机物理内存的 1/4。
This is changed in Java 6 update 18.
Assuming that we have more than 1 GB of physical memory (quite common these days), it's always 1/4th of your physical memory for the server vm.
最后!
从 Java 8u191 开始,您现在拥有以下选项:
可用于将堆大小设置为可用物理 RAM 的百分比。 (这与安装的 RAM 减去内核使用的 RAM 相同)。
有关详细信息,请参阅 Java8 u191 发行说明。请注意,这些选项是在 Docker 标题下提到的,但事实上,无论您是在 Docker 环境中还是在传统环境中,它们都适用。
MaxRAMPercentage
的默认值为 25%。这是极其保守的。我自己的规则:如果您的主机或多或少专用于运行给定的java应用程序,那么您可以毫无问题地大幅增加。如果您使用的是 Linux,仅运行标准守护进程,并且安装了大约 1 Gb 及以上的 RAM,那么我会毫不犹豫地将 75% 用于 JVM 堆。再次强调,这是可用 RAM 的 75%,而不是已安装 RAM 的 75%。剩下的是可能在主机上运行的其他用户态进程以及 JVM 需要的其他类型的内存(例如堆栈)。总而言之,这通常非常适合剩下的 25%。显然,如果安装的内存更多,75% 是一个越来越安全的选择。 (我希望 JDK 人员已经实现了一个可以指定梯子的选项)
设置 MaxRAMPercentage 选项如下所示:
请注意,这些百分比值是“双精度”类型,因此您必须 用小数点指定它们。如果您使用“75”而不是“75.0”,则会出现一些奇怪的错误。
Finally!
As of Java 8u191 you now have the options:
that can be used to size the heap as a percentage of the usable physical RAM. (which is same as the RAM installed less what the kernel uses).
See Release Notes for Java8 u191 for more information. Note that the options are mentioned under a Docker heading but in fact they apply whether you are in Docker environment or in a traditional environment.
The default value for
MaxRAMPercentage
is 25%. This is extremely conservative.My own rule: If your host is more or less dedicated to running the given java application, then you can without problems increase dramatically. If you are on Linux, only running standard daemons and have installed RAM from somewhere around 1 Gb and up then I wouldn't hesitate to use 75% for the JVM's heap. Again, remember that this is 75% of the RAM available, not the RAM installed. What is left is the other user land processes that may be running on the host and the other types of memory that the JVM needs (eg for stack). All together, this will typically fit nicely in the 25% that is left. Obviously, with even more installed RAM the 75% is a safer and safer bet. (I wish the JDK folks had implemented an option where you could specify a ladder)
Setting the
MaxRAMPercentage
option look like this:Note that these percentage values are of 'double' type and therefore you must specify them with a decimal dot. You get a somewhat odd error if you use "75" instead of "75.0".
Xms
和Xmx
是 Java 虚拟机 (JVM) 的标志:Xms
:初始和最小
JVM堆大小
格式
:-Xms[g|G|m|M|k|K]
默认大小
:-server
模式:可用物理内存的 25%,>=8MB 且 <= 64MB-客户端模式
:可用物理内存的 25%,>=8MB 且 <= 16MB典型尺寸
:-Xms128M
-Xms256M
-Xms512M
功能
/效果
:Xms
大小的内存Xmx
:maximum
JVMheap size
格式
:-Xmx[g|G|m|M|k|K]
默认大小
:<= R27.2
Windows
:总物理内存的75%
,最多1GB
Linux/Solaris
:可用物理内存的50%
,最多1GB
>= R27.3
Windows X64
:总物理内存的75%
,最高2GB
Linux/Solaris X64
:可用物理内存的50%
,高达2GB
Windows x86
:总物理内存的75%
,最高1GB
Linux/Solaris X86
:可用物理内存的50%
,最多1GB
典型尺寸
:-Xmx1g
-Xmx2084M
-Xmx4g
-Xmx6g
-Xmx8g
功能
/效果
:Xmx
大小的内存Xmx
时,会出现java.lang.OutOfMemoryError
OutOfMemoryError
?Xmx
值-Xmx4g
到-Xmx8g
更多详细信息
请参阅官方文档:-X 命令行选项
The
Xms
andXmx
are flag of Java virtual machine (JVM):Xms
:initial and minimum
JVMheap size
Format
:-Xms<size>[g|G|m|M|k|K]
Default Size
:-server
mode: 25% of free physical memory, >=8MB and <= 64MB-client mode
: 25% of free physical memory, >=8MB and <= 16MBTypical Size
:-Xms128M
-Xms256M
-Xms512M
Function
/Effect
:Xms
size memoryXmx
:maximum
JVMheap size
Format
:-Xmx<size>[g|G|m|M|k|K]
Default Size
:<= R27.2
Windows
:75%
of total physical memory up to1GB
Linux/Solaris
:50%
of available physical memory up to1GB
>= R27.3
Windows X64
:75%
of total physical memory up to2GB
Linux/Solaris X64
:50%
of available physical memory up to2GB
Windows x86
:75%
of total physical memory up to1GB
Linux/Solaris X86
:50%
of available physical memory up to1GB
Typical Size
:-Xmx1g
-Xmx2084M
-Xmx4g
-Xmx6g
-Xmx8g
Function
/Effect
:Xmx
size memoryXmx
, willjava.lang.OutOfMemoryError
OutOfMemoryError
?Xmx
value-Xmx4g
to-Xmx8g
More detail
see official doc: -X Command-line Options
埃内斯托是对的。根据他发布的链接[1]:
[1] http://www.oracle.com/technetwork/java/ javase/6u18-142093.html
Ernesto is right. According to the link he posted [1]:
[1] http://www.oracle.com/technetwork/java/javase/6u18-142093.html
对于 IBM JVM,命令如下:
有关 IBM SDK for Java 8 的更多信息:http://www-01.ibm.com/support/knowledgecenter/SSYKE2_8.0.0/com。 ibm.java.lnx.80.doc/diag/appendixes/defaults.html?lang=en
For the IBM JVM, the command is the following:
For more information about the IBM SDK for Java 8: http://www-01.ibm.com/support/knowledgecenter/SSYKE2_8.0.0/com.ibm.java.lnx.80.doc/diag/appendixes/defaults.html?lang=en