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 0DDDCC433E0 for ; Thu, 21 Jan 2021 04:27:51 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 8A05D2389A for ; Thu, 21 Jan 2021 04:27:50 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 8A05D2389A 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 068FD6B0008; Wed, 20 Jan 2021 23:27:50 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 019E06B000C; Wed, 20 Jan 2021 23:27:49 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id E24406B000D; Wed, 20 Jan 2021 23:27:49 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0221.hostedemail.com [216.40.44.221]) by kanga.kvack.org (Postfix) with ESMTP id CE3996B0008 for ; Wed, 20 Jan 2021 23:27:49 -0500 (EST) Received: from smtpin10.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay02.hostedemail.com (Postfix) with ESMTP id 9E4213647 for ; Thu, 21 Jan 2021 04:27:49 +0000 (UTC) X-FDA: 77728499058.10.salt19_3a1302127560 Received: from filter.hostedemail.com (10.5.16.251.rfc1918.com [10.5.16.251]) by smtpin10.hostedemail.com (Postfix) with ESMTP id 7CE8B16A4C0 for ; Thu, 21 Jan 2021 04:27:49 +0000 (UTC) X-HE-Tag: salt19_3a1302127560 X-Filterd-Recvd-Size: 5224 Received: from casper.infradead.org (casper.infradead.org [90.155.50.34]) by imf25.hostedemail.com (Postfix) with ESMTP for ; Thu, 21 Jan 2021 04:27:48 +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=PfsugLMlMKM6Eja7Rl0rIsDhrIsWo7j34Z7nIC0Z8zU=; b=RS+/nXccKBqmC2cEMYpopG5tlO 4cOtABty6oC1c1KRHikB1WMmGBOIRELXQwKy03LpDNKf/IoyXc7EK3cKhL6GheaOpluRAQhhYMYCg 9mLlriuaIDL0JJOza7TAFAPKm07G0OvS8r7vCvw1mMOwDDr3s1Zon5VFIfIbaT+FXGwpjcHaR7jnD ozDPX+XH3BfkREIZ/EaueaQj0omWifxz/fOxds1ZyQOZwIyq5UwgD8Fvo85RQ3vyC/H3bTQ3Ek1e8 06phhurooYx46Ne8dnzB+8+v823t2nLs8QQPA5JOAghE4wLUNrZ8HTFSsK79JIAqoBWX9sp16kfyB 6DuiC7JA==; Received: from willy by casper.infradead.org with local (Exim 4.94 #2 (Red Hat Linux)) id 1l2RYS-00GbeX-Pw; Thu, 21 Jan 2021 04:26:50 +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 v4 13/18] mm/filemap: Add filemap_range_uptodate Date: Thu, 21 Jan 2021 04:16:11 +0000 Message-Id: <20210121041616.3955703-14-willy@infradead.org> X-Mailer: git-send-email 2.29.2 In-Reply-To: <20210121041616.3955703-1-willy@infradead.org> References: <20210121041616.3955703-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 | 68 ++++++++++++++++++++++++++++++---------------------- 1 file changed, 40 insertions(+), 28 deletions(-) diff --git a/mm/filemap.c b/mm/filemap.c index 141d5917770d6..df755b86a0a7b 100644 --- a/mm/filemap.c +++ b/mm/filemap.c @@ -2223,11 +2223,36 @@ static int filemap_read_page(struct file *file, s= truct address_space *mapping, return error; } =20 +static bool filemap_range_uptodate(struct address_space *mapping, + loff_t pos, struct iov_iter *iter, struct page *page) +{ + 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; + + count =3D iter->count; + if (page_offset(page) > pos) { + count -=3D page_offset(page) - pos; + pos =3D 0; + } else { + pos -=3D page_offset(page); + } + + 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)) { @@ -2244,34 +2269,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(mapping, iocb->ki_pos, 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, @@ -2341,9 +2357,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) { @@ -2360,8 +2373,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.29.2