﻿---
title: Increase virtual memory
description: Elasticsearch uses a mmapfs directory by default to store its indices, which relies on memory-mapped files. As a result, the default operating system...
url: https://docs-v3-preview.elastic.dev/elastic/docs-content/pull/9659/deploy-manage/deploy/self-managed/vm-max-map-count
products:
  - Elastic Documentation
  - Elasticsearch
applies_to:
  - Self-managed Elastic deployments: Generally available
---

# Increase virtual memory
Elasticsearch uses a [`mmapfs`](https://docs-v3-preview.elastic.dev/elastic/elasticsearch/tree/main/reference/elasticsearch/index-settings/store#mmapfs) directory by default to store its indices, which relies on memory-mapped files. As a result, the default operating system limit for the maximum number of memory mappings per process (`vm.max_map_count`) must be adequately high. If this limit is too low, the node might fail to start or encounter out-of-memory errors.
The recommended `vm.max_map_count` value is `1048576` or higher. If the operating system's default value is lower than `1048576`, configure the `vm.max_map_count` parameter to `1048576`.
If you installed Elasticsearch from the [RPM](https://docs-v3-preview.elastic.dev/elastic/docs-content/pull/9659/deploy-manage/deploy/self-managed/install-elasticsearch-with-rpm) or [Debian](https://docs-v3-preview.elastic.dev/elastic/docs-content/pull/9659/deploy-manage/deploy/self-managed/install-elasticsearch-with-debian-package) package on a `systemd`-based distribution, the Elasticsearch package sets `vm.max_map_count` for you. `systemd` applies the packaged value at every boot, and the package applies it again every time you install or upgrade Elasticsearch:
- <applies-to>Elastic Stack: Planned</applies-to> The package sets the value to `1048576`, so you don't need to change anything unless you want a different value.
- In versions earlier than 9.6, the package sets the value to `262144`, which is lower than the recommended `1048576`. To use `1048576`, you must override the packaged value, as described in [Persist the value across reboots and upgrades](#vm-max-map-count-persist).

If you installed Elasticsearch from an archive (`.tar.gz`), no package sets the value, so you must configure it yourself in all versions.

## Change the value temporarily

On Linux, you can change the running value of `vm.max_map_count` immediately by running the following command as an account with `root` privileges:
```sh
sysctl -w vm.max_map_count=1048576
```

This change doesn't persist across reboots, and on package installs, a package upgrade can also reset it. To keep the value, follow the steps in the next section.

## Persist the value across reboots and upgrades

On `systemd`-based distributions, the Elasticsearch RPM and Debian packages install `/usr/lib/sysctl.d/elasticsearch.conf`. `systemd` applies this file at every boot, and the package applies it again every time you install or upgrade Elasticsearch. To keep your own value, persist it where it takes precedence over the packaged file. How you do this depends on how you installed Elasticsearch.
<tab-set>
  <tab-item title="RPM or Debian package (systemd)">
    1. Persist the value in a file named `/etc/sysctl.d/elasticsearch.conf`, the same name as the packaged file. A file with the same name in `/etc/sysctl.d/` replaces the one in `/usr/lib/sysctl.d/`, so your value is used instead of the packaged one:
       ```sh
       echo "vm.max_map_count=1048576" | sudo tee /etc/sysctl.d/elasticsearch.conf
       ```
    2. Apply the change immediately by running the same command that the package uses when it applies its own settings:
       ```sh
       sudo systemctl restart systemd-sysctl
       ```
    3. Verify that the value is applied. To confirm that it persists, run the same command again after rebooting or after upgrading the Elasticsearch package:
       ```sh
       sysctl vm.max_map_count
       ```
    If you previously set `vm.max_map_count` in `/etc/sysctl.conf` or in another `sysctl.d` file, remove that entry so the old value doesn't conflict with the new one.To see which configuration files are applied and in which order, run:
    ```sh
    systemd-analyze cat-config sysctl.d
    ```
  </tab-item>

  <tab-item title="Archive or other installation">
    If you installed Elasticsearch from an archive (`.tar.gz`), or on a system that doesn't use systemd, no packaged sysctl file exists, so there's nothing to override your value.
    1. Persist the value by updating the `vm.max_map_count` setting in `/etc/sysctl.conf`:
       ```sh
       echo "vm.max_map_count=1048576" | sudo tee -a /etc/sysctl.conf
       ```
    2. Apply the change immediately, without rebooting:
       ```sh
       sudo sysctl --system
       ```
    3. Verify that the value is applied. To confirm that it persists, run the same command again after rebooting:
       ```sh
       sysctl vm.max_map_count
       ```
  </tab-item>
</tab-set>


## Check how many memory mappings Elasticsearch is using

To see how close a running Elasticsearch node is to the `vm.max_map_count` limit, count its current memory mappings. Run the following command, where `$PID` is the process ID of the running Elasticsearch process, and compare the result to the value from `sysctl vm.max_map_count`:
```sh
wc -l /proc/$PID/maps
```