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=-12.6 required=3.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH,MAILING_LIST_MULTI, SIGNED_OFF_BY,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 8ADF2C4741F for ; Sat, 31 Oct 2020 09:15:28 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id B8DBE2076E for ; Sat, 31 Oct 2020 09:15:27 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (2048-bit key) header.d=infradead.org header.i=@infradead.org header.b="q/5iaxo7" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org B8DBE2076E Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=lst.de Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id 4085E6B0036; Sat, 31 Oct 2020 05:15:27 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 392076B005C; Sat, 31 Oct 2020 05:15:27 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 25A846B006C; Sat, 31 Oct 2020 05:15:27 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0158.hostedemail.com [216.40.44.158]) by kanga.kvack.org (Postfix) with ESMTP id EA01E6B0036 for ; Sat, 31 Oct 2020 05:15:26 -0400 (EDT) Received: from smtpin01.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay02.hostedemail.com (Postfix) with ESMTP id 836AB3620 for ; Sat, 31 Oct 2020 09:15:26 +0000 (UTC) X-FDA: 77431662252.01.plate91_5a0d46b2729d Received: from filter.hostedemail.com (10.5.16.251.rfc1918.com [10.5.16.251]) by smtpin01.hostedemail.com (Postfix) with ESMTP id 66FDD1004CB20 for ; Sat, 31 Oct 2020 09:15:26 +0000 (UTC) X-HE-Tag: plate91_5a0d46b2729d X-Filterd-Recvd-Size: 4383 Received: from casper.infradead.org (casper.infradead.org [90.155.50.34]) by imf12.hostedemail.com (Postfix) with ESMTP for ; Sat, 31 Oct 2020 09:15:25 +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=w7pP6ZwoBFCgYWc3JUgMBAPIvDyVUgvDwMandxHayiQ=; b=q/5iaxo7WNboQxCOEfk/hZZKVn lsOCR6oywpH+8Q85yuTc4j6w6RUrKjDYY9Yp/oEVqqgDBB5UUrUKXvwLSMJuTUCgR5fvjvkmywmw0 LK8pbVDmYAWjwr4omJ4hPvYfzqE11pKgHLcMS/3XapoBYtpO7FZrLwoxn/vA/kEkG1y8SKUdT5koP wsLb0OmJ3lPbuEsRxW0GkOfXHLSAKEtgSYLtpjTFV3NNDsyW4rvrQX75CaAmhoynw8xD/JXfAQNEQ gju31KMDTItTMPfvJl99M9THTaSjHSEmTzhcKo9IWonpBr2KyjVAoEGR6vpkq05SnSIZRGue6jFO/ WNc3pkOA==; Received: from 089144193201.atnat0002.highway.a1.net ([89.144.193.201] helo=localhost) by casper.infradead.org with esmtpsa (Exim 4.92.3 #3 (Red Hat Linux)) id 1kYmyp-0007tB-0l; Sat, 31 Oct 2020 09:15:23 +0000 From: Christoph Hellwig To: Andrew Morton Cc: Kent Overstreet , Matthew Wilcox , linux-mm@kvack.org, linux-fsdevel@vger.kernel.org Subject: [PATCH 06/13] mm: factor out a filemap_find_get_pages helper Date: Sat, 31 Oct 2020 09:59:57 +0100 Message-Id: <20201031090004.452516-7-hch@lst.de> X-Mailer: git-send-email 2.28.0 In-Reply-To: <20201031090004.452516-1-hch@lst.de> References: <20201031090004.452516-1-hch@lst.de> MIME-Version: 1.0 X-SRS-Rewrite: SMTP reverse-path rewritten from by casper.infradead.org. See http://www.infradead.org/rpr.html 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: Factor out a helper to lookup a range of contiguous pages from generic_file_buffered_read_get_pages. Signed-off-by: Christoph Hellwig --- mm/filemap.c | 47 +++++++++++++++++++++++++++-------------------- 1 file changed, 27 insertions(+), 20 deletions(-) diff --git a/mm/filemap.c b/mm/filemap.c index 9e1cc18afe1134..0af7ddaa0fe7ba 100644 --- a/mm/filemap.c +++ b/mm/filemap.c @@ -2323,39 +2323,46 @@ static int filemap_new_page(struct kiocb *iocb, s= truct iov_iter *iter, return filemap_readpage(iocb, *page); } =20 +static int filemap_find_get_pages(struct kiocb *iocb, struct iov_iter *i= ter, + struct page **pages, unsigned int nr) +{ + struct address_space *mapping =3D iocb->ki_filp->f_mapping; + pgoff_t index =3D iocb->ki_pos >> PAGE_SHIFT; + pgoff_t last_index =3D (iocb->ki_pos + iter->count + PAGE_SIZE - 1) >> + PAGE_SHIFT; + int nr_pages; + + nr =3D min_t(unsigned long, last_index - index, nr); + nr_pages =3D find_get_pages_contig(mapping, index, nr, pages); + if (nr_pages) + return nr_pages; + + if (iocb->ki_flags & IOCB_NOIO) + return -EAGAIN; + page_cache_sync_readahead(mapping, &iocb->ki_filp->f_ra, iocb->ki_filp, + index, last_index - index); + return find_get_pages_contig(mapping, index, nr, pages); +} + static int generic_file_buffered_read_get_pages(struct kiocb *iocb, struct iov_iter *iter, struct page **pages, unsigned int nr) { - struct file *filp =3D iocb->ki_filp; - struct address_space *mapping =3D filp->f_mapping; - struct file_ra_state *ra =3D &filp->f_ra; pgoff_t index =3D iocb->ki_pos >> PAGE_SHIFT; - pgoff_t last_index =3D (iocb->ki_pos + iter->count + PAGE_SIZE-1) >> PA= GE_SHIFT; int i, j, nr_got, err =3D 0; =20 - nr =3D min_t(unsigned long, last_index - index, nr); find_page: if (fatal_signal_pending(current)) return -EINTR; =20 - nr_got =3D find_get_pages_contig(mapping, index, nr, pages); - if (nr_got) - goto got_pages; - - if (iocb->ki_flags & IOCB_NOIO) - return -EAGAIN; - - page_cache_sync_readahead(mapping, ra, filp, index, last_index - index)= ; + nr_got =3D filemap_find_get_pages(iocb, iter, pages, nr); + if (!nr_got) { + err =3D filemap_new_page(iocb, iter, &pages[0]); + if (!err) + nr_got =3D 1; + } =20 - nr_got =3D find_get_pages_contig(mapping, index, nr, pages); - if (nr_got) - goto got_pages; - err =3D filemap_new_page(iocb, iter, &pages[0]); - if (!err) - nr_got =3D 1; -got_pages: for (i =3D 0; i < nr_got; i++) { err =3D filemap_make_page_uptodate(iocb, iter, pages[i], index + i, i =3D=3D 0); --=20 2.28.0