`malloc_info` 输出中的字段是什么意思?

Rog*_*mbe 6 malloc glibc eglibc

我正在调用malloc_info(3)并获取 XML 输出。

我在网上找到的所有内容都说明了“这可能会发生变化,我们不会费心记录它”。

但这对于调查潜在内存碎片问题的人来说并不是非常有用。

以下是一些片段:

<malloc version="1">
  <heap nr="0">
    <sizes>
      <size from="257" to="257" total="257" count="1"/>
    </sizes>
    <total type="fast" count="0" size="0"/>
    <total type="rest" count="1" size="257"/>
    <system type="current" size="303104"/>
    <system type="max" size="303104"/>
    <aspace type="total" size="303104"/>
    <aspace type="mprotect" size="303104"/>
  </heap>
Run Code Online (Sandbox Code Playgroud)
  <heap nr="1">
    <sizes>
      <size from="17" to="32" total="96" count="3"/>
      <!-- etc. -->
      <size from="10609" to="10609" total="10609" count="1"/>
      <unsorted from="145" to="209" total="740" count="4"/>
    </sizes>
    <total type="fast" count="95" size="7328"/>
    <total type="rest" count="2633564" size="112589836"/>
    <system type="current" size="2032623616"/>
    <system type="max" size="2032947200"/>
    <aspace type="total" size="19451904"/>
    <aspace type="mprotect" size="19775488"/>
  </heap>
Run Code Online (Sandbox Code Playgroud)

等等等等,直到……


  <heap nr="27">
    <sizes>
</sizes>
    <total type="fast" count="0" size="0"/>
    <total type="rest" count="0" size="0"/>
    <system type="current" size="32768"/>
    <system type="max" size="32768"/>
    <aspace type="total" size="32768"/>
    <aspace type="mprotect" size="32768"/>
  </heap>
  <total type="fast" count="4232" size="293312"/>
  <total type="rest" count="22498068" size="1597097332"/>
  <system type="current" size="17265770496"/>
  <system type="max" size="17271173120"/>
  <aspace type="total" size="491339776"/>
  <aspace type="mprotect" size="496742400"/>
</malloc>
Run Code Online (Sandbox Code Playgroud)

这一切究竟意味着什么?

我会将我自己的一些笔记/想法放在答案中,但如果有人比我知道的更多,我会很感激。

ldd --version报告Ubuntu EGLIBC 2.19-0ubuntu6.13,这是我对 glibc 版本的最佳猜测。

我用标记了它,因为它取自 Ubuntu 14.04,但它可能也与相关。

Rog*_*mbe 2

http://core-analyzer.sourceforge.net/index_files/Page335.html上的图表相当有用。

我非常确定的事情:

  • 堆 0 是主要竞技场。

    • 空闲块保存在“垃圾箱”中,按大小排列,以便快速重复使用。
    • 堆 0 有一个空闲块,大小为 257 字节。
    • current我不知道、maxtotal和之间有什么关系mprotect
  • 其他堆的编号从 1 开始。

  • 堆 1:

    • 一堆不同大小的空闲块。
    • fast和中的值rest跟踪空闲块的总大小:fast.count + rest.count == SUM(size.count)fast.size + rest.size == SUM(size.total)
    • 当前大小 = 2032623616 (~2GiB)
    • 总计(当前使用?)= 19451904 (~19MiB)
  • 堆 27:

    • 没有空闲块?
    • 分配了 32KiB,使用了 32KiB?
  • 总计?

    • 分配了~17.2GiB?
    • 使用了~491MiB?

最后一个数字看起来并不可靠;如果我将已用内存(通过其他方式)加起来,我会得到~3GiB。