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 DE839C388F7 for ; Tue, 10 Nov 2020 03:38:12 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 52E1721D7F for ; Tue, 10 Nov 2020 03:37:40 +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="TBn40tnS" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 52E1721D7F 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 B46976B007D; Mon, 9 Nov 2020 22:37:20 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id ACCCF6B007E; Mon, 9 Nov 2020 22:37:20 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 996086B0080; Mon, 9 Nov 2020 22:37:20 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0016.hostedemail.com [216.40.44.16]) by kanga.kvack.org (Postfix) with ESMTP id 60CE96B007E for ; Mon, 9 Nov 2020 22:37:20 -0500 (EST) Received: from smtpin27.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay04.hostedemail.com (Postfix) with ESMTP id 08F221EE6 for ; Tue, 10 Nov 2020 03:37:20 +0000 (UTC) X-FDA: 77467098240.27.hole12_6300466272f1 Received: from filter.hostedemail.com (10.5.16.251.rfc1918.com [10.5.16.251]) by smtpin27.hostedemail.com (Postfix) with ESMTP id E5FE13D663 for ; Tue, 10 Nov 2020 03:37:19 +0000 (UTC) X-HE-Tag: hole12_6300466272f1 X-Filterd-Recvd-Size: 5303 Received: from casper.infradead.org (casper.infradead.org [90.155.50.34]) by imf27.hostedemail.com (Postfix) with ESMTP for ; Tue, 10 Nov 2020 03:37:19 +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=p6/FzLUqNq8Oj1Kl3pi7IxuekojVQysmc5spzhprX8U=; b=TBn40tnSi2ETC0F7AosdAOQRi9 faNmhZ+q7JZoa82e0F0uitcfAeq3iAcQBcE7pOUYlYGRK5QkVQkgYlTz+LsUD5u8moKyTZPjKMe98 CGD0vzgCt+LUU5cmDOhKUOCxqz0I+m2XqwySD2WgP7IDTSX50uFcEr5ehTnmIYx7Wh6LNuTN0Owka ZU8VIEgi/JcJ/MgvVrA6rAmjcRdWVbez9dzMe1Ypv4rZfACZWQNU2rChyn74ffTuUHdxu5ZOq7z7C HT4r/3WKmU/dapvJFtHjLCHEh2aZNNBuuKVuhBUdYKaTMu/r7VlRobfAKUxIwUWd94gY8oI4ZmeUa JjV022Cg==; Received: from willy by casper.infradead.org with local (Exim 4.92.3 #3 (Red Hat Linux)) id 1kcKT4-00066k-Kb; Tue, 10 Nov 2020 03:37:15 +0000 From: "Matthew Wilcox (Oracle)" To: linux-fsdevel@vger.kernel.org, linux-mm@kvack.org Cc: "Matthew Wilcox (Oracle)" , hch@lst.de, kent.overstreet@gmail.com Subject: [PATCH v3 13/18] mm/filemap: Add filemap_range_uptodate Date: Tue, 10 Nov 2020 03:36:58 +0000 Message-Id: <20201110033703.23261-14-willy@infradead.org> X-Mailer: git-send-email 2.21.3 In-Reply-To: <20201110033703.23261-1-willy@infradead.org> References: <20201110033703.23261-1-willy@infradead.org> MIME-Version: 1.0 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 complicated condition and the calculations out of filemap_update_page() into its own function. Signed-off-by: Matthew Wilcox (Oracle) Reviewed-by: Kent Overstreet --- mm/filemap.c | 71 +++++++++++++++++++++++++++++++--------------------- 1 file changed, 43 insertions(+), 28 deletions(-) diff --git a/mm/filemap.c b/mm/filemap.c index 2218fe610c42..1cacadef0ded 100644 --- a/mm/filemap.c +++ b/mm/filemap.c @@ -2231,11 +2231,39 @@ static int filemap_read_page(struct file *file, s= truct address_space *mapping, return error; } =20 +static bool filemap_range_uptodate(struct kiocb *iocb, + struct address_space *mapping, struct iov_iter *iter, + struct page *page) +{ + loff_t pos; + int count; + + if (PageUptodate(page)) + return true; + /* pipes can't handle partially uptodate pages */ + if (iov_iter_is_pipe(iter)) + return false; + if (!mapping->a_ops->is_partially_uptodate) + return false; + if (mapping->host->i_blkbits >=3D (PAGE_SHIFT + thp_order(page))) + return false; + + pos =3D (loff_t) page->index << PAGE_SHIFT; + if (pos > iocb->ki_pos) { + count =3D iocb->ki_pos + iter->count - pos; + pos =3D 0; + } else { + count =3D iter->count; + pos =3D iocb->ki_pos & (thp_size(page) - 1); + } + + return mapping->a_ops->is_partially_uptodate(page, pos, count); +} + static int filemap_update_page(struct kiocb *iocb, struct address_space *mapping, struct iov_iter *iter, - struct page *page, loff_t pos, loff_t count) + struct page *page) { - struct inode *inode =3D mapping->host; int error; =20 if (!trylock_page(page)) { @@ -2252,34 +2280,25 @@ static int filemap_update_page(struct kiocb *iocb= , =20 if (!page->mapping) goto truncated; - if (PageUptodate(page)) - goto uptodate; - if (inode->i_blkbits =3D=3D PAGE_SHIFT || - !mapping->a_ops->is_partially_uptodate) - goto readpage; - /* pipes can't handle partially uptodate pages */ - if (unlikely(iov_iter_is_pipe(iter))) - goto readpage; - if (!mapping->a_ops->is_partially_uptodate(page, - pos & (thp_size(page) - 1), count)) - goto readpage; -uptodate: - unlock_page(page); - return 0; =20 -readpage: - if (iocb->ki_flags & (IOCB_NOIO | IOCB_NOWAIT | IOCB_WAITQ)) { - unlock_page(page); - return -EAGAIN; - } + error =3D 0; + if (filemap_range_uptodate(iocb, mapping, iter, page)) + goto unlock; + + error =3D -EAGAIN; + if (iocb->ki_flags & (IOCB_NOIO | IOCB_NOWAIT | IOCB_WAITQ)) + goto unlock; + error =3D filemap_read_page(iocb->ki_filp, mapping, page); if (error =3D=3D AOP_TRUNCATED_PAGE) put_page(page); return error; truncated: - unlock_page(page); + error =3D AOP_TRUNCATED_PAGE; put_page(page); - return AOP_TRUNCATED_PAGE; +unlock: + unlock_page(page); + return error; } =20 static int filemap_create_page(struct file *file, @@ -2349,9 +2368,6 @@ static int filemap_get_pages(struct kiocb *iocb, st= ruct iov_iter *iter, { struct page *page =3D pvec->pages[pvec->nr - 1]; pgoff_t pg_index =3D page->index; - 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; =20 if (PageReadahead(page)) { if (iocb->ki_flags & IOCB_NOIO) { @@ -2368,8 +2384,7 @@ static int filemap_get_pages(struct kiocb *iocb, st= ruct iov_iter *iter, if ((iocb->ki_flags & IOCB_WAITQ) && pagevec_count(pvec) > 1) iocb->ki_flags |=3D IOCB_NOWAIT; - err =3D filemap_update_page(iocb, mapping, iter, page, - pg_pos, pg_count); + err =3D filemap_update_page(iocb, mapping, iter, page); if (err) { if (err < 0) put_page(page); --=20 2.28.0