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 X-Spam-Level: X-Spam-Status: No, score=-16.6 required=3.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 5754EC07E99 for ; Mon, 12 Jul 2021 03:50:07 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id EC80161006 for ; Mon, 12 Jul 2021 03:50:06 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org EC80161006 Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=infradead.org Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id 180016B0099; Sun, 11 Jul 2021 23:50:07 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 130076B009A; Sun, 11 Jul 2021 23:50:07 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id F3A796B009B; Sun, 11 Jul 2021 23:50:06 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0095.hostedemail.com [216.40.44.95]) by kanga.kvack.org (Postfix) with ESMTP id D13166B0099 for ; Sun, 11 Jul 2021 23:50:06 -0400 (EDT) Received: from smtpin40.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay02.hostedemail.com (Postfix) with ESMTP id 00D61235B4 for ; Mon, 12 Jul 2021 03:50:06 +0000 (UTC) X-FDA: 78352557612.40.DD6A971 Received: from casper.infradead.org (casper.infradead.org [90.155.50.34]) by imf14.hostedemail.com (Postfix) with ESMTP id 79E1C600199D for ; Mon, 12 Jul 2021 03:50:05 +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=RznbpItH7Hf5+tg8WiyybH0ySpwIattHKDhAoYM7Hlo=; b=STsJ1wAG6bvlnUTyNT49ILj7Jv tOagt2Rlf0x7UrwsNRMRJm7vGf7LtAiZXydgXyWAr5SE8TVWPMTcBJjZjy+gg2Vdx+m67kQN6qLcR cXV1xX8IlsHdkiCHUHaZ7VaZh51nJf5DlZyKAGTHa/v9OVO7deFhdEeRs05uM4rQfcd8uzTDbBK5m rz7uC4VsoMxblgK/0fqjaozb4MjbzWB/Lz8qIH133c55yl81skcu/Rg8cAi6TejRBCAb31pEhMD+Z n+TqipukC8w1i6P2YoVcCbn4QOdAwAenr/INkuAEQu1TgoDgFpTE5SEVPYfXw13lpiAV/7ft9AapX gMwX1J/g==; Received: from willy by casper.infradead.org with local (Exim 4.94.2 #2 (Red Hat Linux)) id 1m2mwD-00Gpj3-RN; Mon, 12 Jul 2021 03:49:07 +0000 From: "Matthew Wilcox (Oracle)" To: linux-kernel@vger.kernel.org Cc: "Matthew Wilcox (Oracle)" , linux-mm@kvack.org, linux-fsdevel@vger.kernel.org, Christoph Hellwig Subject: [PATCH v13 078/137] mm/filemap: Add readahead_folio() Date: Mon, 12 Jul 2021 04:06:02 +0100 Message-Id: <20210712030701.4000097-79-willy@infradead.org> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210712030701.4000097-1-willy@infradead.org> References: <20210712030701.4000097-1-willy@infradead.org> MIME-Version: 1.0 Authentication-Results: imf14.hostedemail.com; dkim=pass header.d=infradead.org header.s=casper.20170209 header.b=STsJ1wAG; spf=none (imf14.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-Rspamd-Server: rspam02 X-Stat-Signature: sbgpx7x794amn4eannkk43tosud3psks X-Rspamd-Queue-Id: 79E1C600199D X-HE-Tag: 1626061805-540301 Content-Transfer-Encoding: quoted-printable 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: The pointers stored in the page cache are folios, by definition. This change comes with a behaviour change -- callers of readahead_folio() are no longer required to put the page reference themselves. This matche= s how readpage works, rather than matching how readpages used to work. Signed-off-by: Matthew Wilcox (Oracle) Reviewed-by: Christoph Hellwig --- include/linux/pagemap.h | 53 +++++++++++++++++++++++++++++------------ 1 file changed, 38 insertions(+), 15 deletions(-) diff --git a/include/linux/pagemap.h b/include/linux/pagemap.h index 1aee9f711de8..c0506722d209 100644 --- a/include/linux/pagemap.h +++ b/include/linux/pagemap.h @@ -988,33 +988,56 @@ void page_cache_async_readahead(struct address_spac= e *mapping, page_cache_async_ra(&ractl, page, req_count); } =20 +static inline struct folio *__readahead_folio(struct readahead_control *= ractl) +{ + struct folio *folio; + + BUG_ON(ractl->_batch_count > ractl->_nr_pages); + ractl->_nr_pages -=3D ractl->_batch_count; + ractl->_index +=3D ractl->_batch_count; + + if (!ractl->_nr_pages) { + ractl->_batch_count =3D 0; + return NULL; + } + + folio =3D xa_load(&ractl->mapping->i_pages, ractl->_index); + VM_BUG_ON_FOLIO(!folio_locked(folio), folio); + ractl->_batch_count =3D folio_nr_pages(folio); + + return folio; +} + /** * readahead_page - Get the next page to read. - * @rac: The current readahead request. + * @ractl: The current readahead request. * * Context: The page is locked and has an elevated refcount. The caller * should decreases the refcount once the page has been submitted for I/= O * and unlock the page once all I/O to that page has completed. * Return: A pointer to the next page, or %NULL if we are done. */ -static inline struct page *readahead_page(struct readahead_control *rac) +static inline struct page *readahead_page(struct readahead_control *ract= l) { - struct page *page; + struct folio *folio =3D __readahead_folio(ractl); =20 - BUG_ON(rac->_batch_count > rac->_nr_pages); - rac->_nr_pages -=3D rac->_batch_count; - rac->_index +=3D rac->_batch_count; - - if (!rac->_nr_pages) { - rac->_batch_count =3D 0; - return NULL; - } + return &folio->page; +} =20 - page =3D xa_load(&rac->mapping->i_pages, rac->_index); - VM_BUG_ON_PAGE(!PageLocked(page), page); - rac->_batch_count =3D thp_nr_pages(page); +/** + * readahead_folio - Get the next folio to read. + * @ractl: The current readahead request. + * + * Context: The folio is locked. The caller should unlock the folio onc= e + * all I/O to that folio has completed. + * Return: A pointer to the next folio, or %NULL if we are done. + */ +static inline struct folio *readahead_folio(struct readahead_control *ra= ctl) +{ + struct folio *folio =3D __readahead_folio(ractl); =20 - return page; + folio_put(folio); + return folio; } =20 static inline unsigned int __readahead_batch(struct readahead_control *r= ac, --=20 2.30.2