﻿---
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://www.elastic.co/elastic/docs-builder/docs/5106/deploy-manage/deploy/self-managed/vm-max-map-count
products:
  - Elastic Documentation
  - Elasticsearch
applies_to:
  - Self-managed Elastic deployments: Generally available
---

# Increase virtual memory
<note>
  This is only relevant for Linux.
</note>

Elasticsearch uses a [`mmapfs`](https://docs-v3-preview.elastic.dev/elastic/docs-builder/docs/5106/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`.

## Default virtual memory values

If you installed Elasticsearch from the [RPM](https://www.elastic.co/elastic/docs-builder/docs/5106/deploy-manage/deploy/self-managed/install-elasticsearch-with-rpm) or [Debian](https://www.elastic.co/elastic/docs-builder/docs/5106/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. The value depends on your Elastic Stack version:
- <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.
- <applies-to>Elastic Stack: Generally available from 9.0 to 9.5</applies-to> 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`) on Linux, the value is not set, so you must configure it yourself in all versions.
If you run Elasticsearch in Docker, set `vm.max_map_count` on the host. Refer to [Set `vm.max_map_count`](/elastic/docs-builder/docs/5106/deploy-manage/deploy/self-managed/install-elasticsearch-docker-prod#_set_vm_max_map_count).

## 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 non-systemd 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 in a file under `/etc/sysctl.d/`, for example `/etc/sysctl.d/elasticsearch.conf`. Some distributions, such as Debian 13, no longer read `/etc/sysctl.conf` at boot:
       ```sh
       echo "vm.max_map_count=1048576" | sudo tee /etc/sysctl.d/elasticsearch.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-item title="Docker">
    Set `vm.max_map_count` on the host, not in the container. Refer to [Set `vm.max_map_count`](/elastic/docs-builder/docs/5106/deploy-manage/deploy/self-managed/install-elasticsearch-docker-prod#_set_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
```