# Memory lock check on Elastic Cloud

**URL:** <https://discuss.elastic.co/t/memory-lock-check-on-elastic-cloud/264867>\
**Category:** Elasticsearch\
**Created:** [February 19, 2021, 1:58pm UTC](https://discuss.elastic.co/t/memory-lock-check-on-elastic-cloud/264867 "2021-02-19T13:58:41Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![val](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/val/32/138203_2.png) [@val](https://discuss.elastic.co/u/val)\
**Post date:** [February 19, 2021, 1:58pm UTC](https://discuss.elastic.co/t/memory-lock-check-on-elastic-cloud/264867/1 "2021-02-19T13:58:41Z")

</div>

I'm curious how it is possible that a cluster on Elastic Cloud passes the [memory lock bootstrap check](https://www.elastic.co/guide/en/elasticsearch/reference/current/_memory_lock_check.html) even though the memory doesn't seem to be locked.

Here is the `mlockall` state on all nodes

```
GET _nodes?filter_path=**.mlockall
{
  "nodes" : {
    "9jimFRh_SpCU6zWrdzb2cA" : {
      "process" : {
        "mlockall" : false
      }
    },
    "7NRLpZlnRjuvww7vtV8AQw" : {
      "process" : {
        "mlockall" : false
      }
    },
    "UHJ96_PzTSmwAVbbLAc5xQ" : {
      "process" : {
        "mlockall" : false
      }
    },
    ...
}

```

And here is the default cluster setting for `bootstrap.memory_lock`:

```
GET _cluster/settings?include_defaults&filter_path=**.memory_lock
{
  "defaults" : {
    "bootstrap" : {
      "memory_lock" : "false"
    }
  }
}

```

Is it because [swappiness](https://www.elastic.co/guide/en/elasticsearch/reference/current/setup-configuration-memory.html#swappiness) and/or [swapoff](https://www.elastic.co/guide/en/elasticsearch/reference/current/setup-configuration-memory.html#disable-swap-files) is/are enough?

I'd be happy if anyone has an idea about this. Thanks in advance

---

<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:** [February 20, 2021, 6:11pm UTC](https://discuss.elastic.co/t/memory-lock-check-on-elastic-cloud/264867/2 "2021-02-20T18:11:25Z")

</div>

> [@val](#):
>
> Is it because [swappiness](https://www.elastic.co/guide/en/elasticsearch/reference/current/setup-configuration-memory.html#swappiness) and/or [swapoff](https://www.elastic.co/guide/en/elasticsearch/reference/current/setup-configuration-memory.html#disable-swap-files) is/are enough?

No, it's because memory locking is disabled. From the docs you linked:

> The memory lock check verifies that **if** the `bootstrap.memory_lock` setting is enabled, that the JVM was successfully able to lock the heap.

Since `bootstrap.memory_lock` is not enabled, this check does nothing.

---

<div class="post-metadata">

**Author:** ![val](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/val/32/138203_2.png) [@val](https://discuss.elastic.co/u/val)\
**Post date:** [February 22, 2021, 6:17am UTC](https://discuss.elastic.co/t/memory-lock-check-on-elastic-cloud/264867/3 "2021-02-22T06:17:39Z")

</div>

Thank you David.  
What I don't understand is how it is possible that a production cluster on Elastic Cloud can start even though the [memory lock bootstrap check](https://www.elastic.co/guide/en/elasticsearch/reference/current/_memory_lock_check.html) is not satisfied?

According to the [bootstrap checks](https://www.elastic.co/guide/en/elasticsearch/reference/current/bootstrap-checks.html) description:

> If Elasticsearch is in production mode, any bootstrap checks that fail will cause Elasticsearch to refuse to start.

---

<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:** [February 22, 2021, 8:24am UTC](https://discuss.elastic.co/t/memory-lock-check-on-elastic-cloud/264867/4 "2021-02-22T08:24:10Z")

</div>

Maybe it helps to look at the source code?

> <https://github.com/elastic/elasticsearch/blob/780f27306777399db574b9f9a9f44e77f41779f3/server/src/main/java/org/elasticsearch/bootstrap/BootstrapChecks.java#L309-L313>

> <https://github.com/elastic/elasticsearch/blob/a92a647b9f17d1bddf5c707490a19482c273eda3/server/src/main/java/org/elasticsearch/bootstrap/BootstrapSettings.java#L23-L24>

In Cloud, the `bootstrap.memory_lock` setting is not set, so `BootstrapSettings.MEMORY_LOCK_SETTING.get(context.settings())` returns its default, which is `false`, so it doesn't matter what `isMemoryLocked()` returns, the check is always satisfied.

---

<div class="post-metadata">

**Author:** ![val](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/val/32/138203_2.png) [@val](https://discuss.elastic.co/u/val)\
**Post date:** [February 22, 2021, 8:25am UTC](https://discuss.elastic.co/t/memory-lock-check-on-elastic-cloud/264867/5 "2021-02-22T08:25:29Z")

</div>

You're right, I could have checked the source code first.  
Thanks for the insights!

---

<div class="post-metadata">

**Author:** ![val](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/val/32/138203_2.png) [@val](https://discuss.elastic.co/u/val)\
**Post date:** [February 23, 2021, 5:07am UTC](https://discuss.elastic.co/t/memory-lock-check-on-elastic-cloud/264867/6 "2021-02-23T05:07:39Z")

</div>

@DavidTurner Maybe you can shed some more light on why it is recommended to lock memory and Elastic Cloud doesn't?

---

<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:** [February 23, 2021, 7:28am UTC](https://discuss.elastic.co/t/memory-lock-check-on-elastic-cloud/264867/7 "2021-02-23T07:28:15Z")

</div>

The recommendation is to [disable swap entirely](https://www.elastic.co/guide/en/elasticsearch/reference/current/setup-configuration-memory.html):

> There are three approaches to disabling swapping. The preferred option is to completely disable swap. If this is not an option, whether or not to prefer minimizing swappiness versus memory locking is dependent on your environment.

`bootstrap.memory_lock` is a poor substitute for fixing the OS-level configuration to prevent swapping, because it does not prevent swapping of direct (off-heap) memory.

---

<div class="post-metadata">

**Author:** ![val](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/val/32/138203_2.png) [@val](https://discuss.elastic.co/u/val)\
**Post date:** [February 23, 2021, 7:41am UTC](https://discuss.elastic.co/t/memory-lock-check-on-elastic-cloud/264867/8 "2021-02-23T07:41:52Z")

</div>

Ok, so that means on Elastic Cloud, this is done at the OS-level using swapoff and it's not necessarily apparent in the cluster/node configuration.

That makes perfect sense then. Thank you so much!!

---

<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 23, 2021, 7:42am UTC](https://discuss.elastic.co/t/memory-lock-check-on-elastic-cloud/264867/9 "2021-03-23T07:42:31Z")

</div>

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