Maximum number of mmap()'ed ranges and how to set it on Linux?

What's the maximum number of mmap()'ed ranges that a process can makes and how to set the limits on Linux?

I have a program that mmap()s and mprotect()s lots ranges. After allocating many ranges, mprotect() starts to fail with ENOMEM error number. From the man page, ENOMEM means 2 possible problems:

ENOMEM

Internal kernel structures could not be allocated.

ENOMEM

Addresses in the range [addr, addr+len-1] are invalid for the address space of the process, or specify one or more pages that are

not mapped.

I am sure that the mprotect()ed range is mapped and valid. So the problem is the first situation: internal kernel structure allocation failed.

That question is what is the limit here and how to enlarge the limit?

asked Nov 19, 2015 by anonymous

1 Answer

There is a kernel parameter vm.max_map_count that controls the number of ranges that you can mmap().

You can find the current limit by

$ sysctl vm.max_map_count

On my system, the default value is 65530:

vm.max_map_count = 65530

To change the maximum number of mapped ranges allowed to some number such as 655300:

# sysctl -w vm.max_map_count=655300

This changes the runtime parameter of the Linux kernel. To make the change permanent to take effect every time the Linux is rebooted, add a like to the /etc/sysctl.conf file like

vm.max_map_count=655300
answered Dec 8, 2015 by Eric Z Ma (43,500 points)

Please log in or register to answer this question.

Copyright © SysTutorials. User contributions licensed under cc-wiki with attribution required.
Hosted on Dreamhost

...