开发者

disable copy-on-write(COW) on some memory pages when doing fork()

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:-)


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 as volatile.


Take a look at the clone system call. The most relevant option is CLONE_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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜