mremap 是否“初始化”?成长记忆?
如果我有 mmap() 一些 PRIVATE 和 ANONYMOUS 页面,然后扩展它们与 mremap() 一样,新空间是否也被初始化为零?
我尝试阅读 Linux 源代码中的 mremap (mm/mremap.c) 代码,但它需要一些我目前没有的特定领域知识(vma_### 东西)。甚至不确定这是查看的正确位置...
但是,根据我收集的信息,我认为 mremap()ed 内存将被清除,这是正确的吗?
分配是这样完成的
list = mmap(NULL, newSize, PROT_READ | PROT_WRITE, MAP_PRIVATE | MAP_ANONYMOUS, -1, 0)
,然后重新映射是这样完成的
newList = mremap(list, oldSize, newSize, MREMAP_MAYMOVE)
啊,最后,这是一个 Linux 特定问题,运行最近的内核(>=2.6.28)并且libc (>= 2.11.1)
If I've mmap() some PRIVATE and ANONYMOUS pages and then extend them with mremap(), does the new space also get initialized to zeroes?
I've tried reading the code for mremap (mm/mremap.c) in the linux source but it requires some domain-specific knowledge that I don't currently have (vma_### stuff). Not even sure that's the right place to look...
But, from what I've gathered I think that mremap()ed memory would be cleared, is this correct?
Allocation is done like this
list = mmap(NULL, newSize, PROT_READ | PROT_WRITE, MAP_PRIVATE | MAP_ANONYMOUS, -1, 0)
and then remap is done like this
newList = mremap(list, oldSize, newSize, MREMAP_MAYMOVE)
Ah, and last, it's a Linux specific question, running a recent kernel (>=2.6.28) and libc (>= 2.11.1)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
匿名页是通用零页的写时复制映射。它们一直如此(在每个系统上,不仅仅是 Linux,提供匿名映射)并且永远如此。当
mremap
(或brk
)扩展匿名映射时,您将获得新的匿名(零)页面。不需要自己初始化它们。Anonymous pages are copy-on-write mappings of the universal zero page. They always have been (on every system, not just Linux, that offers anonymous mappings) and always will be. When
mremap
(orbrk
) extends an anonymous mapping, you get new anonymous (zero) pages. There is no need to initialize them yourself.