linux脚本制定java堆大小_Java:什么决定了Linux机器中可能的最大最大堆大小

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

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.

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值