mm, thp: Do not make pmd/pud dirty without a reason

Currently we make page table entries dirty all the time regardless of
access type and don't even consider if the mapping is write-protected.
The reasoning is that we don't really need dirty tracking on THP and
making the entry dirty upfront may save some time on first write to the
page.

Unfortunately, such approach may result in false-positive
can_follow_write_pmd() for huge zero page or read-only shmem file.

Let's only make page dirty only if we about to write to the page anyway
(as we do for small pages).

I've restructured the code to make entry dirty inside
maybe_p[mu]d_mkwrite(). It also takes into account if the vma is
write-protected.

Signed-off-by: Kirill A. Shutemov <[email protected]>
Acked-by: Michal Hocko <[email protected]>
Cc: Hugh Dickins <[email protected]>
Signed-off-by: Linus Torvalds <[email protected]>
This commit is contained in:
Kirill A. Shutemov 2017-11-27 06:21:26 +03:00 • committed by Linus Torvalds
commit 152e93af3c
5 changed files with 24 additions and 16 deletions

View file

@ -328,7 +328,8 @@ static inline void mlock_migrate_page(struct page *newpage, struct page *page)
}
}
extern pmd_t maybe_pmd_mkwrite(pmd_t pmd, struct vm_area_struct *vma);
extern pmd_t maybe_pmd_mkwrite(pmd_t pmd, struct vm_area_struct *vma,
bool dirty);
/*
* At what user virtual address is page expected in @vma?