malloc对linux内核中的内部碎片感到担忧吗?例如,当我想要分配5页时,malloc会把大小增加到2: 5->8,以避免内核中的内部碎片,因为linux内核使用好友系统作为页面分配器。
发布于 2019-09-18 17:12:47
至少对于glibc来说,它并不真正关心内核中的碎片问题。它主要是一个“最适合”的分配器,除了非常小或非常大的分配。下面是glibc的“malloc.c”顶部评论的摘录:
- For large (>= 512 bytes) requests, it is a pure best-fit allocator, with ties normally decided via FIFO (i.e. least recently used).
- For small (<= 64 bytes by default) requests, it is a caching allocator, that maintains pools of quickly recycled chunks.
- In between, and for combinations of large and small requests, it does the best it can trying to meet both goals at once.
- For very large requests (>= 128KB by default), it relies on system memory mapping facilities, if supported.有关更长但稍微过时的高级描述,请参见http://gee.cs.oswego.edu/dl/html/malloc.html。
glibc malloc实现可以使用mallopt函数或各种环境变量来设置各种参数,如手册页mallopt(3)所述。
https://stackoverflow.com/questions/57996975
复制相似问题