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 25DC0C43460 for ; Wed, 5 May 2021 16:33:47 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id A1BC561476 for ; Wed, 5 May 2021 16:33:46 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org A1BC561476 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 CF72C6B006E; Wed, 5 May 2021 12:33:45 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id C93D46B0071; Wed, 5 May 2021 12:33:45 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id B5B046B0072; Wed, 5 May 2021 12:33:45 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0193.hostedemail.com [216.40.44.193]) by kanga.kvack.org (Postfix) with ESMTP id 99D8F6B006E for ; Wed, 5 May 2021 12:33:45 -0400 (EDT) Received: from smtpin32.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay02.hostedemail.com (Postfix) with ESMTP id 467EF6D7B for ; Wed, 5 May 2021 16:33:45 +0000 (UTC) X-FDA: 78107723610.32.0F77A5B Received: from casper.infradead.org (casper.infradead.org [90.155.50.34]) by imf09.hostedemail.com (Postfix) with ESMTP id A324B601D8FF for ; Wed, 5 May 2021 16:33:35 +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=7erbrWi96udzk9FwXiNGJPahIb3q21i3Mxk6+d4+BqU=; b=cHv+FwvwiSiOf/bo48hwA2+V1M U8+IPeQZ3qHLzZOPpDbJyyNc+PXjeWZAKmTpm8bP47pbaTuiVOL3SFjH2wHmsI6Pm9xaNXXxYFnu0 PKVsj4lPLZ+I32wbM7MDQI27M96ZCLnKOqJ85nhDgUu5UTK4YKk110DXUo7cBFiM+QaUFJ3dGZHwJ y63LeRjgsl4DlmFHe04jcGtc87nXVeTE1bHD1A4Vzo1XnGGt4WyjPq6vb8Xq7fRHtxkVBIwXe1GDE f9n15Whp2BD8K99cMuZDWkOj1flDON0aVRSoytXL0JcTcsW6tlXL8lAIoGPeBRfEsbBLg3V+XwRJd zTX2HrRg==; Received: from willy by casper.infradead.org with local (Exim 4.94 #2 (Red Hat Linux)) id 1leKPr-000aml-Og; Wed, 05 May 2021 16:31:00 +0000 From: "Matthew Wilcox (Oracle)" To: linux-fsdevel@vger.kernel.org, linux-mm@kvack.org Cc: "Matthew Wilcox (Oracle)" , linux-kernel@vger.kernel.org Subject: [PATCH v9 70/96] mm/filemap: Add readahead_folio Date: Wed, 5 May 2021 16:06:02 +0100 Message-Id: <20210505150628.111735-71-willy@infradead.org> X-Mailer: git-send-email 2.29.2 In-Reply-To: <20210505150628.111735-1-willy@infradead.org> References: <20210505150628.111735-1-willy@infradead.org> MIME-Version: 1.0 Authentication-Results: imf09.hostedemail.com; dkim=pass header.d=infradead.org header.s=casper.20170209 header.b=cHv+Fwvw; dmarc=none; spf=none (imf09.hostedemail.com: domain of willy@infradead.org has no SPF policy when checking 90.155.50.34) smtp.mailfrom=willy@infradead.org X-Stat-Signature: tx8hjmnfgydn7rh9q7hghfn38319urbi X-Rspamd-Server: rspam02 X-Rspamd-Queue-Id: A324B601D8FF Received-SPF: none (infradead.org>: No applicable sender policy available) receiver=imf09; identity=mailfrom; envelope-from=""; helo=casper.infradead.org; client-ip=90.155.50.34 X-HE-DKIM-Result: pass/pass X-HE-Tag: 1620232415-617338 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) --- 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 8fd00dc5ebd5..d54772aa7a3a 100644 --- a/include/linux/pagemap.h +++ b/include/linux/pagemap.h @@ -1062,33 +1062,56 @@ void page_cache_async_readahead(struct address_sp= ace *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