pmap 结果中的堆 VS 匿名内存
下面是在solaris上运行后的结果,显示有两个堆,但在我的理解中,对于一个进程来说,只有一个堆,它是一大块连续的内存,可以通过brk管理来扩展或缩小大小。对于匿名内存,一个进程可以拥有许多匿名内存,这些内存可以通过 mmap/munmap 来管理。我的理解正确吗?或者我错误地读取了 pmap 的结果?
sol9# pmap -sx pgrep testprog
... 00022000 3960 3960 3960 - 8K rwx-- [堆]
00400000 131072 131072 131072 - 4M rwx-- [堆]
... FF390000 8 8 - - 8K rx-- libc_psr.so.1
FF3B0000 8 8 8 - 8K rwx-- [ anon ]
...
总计 Kb 135968 135944 135112 -
The following is the result after run on solaris, it shows there are two heaps, but in my understanding, for a process, there is only one heap which is a large continuous memory which can be managed by brk to expand or shrink the size. And for anon memory, a process can have many anon memory which can be managed by mmap/munmap. Is my understanding correct? or I read the result of the pmap wrongly?
sol9# pmap -sx pgrep testprog
...
00022000 3960 3960 3960 - 8K rwx-- [ heap ]
00400000 131072 131072 131072 - 4M rwx-- [ heap ]
...
FF390000 8 8 - - 8K r-x-- libc_psr.so.1
FF3B0000 8 8 8 - 8K rwx-- [ anon ]
...
total Kb 135968 135944 135112 -
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您是正确的,但误解了 pmap 输出。如果您执行了
pmap -x
,结果可能不会那么混乱,只显示一次堆,但由于您添加了-s
标志,它将堆分解为具有不同页面映射的段。从 0x0022000 开始的地址未正确对齐以映射到 4Mb 页,因此它们使用 8k 页中的 3960kb。 0x0022000+(3960*1024) = 0x00400000
在 0x00400000 处,地址已正确对齐 4Mb 页,因此堆切换为使用具有较少页表条目的较大页。
如果您想确保堆以正确的对齐方式开始,以便在整个过程中使用 4Mb 页面,而不是从 8k 开始直到达到对齐边界,那么您可以将程序与 <代码>-M /usr/lib/ ld/map.bssalign 来做到这一点。
可以在页面大小和内存布局博客文章 来自 Solaris 应用程序编程 作者 达里尔·戈夫。
You are both correct and misreading the pmap output. If you had done
pmap -x
the results would probably be less confusing, showing the heap just once, but since you added the-s
flag, it breaks down the heap into segments with different page mappings.The addresses starting at 0x0022000 are not aligned properly to be mapped to a 4Mb page, so they use 3960kb of 8k pages. 0x0022000+(3960*1024) = 0x00400000
At 0x00400000 the address is properly aligned for 4Mb pages, so the heap switches to using the larger pages with fewer page table entries.
If you wanted to ensure that your heap started at the proper alignment to use 4Mb pages for the whole thing instead of starting with 8k until it reached an alignment boundary, then you would link your program with
-M /usr/lib/ld/map.bssalign
to do that.A slightly more in-depth explanation can be found in the Page Size and Memory Layout blog post from Solaris Application Programming author Darryl Gove.