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 32542C4741F for ; Sat, 31 Oct 2020 09:11:07 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 91C752076D for ; Sat, 31 Oct 2020 09:11:06 +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="ACTuWGop" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 91C752076D 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 108B66B005D; Sat, 31 Oct 2020 05:11:06 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 0DDD96B0062; Sat, 31 Oct 2020 05:11:06 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id EE9166B006C; Sat, 31 Oct 2020 05:11:05 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0066.hostedemail.com [216.40.44.66]) by kanga.kvack.org (Postfix) with ESMTP id C1F606B005D for ; Sat, 31 Oct 2020 05:11:05 -0400 (EDT) Received: from smtpin17.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay05.hostedemail.com (Postfix) with ESMTP id 64DCE181AEF15 for ; Sat, 31 Oct 2020 09:11:05 +0000 (UTC) X-FDA: 77431651290.17.trail80_210b3132729d Received: from filter.hostedemail.com (10.5.16.251.rfc1918.com [10.5.16.251]) by smtpin17.hostedemail.com (Postfix) with ESMTP id 4D005180D0181 for ; Sat, 31 Oct 2020 09:11:05 +0000 (UTC) X-HE-Tag: trail80_210b3132729d X-Filterd-Recvd-Size: 5171 Received: from casper.infradead.org (casper.infradead.org [90.155.50.34]) by imf29.hostedemail.com (Postfix) with ESMTP for ; Sat, 31 Oct 2020 09:11:04 +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=2sJM8L6vqDc82P4Zib4xzj+qKJ0+sgvNKXsT+iu4GIo=; b=ACTuWGopBUTRfiwiY/2UfoxmBR rxlS/8ys9h/z7FKsIObrB0RA1+xvAQ9HVg0vBHoa/CVwBaxVa8CUyrKCfZk9Zbs0BMxExyA4D4rov C0hKhk1MiwGZfLO6hspSTCPN9O0aBkqKxGS53TmTdDsswPbzGIBnU5WxADliiqgtmGxhMFu+NV4Fb KcVxuvmXwbfAk2OxgHAbfnPD4/pAVSEFIYE4MK4ldW6XnJmi0ej1WSV3dMccPpFKexJ+5ZqgrybcR Hcffrm3fEpATXviWbUOiL8YwF1+Jj8mZpZEXWUz8/EHBIkLnHcJM+gRgXz4ggpFq9r4mVtRGAsBPn x2T2HJtg==; 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 1kYmua-0007ZY-Ru; Sat, 31 Oct 2020 09:11:01 +0000 From: Christoph Hellwig To: Andrew Morton Cc: Kent Overstreet , Matthew Wilcox , linux-mm@kvack.org, linux-fsdevel@vger.kernel.org Subject: [PATCH 04/13] mm: handle readahead in generic_file_buffered_read_pagenotuptodate Date: Sat, 31 Oct 2020 09:59:55 +0100 Message-Id: <20201031090004.452516-5-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: Move the calculation of the per-page variables and the readahead handling from the only caller into generic_file_buffered_read_pagenotuptodate, which now becomes a routine to handle everything related to bringing one page uptodate and thus is renamed to filemap_read_one_page. Signed-off-by: Christoph Hellwig --- mm/filemap.c | 63 +++++++++++++++++++++++----------------------------- 1 file changed, 28 insertions(+), 35 deletions(-) diff --git a/mm/filemap.c b/mm/filemap.c index bae5b905aa7bdc..5cdf8090d4e12c 100644 --- a/mm/filemap.c +++ b/mm/filemap.c @@ -2217,13 +2217,26 @@ static int filemap_readpage(struct kiocb *iocb, s= truct page *page) return error; } =20 -static int generic_file_buffered_read_pagenotuptodate(struct kiocb *iocb= , - struct iov_iter *iter, struct page *page, loff_t pos, - loff_t count, bool first) +static int filemap_make_page_uptodate(struct kiocb *iocb, struct iov_ite= r *iter, + struct page *page, pgoff_t pg_index, bool first) { - struct address_space *mapping =3D iocb->ki_filp->f_mapping; + struct file *file =3D iocb->ki_filp; + struct address_space *mapping =3D file->f_mapping; + loff_t last =3D iocb->ki_pos + iter->count; + pgoff_t last_index =3D (last + PAGE_SIZE - 1) >> PAGE_SHIFT; + loff_t pos =3D max(iocb->ki_pos, (loff_t)pg_index << PAGE_SHIFT); int error =3D -EAGAIN; =20 + if (PageReadahead(page)) { + if (iocb->ki_flags & IOCB_NOIO) + goto put_page; + page_cache_async_readahead(mapping, &file->f_ra, file, page, + pg_index, last_index - pg_index); + } + + if (PageUptodate(page)) + return 0; + if (iocb->ki_flags & IOCB_NOWAIT) goto put_page; =20 @@ -2255,8 +2268,8 @@ static int generic_file_buffered_read_pagenotuptoda= te(struct kiocb *iocb, /* Did it get truncated before we got the lock? */ if (!page->mapping) goto page_not_up_to_date_locked; - if (!mapping->a_ops->is_partially_uptodate(page, - pos & ~PAGE_MASK, count)) + if (!mapping->a_ops->is_partially_uptodate(page, pos & ~PAGE_MASK, + last - pos)) goto page_not_up_to_date_locked; =20 unlock_page: @@ -2360,35 +2373,15 @@ static int generic_file_buffered_read_get_pages(s= truct kiocb *iocb, nr_got =3D 1; got_pages: for (i =3D 0; i < nr_got; i++) { - struct page *page =3D pages[i]; - pgoff_t pg_index =3D index + i; - loff_t pg_pos =3D max(iocb->ki_pos, - (loff_t) pg_index << PAGE_SHIFT); - loff_t pg_count =3D iocb->ki_pos + iter->count - pg_pos; - - if (PageReadahead(page)) { - if (iocb->ki_flags & IOCB_NOIO) { - for (j =3D i; j < nr_got; j++) - put_page(pages[j]); - nr_got =3D i; - err =3D -EAGAIN; - break; - } - page_cache_async_readahead(mapping, ra, filp, page, - pg_index, last_index - pg_index); - } - - if (!PageUptodate(page)) { - err =3D generic_file_buffered_read_pagenotuptodate(iocb, - iter, page, pg_pos, pg_count, i =3D=3D 0); - if (err) { - if (err =3D=3D AOP_TRUNCATED_PAGE) - err =3D 0; - for (j =3D i + 1; j < nr_got; j++) - put_page(pages[j]); - nr_got =3D i; - break; - } + err =3D filemap_make_page_uptodate(iocb, iter, pages[i], + index + i, i =3D=3D 0); + if (err) { + if (err =3D=3D AOP_TRUNCATED_PAGE) + err =3D 0; + for (j =3D i + 1; j < nr_got; j++) + put_page(pages[j]); + nr_got =3D i; + break; } } =20 --=20 2.28.0