“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.”
max_map_count文件包含限制一個進程可以擁有的VMA(虛擬內存區域)的數量。虛擬內存區域是一個連續的虛擬地址空間區域。在進程的生命周期中,每當程序嘗試在內存中映射文件,鏈接到共享內存段,或者分配堆空間的時候,這些區域將被創建。調優這個值將限制進程可擁有VMA的數量。限制一個進程擁有VMA的總數可能導致應用程序出錯,因為當進程達到了VMA上線但又只能釋放少量的內存給其他的內核進程使用時,操作系統會拋出內存不足的錯誤。如果你的操作系統在NORMAL區域僅占用少量的內存,那么調低這個值可以幫助釋放內存給內核用。
調整示例,如下調整為默認的4倍
此操作需要root權限
[root@localhost ~]# sysctl -w vm.max_map_count=262144
查看修改結果
[root@localhost ~]# sysctl -a|grep vm.max_map_count vm.max_map_count = 262144