简体   繁体   English

malloc_info()如何工作?

[英]How does malloc_info() work?

I've been trying to figure out how the malloc_info() function located in malloc.h works. 我一直试图弄清楚malloc.h中的malloc_info()函数是如何工作的。 I know you have to pass it a FILE* and that no options are implemented yet, but I am at a loss as to what it is actually reporting!? 我知道你必须传递一个FILE *并且还没有实现任何选项,但我对它实际报告的内容感到茫然!? Furthermore i've written a test app that allocates a whole bunch of memory and the values reported from malloc_info() don't change, except when I did 20,000 1 byte allocations? 此外,我编写了一个测试应用程序,分配了一大堆内存,并且malloc_info()报告的值不会改变,除非我做了20,000个1字节分配?

Is there anyone out there who has any experience with malloc_info() and can shed some light on what aspects of memory it is supposed to measure? 有没有人对malloc_info()有任何经验,并且可以了解它应该测量的内存的哪些方面?

It should be noted that I could find next to nothing on google about malloc_info(), just some sketchy bug reports. 应该注意的是,我可以在谷歌上找到关于malloc_info()的一切,只是一些粗略的错误报告。

Example Output from malloc_info(): 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 a further explanation; 作为进一步的解释; my fallback position is the mallinfo() function, but I was hoping to use malloc_info() as from what I can gather it is targeted to replace mallinfo(). 我的后备位置是mallinfo()函数,但我希望使用malloc_info()作为我可以收集的内容,它的目标是替换mallinfo()。 What I've found is that mallinfo() and malloc_info() do not work the same. 我发现mallinfo()和malloc_info()的工作方式不同。 In my tests mallinfo() tracks all my allocations while malloc_info() fails to do so at all. 在我的测试中,mallinfo()跟踪我的所有分配,而malloc_info()完全没有这样做。 I can only assume that malloc_info() is currently broken, or it is not intended to serve the same purpose as mallinfo(). 我只能假设malloc_info()当前已被破坏,或者它的目的不是与mallinfo()相同的目的。

In the article given by omnifarious there are good reasons that mallinfo() should be deprecated: 在omnifarious给出的文章中,有很好的理由应该弃用mallinfo():

it is completely unsuitable for 64-bit machines. 它完全不适合64位机器。 The data types required by the SysV spec don't allow for values larger 2^31 bytes (all fields in the structure are ints). SysV规范要求的数据类型不允许大于2 ^ 31字节的值(结构中的所有字段都是整数)。 The second problem is that the data structure is really specific to the malloc implementation SysV used at that time. 第二个问题是数据结构确实特定于当时使用的malloc实现SysV。

However I think that at this time malloc_info() is not yet ready to take it's place. 但是我认为目前malloc_info()还没有准备好接受它的位置。

FURTHER EDIT: After a bit more digging it seems that malloc_info() is reporting the arena size from mallinfo() in all places where 135168 appears (at least that's what it corresponds to). 进一步编辑:经过多一点挖掘后,似乎malloc_info()在所有出现135168的地方报告了mallinfo()的竞技场大小(至少这是它所对应的)。 This seems much less useful and is a very one dimensional piece of information compared with what mallinfo() allows for. 这似乎没那么有用,与mallinfo()允许的相比,它是一个非常一维的信息。

Just to mention the linux man-pages project provides a manpage for malloc_info since version 3.41: 仅提及linux man-pages项目为版本3.41提供了malloc_info的联机帮助页:

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

Large allocations are typically handled by just telling the OS "I need x number of memory pages.", often by mmap ing /dev/zero . 大量分配通常只通过告诉操作系统“我需要x个内存页面”来处理,通常是通过mmap /dev/zero Allocations of larger than a page or 4 (A page is usualy 4096 bytes) are usually handled this way and those allocations are not things I'd expect a malloc diagnostic to track. 大于一页或4的分配(一页通常是4096字节)通常以这种方式处理,这些分配不是我期望的malloc诊断跟踪的东西。

Unfortunately, I don't know anything more than anybody else about malloc_info. 不幸的是,我对malloc_info的了解不多。 The LJ post about the removal of mallinfo (among other things), by Ulrich Drepper, our inestimable glibc author, appears to be the best information available, and that's pretty darned thin, and what you would've probably found with Google anyway. 关于删除mallinfo (以及其他内容)的LJ帖子 ,由我们无法估量的glibc作者Ulrich Drepper,似乎是最好的信息,而且相当稀薄,以及你可能会在谷歌找到的东西。

The program I pasted at paste.lisp.org should run malloc through it's paces and print out the heap info. 我粘贴在paste.lisp.org上程序应该通过它的步调运行malloc并打印出堆信息。 It's very Linux and gcc specific, but, of course, so is this question. 这是非常具体的Linux和gcc,当然,这个问题也是如此。 Maybe fiddling around with the output of the test program will give you some insight into what it's talking about. 也许摆弄测试程序的输出可以让你深入了解它所谈论的内容。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM