mmap vs sbrk, performance comparison

我的梦境 提交于 2019-12-18 13:39:20

问题


Which of these calls is faster on average? I've heard that mmap is faster for smaller allocations but I haven't heard a comparison of either. Any information on performance for these would be nice.


回答1:


You should tag this with a particular implementation (like linux) since the answer surely varies by implementation. For now I'll assume Linux since it's the most popular.

With that said, brk is in theory more optimizable, and in practice it runs about 10% faster on my machine. Allocating one page, these are the times I get:

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

I remember hearing something along the lines of brk being able to skip locking the mmap semaphore, which would explain the discrepancy.

Note: I updated these times after adjusting my test to make a dummy calls prior to timing, to ensure that the code would all be in the cache.



来源:https://stackoverflow.com/questions/5517601/mmap-vs-sbrk-performance-comparison

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