Mmap vs sbrk, performance comparison

Which of these calls is faster on average? I heard that mmap is faster for smaller distributions, but I have not heard a comparison either. Any information on effectiveness for them will be pleasant.

+3
source share
1 answer

You should mark this with a specific implementation (e.g. linux ), as the answer certainly depends on the implementation. For now, I will use Linux, as it is the most popular.

With that said, brk theoretically more optimized, and in practice it works on my machine by about 10%. By highlighting one page, this is the time I get:

  • brk : min 2550 cycles, typical 2650 cycles
  • mmap : min 2700 cycles, typical 2800 cycles

I remember hearing something along the brk lines that could skip the mmap semaphore lock, which would explain the mismatch.

Note. . I updated these points after setting up my test to make fictitious calls before timing, to make sure that they will all be in the cache.

+10
source

All Articles