5

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.

greeness
  • 15,956
  • 5
  • 50
  • 80
user1783732
  • 1,599
  • 5
  • 22
  • 44
  • Your only concern should be on either a system with very low memory and swap or a 32 bit system without PAE where your application is hogging a lot of virtual memory, other than that I believe the chances of this are very low. If you could provide some more details about your applications memory usage that would help. – Jesus Ramos Oct 29 '12 at 19:22
  • 1
    Practically, the limit is the largest range of currently unallocated address space after the program text, data, heap, stack, all shared libraries and their text/data/heap, the kernel and any other sorts of "usual" mappings are accounted for... – twalberg Oct 29 '12 at 19:48
  • @twalberg Yes, that is true. I was wondering after all the usual accounting for the virtual memory space, what are the size of the remaining space. Especially how it would change over time after the application runs for a long time. The CPU is 32-bit Intel CPU. I believe it has PAE. – user1783732 Oct 29 '12 at 20:42

2 Answers2

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

Maxime Lorant
  • 34,607
  • 19
  • 87
  • 97
1

/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.

Ciro Santilli OurBigBook.com
  • 347,512
  • 102
  • 1,199
  • 985