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 Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id E2BC4C433F5 for ; Fri, 4 Feb 2022 21:28:54 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 11F6A6B0072; Fri, 4 Feb 2022 16:28:54 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 0CFB66B0073; Fri, 4 Feb 2022 16:28:54 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id ED9416B0074; Fri, 4 Feb 2022 16:28:53 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0251.hostedemail.com [216.40.44.251]) by kanga.kvack.org (Postfix) with ESMTP id DC0A16B0072 for ; Fri, 4 Feb 2022 16:28:53 -0500 (EST) Received: from smtpin30.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay02.hostedemail.com (Postfix) with ESMTP id 920F09A26E for ; Fri, 4 Feb 2022 21:28:53 +0000 (UTC) X-FDA: 79106387346.30.BA753D6 Received: from casper.infradead.org (casper.infradead.org [90.155.50.34]) by imf27.hostedemail.com (Postfix) with ESMTP id B9CD640003 for ; Fri, 4 Feb 2022 21:28:52 +0000 (UTC) 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-Rspam-User: nil X-Rspamd-Server: rspam05 X-Rspamd-Queue-Id: B9CD640003 X-Stat-Signature: nfky9kafp4gtsxnbgd7wce3yb4uyxzpi Authentication-Results: imf27.hostedemail.com; dkim=pass header.d=infradead.org header.s=casper.20170209 header.b=k5sR88CD; dmarc=none; spf=none (imf27.hostedemail.com: domain of willy@infradead.org has no SPF policy when checking 90.155.50.34) smtp.mailfrom=willy@infradead.org X-HE-Tag: 1644010132-670155 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 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.