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?

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

Similar Posts

  • Several Vim Tips (in Chinese)

    窗口模式操作 CTRL-W CTRL-S 将当前窗口分割为两窗口 CTRL-W CTRL-W 切换窗口 CTRL-W j 切换到下一窗口 CTRL-W k 切换到上一窗口 CTRL-W CTRL-R 将窗口的位置轮换 CTRL-W CTRL-_ 将当前窗口最小化 CTRL-W CTRL-= 将所有窗口变为等大 搜索和替换 /word 搜索word 搜索之后按回车高亮显示,n 下一个 p 上一个 :%s/模式/替换成的内容/gc % 全局选项,如果没有开启则只在当前行进行替换 g 表示 全局替换,如果没有g选项则只替换每行出现的第一个单词 c 表示需要确认 Esc替换按键 ESC键在键盘的左上角,按起来很不方便,而在VIM中ESC经常用到,其实有一个同样作用的组合按键:CTRL-[,这两个按起来手基本不用做大的动作,方便多了。 块操作 使用visual可视模式 v 进入可视模式,移动光标可进行选择 CTRL-Q 或 CTRL-V 进入列式模式,可进行块操作,选定的是一个矩形块。如果使用behave mswin CTRL-V可能映射成为past Read more: How to convert between…

  • Micosoft招聘部分算法题

    Micosoft招聘部分算法题 1.链表和数组的区别在哪里? 2.编写实现链表排序的一种算法。说明为什么你会选择用这样的方法? 3.编写实现数组排序的一种算法。说明为什么你会选择用这样的方法? 4.请编写能直接实现strstr()函数功能的代码。 5.编写反转字符串的程序,要求优化速度、优化空间。 6.在链表里如何发现循环链接? 7.给出洗牌的一个算法,并将洗好的牌存储在一个整形数组里。 8.写一个函数,检查字符是否是整数,如果是,返回其整数值。(或者:怎样只用4行代码编写出一个从字符串到长整形的函数?) 9.给出一个函数来输出一个字符串的所有排列。 10.请编写实现malloc()内存分配函数功能一样的代码。 11.给出一个函数来复制两个字符串A和B。字符串A的后几个字节和字符串B的前几个字节重叠。 12.怎样编写一个程序,把一个有序整数数组放到二叉树中? 13.怎样从顶部开始逐层打印二叉树结点数据?请编程。 14.怎样把一个链表掉个顺序(也就是反序,注意链表的边界条件并考虑空链表)? 来源:·日月光华 bbs.fudan.edu.cn Read more: Java与C++在语言方面上的不同 4 Ways of Converting String to Int in C++ x86-64 ISA / Assembly Programming References How to Measure Time Accurately in Programs How to Get Available Filesystem Space on Linux: a C Function with a…

  • |

    File system Inode flags: difference between FS_IOC_GETFLAGS and FS_IOC_FSGETXATT

    What is the difference between FS_IOC_GETFLAGS and FS_IOC_FSGETXATTR ioctl commands? What flags do both return? The comment in fs.h is clear enough to explain itself. In short, FS_IOC_GETFLAGS was for ext2/ext3 only, and FS_IOC_FSGETXATTR is a generic FS level interface. Full comment as follows for your reference (source): /* * Inode flags (FS_IOC_GETFLAGS / FS_IOC_SETFLAGS)…

2 Comments

  1. Pingback: Elasticsearch: administration | SnowCrash

Leave a Reply

Your email address will not be published. Required fields are marked *