linux - Linux 中的内存区域标志 : why both VM_WRITE and VM_MAYWRITE are needed?

标签 linux linux-kernel kernel virtual-memory

Mel Gorman 的“Understanding the Linux Virtual Memory Manager”(2007 年)(这里是 link to the book chapter )描述了内存区域的标志 (vm_area_struct):

VM_WRITE - Pages may be written

VM_MAYWRITE - Allow the VM_WRITE flag to be set

我不明白为什么 Linux 需要这两个标志,而不是其中之一。从上面的描述来看,听起来好像设置了VM_MAYWRITE,但没有设置VM_WRITE。在什么情况下? Linux 内核在这些情况下的行为有何不同?

例如,COW 机制根据 VM_MAYWRITE 标志检测受 COW 保护的页面(请参阅 source code )。当设置VM_MAYWRITE时,Linux内核不会设置VM_WRITE标志吗?如果是,为什么不使用单个标志并从一开始就设置它?

最佳答案

内存保护级别可以更改,内核使用 VM_MAY% 标志来确定是否允许此类更改。

From the description above, it sounds like VM_MAYWRITE be set while VM_WRITE is not. In what situations?

内存最初是只读的,而您希望将其设置为可写的情况。

For example, the COW mechanism detects COW-protected pages according to their VM_MAYWRITE flag (see the source code). Doesn't the Linux kernel set the VM_WRITE flag when the VM_MAYWRITE is set? If yes, why not having a single flag and have it set from the beginning?

不,事实并非如此。 is_cow_mapping() 并不检查内存是否可写,而是检查内存是否可以通过 mprotect() 设为可写。如果不能,那么它显然不是 COW 映射!

关于linux - Linux 中的内存区域标志 : why both VM_WRITE and VM_MAYWRITE are needed?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48241187/

相关文章:

c - 如何获取 C 程序本身设置的所有环境变量?

php - 关于SQL注入(inject)中set id=1 and password = ' '

c - 动态添加条目到 sysctl

linux - 在 USB 设备内部调用 USB 批量发送消息时出现问题 Linux 内核模块

linux - 如何在 Linux 中加快编译时间

linux - 使用 "exit"后如何保留 docker alpine 容器?

linux - 计算bash中每个进程的CPU使用率%

linux - 如何在 Linux 中读取 SRAM 信息?

linux - 限制守护进程在 Linux 上打开某些端口

c - Linux,kprobes/kretprobes : a way to recover [from registers?] 探测函数的参数?