gpt4 book ai didi

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

转载 作者:塔克拉玛干 更新时间:2023-11-03 00:36:38 24 4
gpt4 key购买 nike

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/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com