查找不再与写时复制共享的页面 [英] Find which pages are no longer shared with copy-on-write

查看:98
本文介绍了查找不再与写时复制共享的页面的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

说我在Linux中有一个进程,从中我fork()是另一个相同的进程. fork之后,由于原始进程将开始写入内存,因此Linux的 copy-on-write 机制将为该进程提供唯一的物理内存页面,该页面与分叉进程所使用的页面不同.

Say I have a process in Linux from which I fork() another identical process. After forking, as the original process will start writing to memory, the Linux copy-on-write mechanism will give the process unique physical memory pages which are different from the one used by the forked process.

在执行的某个时候,我如何知道原始过程的哪些页面已在写时复制?

我不想使用SIGSEGV信号处理程序,并且对开头的所有页面都具有只读访问权限,因为这会导致我不希望的开销.

I don't want to use SIGSEGV signal handler and give read only access to all the pages in the beginning as that induces an overhead I don't want.

推荐答案

跟踪系统调用-fork(),clone():

Tracing the syscall - fork(), clone():

copy_process()-> copy_mm()-> dup_mm()-> dup_mmap()->在这里,您会发现算法通过VMA进行VMA,以将其标记为写时复制":

copy_process()->copy_mm()->dup_mm()->dup_mmap()-->and here you will find the algorithm to go through VMA by VMA to mark them as "copy-on-write":

http://www.cs.columbia.edu /~krj/os/lectures/L17-LinuxPaging.pdf

http://www.cs .columbia.edu/〜junfeng/13fa-w4118/lectures/l20-adv-mm.pdf

从本质上讲(请参见幻灯片),如果PTE不可写(基于硬件),并且VMA被标记为可写(基于软件),则意味着内存是写时复制的. /strong>

Essentially (refer to slides), if PTE in unwriteable (which is hardware-based), and VMA is marked as writeable (which is software based) - that means the memory is copy-on-write.

您总是可以编写一个内核模块来实现这一点.

You can always write a kernel module to do that.

这篇关于查找不再与写时复制共享的页面的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆