简体   繁体   English

jvm 参数 xms 是否意味着如果指定的 memory 丢失,进程将不会启动?

[英]Doesn't the jvm argument xms mean process won't start if the specified memory is missing?

I had set the xms to 32g and xmx to 32g我已将 xms 设置为 32g,将 xmx 设置为 32g

The program started, but when around 25GB data was loaded into memory, the process was killed by Linux, giving the reason of memory issues.程序启动,但是当大约 25GB 数据加载到 memory 时,进程被 Linux 杀死,给出了 memory 问题的原因。

If 32g was already assigned to the process due to xms being 32g, why did it went out of memory?如果因为xms是32g就已经给进程分配了32g,为什么会出memory呢? Doesn't xms mean allocate this memory in beginning and if you cannot please don't start the process? xms 不是意味着在开始时分配这个 memory 如果你不能请不要开始这个过程?

Can someone please explain, why programs fails?有人可以解释一下,为什么程序会失败?

"Allocating memory" really means "allocating virtual address space". “分配内存”的真正意思是“分配虚拟地址空间”。 Modern operating systems separate the address space used by a process from physical memory.现代操作系统将进程使用的地址空间与物理地址空间 memory 分开。

So, with -Xms32G, you've got 32G of address space.因此,使用 -Xms32G,您将获得 32G 的地址空间。

Actual memory is allocated in pages and on demand, which generally means that something has to actually 'touch' a page before memory is 'committed' to the page.实际的 memory 在页面中按需分配,这通常意味着在 memory 被“提交”到页面之前,某些东西必须实际“接触”页面。

Thus in reality, memory is only being committed as needed.因此实际上,memory 只是在需要时才提交。 And if the OS decides it is under real-memory pressure at the time, you're likely to get killed.如果操作系统确定它当时处于实际内存压力之下,您很可能会被杀死。

You can force the JVM to touch each page at startup by using the JVM option -XX:+AlwaysPreTouch.您可以使用 JVM 选项 -XX:+AlwaysPreTouch 强制 JVM 在启动时触摸每个页面。 The likely effect of this will be that the JVM process starts and gets killed during its initialization, before your program is entered at main().这可能会导致 JVM 进程在其初始化期间启动并在您的程序进入 main() 之前被终止。 You still can't get the memory, you just find out sooner.你仍然无法获得 memory,你只是早点发现。

The OOM killer being what it is, it is also possible that the pretouch will go ok, your code will run, but at some later time due to other system activity, the kernel will decide it's critically low on available resources, and since you're probably the largest process around, there's a target on your back. OOM 杀手就是它的本质,pretouch 也有可能 go ok,您的代码将运行,但在稍后的某个时间,由于其他系统活动,kernel 将决定它的可用资源严重不足,并且由于您可能是最大的过程,你的背上有一个目标。

First of all -Xms and -Xmx control the heap of your java process.首先-Xms-Xmx控制 java 进程的 A java process need memory for other things too, like off heap allocation, GC structures, etc. What this means is that when you set your application to a heap of 1GB , your java process is going to need more than that.一个 java 进程也需要 memory 用于其他事情,比如堆外分配、GC 结构等。这意味着当您将应用程序设置为1GB的堆时,您的 java 进程将需要更多

Second point is that -Xms controls the committed memory in the virtual space.第二点是-Xms控制虚拟空间中提交的 memory。 Virtual space for a 64 bit CPU is huge. 64 位 CPU 的虚拟空间很大。 Committed memory becomes resident in a lazy fashion (resident is actual in RAM, for example).提交的 memory 以惰性方式变为常驻(例如,常驻在 RAM 中)。 So when you set -Xmx and -Xms , you will get a portion of virtual memory allocated as needed.因此,当您设置-Xmx-Xms时,您将根据需要分配虚拟 memory 的一部分。

You should carefully read the logs on this part:您应该仔细阅读这部分的日志:

giving the reason of memory issues给出 memory 问题的原因

you probably are killed by the OOM Killer, which kills the process, which you already know (from the above) that needs more than the heap.你可能被 OOM Killer 杀死了,它杀死了你已经知道(从上面)需要的不仅仅是堆的进程。

If you want to allocate memory and make it resident, add the -XX:+AlwaysPreTouch flag.如果要分配 memory 并使其驻留,请添加-XX:+AlwaysPreTouch标志。 This will make your process start a lot slower though and in general, is not a great idea.这会使您的流程启动速度变慢,但总的来说,这不是一个好主意。 It has its benefits in various applications.它在各种应用中都有其优势。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM