堆在哪里?

编程入门 行业动态 更新时间:2024-10-24 17:32:37
本文介绍了堆在哪里?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我了解在Linux中, mm_struct 描述了进程的内存布局.我也理解 start_brk 和 brk 分别标记了进程堆部分的开始和结束.

I understand that in Linux the mm_struct describes the memory layout of a process. I also understand that the start_brk and brk mark the start and end of the heap section of a process respectively.

现在,这是我的问题:我有一个过程为我编写了源代码,该过程使用 malloc 分配了5.25 GB的堆内存.但是,当我使用内核模块检查进程的 mm_sruct 时,我发现的值等于135168.这与我的预期不同:我期望的是 brk-start_brk 略高于5.25 GB.

Now, this is my problem: I have a process, for which I wrote the source code, that allocates 5.25 GB of heap memory using malloc. However, when I examine the process's mm_sruct using a kernel module I find the value of is equal to 135168. And this is different from what I expected: I expected brk - start_brk to be equal slight above 5.25 GB.

那么,这是怎么回事?

谢谢.

推荐答案

我在中注意到以下内容 malloc(3) 的联机帮助页:

I notice the following in the manpage for malloc(3):

通常,malloc()使用sbrk(2)从堆中分配内存,并根据需要调整堆的大小.当分配大于MMAP_THRESHOLD字节的内存块时,glibc malloc()实现使用mmap(2)将内存分配为私有匿名映射.MMAP_THRESHOLD默认情况下为128 kB,但可以使用mallopt(3)进行调整.使用mmap(2)执行的分配不受RLIMIT_DATA资源限制的影响(请参阅getrlimit(2)).

Normally, malloc() allocates memory from the heap, and adjusts the size of the heap as required, using sbrk(2). When allocating blocks of memory larger than MMAP_THRESHOLD bytes, the glibc malloc() implementation allocates the memory as a private anonymous mapping using mmap(2). MMAP_THRESHOLD is 128 kB by default, but is adjustable using mallopt(3). Allocations performed using mmap(2) are unaffected by the RLIMIT_DATA resource limit (see getrlimit(2)).

所以听起来好像使用了 mmap 而不是堆.

So it sounds like mmap is used instead of the heap.

更多推荐

堆在哪里?

本文发布于:2023-11-08 06:57:54,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1568661.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!