# Weird JVM Heap Usage

**URL:** <https://discuss.elastic.co/t/weird-jvm-heap-usage/67097>\
**Category:** Elasticsearch\
**Created:** [November 24, 2016, 11:18am UTC](https://discuss.elastic.co/t/weird-jvm-heap-usage/67097 "2016-11-24T11:18:03Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![Brad\_Jungsu\_Heo](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/brad_jungsu_heo/32/13135_2.png) [@Brad\_Jungsu\_Heo](https://discuss.elastic.co/u/Brad_Jungsu_Heo)\
**Post date:** [November 24, 2016, 11:18am UTC](https://discuss.elastic.co/t/weird-jvm-heap-usage/67097/1 "2016-11-24T11:18:03Z")

</div>

(Sorry if this is not directly related to ES. But I don't know where to ask)

my environments

- ES Version: 2.3.2
- GC: CMS gc
- Heap Size: 20GB
- Total Ram: 64GB
- Java Version: 1.8.0\_60 Java HotSpot(TM) 64-Bit
- OS: CentOS 7.2

Here is Heap Usage of one of my test servers

![heap usage](https://cdn.pbrd.co/images/1LccApSIZ.png)

ES only uses less than 4GB (20% of heap of 20GB)

But Java process uses 16GB of resident memory!

```auto
$ jps
53089 Elasticsearch

$ ps aux | grep 53089
username 53089 112 35.7 168712820 17672036 ? Sl Nov16 13599:09 /path/to/java ... -Xms20g -Xmx20g -Des.path.home=/path/to/elasticsearch -cp /path/to/elasticsearch/lib/elasticsearch-2.3.2.jar:/path/to/elasticsearch/lib/* org.elasticsearch.bootstrap.Elasticsearch start -d

```

**Q** : Does this means, almost the most of resident memory are fragmented?

Here is `jmap` output:

```auto
$ jmap -histo:live 53089 | head -n 20

 num #instances #bytes class name
----------------------------------------------
   1: 264406 1274923328 [B
   2: 105756 102571056 [J
   3: 98842 12137408 [C
   4: 125753 9054216 org.apache.lucene.util.fst.FST$Arc
   5: 34735 5001840 org.apache.lucene.codecs.blocktree.SegmentTermsEnumFrame
   6: 145887 4668384 org.apache.lucene.store.ByteArrayDataInput
   7: 34736 3334656 org.apache.lucene.codecs.lucene50.Lucene50PostingsFormat$IntBlockTermState
   8: 92266 2952512 java.util.HashMap$Node
...

```

Thank you for advenced answer.

---

<div class="post-metadata">

**Author:** ![jprante](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/jprante/32/44941_2.png) [@jprante](https://discuss.elastic.co/u/jprante)\
**Post date:** [November 24, 2016, 7:36pm UTC](https://discuss.elastic.co/t/weird-jvm-heap-usage/67097/2 "2016-11-24T19:36:00Z")

</div>

You configured 20 GB heap for Elasticsearch, so I do not understand why you are concerned about 16 GB process size in memory. This is to be expected.

---

<div class="post-metadata">

**Author:** ![Brad\_Jungsu\_Heo](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/brad_jungsu_heo/32/13135_2.png) [@Brad\_Jungsu\_Heo](https://discuss.elastic.co/u/Brad_Jungsu_Heo)\
**Post date:** [November 25, 2016, 1:00am UTC](https://discuss.elastic.co/t/weird-jvm-heap-usage/67097/3 "2016-11-25T01:00:45Z")

</div>

@jprante

Thank you for your reply.

Yes. It is not a problem. What I'd like to know is that...

ES uses only 2~4GB of heap but 16GB of redisdent memory. So I'd like to know what is occupying 12~14GB resident memory (heap usage graph and `jmap` output show this)

Thanks

---

<div class="post-metadata">

**Author:** ![jprante](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/jprante/32/44941_2.png) [@jprante](https://discuss.elastic.co/u/jprante)\
**Post date:** [November 25, 2016, 8:02am UTC](https://discuss.elastic.co/t/weird-jvm-heap-usage/67097/4 "2016-11-25T08:02:25Z")

</div>

The JVM allocates the whole heap at startup, no matter if it is used or not, and keeps it allocated from the OS. This for performance reasons. See `-Xms` and `-Xmx` JVM flags.

---

<div class="post-metadata">

**Author:** ![Brad\_Jungsu\_Heo](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/brad_jungsu_heo/32/13135_2.png) [@Brad\_Jungsu\_Heo](https://discuss.elastic.co/u/Brad_Jungsu_Heo)\
**Post date:** [November 25, 2016, 9:18am UTC](https://discuss.elastic.co/t/weird-jvm-heap-usage/67097/5 "2016-11-25T09:18:29Z")

</div>

OK. I see.

I'm not a JVM guy. So I missed `-Xms 20g` option.

Thanks alot.

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)\
**Post date:** [December 23, 2016, 9:19am UTC](https://discuss.elastic.co/t/weird-jvm-heap-usage/67097/6 "2016-12-23T09:19:06Z")

</div>

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.
