malloc_info() 是如何工作的?

发布于 2024-09-26 21:29:23 字数 1703 浏览 5 评论 0原文

我一直在试图弄清楚位于 malloc.h 中的 malloc_info() 函数是如何工作的。我知道你必须向它传递一个 FILE* 并且尚未实现任何选项,但我不知道它实际报告的内容!?此外,我编写了一个测试应用程序,它分配一大堆内存,并且从 malloc_info() 报告的值不会改变,除非我进行了 20,000 1 字节分配?

有没有人对 malloc_info() 有任何经验,并且可以阐明它应该测量内存的哪些方面?

应该指出的是,我在谷歌上几乎找不到任何关于 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>

编辑:

作为进一步的解释;我的后备位置是 mallinfo() 函数,但我希望使用 malloc_info() ,因为据我所知,它的目标是替换 mallinfo() 。我发现 mallinfo() 和 malloc_info() 的工作方式不同。在我的测试中, mallinfo() 跟踪我的所有分配,而 malloc_info() 根本无法做到这一点。我只能假设 malloc_info() 当前已损坏,或者它不具有与 mallinfo() 相同的用途。

在omnifarious 给出的文章中,有充分的理由表明应弃用 mallinfo():

它完全不适合64位机器。数据类型 SysV 规范要求不允许 对于大于 2^31 字节的值(全部 结构中的字段是整数)。这 第二个问题是数据 结构确实是特定于 malloc 实现 SysV 用于 那个时候。

不过我认为此时 malloc_info() 还没有准备好取代它。

进一步编辑: 经过更多挖掘后,似乎 malloc_info() 在 135168 出现的所有位置(至少是它对应的位置)报告了 mallinfo() 的竞技场大小。与 mallinfo() 所允许的相比,这似乎没那么有用,并且是一个非常一维的信息。

I've been trying to figure out how the malloc_info() function located in malloc.h works. 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!? 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?

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?

It should be noted that I could find next to nothing on google about malloc_info(), just some sketchy bug 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 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(). What I've found is that mallinfo() and malloc_info() do not work the same. In my tests mallinfo() tracks all my allocations while malloc_info() fails to do so at all. I can only assume that malloc_info() is currently broken, or it is not intended to serve the same purpose as mallinfo().

In the article given by omnifarious there are good reasons that mallinfo() should be deprecated:

it is completely unsuitable for 64-bit machines. The data types
required by the SysV spec don’t allow
for values larger 2^31 bytes (all
fields in the structure are ints). The
second problem is that the data
structure is really specific to the
malloc implementation SysV used at
that time.

However I think that at this time malloc_info() is not yet ready to take it's place.

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). This seems much less useful and is a very one dimensional piece of information compared with what mallinfo() allows for.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

各空 2024-10-03 21:29:23

大型分配通常只需告诉操作系统“我需要 x 数量的内存页”即可处理,通常是通过 mmaping /dev/zero 来处理。大于一个页面或 4 个页面(一个页面通常为 4096 字节)的分配通常以这种方式处理,并且这些分配不是我期望 malloc 诊断跟踪的内容。

不幸的是,我对 malloc_info 的了解并不比其他人多。 关于删除 mallinfo 的 LJ 帖子(除其他外),作者:Ulrich Drepper,我们不可估量的 glibc作者,似乎是最好的可用信息,而且非常薄弱,无论如何你都可能通过谷歌找到。

我在paste.lisp.org粘贴的程序应该通过malloc运行它是步伐并打印出堆信息。这是非常针对 Linux 和 gcc 的,但是,当然,这个问题也是如此。也许摆弄测试程序的输出会让您对它所讨论的内容有所了解。

Large allocations are typically handled by just telling the OS "I need x number of memory pages.", often by mmaping /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.

Unfortunately, I don't know anything more than anybody else about 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.

The program I pasted at paste.lisp.org should run malloc through it's paces and print out the heap info. It's very Linux and gcc specific, but, of course, so is this question. Maybe fiddling around with the output of the test program will give you some insight into what it's talking about.

是你 2024-10-03 21:29:23

值得一提的是,linux 手册页项目从版本 3.41 开始提供了 malloc_info 的手册页:

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

Just to mention the linux man-pages project provides a manpage for malloc_info since version 3.41:

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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文