Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What do the fields in the output from `malloc_info` mean?

I'm calling malloc_info(3) and getting XML output.

Everything I've found online says something along the lines of "this is subject to change and we're not gonna bother documenting it".

But that's not terribly useful for someone investigating a potential memory fragmentation issue.

Here are some snippets:

<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>

  <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>

etc., etc., until...


  <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>

What does this all actually mean?

I'll put some of my own notes/thoughts in an answer, but I'd appreciate it if someone who knew more than I do would chip in.

ldd --version reports Ubuntu EGLIBC 2.19-0ubuntu6.13, which is the best guess I've got for the glibc version.

I've tagged this with eglibc because it's taken from Ubuntu 14.04, but it's probably relevant to glibc as well.

like image 744
Roger Lipscombe Avatar asked Jan 05 '18 13:01

Roger Lipscombe


1 Answers

The diagram at http://core-analyzer.sourceforge.net/index_files/Page335.html is fairly useful.

Things I'm pretty sure of:

  • Heap 0 is the main arena.

    • Free blocks are kept in "bins", arranged by size, for quick re-use.
    • Heap 0 has a single free block, size 257 bytes.
    • I don't know what the relationship between current, max, total and mprotect is.
  • Other heaps are numbered starting at 1.

  • Heap 1:

    • A bunch of free blocks, of various sizes.
    • The values in fast and rest track the total size of the free blocks: fast.count + rest.count == SUM(size.count) and fast.size + rest.size == SUM(size.total)
    • current size = 2032623616 (~2GiB)
    • total (currently used?) = 19451904 (~19MiB)
  • Heap 27:

    • No free blocks?
    • 32KiB allocated, 32KiB used?
  • Totals?

    • ~17.2GiB allocated?
    • ~491MiB used?

That last number doesn't look reliable; if I total up the used memory (through other means), I get ~3GiB.

like image 51
Roger Lipscombe Avatar answered Nov 03 '22 07:11

Roger Lipscombe