From patchwork Sun Jan 2 21:57:19 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Matthew Wilcox X-Patchwork-Id: 12702371 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 739CDC433F5 for ; Sun, 2 Jan 2022 21:57:52 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 471546B0081; Sun, 2 Jan 2022 16:57:47 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 3FB0D6B0082; Sun, 2 Jan 2022 16:57:47 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 1B02D6B0083; Sun, 2 Jan 2022 16:57:47 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0069.hostedemail.com [216.40.44.69]) by kanga.kvack.org (Postfix) with ESMTP id 02CAF6B0081 for ; Sun, 2 Jan 2022 16:57:47 -0500 (EST) Received: from smtpin12.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay05.hostedemail.com (Postfix) with ESMTP id B4317181AC9C6 for ; Sun, 2 Jan 2022 21:57:46 +0000 (UTC) X-FDA: 78986709732.12.4C9D409 Received: from casper.infradead.org (casper.infradead.org [90.155.50.34]) by imf07.hostedemail.com (Postfix) with ESMTP id 3E43D40002 for ; Sun, 2 Jan 2022 21:57:46 +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=LMlTYupDjmdQdz1OVwZOJWvhaN7jKXAby3ZJWkuTnfY=; b=DVr6g0TpicQ0sPagN/WVWanq3J +Q3tmnVN+81jXpCK7a7Mtum4fxAvBfALfzgW0lnSRTUBHiM0/sZke8PuJa3x6xds48W69M1VxlNUj fTHcTjBHGgGo733wmTjtV1waMwQRwssCJpgJZxpZZeb6Od1OTrOOkA/PQG2hLybmlCk+q7Z2X4bXK te5WOSukv/oY63PDd2k+hisw+RLGgGwImyWKd9PDt7VlKv456w8kCgOK8vpgaZU3ggR+FX8GVnOt8 db0TFJ6PsldGd7phXmmw2JRGNSSEBvtJmXymVUlPAS1i/oibdYUrPooIxLq0gs4D5mFGWRuAAhbd9 sOHqy2wQ==; Received: from willy by casper.infradead.org with local (Exim 4.94.2 #2 (Red Hat Linux)) id 1n48r6-00CLoC-CO; Sun, 02 Jan 2022 21:57:32 +0000 From: "Matthew Wilcox (Oracle)" To: linux-mm@kvack.org Cc: "Matthew Wilcox (Oracle)" , John Hubbard , Andrew Morton Subject: [PATCH 07/17] gup: Add gup_put_folio() Date: Sun, 2 Jan 2022 21:57:19 +0000 Message-Id: <20220102215729.2943705-8-willy@infradead.org> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20220102215729.2943705-1-willy@infradead.org> References: <20220102215729.2943705-1-willy@infradead.org> MIME-Version: 1.0 X-Rspamd-Server: rspam03 X-Rspamd-Queue-Id: 3E43D40002 X-Stat-Signature: hgg9y8nmqtutmag7szh59iks1juzcqri Authentication-Results: imf07.hostedemail.com; dkim=pass header.d=infradead.org header.s=casper.20170209 header.b=DVr6g0Tp; dmarc=none; spf=none (imf07.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: 1641160666-880518 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: put_compound_head() is turned into a call to gup_put_folio(). This removes the last call to put_page_refs(), so delete it. Signed-off-by: Matthew Wilcox (Oracle) Reviewed-by: Christoph Hellwig Reviewed-by: John Hubbard --- mm/gup.c | 44 +++++++++++++++----------------------------- 1 file changed, 15 insertions(+), 29 deletions(-) diff --git a/mm/gup.c b/mm/gup.c index 58e5cfaaa676..6d827f7d66d8 100644 --- a/mm/gup.c +++ b/mm/gup.c @@ -36,29 +36,11 @@ static void folio_pincount_add(struct folio *folio, int refs) atomic_add(refs, folio_pincount_ptr(folio)); } -static void hpage_pincount_sub(struct page *page, int refs) +static void folio_pincount_sub(struct folio *folio, int refs) { - VM_BUG_ON_PAGE(!hpage_pincount_available(page), page); - VM_BUG_ON_PAGE(page != compound_head(page), page); - - atomic_sub(refs, compound_pincount_ptr(page)); -} - -/* Equivalent to calling put_page() @refs times. */ -static void put_page_refs(struct page *page, int refs) -{ -#ifdef CONFIG_DEBUG_VM - if (VM_WARN_ON_ONCE_PAGE(page_ref_count(page) < refs, page)) - return; -#endif + VM_BUG_ON_FOLIO(!folio_pincount_available(folio), folio); - /* - * Calling put_page() for each ref is unnecessarily slow. Only the last - * ref needs a put_page(). - */ - if (refs > 1) - page_ref_sub(page, refs - 1); - put_page(page); + atomic_sub(refs, folio_pincount_ptr(folio)); } /* @@ -175,19 +157,23 @@ struct page *try_grab_compound_head(struct page *page, return NULL; } -static void put_compound_head(struct page *page, int refs, unsigned int flags) +static void gup_put_folio(struct folio *folio, int refs, unsigned int flags) { if (flags & FOLL_PIN) { - mod_node_page_state(page_pgdat(page), NR_FOLL_PIN_RELEASED, - refs); - - if (hpage_pincount_available(page)) - hpage_pincount_sub(page, refs); + node_stat_mod_folio(folio, NR_FOLL_PIN_RELEASED, refs); + if (folio_pincount_available(folio)) + folio_pincount_sub(folio, refs); else refs *= GUP_PIN_COUNTING_BIAS; } - put_page_refs(page, refs); + folio_put_refs(folio, refs); +} + +static void put_compound_head(struct page *page, int refs, unsigned int flags) +{ + VM_BUG_ON_PAGE(PageTail(page), page); + gup_put_folio((struct folio *)page, refs, flags); } /** @@ -228,7 +214,7 @@ bool __must_check try_grab_page(struct page *page, unsigned int flags) */ void unpin_user_page(struct page *page) { - put_compound_head(compound_head(page), 1, FOLL_PIN); + gup_put_folio(page_folio(page), 1, FOLL_PIN); } EXPORT_SYMBOL(unpin_user_page);