堆在哪里? [英] Where is the heap?
问题描述
我了解在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.
这篇关于堆在哪里?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!