本文介绍了无法使用-XX:+ UseLargePages启用JVM的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个Java服务,目前运行一个14GB的堆。我热衷于尝试选项来查看这可能会如何影响系统的性能。我按照配置了操作系统使用适当的共享内存和页面值(这些也可以通过计算)。 p>

一旦配置了操作系统,我可以看到它将预期的内存量分配为巨大页面。但是,使用 -XX:+ UseLargePages 选项集启动VM始终会导致以下错误之一:



-Xms / -Xmx 几乎等于巨大的页面分配:

 无法预留共享内存(errno = 28)。 //设备上没有空格

-Xms / -Xmx 小于巨大的页面分配:

 无法预留共享内存(errno = 12)。 //'内存不足'

我尝试引入一些余地 - 所以在一个32GB的系统上我分配了24GB的共享内存和hugepages与配置有20GB堆的JVM一起使用,其中目前仅使用14GB。我还验证了执行JVM的用户的组权限与 / proc / sys / vm / hugetlb_shm_group 一致。



任何人都可以给我一些关于我可能会出错的地方,下面可以尝试什么?



分配/利用率:




  • -Xms / -Xmx - 20GB

  • 使用堆 - 14GB

  • / proc / sys / kernel / shmmax - 25769803776(24GB) li>
  • / proc / sys / vm / nr_hugepages - 12288



环境:




  • 系统内存 - 32GB

  • 系统页面大小 - 2048KB

  • debian 2.6.26-2-amd64

  • Sun JVM 1.6.0_20-b02



解决方案



感谢提供一个导致解决方案的答案。除了
/ proc / sys / kernel / shmall
设置(指定为4KB页),我不得不添加条目到 / etc / security / limits.conf ,如所述。但是,由于我的应用程序是使用 jsvc 开始的,所以我也必须复制root用户的设置(请注意,限制以KB为单位):

 根软件锁25165824 
根硬盘锁25165824
pellegrino软密码25165824
pellegrino hard memlock 25165824
还有一点值得一提的是,可以通过启动具有 -version的JVM来快速测试设置。



参数:

  java -XX:+ UseLargePages -Xmx20g -version 


解决方案

当您使用Java使用庞大的页面时,不仅堆使用巨大的页面,还有PermGen:别忘了为它分配空间。似乎这就是为什么当您在巨大的页面上设置 Xmx 时,您有一个不同的错误信息。



还有你没有提到的需要设置的 shmall 内核参数,也许是阻止你的内容。在您的情况下,您应该将其设置为6291456。



最后一点要说:使用大页面时, Xms 参数不再被使用:Java在共享内存中使用庞大的页面保留所有的 Xmx


I have a Java service that currently runs with a 14GB heap. I am keen to try out the -XX:+UseLargePages option to see how this might affect the performance of the system. I have configured the OS as described by Oracle using appropriate shared memory and page values (these can also be calculated with an online tool).

Once the OS is configured, I can see that it allocates the expected amount of memory as huge-pages. However, starting the VM with the -XX:+UseLargePages option set always results in one of the following errors:

When -Xms / -Xmx is almost equal to the huge page allocation:

    Failed to reserve shared memory (errno = 28). // 'No space left on device'

When -Xms / -Xmx is less than the huge page allocation:

    Failed to reserve shared memory (errno = 12). // 'Out of memory'

I did try introducing some leeway - so on a 32GB system I allocated 24GB of shared memory and hugepages to use with a JVM configured with a 20GB heap, of which only 14GB is currently utilized. I also verified that the user executing the JVM did have group rights consistent with /proc/sys/vm/hugetlb_shm_group.

Can anyone give me some pointers on where I might be going wrong and what I could try next?

Allocations/utilization:

  • -Xms / -Xmx - 20GB
  • Utilized heap - 14GB
  • /proc/sys/kernel/shmmax - 25769803776 (24GB)
  • /proc/sys/vm/nr_hugepages - 12288

Environment:

  • System memory - 32GB
  • System page size - 2048KB
  • debian 2.6.26-2-amd64
  • Sun JVM 1.6.0_20-b02

Solution

Thanks to @jfgagne for providing an answer that lead to a solution. In addition to the /proc/sys/kernel/shmall setting (specified as 4KB pages), I had to add entries to /etc/security/limits.conf as described on Thomas' blog. However, as my application is started using jsvc I also had to duplicate the settings for the root user (note that the limits are specified in KB):

    root       soft memlock 25165824
    root       hard memlock 25165824
    pellegrino soft memlock 25165824
    pellegrino hard memlock 25165824

It's also worth mentioning that settings could be tested quickly by starting the JVM with the -version argument:

    java -XX:+UseLargePages -Xmx20g -version
解决方案

When you use huge pages with Java, there is not only the heap using huge pages, but there is also the PermGen: do not forget to allocate space for it. It seems this is why you have a different errno message when you set Xmx near the amount of huge pages.

There is also the shmall kernel parameter that needs to be set which you did not mention, maybe it is what is blocking you. In your case, you should set it to 6291456.

The last thing to say: when using huge pages, the Xms parameter is not used anymore: Java reserves all Xmx in shared memory using huge pages.

这篇关于无法使用-XX:+ UseLargePages启用JVM的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-01 03:13