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=-7.2 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, 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 E9018C07E99 for ; Tue, 6 Jul 2021 01:24:14 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 7777A6197E for ; Tue, 6 Jul 2021 01:24:13 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 7777A6197E Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=redhat.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id 114BA6B0011; Mon, 5 Jul 2021 21:24:13 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 0C4E46B0036; Mon, 5 Jul 2021 21:24:13 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id E7F366B005D; Mon, 5 Jul 2021 21:24:12 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0047.hostedemail.com [216.40.44.47]) by kanga.kvack.org (Postfix) with ESMTP id BEE5E6B0011 for ; Mon, 5 Jul 2021 21:24:12 -0400 (EDT) Received: from smtpin37.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay02.hostedemail.com (Postfix) with ESMTP id 27E6522AC4 for ; Tue, 6 Jul 2021 01:24:12 +0000 (UTC) X-FDA: 78330417144.37.DCE1CF6 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [216.205.24.124]) by imf21.hostedemail.com (Postfix) with ESMTP id AED9CD007F20 for ; Tue, 6 Jul 2021 01:24:11 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1625534651; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=YvZBRUsopGooyKZXDbaAcSKCsLR31fbe6LlHCtiGnAg=; b=i/1ud7e1YQfELGxv5ML+DXU9VR3vsZxvBPeI4iKQfuIrxpZEQ6CJ0ptImB05VNSBM0j2v+ UNbzV52s+uOFwxFijrPFpD8rAxVim9CSTszJ8x3HIx/dqRaYKNaht99bcLz99VsbSYGhuQ C1K7qft3qW3wYMMqqXIXhIaXDWh+2BU= Received: from mail-qv1-f70.google.com (mail-qv1-f70.google.com [209.85.219.70]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-173-3Xz4PM29Og-eIAAb9TdDcQ-1; Mon, 05 Jul 2021 21:24:09 -0400 X-MC-Unique: 3Xz4PM29Og-eIAAb9TdDcQ-1 Received: by mail-qv1-f70.google.com with SMTP id u40-20020a0cb9280000b0290290c3a9f6f1so12114607qvf.0 for ; Mon, 05 Jul 2021 18:24:09 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to; bh=YvZBRUsopGooyKZXDbaAcSKCsLR31fbe6LlHCtiGnAg=; b=Aevk1Z410l0ZY63+CfD68I7tM3DzeGBrKbebld7rXgmkwORrUB6l1ie4TNqth8Cm3P HopacTsmYIs6Mf0B5wxwXW+3gXn2tOOPmY1EKfHNXZXcXeeDYC/Yjo7XKJ8rZUr5k4Ah wQqjuvM0t2uTkBjf5xVcdyILtrkMctJ63HmdJ+CDXGBq2FcR6LbPdkVA8z9iEe3Oim1w 4GXFC6ETip6dq3fdOEhRoKMsbkbFHBI21u/6sZPzt4ZX9ISZYWCQkhw/U5x7FgMeWuQC K0du0Td6ybhEqTOugdWXp5uPO9+I6F9D8IRxqvn/CtIxE87U3vpedr92IKGKx8pVtG3k +mbQ== X-Gm-Message-State: AOAM533QFdtguRoGgVdEAbNb9IMvr5Cwf5s4yLoiQsdKvwE8niQ8VIJg 7uzFZQI5N0fKJP2w5Nvguah6TVRoB4C9xEpQFHwTX8xQDPjTX3M6Nnnl44f+zUbFnhS7jLljyQp AqPLZ5c9Nguc= X-Received: by 2002:a05:620a:10aa:: with SMTP id h10mr16699660qkk.377.1625534649347; Mon, 05 Jul 2021 18:24:09 -0700 (PDT) X-Google-Smtp-Source: ABdhPJx/eQpyZLHFvCEa2LsJAhfmrABQfRdFHK4D+g9Ktz7ssugyDWpaVhtqdGRSq+x59+YIDPgT+g== X-Received: by 2002:a05:620a:10aa:: with SMTP id h10mr16699630qkk.377.1625534649021; Mon, 05 Jul 2021 18:24:09 -0700 (PDT) Received: from t490s (bras-base-toroon474qw-grc-65-184-144-111-238.dsl.bell.ca. [184.144.111.238]) by smtp.gmail.com with ESMTPSA id g1sm6028001qkm.58.2021.07.05.18.24.07 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 05 Jul 2021 18:24:08 -0700 (PDT) Date: Mon, 5 Jul 2021 21:24:07 -0400 From: Peter Xu To: Linus Torvalds Cc: Andrew Morton , Andrea Arcangeli , Evgeniy Stepanov , Kostya Kortchinsky , Linux-MM , mm-commits@vger.kernel.org, Peter Collingbourne Subject: Re: [patch 128/192] mm: improve mprotect(R|W) efficiency on pages referenced once Message-ID: References: <20210628193256.008961950a714730751c1423@linux-foundation.org> <20210629023959.4ZAFiI8oZ%akpm@linux-foundation.org> MIME-Version: 1.0 In-Reply-To: X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset=utf-8 Content-Disposition: inline X-Rspamd-Server: rspam05 X-Rspamd-Queue-Id: AED9CD007F20 X-Stat-Signature: k4udb5cabzsjki7s6h3ojyqypgzwufxz Authentication-Results: imf21.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b="i/1ud7e1"; dmarc=pass (policy=none) header.from=redhat.com; spf=none (imf21.hostedemail.com: domain of peterx@redhat.com has no SPF policy when checking 216.205.24.124) smtp.mailfrom=peterx@redhat.com X-HE-Tag: 1625534651-858290 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: (sorry for a very late reply) On Thu, Jul 01, 2021 at 11:29:50AM -0700, Linus Torvalds wrote: > On Wed, Jun 30, 2021 at 6:27 PM Peter Xu wrote: > > > > On Wed, Jun 30, 2021 at 11:03:25AM -0700, Linus Torvalds wrote: > > > > > > What about that page_count() test, for example: it has a comment, it > > > looks obvious, but it's very different from what do_wp_page() does. So > > > what happens if we have a page-out at the same time that turns that > > > page into a swap cache page, and increments the page count? What about > > > that race? Do we end up with a writable page that is shared with a > > > swap cache entry? Is that ok? Why isn't it ok in the page fault case? > > > > That looks fine to me: when the race happens we must have checked page_count==1 > > first and granted the write bit, then add_to_swap_cache() happens after the > > page_count==1 check (as it takes another refcount, so >2 otherwise). Then it > > also means unmap mappings should happen even after that point. If my above > > understanding is correct, our newly installed pte will be zapped safely soon, > > but of course after we release the pgtable lock in change_pte_range(). > > So if this is fine, then maybe we should just remove the page lock in > the do_wp_page() path (and remove the PageKSM check while at it)? I could be wrong, but I thought the page lock in do_wp_page() is more for the PageKsm() race (e.g., to make sure we don't grant write to a page that is becoming a ksm page in parallel). > > If it's not required by mprotect() to say "I can make the page > writable directly", then it really shouldn't be required by the page > fault path either. > > Which I'd love to do, and was really itching to do (it's a nasty > lock), but I worried about it.. > > I'd hate to have mprotect do one thing, and page faulting do another > thing, and not have some logic to why they have to be different. Agreed; perhaps no need to be identical - I think the mprotect path can be even stricter than the fault page, as it's a fast-path only. It should never apply the write bit when the page fault path won't. So I think the original patch does need a justification on why it didn't handle ksm page while do_wp_page handled it. Thanks, -- Peter Xu