让Java知道交换已存在,并鼓励他使用它 [英] Make java understand that swap exists, and encourage him to use it

查看:58
本文介绍了让Java知道交换已存在,并鼓励他使用它的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

因此,我有一个Java jar可以在我的树莓派上运行,并且需要大量内存.我在外部USB闪存驱动器上设置了2 GB交换空间.但是,当我使用-Xmx2048M启动jar时,它表示无法为2097152KB对象堆保留足够的空间.我知道这是个坏主意,但我还是想这样做.如何使Java将交换识别为堆空间?

So, I have a java jar to run on my raspberry pi, and it requires a lot of memory. I have set up 2 gb swap on an external usb flash drive. But when I start the jar with -Xmx2048M, it says that it could not reserve enough space for 2097152KB object heap. I know this is a bad idea, but I want to do it anyway. How do I go about making java recognize the swap as heap space?

推荐答案

Java不知道交换空间.它只是向OS询问更多的内存",而OS则对操作系统说是".或否"取决于仍然可用.

Java doesn't know about swap space. It just asks the OS for "more memory", and the OS says "yes" or "no" depending on what is still available.

交换空间是在Raspberry Pi操作系统级别配置的;有关详细信息,请参见如何设置交换空间.

Swap space is configured at the Raspberry Pi operating system level; see How to set up swap space for details.

但是您尝试过正常的事情吗?

But have you tried the normal things?

  • 使用 -Xmx JVM命令行选项设置Java堆大小 1 .(有关详细信息,请参见 man java .)
  • 检查是否没有每个进程的"ulimit".这将阻止JVM进程请求更多内存.(有关详细信息,请参见 man ulimit .)
  • Use the -Xmx JVM command line option to set the Java heap size1. (See man java for the details.)
  • Check that there isn't a per-process "ulimit" that is stopping the JVM process from asking for more memory. (See man ulimit for the details.)

1-这不是告诉它使用交换".告诉Java将最大堆大小设置为与默认最大堆大小不同的值.

更新-我从一条注释中看到,您了解-Xmx选项,并且大概正在使用它.这样就剩下一件事了.由于您在32位操作系统上使用32位JVM,因此JVM的总内存使用量存在体系结构限制.限制将小于4 GB.(根据,尽管该限制为3.6 GB或大约GB我不认为那是正确的.)

UPDATE - I see from a comment that you know about the -Xmx option, and are presumably using it. So that leaves one more thing. Since you are using a 32-bit JVM on a 32-bit OS, there is a architectural limit on the JVM's total memory usage. The limit will be less than 4 GB ... all up. (According to this, the limit is 3.6 GB or thereabouts, though I am not convinced that is accurate.)

恐怕如果您要达到此极限,您将无能为力.

If you are running up against that limit, there is nothing you can do about it, I'm afraid.

您说:

即使我将-Xmx设置为1900M,它也会失败

it fails even if I set -Xmx to 1900M

完整的错误/异常消息是什么?

What is the complete error / exception message?

我只需要更多的公羊.

I just need more ram.

好吧,如果您从字面上看需要更多的RAM,则需要购买具有更多RAM的Raspberry Pi.(显然,没有任何支持的选项可用于在现有Pi上扩展RAM.)

Well, if you literally need more RAM, you need to buy a Raspberry Pi with more RAM. (Apparently, there aren't any supported options for expanding the RAM on an existing Pi.)

增加RAM和增加可用虚拟内存不是同一件事...

Increasing the RAM and increasing the available virtual memory are NOT the same thing ...

请注意,如果将JVM的堆大小设置为大于可用的RAM,则当JVM进行完整的垃圾回收时,很可能会遇到系统崩溃的问题.

Note that if you size a JVM's heap to be larger than the available RAM, you are liable to run into problems with thrashing when the JVM does a full garbage collection.

这篇关于让Java知道交换已存在,并鼓励他使用它的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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