From patchwork Tue Oct 16 13:13:40 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nicholas Piggin X-Patchwork-Id: 10643535 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 7514113B0 for ; Tue, 16 Oct 2018 13:14:09 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 6228228C31 for ; Tue, 16 Oct 2018 13:14:09 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 561DA29654; Tue, 16 Oct 2018 13:14:09 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-3.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FROM,MAILING_LIST_MULTI,RCVD_IN_DNSWL_NONE autolearn=ham version=3.3.1 Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id EA59328C31 for ; Tue, 16 Oct 2018 13:14:08 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id ABF696B0008; Tue, 16 Oct 2018 09:14:07 -0400 (EDT) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id A70126B000A; Tue, 16 Oct 2018 09:14:07 -0400 (EDT) X-Original-To: int-list-linux-mm@kvack.org X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 985A86B000C; Tue, 16 Oct 2018 09:14:07 -0400 (EDT) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org 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) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:dkim-signature:from:to:cc:subject:date :message-id:in-reply-to:references; bh=vbOXilnyHM7Y3HZf42CmhT0al3ZotZPzM5/9KSS+Wl0=; b=Cyz6B0uf4Chxg+YStY94gn+i27VddluFcmul9JcsuH4nkmkUtaEsWobaNtxGO6L8Sr agvI9e8Iv8lYowS/aplO5r/OVrhV41WxAOoYjh4JR4kg3p0Khz6hA91avPLlr10gEchK hW2UJhLv3h4fRZ1qlhsdRpshpLpZTuiIOgJviyQqTaxRiGgPztleXNOwDsomRbB7rr1H V8oWbtrqnpvvXWpsK2Mf1UQj/EbnGhY99Z1vvJxHV2VspHzpdTc1VY6JyAkrAddW27yG OJ48FZCaPJFXiIicr3jzQTpFiR5VfhWt7mN/th+u7SbK15y4jkiX2kcpzWEt4qQ7muKw 6r8Q== X-Gm-Message-State: ABuFfoiOPBvbKqBKIWv22BP18MIj3F6lJk8LlknIZV0Cjama9gw+fqKQ lqNJ1BGnWbW3TID2TjzhXeMu6YwrTUtMrtaOG/1v1Db5vS/kffK+3gK2/Nzlr7ttIAUbVPKzgSF EitAjg+kaY8OhUJMpsroBgYXFI9Q+1l43f5nLyypCOY/8Dz+H6MB53AtAvKmgDlrky7co43xZM2 A0o+d1LMJOKzENIo0QxzhFvCe3SmTrVp1PR5t0AvhCk+ueuU/MVnYJkZCbALm4TxX78m7ACC6uo OxylN1T3ikifd7dDmyLKYLK9Nr+mdFU39YcM68f4W870KvA1uV7XdtvrQ2L7pYD+Z2J8gsW6lsd 5RGiZAtkd4uYwS6LQuyMgvJUgfmaFlnabdqmzpahnwacykKEcmzmGLk1wpdOK5/BKAJBWynVyuG p X-Received: by 2002:a63:e943:: with SMTP id q3-v6mr19998831pgj.42.1539695647054; Tue, 16 Oct 2018 06:14:07 -0700 (PDT) X-Received: by 2002:a63:e943:: with SMTP id q3-v6mr19998779pgj.42.1539695646303; Tue, 16 Oct 2018 06:14:06 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1539695646; cv=none; d=google.com; s=arc-20160816; b=GxKtgR/TjlutoTjcGrqlyx7muaM1m76dj6/BM0ceOaQrHVcuQaH3WDg265cYozlGdB Lw3GT1DHtQLjeI/Bfqx25Ry71kil+W1IRq/KCcxhuu9m/6qT4nSvZqtqHImzis4Ur+7H sawt2vSyraJwb66CFY4AIitdjtCra94Z0Vq/IKJWSi/ViOCfvWVeTyN5p57hL76q/aqF k7c3Zj+J7st8NYqbZZqRHeZ8J3UILnKLyJMRvH4kHsppLhagNBjU8Dm16Mgj5c8APcIq H8m35m2v6kyQJO4aEGwskQuw9VAjZJg+SFo6xH2/3WXhCNvWuWqIzEOz+1fTQXNyGuME XsvQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=vbOXilnyHM7Y3HZf42CmhT0al3ZotZPzM5/9KSS+Wl0=; b=Rf5UP3bJo14pNYw0Yz3/jg/h9D8N86W6YrimuMWXNpy+JHSMw5n06Zfe3TQFwfUNyn BEKKg+CqBS1Yfp+txwjxTNgy7o0TaoXc67OvYhqoVF4SqnyuAgghlD2IATyuonn69zzB iIPkKW6A+Dx2ZIKOq11OeBqNtnKd9ncXTx9SYD/iNJHVbDwa3AKW9u188IXRxPK+IjCL GGLqj2TA6nfj4YAB5mle1ySzLbaw10C25ci3a+5A2AbrqiVQifXvbuMzYXS7oCVLw/pI +wUaE3EF4HlwtMM6f3cSNWGCvuM50CEs16fP7+Tag3xcAJgkU+jnof8g34SIID34wn3Z m3WA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b="A/SSJVZx"; spf=pass (google.com: domain of npiggin@gmail.com designates 209.85.220.65 as permitted sender) smtp.mailfrom=npiggin@gmail.com; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com 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) Received-SPF: pass (google.com: domain of npiggin@gmail.com designates 209.85.220.65 as permitted sender) client-ip=209.85.220.65; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b="A/SSJVZx"; spf=pass (google.com: domain of npiggin@gmail.com designates 209.85.220.65 as permitted sender) smtp.mailfrom=npiggin@gmail.com; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com 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; bh=vbOXilnyHM7Y3HZf42CmhT0al3ZotZPzM5/9KSS+Wl0=; b=A/SSJVZxVxROnzdtTJGd3Rl0mtQnn0aeP262cO0PG37AB5aJFbY1kcl0Q9RVU+AsSN hnGdUUZtKTqK8l4cdbSjbZ9BUzn/hPxOFdEPN4vlGKIB25R+NFVzhjzkDFWSAaFBLaSt xrSM6/l6UKnNfWzsSJg7ulrXaZrJXIUqdvEaGukSxIoLvU3Es6tmC1I+PECGOfrldZKg NLn/cJoSesrvsErHZ4uFkC2dmA03+a8M23DZATqifHAalHpK02AeaGxYq3X86uOI4su5 c7wNfOzT0sZv7rpzm5n9vvCGcZMKbl4VkQEOnVbCI02AICWJXxrRFSVG1IEGRym457Rs WgRA== X-Google-Smtp-Source: ACcGV625ozmXlwQNgWm1xWhrstSjyDp7scuMStIV7BLFGcBHbvseOYBjb3efegUxYSoldpVrEtpcww== X-Received: by 2002:a17:902:9b84:: with SMTP id y4-v6mr21817926plp.332.1539695646081; Tue, 16 Oct 2018 06:14:06 -0700 (PDT) Received: from roar.local0.net ([60.240.252.156]) by smtp.gmail.com with ESMTPSA id j62-v6sm16043423pgd.40.2018.10.16.06.14.01 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 16 Oct 2018 06:14:05 -0700 (PDT) From: Nicholas Piggin To: Andrew Morton Cc: Nicholas Piggin , Linus Torvalds , linux-mm , linux-arch , Linux Kernel Mailing List , ppc-dev , Ley Foon Tan 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> X-Mailer: git-send-email 2.18.0 In-Reply-To: <20181016131343.20556-1-npiggin@gmail.com> References: <20181016131343.20556-1-npiggin@gmail.com> X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: X-Virus-Scanned: ClamAV using ClamSMTP 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