Linux下的Java虚拟内存使用情况,使用的内存过多 [英] Virtual Memory Usage from Java under Linux, too much memory used

查看:1341
本文介绍了Linux下的Java虚拟内存使用情况,使用的内存过多的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在Linux下运行的Java应用程序有问题。

I have a problem with a Java application running under Linux.

当我启动应用程序时,使用默认的最大堆大小(64 MB),我看到使用top应用程序,240 MB的虚拟内存分配给应用程序。这会在计算机上产生一些其他软件的问题,这些软件相对资源有限。

When I launch the application, using the default maximum heap size (64 MB), I see using the tops application that 240 MB of virtual Memory are allocated to the application. This creates some issues with some other software on the computer, which is relatively resource-limited.

据我所知,保留的虚拟内存无论如何都不会被使用,因为一旦我们达到堆限制,就会抛出 OutOfMemoryError 。我在Windows下运行相同的应用程序,我发现虚拟内存大小和堆大小相似。

The reserved virtual memory will not be used anyway, as far as I understand, because once we reach the heap limit an OutOfMemoryError is thrown. I ran the same application under windows and I see that the Virtual Memory size and the Heap size are similar.

无论如何我可以配置正在使用的虚拟内存Linux下的Java进程?

Is there anyway that I can configure the Virtual Memory in use for a Java process under Linux?

编辑1 :问题不在于堆。问题是,如果我设置128 MB的堆,例如,Linux仍然会分配210 MB的虚拟内存,这是不需要的。**

Edit 1: The problem is not the Heap. The problem is that if I set a Heap of 128 MB, for example, still Linux allocates 210 MB of Virtual Memory, which is not needed, ever.**

编辑2 :使用 ulimit -v 允许限制虚拟内存量。如果大小设置低于204 MB,则应用程序将不会运行,即使它不需要204 MB,只需64 MB。所以我想了解为什么Java需要这么多虚拟内存。可以更改吗?

Edit 2: Using ulimit -v allows limiting the amount of virtual memory. If the size set is below 204 MB, then the application won't run even though it doesn't need 204 MB, only 64 MB. So I want to understand why Java requires so much virtual memory. Can this be changed?

编辑3 :系统中还运行了其他几个应用程序,这些应用程序是嵌入式的。并且系统确实有虚拟内存限制(来自评论,重要细节)。

Edit 3: There are several other applications running in the system, which is embedded. And the system does have a virtual memory limit (from comments, important detail).

推荐答案

这是一个长期存在的抱怨使用Java,但它基本上没有意义,通常基于查看错误的信息。通常的措辞就像Java上的Hello World需要10兆字节!为什么需要它?好吧,这是一种让64位JVM上的Hello World占用超过4千兆字节的方法......至少通过一种测量形式。

This has been a long-standing complaint with Java, but it's largely meaningless, and usually based on looking at the wrong information. The usual phrasing is something like "Hello World on Java takes 10 megabytes! Why does it need that?" Well, here's a way to make Hello World on a 64-bit JVM claim to take over 4 gigabytes ... at least by one form of measurement.


java -Xms1024m -Xmx4096m com.example.Hello



测量内存的不同方法



在Linux上, top 命令为您提供了几个不同的内存编号。以下是关于Hello World示例的内容:

Different Ways to Measure Memory

On Linux, the top command gives you several different numbers for memory. Here's what it says about the Hello World example:


  PID USER      PR  NI  VIRT  RES  SHR S %CPU %MEM    TIME+  COMMAND
 2120 kgregory  20   0 4373m  15m 7152 S    0  0.2   0:00.10 java



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