# Where to set MAX\_LOCKED\_MEMORY=unlimited in Elasticsearch 5.0

**URL:** <https://discuss.elastic.co/t/where-to-set-max-locked-memory-unlimited-in-elasticsearch-5-0/74760>\
**Category:** Elasticsearch\
**Created:** [February 11, 2017, 2:22pm UTC](https://discuss.elastic.co/t/where-to-set-max-locked-memory-unlimited-in-elasticsearch-5-0/74760 "2017-02-11T14:22:02Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![sumo7](https://avatars.discourse-cdn.com/v4/letter/s/e274bd/32.png) [@sumo7](https://discuss.elastic.co/u/sumo7)\
**Post date:** [February 11, 2017, 2:22pm UTC](https://discuss.elastic.co/t/where-to-set-max-locked-memory-unlimited-in-elasticsearch-5-0/74760/1 "2017-02-11T14:22:02Z")

</div>

I run Ubuntu 16.04 in my production environment.

I downloaded Elasticsearch 5.0 from TAR.

According to [this post](http://stackoverflow.com/a/18152957/6033164), I can set MAX\_LOCKED\_MEMORY=unlimited in /etc/default/elasticsearch on Ubuntu 14.04, but there is no such file in that directory. I even created /etc/default/elasticsearch and put MAX\_LOCKED\_MEMORY=unlimited in that file, but it didn't work.

Where can I set MAX\_LOCKED\_MEMORY=unlimited in my situation?

---

<div class="post-metadata">

**Author:** ![jasontedor](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/jasontedor/32/66992_2.png) [@jasontedor](https://discuss.elastic.co/u/jasontedor)\
**Post date:** [February 12, 2017, 12:11am UTC](https://discuss.elastic.co/t/where-to-set-max-locked-memory-unlimited-in-elasticsearch-5-0/74760/2 "2017-02-12T00:11:10Z")

</div>

If you're running from the tar archive, `/etc/default/elasticsearch` and so on will never have any effect (it's only sourced by the System V init files). Instead, you have to modify `/etc/security/limits.conf` or create `/etc/security/limits.d/elasticsearch.conf` and set

```nohighlight
<username of user that will be running Elasticsearch> - memlock unlimited

```

and start a new login shell for this to be picked up.

---

<div class="post-metadata">

**Author:** ![sumo7](https://avatars.discourse-cdn.com/v4/letter/s/e274bd/32.png) [@sumo7](https://discuss.elastic.co/u/sumo7)\
**Post date:** [February 12, 2017, 10:58am UTC](https://discuss.elastic.co/t/where-to-set-max-locked-memory-unlimited-in-elasticsearch-5-0/74760/3 "2017-02-12T10:58:59Z")

</div>

Thank you for your reply.  
Could you tell me how to start a new login shell for the setting to be picked up?  
I run systems using `systemd`, so I ran `systemctl daemon-reload` after the setup (Please tell me if this is a wrong command.).  
But I still get an error like the follows.

```
[2017-02-12T10:44:16,561][WARN][o.e.b.JNANatives] Unable to lock JVM Memory: error=12, reason=Cannot allocate memory
[2017-02-12T10:44:16,564][WARN][o.e.b.JNANatives] This can result in part of the JVM being swapped out.
[2017-02-12T10:44:16,564][WARN][o.e.b.JNANatives] Increase RLIMIT_MEMLOCK, soft limit: 65536, hard limit: 65536
[2017-02-12T10:44:16,564][WARN][o.e.b.JNANatives] These can be adjusted by modifying /etc/security/limits.conf, for example: 
    # allow user 'ubuntu' mlockall
    ubuntu soft memlock unlimited
    ubuntu hard memlock unlimited

```

After I received this error, I set `ubuntu soft memlock unlimited` and `ubuntu hard memlock unlimited` in `/etc/security/limits.conf` and ran `systemctl daemon-reload`.  
But the error doesn't disappear.

Now I looked into [this doc](https://www.elastic.co/guide/en/elasticsearch/reference/5.0/setup-configuration-memory.html#disable-swap-files) in which they say there is another option to disable swapping.  
That option is to comment out any lines that contain the word `swap` in `/etc/fstab`, but there is no lines with the word in the first place in that file. Does this mean I don't have to do anything and it's configured correctly out of the box?

---

<div class="post-metadata">

**Author:** ![jasontedor](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/jasontedor/32/66992_2.png) [@jasontedor](https://discuss.elastic.co/u/jasontedor)\
**Post date:** [February 12, 2017, 12:16pm UTC](https://discuss.elastic.co/t/where-to-set-max-locked-memory-unlimited-in-elasticsearch-5-0/74760/4 "2017-02-12T12:16:48Z")

</div>

You said you're using the tar archive, not a package install that would setup systemd for you. Since you're not using systemd, there's no need to run any systemd commands here. To start a new login shell just logout and login again.

---

<div class="post-metadata">

**Author:** ![sumo7](https://avatars.discourse-cdn.com/v4/letter/s/e274bd/32.png) [@sumo7](https://discuss.elastic.co/u/sumo7)\
**Post date:** [February 12, 2017, 12:33pm UTC](https://discuss.elastic.co/t/where-to-set-max-locked-memory-unlimited-in-elasticsearch-5-0/74760/5 "2017-02-12T12:33:03Z")

</div>

Oh, excuse my lack of knowledge.  
Yes, I downloaded Elasticsearch from TAR.  
After logging out and logging in, it worked.  
Thank you.

---

<div class="post-metadata">

**Author:** ![jasontedor](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/jasontedor/32/66992_2.png) [@jasontedor](https://discuss.elastic.co/u/jasontedor)\
**Post date:** [February 12, 2017, 12:51pm UTC](https://discuss.elastic.co/t/where-to-set-max-locked-memory-unlimited-in-elasticsearch-5-0/74760/6 "2017-02-12T12:51:55Z")

</div>

You're very welcome.

---

<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 12, 2017, 12:52pm UTC](https://discuss.elastic.co/t/where-to-set-max-locked-memory-unlimited-in-elasticsearch-5-0/74760/7 "2017-03-12T12:52:33Z")

</div>

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