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/