初始Java堆大小意味着什么? [英] initial Java heap size means?

查看:216
本文介绍了初始Java堆大小意味着什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

所以我有一个使用Java堆的程序

So i got a program who use Java heap

-Xms5g -Xmx12g 

我将初始Java堆大小设置为5gb,将MAX堆大小设置为12gb

I have set the initial Java heap size to 5gb and MAX heap size to 12gb

但是当我查看任务管理器或资源监视器时,我的程序仅使用400mb.

But when i look in task manager or resource monitor, My program is only using 400mb.

这是我的问题:

  1. 初始Java堆大小是什么意思?
  2. 如果我将初始Java堆大小设置为5gb,为什么我只看到程序上的RAM使用为400mb,而不是5gb?最初的堆意味着最小的大小对吗?

推荐答案

-Xmx最大堆大小是堆可以增长到的最大大小.

The -Xmx maximum heap size is the largest size the heap can grow up to.

-Xms初始堆大小是堆范围的大小.在不触发完整GC的情况下,它不会使用超过此数量的空间.

The -Xms initial heap size is the of the extents of the heap. It won't use more than this amount of space without triggering a full GC.

但是,此堆分为多个区域,例如说你有一个5 GiB的初始堆,

However this heap is divided into regions e.g. say you have a 5 GiB initial heap with

  • 伊甸园大小为200 MB
  • 两个100 MB的幸存者空间
  • 永久性的4.6 GB空间.

当您开始使用内存时,在Linux上按需分配了被触摸的页面(4个KiB区域)(除非您使用一个选项来对它们全部进行预触摸)

When you start using the memory, the pages (4 KiB regions) which are touched are allocated on demand on Linux (unless you use an option to pretouch them all)

您的Eden空间将很快被使用,因此前200 MB的使用速度非常快(如果在调用main之前就已经使用了很多).幸存者空间在经过少量收集后将被使用,但是最初它们可能不会被全部碰到,例如.说他们永远不会填满超过50 MB(可用的100 MB),此时的总内存为200 MB + 2 * 50 MB.

Your Eden space will be used pretty quickly so the first 200 MB gets used quite fast (quite a lot if used even before main is called). The survivors spaces will get used after a couple of minor collection however initially they might not be all touched e.g. say they never fill to more than 50 MB each (of the 100 MB available), the total memory touched at this point is 200 MB + 2 * 50 MB.

一些大对象直接进入租用空间,但是对于大多数应用程序而言,租用空间在很大程度上占用了较小的,寿命长的对象.可以说,经过多次次要收集,大约100 MB的对象已被提升到永久性空间.

Some large objects go straight into tenured space, however for most applications, the tenured space is largely taken up with smaller, long lived objects. Lets say after many minor collections, about 100 MB of objects have been promoted to tenured space.

此时,即使扩展区为5 GB,也仅触摸或分配了200 + 2 * 50 + 100 MB的内存.

At this point even though the extents are 5 GB, only 200 + 2 * 50 + 100 MB of memory has been touched or allocated.

简而言之,Linux延迟分配页面,因此您必须写入页面以使用内存.

In short, Linux allocates pages lazily so you have to write to them to use memory.

这篇关于初始Java堆大小意味着什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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