76

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.

5
  • I know 65535 is the default, I want to know how I should calculate the real memory vm could use Jul 27, 2012 at 8:20
  • Hi, found something here - Article it's written there 256MB.
    – TheNewOne
    Jul 27, 2012 at 8: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 Jul 27, 2012 at 8:49
  • This suppose to be the source of the article which i mentioned above Source - i didn't really understand what you mean in the above comment
    – TheNewOne
    Jul 27, 2012 at 9: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, 2015 at 16:35

3 Answers 3

117

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
6
  • 1
    possibly additional interesting information: ynuxtechblog.wordpress.com/2016/01/05/… Jun 8, 2017 at 8:31
  • 21
    Could you explain, what the negative effects might be if increasing the default? Dec 4, 2017 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. Apr 25, 2019 at 17:31
  • 11
    @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. May 1, 2019 at 0:08
  • 2
    @user1767754 suse.com/support/kb/doc/?id=000016692
    – bomben
    Aug 25, 2020 at 11:14
19
echo 'vm.max_map_count=262144' >> /etc/sysctl.conf

sysctl -p
0
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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.