Received: by 2002:a25:1506:0:0:0:0:0 with SMTP id 6csp781869ybv; Wed, 19 Feb 2020 09:07:20 -0800 (PST) X-Google-Smtp-Source: APXvYqwrW0SGa6C5KHxO9cEQP8I5OeA0okjs47GAFnm3zdEaKgm2Iftjdfa2TlcSw8mOuSMlp3Ki X-Received: by 2002:a05:6830:16d8:: with SMTP id l24mr20428233otr.268.1582132039979; Wed, 19 Feb 2020 09:07:19 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1582132039; cv=none; d=google.com; s=arc-20160816; b=AVanttdya2woKSO0SfttnAJYw4IP1S2eFKblfiXnshn9BFKWRNsLqvGcgoWZKdiVt1 4tVuO4Xa8flsIPW2BKCQU+1ua0+6zOZKGQf7GIdJpjAzcyCTACwfbN4DO9myMMSZf14Q 5nU+kGyxEqkbqPyXhAd3MLMVmA/MJyy4g9WjBjzj5x1zd6xorcefo5Enk+0LPdzHdAYk BgcsETM0a/0guoKaRcX3oN92NCqPMSSppOvUDFsZdng8Ck0gaxOi5h0ZyxWBxRA0PUs8 bah/1mh3cVYUdk7B05mwBewA8inaszyJfzO8i60w3vtynTDWp57h/TPGCoE0WD1wrpAT abhQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:in-reply-to:content-disposition :mime-version:references:message-id:subject:cc:to:from:date :dkim-signature; bh=6hWL64aU7/cD1s4UTpPss89s1pka8CcWGCJ5BHjUC9M=; b=NP6ZE09fZFAqu5jse69x0ZT1ZO4oFSPdlZnaKbiBuLEzH8PT3TyBBxF7E0jA1nrbBm 2v9CZzX/n/ycFYW41vR8EMV8ZUBG1ldyA0Ltg0n/r+fGcLvI25J9jU3OKJ50nJpuOwDz ujht/K8gn9XDaJyxDU7Rg4LmsfIsl+Udj1XWhFLwKPlm+KVYQF3gqfjI7evBbA0SI0zJ r6osEZ+Cvhvqryt2wdwIp1yhOtyL/LWfULWI/x6gOcby64LIoiiOah2BbNflQ0BsMpoq IPLBdhiQqbGTVxj8SbgIOHYQ4Rb9Dn1oDXW7BwvPwq/DTgk9Xc+2w2rg5Muxm2uGsm9Z zhcw== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@infradead.org header.s=bombadil.20170209 header.b=YD6KASfC; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id q9si10051809oif.92.2020.02.19.09.07.04; Wed, 19 Feb 2020 09:07:19 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=fail header.i=@infradead.org header.s=bombadil.20170209 header.b=YD6KASfC; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726828AbgBSRGp (ORCPT + 99 others); Wed, 19 Feb 2020 12:06:45 -0500 Received: from bombadil.infradead.org ([198.137.202.133]:37054 "EHLO bombadil.infradead.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726558AbgBSRGn (ORCPT ); Wed, 19 Feb 2020 12:06:43 -0500 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=bombadil.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=6hWL64aU7/cD1s4UTpPss89s1pka8CcWGCJ5BHjUC9M=; b=YD6KASfCXNzBE2g7U8C3OPAIMa RN+ihaDs+TqA1PVmJY/G+571Br5Ulv0XQc9EhsoYwQWJIGDt5eVY3v+7OW0ZDPPydpAvd+XANKK7o Yieli5fHS4G8IkuA6ZGWdtYi3uF69BcBtjkIg1txQfTuEC38FUNQpMva7d6LZIwTpJqOi2eTnjQ26 vNRvjsTCftaqhGEu3hEvctNIgYhTUrWaBzOu7hsE+5KmGRNAeS2s5R2DU2EMQh/fz/4XG6YC8Yfkl lb7zA1cZfGKpjcKVeyriFSjz0Jf9srJLBGVWu7kMAFznlMRG+bjJHweFWDFekIpMDNj5yFPnAlDOG rO8cGwug==; Received: from willy by bombadil.infradead.org with local (Exim 4.92.3 #3 (Red Hat Linux)) id 1j4So6-00016p-If; Wed, 19 Feb 2020 17:06:42 +0000 Date: Wed, 19 Feb 2020 09:06:42 -0800 From: Matthew Wilcox To: Dave Chinner Cc: linux-fsdevel@vger.kernel.org, linux-mm@kvack.org, linux-kernel@vger.kernel.org, linux-btrfs@vger.kernel.org, linux-erofs@lists.ozlabs.org, linux-ext4@vger.kernel.org, linux-f2fs-devel@lists.sourceforge.net, cluster-devel@redhat.com, ocfs2-devel@oss.oracle.com, linux-xfs@vger.kernel.org Subject: Re: [PATCH v6 17/19] iomap: Restructure iomap_readpages_actor Message-ID: <20200219170642.GS24185@bombadil.infradead.org> References: <20200217184613.19668-1-willy@infradead.org> <20200217184613.19668-31-willy@infradead.org> <20200219032900.GE10776@dread.disaster.area> <20200219060415.GO24185@bombadil.infradead.org> <20200219064005.GL10776@dread.disaster.area> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20200219064005.GL10776@dread.disaster.area> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Wed, Feb 19, 2020 at 05:40:05PM +1100, Dave Chinner wrote: > Ok, that's what the ctx.cur_page_in_bio check is used to detect i.e. > if we've got a page that the readahead cursor points at, and we > haven't actually added it to a bio, then we can leave it to the > read_pages() to unlock and clean up. If it's in a bio, then IO > completion will unlock it and so we only have to drop the submission > reference and move the readahead cursor forwards so read_pages() > doesn't try to unlock this page. i.e: > > /* clean up partial page submission failures */ > if (ctx.cur_page && ctx.cur_page_in_bio) { > put_page(ctx.cur_page); > readahead_next(rac); > } > > looks to me like it will handle the case of "ret == 0" in the actor > function just fine. Here's what I ended up with: @@ -400,15 +400,9 @@ iomap_readpages_actor(struct inode *inode, loff_t pos, loff_t length, void *data, struct iomap *iomap, struct iomap *srcmap) { struct iomap_readpage_ctx *ctx = data; - loff_t done, ret; - - for (done = 0; done < length; done += ret) { - if (ctx->cur_page && offset_in_page(pos + done) == 0) { - if (!ctx->cur_page_in_bio) - unlock_page(ctx->cur_page); - put_page(ctx->cur_page); - ctx->cur_page = NULL; - } + loff_t ret, done = 0; + + while (done < length) { if (!ctx->cur_page) { ctx->cur_page = iomap_next_page(inode, ctx->pages, pos, length, &done); @@ -418,6 +412,20 @@ iomap_readpages_actor(struct inode *inode, loff_t pos, loff_t length, } ret = iomap_readpage_actor(inode, pos + done, length - done, ctx, iomap, srcmap); + done += ret; + + /* Keep working on a partial page */ + if (ret && offset_in_page(pos + done)) + continue; + + if (!ctx->cur_page_in_bio) + unlock_page(ctx->cur_page); + put_page(ctx->cur_page); + ctx->cur_page = NULL; + + /* Don't loop forever if we made no progress */ + if (WARN_ON(!ret)) + break; } return done; @@ -451,11 +459,7 @@ iomap_readpages(struct address_space *mapping, struct list_head *pages, done: if (ctx.bio) submit_bio(ctx.bio); - if (ctx.cur_page) { - if (!ctx.cur_page_in_bio) - unlock_page(ctx.cur_page); - put_page(ctx.cur_page); - } + BUG_ON(ctx.cur_page); /* * Check that we didn't lose a page due to the arcance calling so we'll WARN if we get a ret == 0 (matching ->readpage), and we'll BUG if we ever see a page being leaked out of readpages_actor, which is a thing that should never happen and we definitely want to be noisy about if it does.