From mboxrd@z Thu Jan 1 00:00:00 1970 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=-5.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI, SPF_HELO_NONE,SPF_PASS autolearn=no 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 1478EC11F69 for ; Wed, 30 Jun 2021 02:26:05 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 8C52A61D8B for ; Wed, 30 Jun 2021 02:26:04 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 8C52A61D8B Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=linux-foundation.org Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id 8E9838D0165; Tue, 29 Jun 2021 22:26:03 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 899A68D0160; Tue, 29 Jun 2021 22:26:03 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 73A808D0165; Tue, 29 Jun 2021 22:26:03 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0190.hostedemail.com [216.40.44.190]) by kanga.kvack.org (Postfix) with ESMTP id 526108D0160 for ; Tue, 29 Jun 2021 22:26:03 -0400 (EDT) Received: from smtpin32.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay05.hostedemail.com (Postfix) with ESMTP id CC95A181CBDDC for ; Wed, 30 Jun 2021 02:26:01 +0000 (UTC) X-FDA: 78308800122.32.A90EC7D Received: from mail-lf1-f47.google.com (mail-lf1-f47.google.com [209.85.167.47]) by imf07.hostedemail.com (Postfix) with ESMTP id 5B26E10000AE for ; Wed, 30 Jun 2021 02:26:01 +0000 (UTC) Received: by mail-lf1-f47.google.com with SMTP id bu19so2084220lfb.9 for ; Tue, 29 Jun 2021 19:26:01 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux-foundation.org; s=google; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=WmcQjM4NtRj2hGLTZ2H2V0YhAbT4pllJIOpllS1okx4=; b=Na9tArEjazj6+sScSHtAWzPkvlasIO2Ly/mGFZ9h6CSZV5V7vDM1S5iz+4EtuhyjKB TkAQj813eo6NTNfMbDdVK8NME8Nm0t7X2gTNtbYjh6LpdB0oUAKRFlTSA3o8X3kvyKmJ 5JmTgy0riT2rd7wQaAYlvZDNVzU2dd73+Ex1U= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=WmcQjM4NtRj2hGLTZ2H2V0YhAbT4pllJIOpllS1okx4=; b=LHbRMYqzrGmg+PVC/Ass3QiLayuiD8H6l7vkWjyy2KVsQs6JaPSROacn/Yh62Pm1xh VUeOru5sKnDkMzl9wJxA0l5boXUaWfL7hBW1bSuzGmS8waV6LDaH48+DnRMxmqVzpy/i CtRZfZKludQqa7M+RDbVggOcy3QjQ8obWzAXB8jqTdoVc7VepTTDHSc4cvAiFCNj+P6z dE+GvGLXQ8ef+8wGqbsvnHIDEB6XIIk3Snl5CLhhzzIHVkktRr/WiUbliPEXALsNFxV3 69tWaEKrkfQROiZOTCcYezllFqwjxaFvDNzdI01Ob8KjX3J4A49Eprf5xgwAEjSVA2IH VfHA== X-Gm-Message-State: AOAM533tgmVr8kh3bBe0kkz30APv4YstfRidLjfepZvBob5K6MHMo3k6 L4HlJuqdkUiOSCwJcWmrvbI1AWDIjTnWl0cTeSM= X-Google-Smtp-Source: ABdhPJxULPLr1frnIQkN5FSYeVtCZ+rmmQ1n6JKacqZ7aHU/3qvFMBy5J5L1hag7IMIplrNWekVTgg== X-Received: by 2002:a05:6512:3592:: with SMTP id m18mr24579277lfr.389.1625019959460; Tue, 29 Jun 2021 19:25:59 -0700 (PDT) Received: from mail-lf1-f52.google.com (mail-lf1-f52.google.com. [209.85.167.52]) by smtp.gmail.com with ESMTPSA id x22sm1944172lfe.10.2021.06.29.19.25.58 for (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Tue, 29 Jun 2021 19:25:58 -0700 (PDT) Received: by mail-lf1-f52.google.com with SMTP id u13so2144730lfk.2 for ; Tue, 29 Jun 2021 19:25:58 -0700 (PDT) X-Received: by 2002:a05:6512:557:: with SMTP id h23mr25719199lfl.253.1625019958291; Tue, 29 Jun 2021 19:25:58 -0700 (PDT) MIME-Version: 1.0 References: <20210628193256.008961950a714730751c1423@linux-foundation.org> <20210629023959.4ZAFiI8oZ%akpm@linux-foundation.org> In-Reply-To: From: Linus Torvalds Date: Tue, 29 Jun 2021 19:25:42 -0700 X-Gmail-Original-Message-ID: Message-ID: Subject: Re: [patch 128/192] mm: improve mprotect(R|W) efficiency on pages referenced once To: Peter Xu Cc: Andrew Morton , Andrea Arcangeli , Evgeniy Stepanov , kostyak@google.com, Linux-MM , mm-commits@vger.kernel.org, Peter Collingbourne Content-Type: text/plain; charset="UTF-8" Authentication-Results: imf07.hostedemail.com; dkim=pass header.d=linux-foundation.org header.s=google header.b=Na9tArEj; spf=pass (imf07.hostedemail.com: domain of torvalds@linuxfoundation.org designates 209.85.167.47 as permitted sender) smtp.mailfrom=torvalds@linuxfoundation.org; dmarc=none X-Rspamd-Server: rspam03 X-Rspamd-Queue-Id: 5B26E10000AE X-Stat-Signature: y9x1gt4tmi9tctt49juubfn7hp1de6ci X-HE-Tag: 1625019961-643811 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: On Tue, Jun 29, 2021 at 6:39 PM Peter Xu wrote: > > And since MM_CP_DIRTY_ACCT implies "VM_WRITE|VM_SHARED" all set, above should > be a slightly faster version of below: That's way too subtle, particularly since the MM_CP_DIRTY_ACCT logic comes from another file entirely. I don't think it's even faster, considering that presumably the anonymous mapping case is the common one, and that's the one that needs all the extra tests, it's likely better to _not_ test that very subtle flag at all, and just doing the straightforward and obvious tests that are understandable _locally_. So I claim that it's (a) not an optimization at all (b) completely locally unintuitive and unreadable > Again, I think in all cases some more comment should be good indeed.. I really want more than a comment. I want that MM_CP_DIRTY_ACCT bit testing gone. The only point where it makes sense to check MM_CP_DIRTY_ACCT is within the context of "is the page already dirty". So I think the logic should be something along the lines of - first: if (!(vma->vm_flags & VM_WRITE)) return false; because that logic is set in stone, and true regardless of anything else. If the vma isn't writable, we're not going to set the write bit. End of story. - then, check the vma_is_anonumous() case: if (vma_is_anonymous(vma)) return page_count(pte_page(pte)) == 1; because if it's a writable mapping, and anonymous, then we can mark it writable if we're the exclusive owners of that page. - and THEN we can handle the "ok, shared mapping, now let's start thinking about dirty accounting" cases. Make it obvious and correct. This is not a sequence where you should try to (incorrectly) optimize away individual instructions. Linus