From patchwork Tue Aug 28 11:20:32 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nicholas Piggin X-Patchwork-Id: 10578279 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 807F414E1 for ; Tue, 28 Aug 2018 11:20:53 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 717BE28D71 for ; Tue, 28 Aug 2018 11:20:53 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 659BF299CF; Tue, 28 Aug 2018 11:20:53 +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 0696228D71 for ; Tue, 28 Aug 2018 11:20:52 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id C6FE26B45EA; Tue, 28 Aug 2018 07:20:51 -0400 (EDT) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id BF5596B45EC; Tue, 28 Aug 2018 07:20:51 -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 A1EC56B45ED; Tue, 28 Aug 2018 07:20:51 -0400 (EDT) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from mail-pg1-f198.google.com (mail-pg1-f198.google.com [209.85.215.198]) by kanga.kvack.org (Postfix) with ESMTP id 5C8316B45EA for ; Tue, 28 Aug 2018 07:20:51 -0400 (EDT) Received: by mail-pg1-f198.google.com with SMTP id a26-v6so968558pgw.7 for ; Tue, 28 Aug 2018 04:20:51 -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=PqIy7bFKrUvh3N2mZhaZbdyHPW+hgwvBa4i30Nw8Ybc=; b=qdTKCDjwEb+DgTaqDtTh5JwsunZEzcpo+xxAJDz2tabeCC+6lQkq9wu0TtzlmmrR/d xmhfY26y6tRpxVu5WHp4PmtwVmN187at175oEG1kM79bPVhcDm6BFEL3gc8lPhekuyoY KtT6KR0ZWrBp2CHySaFRkm4DDjpv//ILZCrqARDronv7QTyxqx3cBssWRZ6cEjqwKV3x wRCxROaQtAuOiK//Pl3akBa/vu2YvzHBpNl4uYuwmG5rAiEKVVxkBva2cq9mwRUxQ7am GsI+lTcVjNg8EPAhPA21yGs0CPcg8eO3hSokw6arOhnS/etmFWJXoVFG3MRxkyyHgpbv nwXg== X-Gm-Message-State: APzg51Bu1xr2y9S4xS6PG1FRBx08t+6bO8rap2g4PeOW1uluKxpSpyse EPur+YGVZDoqops2BQOdG2s9CqDv6F/QSKCYyMoXufAPy9B894JbiQmvEGRXjQQf56kLeKjlVhI NXo/Rbjd2vqj6vgOQXJ0dnz2guUktRV5iFPiBWTLWcpTzicTpOlI92aT0RznJp9cjDgjnR+/Qwz 6hSIv6kNFpVoF8Hskpa4v2KRatqAdQsZZcejLbrrJIC7PEKAucMpFDVkOGDmZUPHHGf3X9Fq8WY BlxKuwpOFIK05z1YEWhBYf7lAhyqI8Lrvsebf4ysfX03gipbvxkqd6UDZyqf9jx5sO6D+F8UsSp qRQ6JmH/TB6FqYzcboDXd4Jsi5/YrammUvCiicePhhfa7hS5GwmjPzy1tEFjJRMyYtFNOQ6Q7+Q 8 X-Received: by 2002:a17:902:82c9:: with SMTP id u9-v6mr1122274plz.138.1535455251043; Tue, 28 Aug 2018 04:20:51 -0700 (PDT) X-Received: by 2002:a17:902:82c9:: with SMTP id u9-v6mr1122206plz.138.1535455250020; Tue, 28 Aug 2018 04:20:50 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1535455250; cv=none; d=google.com; s=arc-20160816; b=DzBqR7MBZcyvahB+gvl57h8L+zJn92sP3Jh9tWb0Xs7eczrWLQyEhbE+V8vNz6yPMe VycZQEQOdFzh6bdxix6YDrphv3DDmwYV2AomKbDeR0ufPqXghotGx4YFqlcoDgRZmlf8 pGEJizJ0aVmrVlNBZ5YmlZLwoC/fW/S0YBJzWqmXQ23fZVoOR9Q+WxWuIngFqRiE0V3B cNtVR7SMjGDOhT8LFdrFKTyxpxr8ZwESNrBDia2viGCbdfCAqXyHtJEimebpueskVjMi fWIBsMVi0Ftlb33tUmcsaaB+iBk5VmIkP7YSsnJbk3TJLaqCl2ztjgND115fI8P2NbHo NzqA== 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:arc-authentication-results; bh=PqIy7bFKrUvh3N2mZhaZbdyHPW+hgwvBa4i30Nw8Ybc=; b=WtaBl6/0mViEuEOSs4M6zMZJA65GyLxPGhGYY6/PiQv2ZWM6VCpC9TEhAaZL9kqlvO Sy8A6lESHsG/BYWU2LyTUdLW9bK0cD54kF6e3G2JZPS+KKPPqdpTxEVFrIDx3/OlYPNX H/iUM87fGpGxgXBFGwW7suZATdEsAtVSOPBHMrTtrlI3vCPJhFxnUdKXvUC2rPFZVS8G QW3vp4B+kNFZ0bQ0rlRt15prxSnHqB51pKAeAPEKKklW92fO8Pxg+z7zWBwrt5hKh2uv 9qOUOG72pVgx/h9gBVrsJtv10Vb1mTMxrztZ5c4noV3w1PEiZcmBpU6xwDsGjDT4wn+3 dslA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=BZHp6QbN; 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 u189-v6sor179715pgd.416.2018.08.28.04.20.49 for (Google Transport Security); Tue, 28 Aug 2018 04:20:49 -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=BZHp6QbN; 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=PqIy7bFKrUvh3N2mZhaZbdyHPW+hgwvBa4i30Nw8Ybc=; b=BZHp6QbN59dTJzQoscwjj/i43FAP0Gjci3ePWXPKsGC8C1C6frC6pwM7ZO9Og1acP6 kalOnMjZXknjI8Nx28NzpbS+Bf3PiNWazSfTSbEb5Tfl+239vryJxYCtq1UZm1KWzn0H LErHEmA5WLAWDKAGAxnCjAXNSt84PWxsr1fyECPVZJQ/WqwNnCqAHpj1BOcu3dssf1Xt ri+KTIc8FfxXuQLLx0wAF3iLM12t2IOTD2KNAaa3tt6ARchgJ8OtW2orWdvTnAmDuRT0 34rrzhoTIK0LlmWUaEsu/2lFprRk1Z7eQ/jprd4BLoyNtsG+l4id/94KNevuGHZiRKdN ojKA== X-Google-Smtp-Source: ANB0Vda1rxfWQ20CAFltZX59amKlHwbHH1qDC49g8kZHwadojwF7gpVndoanEo69eLkZduJDG3UbpQ== X-Received: by 2002:a63:5751:: with SMTP id h17-v6mr1085425pgm.423.1535455249468; Tue, 28 Aug 2018 04:20:49 -0700 (PDT) Received: from roar.au.ibm.com (59-102-81-67.tpgi.com.au. [59.102.81.67]) by smtp.gmail.com with ESMTPSA id s3-v6sm3287917pgj.84.2018.08.28.04.20.45 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 28 Aug 2018 04:20:48 -0700 (PDT) From: Nicholas Piggin To: linux-mm@kvack.org Cc: Nicholas Piggin , linux-arch@vger.kernel.org, linux-kernel@vger.kernel.org, linuxppc-dev@lists.ozlabs.org, Andrew Morton , Linus Torvalds Subject: [PATCH 1/3] mm/cow: don't bother write protectig already write-protected huge pages Date: Tue, 28 Aug 2018 21:20:32 +1000 Message-Id: <20180828112034.30875-2-npiggin@gmail.com> X-Mailer: git-send-email 2.18.0 In-Reply-To: <20180828112034.30875-1-npiggin@gmail.com> References: <20180828112034.30875-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 THP equivalent for 1b2de5d039c8 ("mm/cow: don't bother write protecting already write-protected pages"). Explicit hugetlb pages don't get the same treatment because they don't appear to have the right accessor functions. Signed-off-by: Nicholas Piggin --- mm/huge_memory.c | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/mm/huge_memory.c b/mm/huge_memory.c index 9592cbd8530a..d9bae12978ef 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;