Linux mmap() ENOMEM error causing Segmentation Fault,使用mongodb注意

本文介绍了一个在Linux系统中使用mmap遇到的问题及解决方案。作者创建了一个系统,该系统会在磁盘上生成文件,并使用mmap、madvise和mflush进行异步I/O操作。在运行过程中遇到了段错误,通过strace发现mmap调用失败。文章揭示了Linux进程中的mmap段数量存在限制,并介绍了如何调整/proc/sys/vm/max_map_count以解决问题。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

from: http://www.enchantedage.com/node/235

mongodb 使用了mmap来映射管理文件,使用mongodb的要注意


I have a system that creates files on disk, then uses mmap and madvise and mflush to asynchronously do I/O to the disk. This system may potentially create many, many files, each of which will have three mmap sections, that will be rotated through the file.

After trying to run this system for a while, I started getting segmentation violations that I couldn't quite understand. Initially, I thought it was a threading problem, because I'm using boost::asio and boost::thread quite heavily. I used strace() to figure out what the system was doing, and found that right before the crashes, one or more calls to mmap() would fail.

Long story short: There is a limit to the number of mmap() segments that can be active in a Linux process at any one time. This limit is configurable in /proc/sys/vm/max_map_count. I already knew there was a file descriptor limit, and I raised that pretty high, but apparently Linux doesn't think you'll be using lots of mmap() just because you're using lots of files. Adding the following to /etc/rc.local will fix the problem:

echo 1000000 > /proc/sys/vm/max_map_count


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值