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=-6.5 required=3.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH,MAILING_LIST_MULTI, SPF_HELO_NONE,SPF_PASS autolearn=no 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 411F6C55178 for ; Tue, 3 Nov 2020 15:18:55 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id A23D7221FB for ; Tue, 3 Nov 2020 15:18:54 +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="bcCphGH0" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org A23D7221FB 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 BDFF26B006C; Tue, 3 Nov 2020 10:18:53 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id B99866B0072; Tue, 3 Nov 2020 10:18:53 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id A336E6B0073; Tue, 3 Nov 2020 10:18:53 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0211.hostedemail.com [216.40.44.211]) by kanga.kvack.org (Postfix) with ESMTP id 759DB6B006C for ; Tue, 3 Nov 2020 10:18:53 -0500 (EST) Received: from smtpin06.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay04.hostedemail.com (Postfix) with ESMTP id 1DC3B1EE6 for ; Tue, 3 Nov 2020 15:18:53 +0000 (UTC) X-FDA: 77443464546.06.comb39_3110312272b9 Received: from filter.hostedemail.com (10.5.16.251.rfc1918.com [10.5.16.251]) by smtpin06.hostedemail.com (Postfix) with ESMTP id EE6971003A945 for ; Tue, 3 Nov 2020 15:18:52 +0000 (UTC) X-HE-Tag: comb39_3110312272b9 X-Filterd-Recvd-Size: 4374 Received: from casper.infradead.org (casper.infradead.org [90.155.50.34]) by imf06.hostedemail.com (Postfix) with ESMTP for ; Tue, 3 Nov 2020 15:18:52 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=casper.20170209; h=In-Reply-To:Content-Type:MIME-Version: References:Message-ID:Subject:Cc:To:From:Date:Sender:Reply-To: Content-Transfer-Encoding:Content-ID:Content-Description; bh=p3irT3qFc+4BiDVPWzQS/NgjF9KfOecBSFvDs8AOBLo=; b=bcCphGH0lgZ2Kfq/L/sSvuEjUH 5VfW5MkUG7AiQwiRQtdaRi5BQHUc58AAlbIGC3A3yJrkATxZcj5+tTFdOgZcUVjSKwzkyG3hhxIz7 IkUW/IxqrAbr/o7nV/QF25JpNz9lSWB1xwfXtExmA8y0KUcrj4ijwRB0RWmsxbMb4Ts1HbEldJzvM qRkzM8C1Yf3YgWUeQN6dQgwuxgvdGX/89f7+64Ks0Wor4j7m9Jm+4HIdGj67YCACBsbLhluRm0OoA r3PlYLkyDe82wubHKYJJonJfrJgts8NedZMGDx6/SnRvl8BUrAXU32XGeg+1Thakyi/5c3FlS5Y5+ ITpPIhVw==; Received: from willy by casper.infradead.org with local (Exim 4.92.3 #3 (Red Hat Linux)) id 1kZy59-0006Ee-LI; Tue, 03 Nov 2020 15:18:47 +0000 Date: Tue, 3 Nov 2020 15:18:47 +0000 From: Matthew Wilcox To: Christoph Hellwig Cc: linux-fsdevel@vger.kernel.org, linux-mm@kvack.org, kent.overstreet@gmail.com Subject: Re: [PATCH 11/17] mm/filemap: Add filemap_range_uptodate Message-ID: <20201103151847.GZ27442@casper.infradead.org> References: <20201102184312.25926-1-willy@infradead.org> <20201102184312.25926-12-willy@infradead.org> <20201103074944.GK8389@lst.de> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20201103074944.GK8389@lst.de> 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: On Tue, Nov 03, 2020 at 08:49:44AM +0100, Christoph Hellwig wrote: > On Mon, Nov 02, 2020 at 06:43:06PM +0000, Matthew Wilcox (Oracle) wrote: > > Move the complicated condition and the calculations out of > > filemap_update_page() into its own function. > > The logic looks good, but the flow inside of filemap_update_page looks > odd. The patch below relative to this commit shows how I'd do it: I have a simplification in mind that gets rid of the awkward 'first' parameter. In filemap_get_pages(), do: if ((iocb->ki_flags & IOCB_WAITQ) && (pagevec_count(pvec) > 1)) iocb->ki_flags |= IOCB_NOWAIT; before calling filemap_update_page(). That matches what Kent did in filemap_read(): if ((iocb->ki_flags & IOCB_WAITQ) && already_read) iocb->ki_flags |= IOCB_NOWAIT; > diff --git a/mm/filemap.c b/mm/filemap.c > index 81b569d818a3f8..304180c022d38a 100644 > --- a/mm/filemap.c > +++ b/mm/filemap.c > @@ -2266,40 +2266,39 @@ static int filemap_update_page(struct kiocb *iocb, > if (!trylock_page(page)) { > if (iocb->ki_flags & (IOCB_NOWAIT | IOCB_NOIO)) > goto error; > - if (iocb->ki_flags & IOCB_WAITQ) { > - if (!first) > - goto error; > - error = __lock_page_async(page, iocb->ki_waitq); > - if (error) > - goto error; > - } else { > + if (!(iocb->ki_flags & IOCB_WAITQ)) { > put_and_wait_on_page_locked(page, TASK_KILLABLE); > return AOP_TRUNCATED_PAGE; > } > + if (!first) > + goto error; > + error = __lock_page_async(page, iocb->ki_waitq); > + if (error) > + goto error; > } I see where you're going there. OK. > > + error = AOP_TRUNCATED_PAGE; > if (!page->mapping) > - goto truncated; > - if (filemap_range_uptodate(iocb, mapping, iter, page)) { > - unlock_page(page); > - return 0; > - } > + goto error_unlock_page; > > - if (iocb->ki_flags & (IOCB_NOIO | IOCB_NOWAIT | IOCB_WAITQ)) { > - unlock_page(page); > + if (!filemap_range_uptodate(iocb, mapping, iter, page)) { > error = -EAGAIN; > - } else { > + if (iocb->ki_flags & (IOCB_NOIO | IOCB_NOWAIT | IOCB_WAITQ)) > + goto error_unlock_page; > error = filemap_read_page(iocb->ki_filp, mapping, page); > - if (!error) > - return 0; > + if (error) > + goto error; > + return 0; /* filemap_read_page unlocks the page */ > } > + > + unlock_page(page); > + return 0; > + > +error_unlock_page: > + unlock_page(page); > error: > put_page(page); > return error; > -truncated: > - unlock_page(page); > - put_page(page); > - return AOP_TRUNCATED_PAGE; > } There's something niggling at me about this change ... I'll play with it a bit.