执行 fork() 时禁用某些内存页上的写时复制 (COW)
当父进程fork一个子进程时(在linux下),我想一开始就将父进程中的一些内存页复制到子进程的地址空间中,这意味着,不需要等待copy-on-写(牛)。有什么机制支持吗?谢谢:-)
When a parent process forks a child process (under linux), I want to copy some of the memory pages in parent process to the address space of child process right at the beginning, which means, no need to wait for the copy-on-write(COW). Is there any mechanism support this? Thanks:-)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我不知道有任何接口,但您总是手动执行此操作,无论是使用memcpy还是仅通过触摸有问题的页面(例如,读取第一个单词,然后写回) 。请务必将该页面标记为
易失性
。I'm not aware of any interface for this, but you always do it manually, either with a
memcpy
or just by touching the pages in question (e.g., read the first word, then write it back). Be sure to mark the page asvolatile
.看一下
clone
系统调用。最相关的选项是CLONE_VM
。重要的是要认识到分叉后页面的写时复制行为纯粹是一种优化。我无法预见这可能成为问题的任何情况,除非您希望由于预先的页面复制而招致所有潜在的“惰性”性能损失。即使对于这些,您也可能过于热心地希望触及每个可写页面,因为您将增加从原始进程派生的每个进程的物理内存使用量。Take a look at the
clone
system call. The most relevant option isCLONE_VM
. It's important to realize the copy-on-write behavior of pages after a fork is purely an optimization. I can't foresee any situation where this can be a problem, except perhaps where you wish to incur all potentially "lazy" performance penalties due to page duplication up front. Even for these, you may be overzealous in wishing to touch every writable page, as you'll be increasing physical memory use for every process forked from the original.