# Is there a way to limit RES memory used by ES

**URL:** <https://discuss.elastic.co/t/is-there-a-way-to-limit-res-memory-used-by-es/209100>\
**Category:** Elasticsearch\
**Created:** [November 22, 2019, 5:28pm UTC](https://discuss.elastic.co/t/is-there-a-way-to-limit-res-memory-used-by-es/209100 "2019-11-22T17:28:52Z")\
**Posts on this page:** 11\
**Page:** 1

<div class="post-metadata">

**Author:** ![rnataraja](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/rnataraja/32/26255_2.png) [@rnataraja](https://discuss.elastic.co/u/rnataraja)\
**Post date:** [November 22, 2019, 5:28pm UTC](https://discuss.elastic.co/t/is-there-a-way-to-limit-res-memory-used-by-es/209100/1 "2019-11-22T17:28:53Z")

</div>

ES 6.8.3  
I understand from reading up through forum that ES will use more than actually the Heap Max. On our systems we see that if its given 32Gig of Max Heap. It slowly keeps increasing and consumes a lot more than 32Gig.  
So Is there a way to limit the maximum RES memory ES will use? Are there any breakers to configure its behaviour? If we do limit via Cgroup mechanism, it will cause of OOM killing of the process.

I believe the circuit breakers control how to manage in-heap allocations. But trying to see how the system memory usage beyond heap can be limited.

Thanks  
Rajesh.

---

<div class="post-metadata">

**Author:** ![warkolm](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/warkolm/32/39224_2.png) [@warkolm](https://discuss.elastic.co/u/warkolm)\
**Post date:** [November 23, 2019, 8:29pm UTC](https://discuss.elastic.co/t/is-there-a-way-to-limit-res-memory-used-by-es/209100/2 "2019-11-23T20:29:00Z")

</div>

> [@rnataraja](#):
>
> I understand from reading up through forum that ES will use more than actually the Heap Max

Elasticsearch will only every use the heap you allocate.

Anything else is managed by the OS, so you will need to consult the documentation for it on how to manage this.

---

<div class="post-metadata">

**Author:** ![DavidTurner](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/davidturner/32/22453_2.png) [@DavidTurner](https://discuss.elastic.co/u/DavidTurner)\
**Post date:** [November 23, 2019, 10:13pm UTC](https://discuss.elastic.co/t/is-there-a-way-to-limit-res-memory-used-by-es/209100/3 "2019-11-23T22:13:23Z")

</div>

This isn't quite the full story because Elasticsearch also uses a reasonable amount of direct memory too (plus other minor overheads). Direct memory is also bounded as a function of the configured maximum heap size. In general you should expect the Elasticsearch process to hold at most twice its configured maximum heap size.

---

<div class="post-metadata">

**Author:** ![warkolm](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/warkolm/32/39224_2.png) [@warkolm](https://discuss.elastic.co/u/warkolm)\
**Post date:** [November 24, 2019, 12:29am UTC](https://discuss.elastic.co/t/is-there-a-way-to-limit-res-memory-used-by-es/209100/4 "2019-11-24T00:29:13Z")

</div>

Ahh, thanks for clarifying 🙂

---

<div class="post-metadata">

**Author:** ![Mikhail\_Khludnev](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/mikhail_khludnev/32/59591_2.png) [@Mikhail\_Khludnev](https://discuss.elastic.co/u/Mikhail_Khludnev)\
**Post date:** [November 24, 2019, 9:29am UTC](https://discuss.elastic.co/t/is-there-a-way-to-limit-res-memory-used-by-es/209100/5 "2019-11-24T09:29:05Z")

</div>

FYI, there's -XX:MaxRAM option. I've found it vital to run any java under docker, and wondering why there's no much fame for it in community. Some explanations can be found around [https://developers.redhat.com/blog/2017/04/04/openjdk-and-containers/](https://developers.redhat.com/blog/2017/04/04/openjdk-and-containers/). Note, I haven't ever check ES's startup .sh and don't know whether it controls -XX:MaxRAM at all.

---

<div class="post-metadata">

**Author:** ![rnataraja](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/rnataraja/32/26255_2.png) [@rnataraja](https://discuss.elastic.co/u/rnataraja)\
**Post date:** [November 24, 2019, 4:17pm UTC](https://discuss.elastic.co/t/is-there-a-way-to-limit-res-memory-used-by-es/209100/6 "2019-11-24T16:17:05Z")

</div>

@DavidTurner Thank you. Are there any graceful knobs to limit this? On our setups I cannot definitively say, but before all broke, we noticed ES was using 75Gig of RES with configured at 32Gig.

Even if there are no clear ceiling methods, is there a document that describes best practices to limit its growth?

ES version : 6.8.3

---

<div class="post-metadata">

**Author:** ![rnataraja](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/rnataraja/32/26255_2.png) [@rnataraja](https://discuss.elastic.co/u/rnataraja)\
**Post date:** [November 24, 2019, 4:18pm UTC](https://discuss.elastic.co/t/is-there-a-way-to-limit-res-memory-used-by-es/209100/7 "2019-11-24T16:18:23Z")

</div>

@Mikhail_Khludnev would using that cause ES to go Out of Memory and crash? if it will get killed due to out of memory then there will be other issues to deal with.

---

<div class="post-metadata">

**Author:** ![DavidTurner](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/davidturner/32/22453_2.png) [@DavidTurner](https://discuss.elastic.co/u/DavidTurner)\
**Post date:** [November 24, 2019, 6:47pm UTC](https://discuss.elastic.co/t/is-there-a-way-to-limit-res-memory-used-by-es/209100/8 "2019-11-24T18:47:49Z")

</div>

> [@rnataraja](#):
>
> Even if there are no clear ceiling methods, is there a document that describes best practices to limit its growth?

Yes, [it's documented in the reference manual here](https://www.elastic.co/guide/en/elasticsearch/reference/current/heap-size.html), which also suggests that 32GB of heap is normally too much to get the benefits of compressed oops.

I suspect the 75GB `RES` figure you saw also includes memory-mapped files. This isn't really "used" memory in any meaningful sense since those pages are disk-backed and can be dropped on demand.

---

<div class="post-metadata">

**Author:** ![rnataraja](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/rnataraja/32/26255_2.png) [@rnataraja](https://discuss.elastic.co/u/rnataraja)\
**Post date:** [November 25, 2019, 1:04am UTC](https://discuss.elastic.co/t/is-there-a-way-to-limit-res-memory-used-by-es/209100/9 "2019-11-25T01:04:10Z")

</div>

In that page I only see Heap documentation.But I understand it as follows:

1. RES memory will be twice that of the MAX Heap configured i.e, -Xmx
2. Configure heap lesser than 32Gig (26-28 Gig) so we can take advantage of the compressed OOPS.

Is that fair.

Thanks  
Rajesh.

---

<div class="post-metadata">

**Author:** ![DavidTurner](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/davidturner/32/22453_2.png) [@DavidTurner](https://discuss.elastic.co/u/DavidTurner)\
**Post date:** [November 25, 2019, 8:08am UTC](https://discuss.elastic.co/t/is-there-a-way-to-limit-res-memory-used-by-es/209100/10 "2019-11-25T08:08:57Z")

</div>

> [@rnataraja](#):
>
> RES memory will be twice that of the MAX Heap configured i.e, -Xmx

Not quite, because AIUI the RES figure also includes disk-backed pages from memory-mapped files. There's no need to limit the amount of disk-backed pages since they are a cache and are dropped on demand.

---

<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, 2019, 8:09am UTC](https://discuss.elastic.co/t/is-there-a-way-to-limit-res-memory-used-by-es/209100/11 "2019-12-23T08:09:08Z")

</div>

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