Java:什么决定了Linux机器中可能的最大最大堆大小 [英] Java: what determines the maximum max heap size possible in a linux machine

查看:109
本文介绍了Java:什么决定了Linux机器中可能的最大最大堆大小的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有两台Linux机器(均为VM),一台具有12GB内存,另一台具有8GB内存.

我试图在两台机器上启动相同的Java程序,并且最大可能的最大堆大小(使用-Xmx标志).以下是我得到的结果.

  • 12GB机器:9460MB
  • 8GB机器:4790MB

如果我指定的最大堆大小超出限制,我将得到以下错误.

Error occurred during initialization of VM
Could not allocate metaspace: 1073741824 bytes

我检查了两个系统中的可用内存(使用free命令),然后得到关注.

  • 12GB机器:大约3GB可用空间.
  • 8GB机器:大约4GB可用空间.

我的问题是,什么决定了可以启动Java程序的最大最大堆大小,这不会导致上述错误? (当程序出现上述错误时,系统有足够的内存来分配1073741824个字节的内存)

解决方案

我用ravindra给出的线索做了一些实验,发现最大最大堆大小与系统中可用的总虚拟内存有直接关系. /p>

可以通过以下方式找到系统中的总虚拟内存(以KB为单位):

ulimit-v

总虚拟内存可以通过以下方式更改:

ulimit -v <new amount in KB>

最大可能的最大堆大小比虚拟内存少大约2GB.如果使用ulimit -v unlimited指定无限的虚拟内存,则可以为最大堆大小指定任何较大的值.

I have two linux machines (both are VMs), one having 12GB memory and other having 8GB memory.

I tried to start the same java program on both machines, with maximum max heap size possible (using -Xmx flag). Following are the results I got.

  • 12GB machine: 9460MB
  • 8GB machine: 4790MB

If I specify a max heap size beyond above limits, I get below error.

Error occurred during initialization of VM
Could not allocate metaspace: 1073741824 bytes

I checked the free memory in two systems (using free command), and I got following.

  • 12GB machine: approximately 3GB free.
  • 8GB machine: approximately 4GB free.

My question is, what determines the maximum max heap size a java program can be started with, which would not result in above mentioned error? (System had sufficient memory to allocate 1073741824 bytes of memory when the program gave above error)

解决方案

I did some experiments with the clues given by ravindra and found that the maximum max heap size has a direct relationship with the total virtual memory available in the system.

Total virtual memory in the system can be found (in KB) with:

ulimit-v

Total virtual memory can be altered with:

ulimit -v <new amount in KB>

The maximum max heap size possible was approximately 2GB less than the virtual memory. If you specify unlimited virtual memory using ulimit -v unlimited, You can specify any large value for the max heap size.

这篇关于Java:什么决定了Linux机器中可能的最大最大堆大小的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆