]> rtime.felk.cvut.cz Git - can-eth-gw-linux.git/blobdiff - mm/mlock.c
mlock: avoid dirtying pages and triggering writeback
[can-eth-gw-linux.git] / mm / mlock.c
index b70919ce4f72e6941f67b1a5462f5f270c231536..4f318642fbbe56b2d426dc6c02d74b9599e03f8e 100644 (file)
@@ -171,7 +171,12 @@ static long __mlock_vma_pages_range(struct vm_area_struct *vma,
        VM_BUG_ON(!rwsem_is_locked(&mm->mmap_sem));
 
        gup_flags = FOLL_TOUCH | FOLL_GET;
-       if (vma->vm_flags & VM_WRITE)
+       /*
+        * We want to touch writable mappings with a write fault in order
+        * to break COW, except for shared mappings because these don't COW
+        * and we would not want to dirty them for nothing.
+        */
+       if ((vma->vm_flags & (VM_WRITE | VM_SHARED)) == VM_WRITE)
                gup_flags |= FOLL_WRITE;
 
        /* We don't try to access the guard page of a stack vma */