From patchwork Mon Jan 10 04:24:03 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Matthew Wilcox X-Patchwork-Id: 12708175 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 89089C43217 for ; Mon, 10 Jan 2022 04:24:38 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id E23596B0082; Sun, 9 Jan 2022 23:24:23 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id D5DB46B0083; Sun, 9 Jan 2022 23:24:23 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id BB2126B0087; Sun, 9 Jan 2022 23:24:23 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0152.hostedemail.com [216.40.44.152]) by kanga.kvack.org (Postfix) with ESMTP id A1B106B0082 for ; Sun, 9 Jan 2022 23:24:23 -0500 (EST) Received: from smtpin05.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay04.hostedemail.com (Postfix) with ESMTP id 6A69B96F15 for ; Mon, 10 Jan 2022 04:24:23 +0000 (UTC) X-FDA: 79013085606.05.64AF7E2 Received: from casper.infradead.org (casper.infradead.org [90.155.50.34]) by imf20.hostedemail.com (Postfix) with ESMTP id 0FBB91C0003 for ; Mon, 10 Jan 2022 04:24:22 +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=SzJAO82OEH7GJ/mx7wGbrx//DOWsumHlBiQh3Qh2tnQ=; b=fjA0ppGWoAmzrPEL5HhRkIA+hr fzlhnHNr4mbg+FEjXHmiirYvrOledQFtXWc+8V+wEmsSXldqHGRyDqFahNY1GgB+Djy/o6DrumHiW a9LAONzmOJGdPQ7c1X+jl+BpOYhqLCvUzgUkFc5bKyNcnzdG1wEL80ExG+BOgn/L3HoDTLwJ00VOW hhsvdm2fk05IAB25GVH39Ip69aba3Bk3Ba2n7Zx7f0L9KpUOCn6Dn9tZ9Gaa2nSJrlxOzyUSIkITB zzm50sqecdqw8qZaSbFuY/V8Qovp1Z8QLFT4/kSUZZ8KBmhTI7AWTA9RGWJC0tgQscXCShYQFp65Z wSTTeGFg==; Received: from willy by casper.infradead.org with local (Exim 4.94.2 #2 (Red Hat Linux)) id 1n6mE9-0025xE-OM; Mon, 10 Jan 2022 04:24:13 +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 25/28] gup: Convert compound_next() to gup_folio_next() Date: Mon, 10 Jan 2022 04:24:03 +0000 Message-Id: <20220110042406.499429-26-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: rspam08 X-Rspamd-Queue-Id: 0FBB91C0003 X-Stat-Signature: us5sujiinfbgqp6yrpqx54qorxuucd7e Authentication-Results: imf20.hostedemail.com; dkim=pass header.d=infradead.org header.s=casper.20170209 header.b=fjA0ppGW; 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; dmarc=none X-HE-Tag: 1641788662-210955 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: Convert both callers to work on folios instead of pages. Signed-off-by: Matthew Wilcox (Oracle) Reviewed-by: Christoph Hellwig Reviewed-by: John Hubbard --- mm/gup.c | 41 ++++++++++++++++++++++------------------- 1 file changed, 22 insertions(+), 19 deletions(-) diff --git a/mm/gup.c b/mm/gup.c index b5786e83c418..0cf2d5fd8d2d 100644 --- a/mm/gup.c +++ b/mm/gup.c @@ -220,20 +220,20 @@ static inline struct page *compound_range_next(unsigned long i, return page; } -static inline struct page *compound_next(unsigned long i, +static inline struct folio *gup_folio_next(unsigned long i, unsigned long npages, struct page **list, unsigned int *ntails) { - struct page *page; + struct folio *folio; unsigned int nr; - page = compound_head(list[i]); + folio = page_folio(list[i]); for (nr = i + 1; nr < npages; nr++) { - if (compound_head(list[nr]) != page) + if (page_folio(list[nr]) != folio) break; } *ntails = nr - i; - return page; + return folio; } /** @@ -261,17 +261,17 @@ static inline struct page *compound_next(unsigned long i, void unpin_user_pages_dirty_lock(struct page **pages, unsigned long npages, bool make_dirty) { - unsigned long index; - struct page *head; - unsigned int ntails; + unsigned long i; + struct folio *folio; + unsigned int nr; if (!make_dirty) { unpin_user_pages(pages, npages); return; } - for (index = 0; index < npages; index += ntails) { - head = compound_next(index, npages, pages, &ntails); + for (i = 0; i < npages; i += nr) { + folio = gup_folio_next(i, npages, pages, &nr); /* * Checking PageDirty at this point may race with * clear_page_dirty_for_io(), but that's OK. Two key @@ -292,9 +292,12 @@ void unpin_user_pages_dirty_lock(struct page **pages, unsigned long npages, * written back, so it gets written back again in the * next writeback cycle. This is harmless. */ - if (!PageDirty(head)) - set_page_dirty_lock(head); - put_compound_head(head, ntails, FOLL_PIN); + if (!folio_test_dirty(folio)) { + folio_lock(folio); + folio_mark_dirty(folio); + folio_unlock(folio); + } + gup_put_folio(folio, nr, FOLL_PIN); } } EXPORT_SYMBOL(unpin_user_pages_dirty_lock); @@ -347,9 +350,9 @@ EXPORT_SYMBOL(unpin_user_page_range_dirty_lock); */ void unpin_user_pages(struct page **pages, unsigned long npages) { - unsigned long index; - struct page *head; - unsigned int ntails; + unsigned long i; + struct folio *folio; + unsigned int nr; /* * If this WARN_ON() fires, then the system *might* be leaking pages (by @@ -359,9 +362,9 @@ void unpin_user_pages(struct page **pages, unsigned long npages) if (WARN_ON(IS_ERR_VALUE(npages))) return; - for (index = 0; index < npages; index += ntails) { - head = compound_next(index, npages, pages, &ntails); - put_compound_head(head, ntails, FOLL_PIN); + for (i = 0; i < npages; i += nr) { + folio = gup_folio_next(i, npages, pages, &nr); + gup_put_folio(folio, nr, FOLL_PIN); } } EXPORT_SYMBOL(unpin_user_pages);