80

I read the document Understanding Virtual Memory and it said one method for changing tunable parameters in the Linux VM was the command:

sysctl -w vm.max_map_count=65535

I want to know what the number 65535 means and how much memory could vm use by the setting.

tshepang
  • 12,111
  • 21
  • 91
  • 136
solomon_wzs
  • 1,711
  • 5
  • 16
  • 29
  • I know 65535 is the default, I want to know how I should calculate the real memory vm could use – solomon_wzs Jul 27 '12 at 08:20
  • Hi, found something here - [Article](http://knowledgebase.progress.com/articles/Article/P145538) it's written there 256MB. – TheNewOne Jul 27 '12 at 08:37
  • i think it can not say 256MB simply here, because at my system vm.max_map_count=65535, but my erlang vm had used about 8GB memory and it was ok – solomon_wzs Jul 27 '12 at 08:49
  • This suppose to be the source of the article which i mentioned above [Source](http://www.psdn.progress.com/realtime/techsupport/documentation/objectstore/r60/ostore/doc/rnotes/chap1.htm) - i didn't really understand what you mean in the above comment – TheNewOne Jul 27 '12 at 09:01
  • 2
    It does not determine directly how much memory a process can use. A process can allocate memory let's say in 64Kb chunks or 256Kb chunks, having 4x different total memory used. vm.max_map_count controls only number of these chunks.. – Tagar Jan 13 '15 at 16:35

3 Answers3

119

From the Linux kernel documentation:

max_map_count:

This file contains the maximum number of memory map areas a process may have. Memory map areas are used as a side-effect of calling malloc, directly by mmap and mprotect, and also when loading shared libraries.

While most applications need less than a thousand maps, certain programs, particularly malloc debuggers, may consume lots of them, e.g., up to one or two maps per allocation.

The default value is 65536.

Bottom line: this setting limits the number of discrete mapped memory areas - on its own it imposes no limit on the size of those areas or on the memory that is usable by a process.

And yes, this:

sysctl -w vm.max_map_count=65535

is just a nicer way of writing this:

echo 65535 > /proc/sys/vm/max_map_count
thkala
  • 84,049
  • 23
  • 157
  • 201
  • It looks like I misinterpreted vm.max_map_count mean – solomon_wzs Jul 27 '12 at 09:44
  • 1
    possibly additional interesting information: https://ynuxtechblog.wordpress.com/2016/01/05/getting-your-system-parameters-right-in-dockered-elasticsearch/#vm.max_map_count – Timothy Dalton Jun 08 '17 at 08:31
  • 22
    Could you explain, what the negative effects might be if increasing the default? – user1767754 Dec 04 '17 at 19:15
  • 1
    Not just a "nicer way", the `sysctl` approach is the *persistent* way to apply this kernel change. With the `echo` approach the memory settings will be reverted to the original value after a node recycle. Good to be aware of if changing to a non-default value. – user9074332 Apr 25 '19 at 17:31
  • 12
    @user9074332, this actually isn't true. Both ways of changing (`sysctl -w` and `echo > /proc/sys/*`) aren't persistent. To make the changes persistent you should modify `/etc/sysctl.conf` and then (optionally) execute `sysctl -p` to apply the changes without reboot. – Ruslan Stelmachenko May 01 '19 at 00:08
  • 4
    @user1767754 https://www.suse.com/support/kb/doc/?id=000016692 – bomben Aug 25 '20 at 11:14
20
echo 'vm.max_map_count=262144' >> /etc/sysctl.conf

sysctl -p
Nathan
  • 8,093
  • 8
  • 50
  • 76
田咖啡
  • 728
  • 8
  • 10
6
echo "vm.max_map_count=262144" >> /etc/sysctl.conf
sysctl -p

This does not work since we cannot change the configuration file directly. Run the below command.

echo vm.max_map_count=262144 | sudo tee -a /etc/sysctl.conf

But check if vm.max_map_count already exists or not. You can do that using

grep vm.max_map_count /etc/sysctl.conf
Chris
  • 5,109
  • 3
  • 19
  • 40
Meet Luhar
  • 79
  • 1
  • 2