From patchwork Fri Feb 4 19:57:53 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Matthew Wilcox X-Patchwork-Id: 12735505 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 65CCEC433FE for ; Fri, 4 Feb 2022 19:59:07 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id DF3FF6B0072; Fri, 4 Feb 2022 14:59:04 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id C34306B0073; Fri, 4 Feb 2022 14:59:04 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 94D7D6B0074; Fri, 4 Feb 2022 14:59:04 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0082.hostedemail.com [216.40.44.82]) by kanga.kvack.org (Postfix) with ESMTP id 7868A6B0073 for ; Fri, 4 Feb 2022 14:59:04 -0500 (EST) Received: from smtpin15.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay02.hostedemail.com (Postfix) with ESMTP id 3F444998DF for ; Fri, 4 Feb 2022 19:59:04 +0000 (UTC) X-FDA: 79106161008.15.C3EBED1 Received: from casper.infradead.org (casper.infradead.org [90.155.50.34]) by imf27.hostedemail.com (Postfix) with ESMTP id 64AB94000B for ; Fri, 4 Feb 2022 19:59:03 +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=ZGUNblaPy+0CLxla8etvidC8Ld2G9pzD+/27Z3AyaUs=; b=I+1Sp/cLkrfSPETrjSyMPUw5/c M48GPdSCSJpo7W/qwrO7qjJ8A8q6oSpA20ghe+5H+X9qZfb28YDHG6AJtUpA+3QtmKVVR1n6TOxhn dvEm3OylxoQDyeEjm55jw/5kV0LjCBYTYIH15S2gskc00EUCz/LjaW2IB0qjl1QPl+DYR5GgsKZIF mP4m9nUhudjs6Brw1/ZcupreVgxe04BIHiTb6RzOg0UE3O7J2AMXoQPP0T4Asoi0hTRwYcpcRhvDp KFQoiWqY9QdLVCQ5TPw7YNVTaCB+Y/CzHni/C5oO98h7AGggbGVHgoID49ES8AWSU2PhcjQOEpzR0 2E25y3cA==; Received: from willy by casper.infradead.org with local (Exim 4.94.2 #2 (Red Hat Linux)) id 1nG4jV-007Llf-0f; Fri, 04 Feb 2022 19:59:01 +0000 From: "Matthew Wilcox (Oracle)" To: linux-mm@kvack.org Cc: "Matthew Wilcox (Oracle)" , linux-kernel@vger.kernel.org Subject: [PATCH 16/75] mm/gup: Convert try_grab_page() to use a folio Date: Fri, 4 Feb 2022 19:57:53 +0000 Message-Id: <20220204195852.1751729-17-willy@infradead.org> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20220204195852.1751729-1-willy@infradead.org> References: <20220204195852.1751729-1-willy@infradead.org> MIME-Version: 1.0 X-Rspamd-Server: rspam06 X-Rspamd-Queue-Id: 64AB94000B X-Stat-Signature: wppa78m61qqugh1gnrgf7ssu8strgepf Authentication-Results: imf27.hostedemail.com; dkim=pass header.d=infradead.org header.s=casper.20170209 header.b="I+1Sp/cL"; 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-Rspam-User: nil X-HE-Tag: 1644004743-376187 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: Hoist the folio conversion and the folio_ref_count() check to the top of the function instead of using the one buried in try_get_page(). Signed-off-by: Matthew Wilcox (Oracle) Reviewed-by: John Hubbard Reviewed-by: Christoph Hellwig --- mm/gup.c | 28 +++++++++++++--------------- 1 file changed, 13 insertions(+), 15 deletions(-) diff --git a/mm/gup.c b/mm/gup.c index 4f1669db92f5..d18ce4da573f 100644 --- a/mm/gup.c +++ b/mm/gup.c @@ -174,15 +174,14 @@ static void put_compound_head(struct page *page, int refs, unsigned int flags) /** * try_grab_page() - elevate a page's refcount by a flag-dependent amount + * @page: pointer to page to be grabbed + * @flags: gup flags: these are the FOLL_* flag values. * * This might not do anything at all, depending on the flags argument. * * "grab" names in this file mean, "look at flags to decide whether to use * FOLL_PIN or FOLL_GET behavior, when incrementing the page's refcount. * - * @page: pointer to page to be grabbed - * @flags: gup flags: these are the FOLL_* flag values. - * * Either FOLL_PIN or FOLL_GET (or neither) may be set, but not both at the same * time. Cases: please see the try_grab_folio() documentation, with * "refs=1". @@ -193,29 +192,28 @@ static void put_compound_head(struct page *page, int refs, unsigned int flags) */ bool __must_check try_grab_page(struct page *page, unsigned int flags) { + struct folio *folio = page_folio(page); + WARN_ON_ONCE((flags & (FOLL_GET | FOLL_PIN)) == (FOLL_GET | FOLL_PIN)); + if (WARN_ON_ONCE(folio_ref_count(folio) <= 0)) + return false; if (flags & FOLL_GET) - return try_get_page(page); + folio_ref_inc(folio); else if (flags & FOLL_PIN) { - page = compound_head(page); - - if (WARN_ON_ONCE(page_ref_count(page) <= 0)) - return false; - /* - * Similar to try_grab_compound_head(): be sure to *also* + * Similar to try_grab_folio(): be sure to *also* * increment the normal page refcount field at least once, * so that the page really is pinned. */ - if (PageHead(page)) { - page_ref_add(page, 1); - atomic_add(1, compound_pincount_ptr(page)); + if (folio_test_large(folio)) { + folio_ref_add(folio, 1); + atomic_add(1, folio_pincount_ptr(folio)); } else { - page_ref_add(page, GUP_PIN_COUNTING_BIAS); + folio_ref_add(folio, GUP_PIN_COUNTING_BIAS); } - mod_node_page_state(page_pgdat(page), NR_FOLL_PIN_ACQUIRED, 1); + node_stat_mod_folio(folio, NR_FOLL_PIN_ACQUIRED, 1); } return true;