If the first access to a folio is a read that is then followed by a
write, we can save a page fault. s390 implemented this in their
mk_pte() in commit
abf09bed3cce ("s390/mm: implement software dirty
bits"), but other architectures can also benefit from this.
Signed-off-by: Matthew Wilcox (Oracle) <willy@infradead.org>
static inline pte_t mk_pte(struct page *page, pgprot_t pgprot)
{
- unsigned long physpage = page_to_phys(page);
- pte_t __pte = mk_pte_phys(physpage, pgprot);
-
- if (pte_write(__pte) && PageDirty(page))
- __pte = pte_mkdirty(__pte);
- return __pte;
+ return mk_pte_phys(page_to_phys(page), pgprot);
}
#define pgd_index(address) (((address) >> PGDIR_SHIFT) & (PTRS_PER_PGD-1))
if (write)
entry = maybe_mkwrite(pte_mkdirty(entry), vma);
+ else if (pte_write(entry) && folio_test_dirty(folio))
+ entry = pte_mkdirty(entry);
if (unlikely(vmf_orig_pte_uffd_wp(vmf)))
entry = pte_mkuffd_wp(entry);
/* copy-on-write page */