what is the size limit for mmap

自古美人都是妖i 提交于 2019-12-12 08:12:25

问题


I am using mmap() to map a shared memory object to a process. My question has two parts:

1) what is the size limit for mmap() to a linux process? (is there such limit?)

2) after the process running a while, I think the process virtual memory address space will be somehow fragmented. Will this impact the max size I can do mmap() in this process?

The linux kernel used is 2.6.27. The size of the shared memory object is around 32MB. I am trying to access what is the possibility that mmap() fails with such shared memory object due to no enough virtual address space.


回答1:


There is no restriction on mmap size but would depend on the existing address space used by the given process. But it is highly suggested that you dont mmap to a large contiguous virtual address space. Another suggestion would be to use the mmap "just-in-time" when a specific physical address (or a device address) is accessed and unmap once done




回答2:


/proc/sys/vm/overcommit_memory controls the maximum on Linux

I have explained this in detail at: maximum memory which malloc can allocate

Basically, the value of 1 allows arbitrary virtual allocations, while 0 and 2 have more complicated limit calculations.



来源:https://stackoverflow.com/questions/13127855/what-is-the-size-limit-for-mmap

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!