From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-pg1-f197.google.com (mail-pg1-f197.google.com [209.85.215.197]) by kanga.kvack.org (Postfix) with ESMTP id 5954B6B0008 for ; Tue, 16 Oct 2018 09:14:07 -0400 (EDT) Received: by mail-pg1-f197.google.com with SMTP id w15-v6so17112611pge.2 for ; Tue, 16 Oct 2018 06:14:07 -0700 (PDT) Received: from mail-sor-f65.google.com (mail-sor-f65.google.com. [209.85.220.65]) by mx.google.com with SMTPS id k33-v6sor4225591pld.54.2018.10.16.06.14.06 for (Google Transport Security); Tue, 16 Oct 2018 06:14:06 -0700 (PDT) From: Nicholas Piggin Subject: [PATCH v2 2/5] mm/cow: don't bother write protecting already write-protected huge pages Date: Tue, 16 Oct 2018 23:13:40 +1000 Message-Id: <20181016131343.20556-3-npiggin@gmail.com> In-Reply-To: <20181016131343.20556-1-npiggin@gmail.com> References: <20181016131343.20556-1-npiggin@gmail.com> Sender: owner-linux-mm@kvack.org List-ID: To: Andrew Morton Cc: Nicholas Piggin , Linus Torvalds , linux-mm , linux-arch , Linux Kernel Mailing List , ppc-dev , Ley Foon Tan This is the HugePage / THP equivalent for 1b2de5d039c8 ("mm/cow: don't bother write protecting already write-protected pages"). Signed-off-by: Nicholas Piggin --- mm/huge_memory.c | 14 ++++++++++---- mm/hugetlb.c | 2 +- 2 files changed, 11 insertions(+), 5 deletions(-) diff --git a/mm/huge_memory.c b/mm/huge_memory.c index 58269f8ba7c4..0fb0e3025f98 100644 --- a/mm/huge_memory.c +++ b/mm/huge_memory.c @@ -973,8 +973,11 @@ int copy_huge_pmd(struct mm_struct *dst_mm, struct mm_struct *src_mm, mm_inc_nr_ptes(dst_mm); pgtable_trans_huge_deposit(dst_mm, dst_pmd, pgtable); - pmdp_set_wrprotect(src_mm, addr, src_pmd); - pmd = pmd_mkold(pmd_wrprotect(pmd)); + if (pmd_write(pmd)) { + pmdp_set_wrprotect(src_mm, addr, src_pmd); + pmd = pmd_wrprotect(pmd); + } + pmd = pmd_mkold(pmd); set_pmd_at(dst_mm, addr, dst_pmd, pmd); ret = 0; @@ -1064,8 +1067,11 @@ int copy_huge_pud(struct mm_struct *dst_mm, struct mm_struct *src_mm, /* No huge zero pud yet */ } - pudp_set_wrprotect(src_mm, addr, src_pud); - pud = pud_mkold(pud_wrprotect(pud)); + if (pud_write(pud)) { + pudp_set_wrprotect(src_mm, addr, src_pud); + pud = pud_wrprotect(pud); + } + pud = pud_mkold(pud); set_pud_at(dst_mm, addr, dst_pud, pud); ret = 0; diff --git a/mm/hugetlb.c b/mm/hugetlb.c index 5c390f5a5207..54a4dcb6ee21 100644 --- a/mm/hugetlb.c +++ b/mm/hugetlb.c @@ -3287,7 +3287,7 @@ int copy_hugetlb_page_range(struct mm_struct *dst, struct mm_struct *src, } set_huge_swap_pte_at(dst, addr, dst_pte, entry, sz); } else { - if (cow) { + if (cow && huge_pte_write(entry)) { /* * No need to notify as we are downgrading page * table protection not changing it to point -- 2.18.0