How does malloc_info () work?

I tried to figure out how the malloc_info () function located in malloc.h works. I know that you must transfer FILE * to him and that no options have been implemented, but I don’t understand what he is actually reporting !? In addition, I wrote a test application that allocates a whole bunch of memory, and the values ​​specified in the malloc_info () file do not change, unless I allocated 20,000 1 bytes.

Is there anyone who has experience with malloc_info () and can shed light on what aspects of memory it should measure?

It should be noted that I almost did not find anything in google about malloc_info (), just some fragmentary error reports.

Example output from malloc_info ():

<malloc version="1"> <heap nr="0"> <sizes> </sizes> <total type="fast" count="0" size="0"/> <total type="rest" count="0" size="0"/> <system type="current" size="135168"/> <system type="max" size="135168"/> <aspace type="total" size="135168"/> <aspace type="mprotect" size="135168"/> </heap> <total type="fast" count="0" size="0"/> <total type="rest" count="0" size="0"/> <system type="current" size="135168"/> <system type="max" size="135168"/> <aspace type="total" size="135168"/> <aspace type="mprotect" size="135168"/> </malloc> 

EDIT:

As an additional explanation; my fallback position is the mallinfo () function, but I was hoping to use malloc_info (), because from what I can collect, it is intended to replace mallinfo (). I found that mallinfo () and malloc_info () do not work the same. In my tests, mallinfo () keeps track of all my distributions, and malloc_info () does not do this at all. I can only assume that malloc_info () is currently broken, or it is not intended to accomplish the same purpose as mallinfo ().

The article submitted by omnifarious has good reasons why mallinfo () should be deprecated:

it is completely unsuitable for 64-bit machines. The data types required by the SysV specification do not allow values ​​greater than 2 ^ 31 bytes (all fields in the structure are ints). The second problem is that the data structure is really specific to the malloc SysV implementation used at that time.

However, I think that at this time malloc_info () is not ready to take this place.

FURTHER CHANGE: After a bit more digging, it seems that malloc_info () reports the arena size from mallinfo () in all places where 135168 appears (at least that matches). This seems much less useful and represents a very one-dimensional piece of information compared to what mallinfo () allows.

+7
c ++ c gcc gnu
source share
2 answers

Large allocations are usually handled by simply specifying the OS “I need x number of pages of memory”, often at mmap ing /dev/zero . Allocations exceeding page or 4 (usually a page of 4096 bytes) are usually handled this way, and these allocations are not things that I would expect to keep track of malloc diagnostics.

Unfortunately, I do not know anything more than anyone else about malloc_info. LJ's message about the removal of mallinfo (among other things), Ulrich Drapper, our invaluable author of glibc, seems to be the best information available, and it's pretty damn subtle, and what you would probably find with Google anyway.

The program pasted on paste.isp.org should run malloc through it and print the heap information. This is very Linux and gcc, but of course that is the question. Perhaps messing around with a test program will give you some idea of ​​what it says.

+1
source share

Just to mention the linux man page project, it provides a man page for malloc_info from version 3.41:

http://man7.org/linux/man-pages/man3/malloc_info.3.html

+1
source share

All Articles