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 Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id BDFA4C46CD2 for ; Tue, 30 Jan 2024 14:32:34 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 4E7486B0075; Tue, 30 Jan 2024 09:32:34 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 495CB6B007D; Tue, 30 Jan 2024 09:32:34 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 384E36B0080; Tue, 30 Jan 2024 09:32:34 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0011.hostedemail.com [216.40.44.11]) by kanga.kvack.org (Postfix) with ESMTP id 281396B0075 for ; Tue, 30 Jan 2024 09:32:34 -0500 (EST) Received: from smtpin11.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay01.hostedemail.com (Postfix) with ESMTP id B7E1C1C1572 for ; Tue, 30 Jan 2024 14:32:33 +0000 (UTC) X-FDA: 81736218186.11.2DDD1EE Received: from verein.lst.de (verein.lst.de [213.95.11.211]) by imf09.hostedemail.com (Postfix) with ESMTP id A3B5A140038 for ; Tue, 30 Jan 2024 14:32:31 +0000 (UTC) Authentication-Results: imf09.hostedemail.com; dkim=none; dmarc=none; spf=pass (imf09.hostedemail.com: domain of hch@lst.de designates 213.95.11.211 as permitted sender) smtp.mailfrom=hch@lst.de ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1706625152; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=FYFcKFCIXoFoTsDVhLMs1KPqEmvm9/8x0qkXUnS7HQc=; b=TvY/yREdeEyx4AEZeCnfVcq24OpEBMvZui7Jy0/1V3mOOSWN0VqugYId64Zpy0DHzusYEl 26t9fZJvgJE41KOQUTOK46thU8qkoVvVvlvek8vbPMhtNxkUe7mghMk86zOtua4joj1Rqw 0S/8BpzY1gwZmSHKsc2GRZr6NwxtkY4= ARC-Authentication-Results: i=1; imf09.hostedemail.com; dkim=none; dmarc=none; spf=pass (imf09.hostedemail.com: domain of hch@lst.de designates 213.95.11.211 as permitted sender) smtp.mailfrom=hch@lst.de ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1706625152; a=rsa-sha256; cv=none; b=olv+t0kFQWCYJtXKYxOQl7BZoouI5ARwhGIriFmI9Pe2yIz3Etn6duZ4eORTzheMyahr7d nJFNz6p0bjKIvL+/vMs4CShMDQKnvgj4i6Jg1NMJvrtuXtdjPFFPSbAb8FCy7YaihjDodI tYzyVX5rHK2Y/h4MIanPzbZEnc+YkUg= Received: by verein.lst.de (Postfix, from userid 2407) id C8B1B68B05; Tue, 30 Jan 2024 15:32:27 +0100 (CET) Date: Tue, 30 Jan 2024 15:32:27 +0100 From: Christoph Hellwig To: Jan Kara Cc: Christoph Hellwig , linux-mm@kvack.org, Matthew Wilcox , Jan Kara , David Howells , Brian Foster , Christian Brauner , "Darrick J. Wong" , linux-xfs@vger.kernel.org, linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH 19/19] writeback: simplify writeback iteration Message-ID: <20240130143227.GC31330@lst.de> References: <20240125085758.2393327-1-hch@lst.de> <20240125085758.2393327-20-hch@lst.de> <20240130104605.2i6mmdncuhwwwfin@quack3> <20240130141601.GA31330@lst.de> <20240130142205.GB31330@lst.de> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20240130142205.GB31330@lst.de> User-Agent: Mutt/1.5.17 (2007-11-01) X-Rspamd-Queue-Id: A3B5A140038 X-Rspam-User: X-Rspamd-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Q7UaPVfSODvIOg89XGiXfuJYbTY1tVc= 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: List-Subscribe: List-Unsubscribe: On Tue, Jan 30, 2024 at 03:22:05PM +0100, Christoph Hellwig wrote: > And now for real: Another slight variant of this would be to move the nr_to_write || err check for WB_SYNC_NONE out of the branch. This adds extra tests for the initial iteration, but unindents a huge comment, and moves it closer to the other branch that it also describes. The downside at least to me is that the normal non-termination path is not the straight line through function. Thoughs? diff --git a/mm/page-writeback.c b/mm/page-writeback.c index 973f57ad9ee548..ff6e73453aa8c4 100644 --- a/mm/page-writeback.c +++ b/mm/page-writeback.c @@ -2461,24 +2461,6 @@ struct folio *writeback_iter(struct address_space *mapping, wbc->nr_to_write -= folio_nr_pages(folio); if (*error && !wbc->err) wbc->err = *error; - - /* - * For integrity sync we have to keep going until we have - * written all the folios we tagged for writeback prior to - * entering the writeback loop, even if we run past - * wbc->nr_to_write or encounter errors. - * - * This is because the file system may still have state to clear - * for each folio. We'll eventually return the first error - * encountered. - * - * For background writeback just push done_index past this folio - * so that we can just restart where we left off and media - * errors won't choke writeout for the entire file. - */ - if (wbc->sync_mode == WB_SYNC_NONE && - (wbc->err || wbc->nr_to_write <= 0)) - goto finish; } else { if (wbc->range_cyclic) wbc->index = mapping->writeback_index; /* prev offset */ @@ -2491,17 +2473,20 @@ struct folio *writeback_iter(struct address_space *mapping, wbc->err = 0; } - folio = writeback_get_folio(mapping, wbc); - if (!folio) - goto finish; - return folio; - -finish: - folio_batch_release(&wbc->fbatch); - /* + * For integrity sync we have to keep going until we have written all + * the folios we tagged for writeback prior to entering the writeback + * loop, even if we run past wbc->nr_to_write or encounter errors. + * + * This is because the file system may still have state to clear for + * each folio. We'll eventually return the first error encountered. + * + * For background writeback just push done_index past this folio so that + * we can just restart where we left off and media errors won't choke + * writeout for the entire file. + * * For range cyclic writeback we need to remember where we stopped so - * that we can continue there next time we are called. If we hit the + * that we can continue there next time we are called. If we hit the * last page and there is more work to be done, wrap back to the start * of the file. * @@ -2509,14 +2494,21 @@ struct folio *writeback_iter(struct address_space *mapping, * of the file if we are called again, which can only happen due to * -ENOMEM from the file system. */ - if (wbc->range_cyclic) { - WARN_ON_ONCE(wbc->sync_mode != WB_SYNC_NONE); - if (wbc->err || wbc->nr_to_write <= 0) + if (wbc->sync_mode == WB_SYNC_NONE && + (wbc->err || wbc->nr_to_write <= 0)) { + if (wbc->range_cyclic) mapping->writeback_index = folio->index + folio_nr_pages(folio); - else + } else { + folio = writeback_get_folio(mapping, wbc); + if (folio) + return folio; + + if (wbc->range_cyclic) mapping->writeback_index = 0; } + + folio_batch_release(&wbc->fbatch); *error = wbc->err; return NULL; }