I was reading a little bit about malloc
and found the following in the malloc
's man page:
Normally, malloc() allocates memory from the heap, and adjusts the size of the heap as required, using sbrk(2). When allocating blocks of memory larger than MMAP_THRESHOLD bytes, the glibc malloc() implementation allocates the memory as a private anonymous mapping using mmap(2). MMAP_THRESHOLD is 128 kB by default, but is adjustable using mallopt(3). Allocations performed using mmap(2) are unaffected by the RLIMIT_DATA resource limit (see getrlimit(2)).
So basically starting from the threshold MMAP_THRESHOLD malloc start using mmap
.
- Is there any reason to switch to
mmap
for large chunks? - Could this hit the process execution performance?
- Does the
mmap
system call force a context switch?