Mmap and malloc

Sreekanth sreekanth at
Thu Apr 3 12:32:45 PST 2003

    I have a situation i am not sure i understand.I am running a 4.6.2
FreeBSD system with a Dual Xeon board with 2GB of Physical memory.I
have a test program which continuoulsy calls mmap(with larger size
each time) till it receives MAP_FAILED return value. I then call
malloc(with bigger memory size each time) continuosly till it
fails.Here are my results.

Max mem mapped = 714 MB
Max mem alloc = 308 MB

My MAXDMSIZ is 1200*1024*1024 and KVA_PAGE is 512 (2GB)

If i swap the order in wich mmap and malloc are called, then i get the
following result.
Max mem alloc = 1200MB
Max mem mapped = 711MB

My questions are as follows
1) Why is the difference between two approaches. ?
2) What exactly is the relationship between mmap malloc and KVA_PAGES.
3) I found that the Maximum mmapped memory = 4GB - KVA_PAGES*PAGE_SIZE
- MAXDSIZ - 134
What is the 134 value..? It is very consistent for me for various
values of KVA_PAGES and MAXDSIZ, so i am ruling it being just a

I hope somebody has already seen this kind of behaviour and therefore
can help me out..

Thanks in advance,

ps: If somebody needs the code i used to generate these results, i
would be more than happy to provide it.

More information about the freebsd-hackers mailing list