Received: by 2002:a05:6a10:8a4f:0:0:0:0 with SMTP id dn15csp5503360pxb; Mon, 7 Feb 2022 05:13:25 -0800 (PST) X-Google-Smtp-Source: ABdhPJz9B0SDopYDLeNnQraUSRG5267v/hApBEDTjc2maCPrCW2vRMyruMVf3biRTFkWilIu1u2w X-Received: by 2002:a17:90b:3c1:: with SMTP id go1mr7198189pjb.48.1644239604979; Mon, 07 Feb 2022 05:13:24 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1644239604; cv=none; d=google.com; s=arc-20160816; b=TT2m0Y9DZs5XYfr57swJXp/tOVm1pNsK2Sk+7+emKC5ZIFZVJ4Mrr8KSfY1tiazGpR ryoHcDUvE8qvpQyCNMYoOCOLnkSDgDlQFXzPKW4qd3x2x+dNY/92DRjPyjBuezNLtJjx TidpJTF7WY78qsgCGEJZv/RsTSCj9hbJzx+mFGmvRPfEJVBAYwCCKTLokjSdZNS7f+zS ckPCo9DIITxOMFUY5nBobl20VWmVfdaUKyeZWGYMPNGYuB87O1qedx3bUIGW8lVptYhI dhR7SFnFWszxyz6DwmziTVG60RXC5A+CCtwgnQC0lNtbc+J6EObAAjOBjZfra8occ3Xk vTOg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date:dkim-signature; bh=NpLdFGMr1FptfNF1DnVYVAlQglqe8Vcxsdlw9r+9Dew=; b=xnDLyPnbF2cs8DhzVJKKmsgtMqG47La8Vg3H8C5FBwtBTKUsLmBGyp99wmuKknXf01 lt4ZGV/LBgftfILuoihxisw9qhOEkN647COWWhLDOI/R2ljmTnvPCZDyJjWGEZ8Y4HeA 48NG2JuFdKVKNLML5McPkDmlC0w5kLdn8xXKugl/LTzYGOxtDCWwH+/6gXwM11dfyQM9 Ol4rJPPeo1XqBWsafD7jRmcSLFfzlSHL0AnNeBWkY7ka+O6hdpfuMf9NOZfY5LRzY1ox 4fnBOIpYEWCZeUesEV3W0lN7eHtlXOsf32egw2jw9tB5yXrmiKNVOuWmTpgF2p5i87jU x/Kg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@infradead.org header.s=casper.20170209 header.b=k5sR88CD; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id f4si10238872pfc.210.2022.02.07.05.13.12; Mon, 07 Feb 2022 05:13:24 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@infradead.org header.s=casper.20170209 header.b=k5sR88CD; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S241102AbiBDV26 (ORCPT + 99 others); Fri, 4 Feb 2022 16:28:58 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37544 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230387AbiBDV25 (ORCPT ); Fri, 4 Feb 2022 16:28:57 -0500 Received: from casper.infradead.org (casper.infradead.org [IPv6:2001:8b0:10b:1236::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id CF54AC061714 for ; Fri, 4 Feb 2022 13:28:54 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=casper.20170209; h=In-Reply-To:Content-Type:MIME-Version: References:Message-ID:Subject:Cc:To:From:Date:Sender:Reply-To: Content-Transfer-Encoding:Content-ID:Content-Description; bh=NpLdFGMr1FptfNF1DnVYVAlQglqe8Vcxsdlw9r+9Dew=; b=k5sR88CDrXPYwJXlFHyfEby3y7 xhRrAn8mGZRUqoUpjLVRsYEKIPvqQfJqn3Dk4Hhtukb0jF3fhEyCU9hBKdftwxmNPgifimAbXYjEb 0imaxImmhu95BuQ/avllsdH4pJzvv/ZkwZNbaOLDEA7RzVOnQNiM7joB9EN4MkdywcW4ZUJ2Accjp sJOc6yFx3uN1iZkFGNLlmGyYKqTVbcEHO7Da4/uqWd+cJe1hG5FBhDzlQZuKtscLzIOR5aN4vzcwX hb6UCTb35Kqx/yXR2to4561Gb8bfFcu6YmyufU/Y1GHiIKkwvbXAa/6KDkUuSBsmsar12Fg19l7QH gALr+pEA==; Received: from willy by casper.infradead.org with local (Exim 4.94.2 #2 (Red Hat Linux)) id 1nG68P-007YKq-TF; Fri, 04 Feb 2022 21:28:49 +0000 Date: Fri, 4 Feb 2022 21:28:49 +0000 From: Matthew Wilcox To: John Hubbard Cc: linux-mm@kvack.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH 01/75] mm/gup: Increment the page refcount before the pincount Message-ID: References: <20220204195852.1751729-1-willy@infradead.org> <20220204195852.1751729-2-willy@infradead.org> <185cd8a2-8d77-1933-987c-7b1d4f0e8603@nvidia.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <185cd8a2-8d77-1933-987c-7b1d4f0e8603@nvidia.com> X-Spam-Status: No, score=-2.5 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_MED,SPF_HELO_NONE,SPF_NONE, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Fri, Feb 04, 2022 at 01:13:29PM -0800, John Hubbard wrote: > On 2/4/22 11:57, Matthew Wilcox (Oracle) wrote: > > We should always increase the refcount before doing anything else to > > the page so that other page users see the elevated refcount first. > > Absolutely agree in principle. Is there anything else to say, though, > such as why this matters here? Or is the change just being done for > "best practices"? (Which is still a very solid reason, of course.) I'm not sure if any software examines both refcount and pincount to determine whether it knows what all of the refcounts to a page mean, but a human might. If someone else calls dump_page() after we update pincount and before we update refcount, we might make a bad decision while debugging. When the updates are the other way around, a spurious extra refcount is to be expected and should not confuse anyone more than they already are. > > Signed-off-by: Matthew Wilcox (Oracle) > > --- > > mm/gup.c | 12 ++++++------ > > 1 file changed, 6 insertions(+), 6 deletions(-) > > > > diff --git a/mm/gup.c b/mm/gup.c > > index a9d4d724aef7..08020987dfc0 100644 > > --- a/mm/gup.c > > +++ b/mm/gup.c > > @@ -220,18 +220,18 @@ bool __must_check try_grab_page(struct page *page, unsigned int flags) > > if (WARN_ON_ONCE(page_ref_count(page) <= 0)) > > return false; > > - if (hpage_pincount_available(page)) > > - hpage_pincount_add(page, 1); > > - else > > - refs = GUP_PIN_COUNTING_BIAS; > > - > > /* > > * Similar to try_grab_compound_head(): even if using the > > * hpage_pincount_add/_sub() routines, be sure to > > * *also* increment the normal page refcount field at least > > * once, so that the page really is pinned. > > */ > > - page_ref_add(page, refs); > > A fine point: this hunk removes the last use of "refs", which means that > this patch will lead to an unused variable warning. So I think it would > be best to remove the "int refs = 1;" line in this patch, rather than > waiting until patch #10. Argh! I noticed that I needed to do that, and then forgot to do it. Thanks! > With that change, please feel free to add: > > Reviewed-by: John Hubbard Added, and git tree updated.