mirror of
https://github.com/torvalds/linux.git
synced 2026-11-26 00:12:52 +00:00
mlock: avoid dirtying pages and triggering writeback
When faulting in pages for mlock(), we want to break COW for anonymous or file pages within VM_WRITABLE, non-VM_SHARED vmas. However, there is no need to write-fault into VM_SHARED vmas since shared file pages can be mlocked first and dirtied later, when/if they actually get written to. Skipping the write fault is desirable, as we don't want to unnecessarily cause these pages to be dirtied and queued for writeback. Signed-off-by: Michel Lespinasse <[email protected]> Cc: Hugh Dickins <[email protected]> Cc: Rik van Riel <[email protected]> Cc: Kosaki Motohiro <[email protected]> Cc: Peter Zijlstra <[email protected]> Cc: Nick Piggin <[email protected]> Cc: Theodore Tso <[email protected]> Cc: Michael Rubin <[email protected]> Cc: Suleiman Souhlal <[email protected]> Cc: Dave Chinner <[email protected]> Cc: Christoph Hellwig <[email protected]> Signed-off-by: Andrew Morton <[email protected]> Signed-off-by: Linus Torvalds <[email protected]>
This commit is contained in:
committed by
Linus Torvalds
parent
72ddc8f722
commit
5ecfda041e
+6
-1
@@ -3299,7 +3299,12 @@ int make_pages_present(unsigned long addr, unsigned long end)
|
||||
vma = find_vma(current->mm, addr);
|
||||
if (!vma)
|
||||
return -ENOMEM;
|
||||
write = (vma->vm_flags & VM_WRITE) != 0;
|
||||
/*
|
||||
* 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.
|
||||
*/
|
||||
write = (vma->vm_flags & (VM_WRITE | VM_SHARED)) == VM_WRITE;
|
||||
BUG_ON(addr >= end);
|
||||
BUG_ON(end > vma->vm_end);
|
||||
len = DIV_ROUND_UP(end, PAGE_SIZE) - addr/PAGE_SIZE;
|
||||
|
||||
+6
-1
@@ -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 */
|
||||
|
||||
Reference in New Issue
Block a user