"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 - Pages may be written
VM_MAYWRITE - Allow the VM_WRITE flag to be set
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?
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?