• malloc算法


    1, splay tree
    http://www.codeproject.com/Articles/14525/Heap-Manager-for-Allocating-Memory-from-a-Shared-M
    有两个树LENGTH_TREE 和 POINTER_TREE

    2. dlmalloc
    http://g.oswego.edu/dl/html/malloc.html
    这是个很出名的实现,据说glibc就是基于它的实现。 它把类似大小的组成bin以便改进速度和降低总体的fragmentation

    对于小于256byte的请求,使用了一个简单的两倍best fit分配器。如果在当前bin里面没有free blocks,就会将下一个bin分成两半

    对于256byte以上但是小于mmap要求的,dlmalloc使用了一个in-place的bitwise trie算法。如果没有足够的空闲空间,dlmalloc会通过system call增大heap大小

    For requests above the mmap threshold (a "largebin" request), the memory is always allocated using the mmap system call. The threshold is usually 256 KB.[11] The mmap method averts problems with huge buffers trapping a small allocation at the end after their expiration, but always allocates an entire page of memory, which on many architectures is 4096 bytes in size.[12]
    对于大于mmap的请求( "largebin" 请求),内存总是使用mmap实现。这个threshold一般是256kb

    3. wiki上列出了常见的一些实现
    http://en.wikipedia.org/wiki/C_dynamic_memory_allocation

    4. tcmalloc (Thread-caching malloc )
    Every thread has local storage for small allocations. For large allocations mmap or sbrk can be used. TCMalloc, a malloc developed by Google,[15] has garbage-collection for local storage of dead threads. The TCMalloc is considered to be more than twice as fast as glibc's ptmalloc for multithreaded programs.[16][17]

    5.支持gc的allocator (for c)

    http://www.hpl.hp.com/personal/Hans_Boehm/gc/

  • 相关阅读:
    互联网商业数据分析(二十七):运营分析(三)用户分层
    鲲鹏服务器上跑dpdk kni bug
    dpdk 网卡顺序
    dpvs ipvsadm.c:114:10: fatal error: popt.h: No such file or directory
    dpvs keepalived编译出错
    ps查看线程所在的cpu + pstack 线程+ strace 线程
    查看内核模块加载时参数
    dpdk kni二
    dpdk eal 参数
    dpdk project gdb
  • 原文地址:https://www.cnblogs.com/cutepig/p/3132636.html
Copyright © 2020-2023  润新知