mremap 是否“初始化”?成长记忆?

发布于 2024-12-13 01:30:36 字数 679 浏览 2 评论 0原文

如果我有 mmap() 一些 PRIVATEANONYMOUS 页面,然后扩展它们与 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 技术交流群。

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

发布评论

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

评论(1

半边脸i 2024-12-20 01:30:36

匿名页是通用零页的写时复制映射。它们一直如此(在每个系统上,不仅仅是 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 (or brk) extends an anonymous mapping, you get new anonymous (zero) pages. There is no need to initialize them yourself.

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