]> Git Repo - linux.git/commitdiff
mm/cow: don't bother write protecting already write-protected pages
authorLinus Torvalds <[email protected]>
Mon, 9 Jul 2018 20:19:49 +0000 (13:19 -0700)
committerLinus Torvalds <[email protected]>
Sat, 25 Aug 2018 20:15:03 +0000 (13:15 -0700)
This is not normally noticeable, but repeated forks are unnecessarily
expensive because they repeatedly dirty the parent page tables during
the page table copy operation.

It's trivial to just avoid write protecting the page table entry if it
was already not writable.

This patch was inspired by

    https://bugzilla.kernel.org/show_bug.cgi?id=200447

which points to an ancient "waste time re-doing fork" issue in the
presence of lots of signals.

That bug was fixed by Eric Biederman's signal handling series
culminating in commit c3ad2c3b02e9 ("signal: Don't restart fork when
signals come in"), but the unnecessary work for repeated forks is still
work just fixing, particularly since the fix is trivial.

Cc: Eric Biederman <[email protected]>
Cc: Oleg Nesterov <[email protected]>
Cc: Andrew Morton <[email protected]>
Signed-off-by: Linus Torvalds <[email protected]>
mm/memory.c

index 83aef222f11b3f1d847279e13f43358566a22b43..c467102a5cbc5de5ab2ea4dff740f2611c1124a4 100644 (file)
@@ -1022,7 +1022,7 @@ copy_one_pte(struct mm_struct *dst_mm, struct mm_struct *src_mm,
         * If it's a COW mapping, write protect it both
         * in the parent and the child
         */
-       if (is_cow_mapping(vm_flags)) {
+       if (is_cow_mapping(vm_flags) && pte_write(pte)) {
                ptep_set_wrprotect(src_mm, addr, src_pte);
                pte = pte_wrprotect(pte);
        }
This page took 0.065568 seconds and 4 git commands to generate.