Increase virtual memory

Elasticsearch uses a 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 or Debian 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 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.

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

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:

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.

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.

  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:

    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:

    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:

    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:

systemd-analyze cat-config sysctl.d
		

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:

    echo "vm.max_map_count=1048576" | sudo tee -a /etc/sysctl.conf
    		
  2. Apply the change immediately, without rebooting:

    sudo sysctl --system
    		
  3. Verify that the value is applied. To confirm that it persists, run the same command again after rebooting:

    sysctl vm.max_map_count
    		

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:

wc -l /proc/$PID/maps