libc malloc与Linux内核伙伴分配器 [英] libc malloc vs linux kernel buddy allocator

查看:61
本文介绍了libc malloc与Linux内核伙伴分配器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

malloc是否担心Linux内核中的内部碎片?例如,当我要分配5个页面时,将malloc舍入为2:5-> 8的幂,以避免内核内部碎片,因为linux内核使用伙伴系统作为页面分配器.

Does malloc wory about internal fragmentation in linux kernel? For example when I want to allocate 5 pages, will malloc round up size to make it power of 2: 5->8 to avoid internal fragmentation in kernel, because linux kernel uses buddy system as page allocator.

推荐答案

至少对于glibc,它实际上并不关心内核中的碎片.除了很小或非常大的分配外,它大多是最佳匹配"分配器.这是glibc"

At least for glibc, it doesn't really care about fragmentation in the kernel. It is mostly a "best-fit" allocator except for very small or very large allocations. Here is an extract from the comments near the top of glibc's "malloc.c":

  • 为什么使用此malloc?

  • Why use this malloc?

这不是最快,最节省空间,最可移植或有史以来最可调的malloc.但是它是最快的同时也是最节省空间,最便于携带和可调的设备之一.这些因素之间的一致平衡可带来良好的通用性malloc密集型程序的分配器.该算法的主要特性是:

This is not the fastest, most space-conserving, most portable, or most tunable malloc ever written. However it is among the fastest while also being among the most space-conserving, portable and tunable. Consistent balance across these factors results in a good general-purpose allocator for malloc-intensive programs. The main properties of the algorithms are:

  • 对于大型(> = 512字节)请求,它是一个最适合的分配器,通常通过FIFO(即最近最少使用)确定联系.
  • 对于较小的请求(默认情况下为< = 64字节),这是一个缓存分配器,用于维护快速回收的块池.
  • 介于两者之间,并且对于大型和小型请求,它确实它可以尝试同时实现两个目标的最佳方法.
  • 对于非常大的请求(默认情况下== 128KB),它依赖于系统内存映射工具(如果支持).

有关较长的但有点过时的高级描述,请参阅 http://gee.cs.oswego.edu/dl/html/malloc.html

For a longer but slightly out of date high-level description, see http://gee.cs.oswego.edu/dl/html/malloc.html

如手册页 查看全文

登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆