# Controlling Elastic memory inside docker

**URL:** <https://discuss.elastic.co/t/controlling-elastic-memory-inside-docker/168368>\
**Category:** Elasticsearch\
**Tags:** docker\
**Created:** [February 14, 2019, 9:18am UTC](https://discuss.elastic.co/t/controlling-elastic-memory-inside-docker/168368 "2019-02-14T09:18:05Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![Tobias\_Eriksson](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/tobias_eriksson/32/61713_2.png) [@Tobias\_Eriksson](https://discuss.elastic.co/u/Tobias_Eriksson)\
**Post date:** [February 14, 2019, 9:18am UTC](https://discuss.elastic.co/t/controlling-elastic-memory-inside-docker/168368/1 "2019-02-14T09:18:05Z")

</div>

I am running Elastic 6.2.3 in a Docker container  
But do not understand how the RAM used by the process goes way beyond the limits set

Container is configured

> "Memory": 34225520640,  
> "CpusetMems": "",  
> "KernelMemory": 0,  
> "MemoryReservation": 0,  
> "MemorySwap": 34225520640,  
> "MemorySwappiness": null,

Elastic JVM is configured

> ```
> ES_JAVA_OPTS=-Xms26112m -Xmx26112m
> 
> ```

And then elasticsearch.yml is configured

> ```
> bootstrap.memory_lock: true
> indices.fielddata.cache.size: 50GB
> 
> ```

When I do 'top' on the host/machine (linux)  
I have seen Virtual Mem all the way up to 75 Gig

> PID USER PR NI VIRT RES SHR S %CPU %MEM TIME+ COMMAND  
> 128908 elastic+ 20 0 68.1g 27.2g 651776 S 151.8 27.6 606:17.50 java

How can I

1. Calculate the max memory Elastic is using
2. Control / Set a max limit to ensure it does not steel memory from other processes I want to run on the same machine

---

<div class="post-metadata">

**Author:** ![jpountz](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/jpountz/32/45836_2.png) [@jpountz](https://discuss.elastic.co/u/jpountz)\
**Post date:** [February 22, 2019, 9:12am UTC](https://discuss.elastic.co/t/controlling-elastic-memory-inside-docker/168368/2 "2019-02-22T09:12:50Z")

</div>

Such a high VIRT usage doesn't mean that Elasticsearch is consuming a lot of memory, just that it is consuming address space, which is a side-effect of the fact that we open some files via mmap. The actual memory usage is RES, which is in line with the JVM options that you configured. See [http://blog.thetaphi.de/2012/07/use-lucenes-mmapdirectory-on-64bit.html](http://blog.thetaphi.de/2012/07/use-lucenes-mmapdirectory-on-64bit.html) if you want more information about this.

---

<div class="post-metadata">

**Author:** ![Tobias\_Eriksson](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/tobias_eriksson/32/61713_2.png) [@Tobias\_Eriksson](https://discuss.elastic.co/u/Tobias_Eriksson)\
**Post date:** [February 22, 2019, 9:35am UTC](https://discuss.elastic.co/t/controlling-elastic-memory-inside-docker/168368/3 "2019-02-22T09:35:00Z")

</div>

Thanx for answering  
The oom\_killer is shooting down the docker Elastic running inside  
and looking at dmesg, see below, I draw the conclusion that it kills it NOT because of the 28 Gigs it is using for the JVM but for the virtual space  
or at least that is my current thinking  
what is your take on this ?  
I wonder if going for NIO instead of mmap would make life better ?  
-Tobias

> [Feb22 05:32] java invoked oom-killer: gfp\_mask=0x50, order=0, oom\_score\_adj=0  
> ....  
> [+0.000003] Task in  
> /docker/120ed3942b7ea7aa984fbaeb0033573cc49f62ad89c539ef4eae7106992bfe6c killed as a result of limit of /docker/120ed3942b7ea7aa984fbaeb0033573cc49f62ad89c539ef4eae7106992bfe6c  
> [+0.000002] memory: usage 33423356kB, limit 33423360kB, failcnt 6794709  
> [+0.000001] memory+swap: usage 33423360kB, limit 33423360kB, failcnt 424118  
> [+0.000002] kmem: usage 5530848kB, limit 9007199254740988kB, failcnt 0  
> [+0.000001] Memory cgroup stats for /docker/120ed3942b7ea7aa984fbaeb0033573cc49f62ad89c539ef4eae7106992bfe6c: cache:2356KB rss:27890152KB rss\_huge:27711488KB mapped\_file:144KB swap:4KB inactive\_anon:279480KB active\_anon:240780KB inactive\_file:1140KB active\_file:1072KB unevictable:27370032KB  
> [+0.000009] [pid] uid tgid total\_vm rss nr\_ptes swapents oom\_score\_adj name  
> [+0.000140] [72588] 64981 72588 9325318 6980834 16006 1 0 java  
> [+0.000007] Memory cgroup out of memory: Kill process 49164 (java) score 837 or sacrifice child  
> [+0.001314] Killed process 72588 (java) total-vm:37301272kB, anon-rss:27886596kB, file-rss:36740kB, shmem-rss:0kB

---

<div class="post-metadata">

**Author:** ![jpountz](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/jpountz/32/45836_2.png) [@jpountz](https://discuss.elastic.co/u/jpountz)\
**Post date:** [February 22, 2019, 9:55am UTC](https://discuss.elastic.co/t/controlling-elastic-memory-inside-docker/168368/4 "2019-02-22T09:55:07Z")

</div>

Sorry I'm not very familiar with Docker and the OOM killer. Elasticsearch allocates some additional directly to the operating system in addition to the memory that is given to the JVM. Maybe try to configure a higher limit to see whether this still fails?

---

<div class="post-metadata">

**Author:** ![Tobias\_Eriksson](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/tobias_eriksson/32/61713_2.png) [@Tobias\_Eriksson](https://discuss.elastic.co/u/Tobias_Eriksson)\
**Post date:** [February 22, 2019, 10:26am UTC](https://discuss.elastic.co/t/controlling-elastic-memory-inside-docker/168368/5 "2019-02-22T10:26:26Z")

</div>

OK Appreciate you answering , thanx !

---

<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:** [March 22, 2019, 10:26am UTC](https://discuss.elastic.co/t/controlling-elastic-memory-inside-docker/168368/6 "2019-03-22T10:26:37Z")

</div>

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