Linux中的内存区域标志:为什么同时需要VM_WRITE和VM_MAYWRITE? [英] Memory region flags in Linux: why both VM_WRITE and VM_MAYWRITE are needed?

查看:458
本文介绍了Linux中的内存区域标志:为什么同时需要VM_WRITE和VM_MAYWRITE?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Mel Gorman的理解Linux虚拟内存管理器"(2007年)(这是链接到本书的章节)描述了内存区域(vm_area_struct)的标志:

"Understanding the Linux Virtual Memory Manager" (2007) by Mel Gorman (here's a link to the book chapter) describes the flags of a memory region (vm_area_struct):

VM_WRITE-页面可能被写入

VM_WRITE - Pages may be written

VM_MAYWRITE-允许设置VM_WRITE标志

VM_MAYWRITE - Allow the VM_WRITE flag to be set

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

I don't understand why Linux needs these two flags, rather than just one of them. From the description above, it sounds like VM_MAYWRITE be set while VM_WRITE is not. In what situations? And how does the Linux kernel behave differently in these situations?

例如,COW机制根据其VM_MAYWRITE标志检测受COW保护的页面(请参见

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?

推荐答案

可以更改内存保护级别,并且内核使用VM_MAY%标志来确定是否允许这种更改.

Memory protection levels can be changed and the kernel uses the VM_MAY% flags to determine if such changes are allowable.

从上面的描述中,听起来好像设置了VM_MAYWRITE,而未设置VM_WRITE.在什么情况下?

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

在内存最初是只读的情况下,并且您想使其可写.

In the situation that memory is initially read-only and you want to make it writable.

例如,COW机制根据其受VM_MAYWRITE标志检测到受COW保护的页面(请参见源代码).设置VM_MAYWRITE时,Linux内核不设置VM_WRITE标志吗?如果是,为什么不拥有一个标志并从头开始设置它?

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映射!

No, it doesn't. is_cow_mapping() isn't checking that the memory is writable, it's checking that the memory can be made writable via mprotect(). If it can't, then it's clearly not a COW mapping!

这篇关于Linux中的内存区域标志:为什么同时需要VM_WRITE和VM_MAYWRITE?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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