From patchwork Mon Jan 10 04:23:47 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Matthew Wilcox (Oracle)" X-Patchwork-Id: 12708184 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 728BDC4332F for ; Mon, 10 Jan 2022 04:24:52 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id F329D6B0099; Sun, 9 Jan 2022 23:24:35 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id E984F6B009B; Sun, 9 Jan 2022 23:24:35 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id C4E1C6B009C; Sun, 9 Jan 2022 23:24:35 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0053.hostedemail.com [216.40.44.53]) by kanga.kvack.org (Postfix) with ESMTP id A7A6B6B0099 for ; Sun, 9 Jan 2022 23:24:35 -0500 (EST) Received: from smtpin17.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay05.hostedemail.com (Postfix) with ESMTP id 656BE181C1958 for ; Mon, 10 Jan 2022 04:24:35 +0000 (UTC) X-FDA: 79013086110.17.291C22E Received: from casper.infradead.org (casper.infradead.org [90.155.50.34]) by imf20.hostedemail.com (Postfix) with ESMTP id 18BB31C0002 for ; Mon, 10 Jan 2022 04:24:34 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=casper.20170209; h=Content-Transfer-Encoding:MIME-Version: References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From:Sender:Reply-To: Content-Type:Content-ID:Content-Description; bh=cNkGRRqE4MZ2IOY+aRtZ6O11ENnM+VUoRZ1VxqjqE3o=; b=XOj3bE4s2SziUPl4NNs9v1GOQC HevnwI8lrxL7DmnEAPUYAWy34kzK5npISqem7T56xj61z6L1q/Ddv/LabQ3++ka6+lsIEVo41JWsX 8rtSy+opZf39sTkTo8cAEMnv/XkqN6anRr/PyfCxHDwlLFFWajLlzFxx8mA+fso+lCsl+OSsqnfJa 6MJvBhMubiCav7PUMH1D4cVum7gqyi9YjODfwdYR0krwMxJO4ODeZhPC8iY0HPWKXqS5m8d63HWV4 CFSi3NBDsz+n8zSkyDHuxQ1sJpNTOR1oMnGth7hL9Z1Ux+EPuZAqRCG7JaoW4hwP7AQx5bDnFoUVp urm0Tg0g==; Received: from willy by casper.infradead.org with local (Exim 4.94.2 #2 (Red Hat Linux)) id 1n6mE8-0025wi-IQ; Mon, 10 Jan 2022 04:24:12 +0000 From: "Matthew Wilcox (Oracle)" To: linux-mm@kvack.org Cc: "Matthew Wilcox (Oracle)" , John Hubbard , Christoph Hellwig , William Kucharski , linux-kernel@vger.kernel.org, Jason Gunthorpe Subject: [PATCH v2 09/28] gup: Turn hpage_pincount_add() into page_pincount_add() Date: Mon, 10 Jan 2022 04:23:47 +0000 Message-Id: <20220110042406.499429-10-willy@infradead.org> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20220110042406.499429-1-willy@infradead.org> References: <20220110042406.499429-1-willy@infradead.org> MIME-Version: 1.0 X-Rspamd-Server: rspam03 X-Rspamd-Queue-Id: 18BB31C0002 X-Stat-Signature: 39ykp31hqd6nyow86t9i1wz7shfxfity Authentication-Results: imf20.hostedemail.com; dkim=pass header.d=infradead.org header.s=casper.20170209 header.b=XOj3bE4s; dmarc=none; spf=none (imf20.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: 1641788674-924390 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: Simplify try_grab_compound_head() and remove an unnecessary VM_BUG_ON by handling pages both with and without a pincount field in page_pincount_add(). Signed-off-by: Matthew Wilcox (Oracle) Reviewed-by: Christoph Hellwig Reviewed-by: John Hubbard --- mm/gup.c | 33 +++++++++++++++------------------ 1 file changed, 15 insertions(+), 18 deletions(-) diff --git a/mm/gup.c b/mm/gup.c index dbb1b54d0def..3ed9907f3c8d 100644 --- a/mm/gup.c +++ b/mm/gup.c @@ -29,12 +29,23 @@ struct follow_page_context { unsigned int page_mask; }; -static void hpage_pincount_add(struct page *page, int refs) +/* + * When pinning a compound page of order > 1 (which is what + * hpage_pincount_available() checks for), use an exact count to track + * it, via page_pincount_add/_sub(). + * + * However, be sure to *also* increment the normal page refcount field + * at least once, so that the page really is pinned. That's why the + * refcount from the earlier try_get_compound_head() is left intact. + */ +static void page_pincount_add(struct page *page, int refs) { - VM_BUG_ON_PAGE(!hpage_pincount_available(page), page); VM_BUG_ON_PAGE(page != compound_head(page), page); - atomic_add(refs, compound_pincount_ptr(page)); + if (hpage_pincount_available(page)) + atomic_add(refs, compound_pincount_ptr(page)); + else + page_ref_add(page, refs * (GUP_PIN_COUNTING_BIAS - 1)); } static void hpage_pincount_sub(struct page *page, int refs) @@ -150,21 +161,7 @@ struct page *try_grab_compound_head(struct page *page, if (!page) return NULL; - /* - * When pinning a compound page of order > 1 (which is what - * hpage_pincount_available() checks for), use an exact count to - * track it, via hpage_pincount_add/_sub(). - * - * However, be sure to *also* increment the normal page refcount - * field at least once, so that the page really is pinned. - * That's why the refcount from the earlier - * try_get_compound_head() is left intact. - */ - if (hpage_pincount_available(page)) - hpage_pincount_add(page, refs); - else - page_ref_add(page, refs * (GUP_PIN_COUNTING_BIAS - 1)); - + page_pincount_add(page, refs); mod_node_page_state(page_pgdat(page), NR_FOLL_PIN_ACQUIRED, refs);