From patchwork Sun Dec 20 04:55:33 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nicholas Piggin X-Patchwork-Id: 11983779 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-13.5 required=3.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED,DKIM_INVALID,DKIM_SIGNED,FREEMAIL_FORGED_FROMDOMAIN, FREEMAIL_FROM,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER, INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id F0C42C4361B for ; Sun, 20 Dec 2020 04:55:47 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id A363923A5E for ; Sun, 20 Dec 2020 04:55:47 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org A363923A5E Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=gmail.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id 3A19A6B005D; Sat, 19 Dec 2020 23:55:47 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 3527C6B0068; Sat, 19 Dec 2020 23:55:47 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 240566B006C; Sat, 19 Dec 2020 23:55:47 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0092.hostedemail.com [216.40.44.92]) by kanga.kvack.org (Postfix) with ESMTP id 0D9A16B005D for ; Sat, 19 Dec 2020 23:55:47 -0500 (EST) Received: from smtpin16.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay02.hostedemail.com (Postfix) with ESMTP id D5E7D3641 for ; Sun, 20 Dec 2020 04:55:46 +0000 (UTC) X-FDA: 77612447892.16.cart37_4a05edb2744c Received: from filter.hostedemail.com (10.5.16.251.rfc1918.com [10.5.16.251]) by smtpin16.hostedemail.com (Postfix) with ESMTP id B840C100E690B for ; Sun, 20 Dec 2020 04:55:46 +0000 (UTC) X-HE-Tag: cart37_4a05edb2744c X-Filterd-Recvd-Size: 4764 Received: from mail-pj1-f48.google.com (mail-pj1-f48.google.com [209.85.216.48]) by imf01.hostedemail.com (Postfix) with ESMTP for ; Sun, 20 Dec 2020 04:55:46 +0000 (UTC) Received: by mail-pj1-f48.google.com with SMTP id l23so4510497pjg.1 for ; Sat, 19 Dec 2020 20:55:46 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=xWd672dBo9Oa6ix0+hhyLcTLYZH2Zvk+xoJHykTA92c=; b=DRvKHlCOwLBnLdj3M27nD7OS7WS1CL9dsWFdy1VEQRPr5A9ITSXQlysyPVhfv3grG2 P6jelf3s1kJINJzugRromFaG6a1yXfHKS8f8hS6+VByTMNtdZytrrINXb8MTjN5PKvIR IOsvbEktdy6Ys+SjFPdqOFNx8l24/yG5LHQCoYRZLZy3UCJvUvrMY01QfP1/Kh5Aczbe VFYZKiqKLuAuEbLh97qb/g1OFzzIO9MY5UA1NnSCyBHEtlbvwjIlLSH1CKVym19u5PDw 476YaZV5+AbXpfO4LXareb5t5u0pDmBFUxsRpypVESAxUeSCcyhdbyrvjAjMLvPw0Rzm rJow== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=xWd672dBo9Oa6ix0+hhyLcTLYZH2Zvk+xoJHykTA92c=; b=bk7KlXloPPWqrKm3df4fYfQHfdjY7Jgn9eUxDEK168C6N7pXo1HK49yHLmidnmumSc lEnXVU1HN+ye6xfXIpI/CUa7z8j4yjCSzJtgHX7eQqYAahYSA1LBM4O0ApJnZI+rldOm eWrWcvIXE+QsWnHVzH5n6ztN/buRx2lTBs2hPypKGAZszHhNxxyMPf2XwzFywN2vrrXi vMrZjpOI6pfOyCA4UzNhdOjQCxYSQHSX5kE8l6/Na6RBZ6GgQ+4FqktWk3yKScKl7jnw 1UprRXr3acbpJDk1+Y1XITMVIlQAuOVuMhT0DrkezJV254wURfIszJcUsPd1AciobqqV hKwA== X-Gm-Message-State: AOAM533/ixiflxH4B51lSAyEl37awvRDsD35PCr3KQyettQLKnk+HExZ Qru/e4qcC95ydsRIqrFppZjg+Q1lk30= X-Google-Smtp-Source: ABdhPJwbY7xRsSUBpwC4t7vnDEpbEz/VAOd+XRsZ5CRDtV8WUNErUyJVBgb65Kvo4OifwU6asHgKGg== X-Received: by 2002:a17:90b:3682:: with SMTP id mj2mr11599960pjb.27.1608440144987; Sat, 19 Dec 2020 20:55:44 -0800 (PST) Received: from bobo.ibm.com (193-116-97-30.tpgi.com.au. [193.116.97.30]) by smtp.gmail.com with ESMTPSA id l13sm13632529pgq.51.2020.12.19.20.55.42 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 19 Dec 2020 20:55:44 -0800 (PST) From: Nicholas Piggin To: linux-mm@kvack.org Cc: Nicholas Piggin , Linus Torvalds , Bibo Mao Subject: [PATCH v3 1/3] mm/cow: don't bother write protecting already write-protected huge pages Date: Sun, 20 Dec 2020 14:55:33 +1000 Message-Id: <20201220045535.848591-2-npiggin@gmail.com> X-Mailer: git-send-email 2.23.0 In-Reply-To: <20201220045535.848591-1-npiggin@gmail.com> References: <20201220045535.848591-1-npiggin@gmail.com> MIME-Version: 1.0 X-Bogosity: Ham, tests=bogofilter, spamicity=0.000021, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: 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 9237976abe72..87da60c583a9 100644 --- a/mm/huge_memory.c +++ b/mm/huge_memory.c @@ -1111,8 +1111,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; @@ -1218,8 +1221,11 @@ int copy_huge_pud(struct mm_struct *dst_mm, struct mm_struct *src_mm, return -EAGAIN; } - 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_mkold(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 cbf32d2824fd..c068ae4b2fef 100644 --- a/mm/hugetlb.c +++ b/mm/hugetlb.c @@ -3813,7 +3813,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