Received: by 2002:a05:7412:d1aa:b0:fc:a2b0:25d7 with SMTP id ba42csp1046791rdb; Tue, 30 Jan 2024 06:33:51 -0800 (PST) X-Google-Smtp-Source: AGHT+IH/iiqr39RzFwNmGC4itBo1GNIT8Cyz0FPzowL2j5UfbB3G6IBgHtmsqIwACN6CXeUPUVf4 X-Received: by 2002:a05:6a00:4b16:b0:6db:d285:ee3e with SMTP id kq22-20020a056a004b1600b006dbd285ee3emr7767516pfb.23.1706625231585; Tue, 30 Jan 2024 06:33:51 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1706625231; cv=pass; d=google.com; s=arc-20160816; b=Qs64+1sVW3rQGu73tBpkCZVVDetc7N+6tMXSrv2QEKeupu2zh9Iq/WaSKQc4fI0IG+ Sbv9BNd1gmDR1ul2hrb4xqHNoPBZVg7WDLTLXfbmV1PF0QIPgNaz7T4elVWssAQwcAHe +dCfs6rqoBygWRAtu/k/zVddWE/SYvgdG/25cEemgKfiVG+E7r03o4S2eXbrEnFKQsO4 YzdWOGtXyxoCc3tE8oVWZr+8WFlZHCubEcWnMAoDix9XmNgqewLSV6SG43dXianoy0Tm rARHYD3xkMGaDbmOlKwtZqCfHkqRqkpkX2FFTomIm9qpdnruWCBo/bDg2h2oS+2QlqlH duCA== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=user-agent:in-reply-to:content-disposition:mime-version :list-unsubscribe:list-subscribe:list-id:precedence:references :message-id:subject:cc:to:from:date; bh=FYFcKFCIXoFoTsDVhLMs1KPqEmvm9/8x0qkXUnS7HQc=; fh=nXbUcV7x7g6s4I96XK8uOKt4C3JEo1/jzFKCJ616FQI=; b=pa3s0e1gD6+NVyehmjHaTL9MyJ3j90EzH5pd3QzfY9oH9GLISQHkg1KAr+x3OvoRWU V6IzgCdNj5XWquoUJ4Khu3J7nZ72ZRWv/oaJ9B6rxm6c4M3CEtJ9uQXVunJ8rfoL6VZr rZk2PNmmkbK04W59Q8qqByOk8DAWb6Dzq0MH+sVxxaueDB/OlQKRIlm0az/NzLrWRiIk 3+U+C4hV5viip6Lzxv1f7llh392Tm1UiOgo1Sn7bJfJlsaF/XT9hsRLozTs9Prq6xw3q HgljM75VRB+ySSqQzctNNlkvFPXv6/2bH+xjEDpuo3u8LTyPuv1i7I8N/AmNbQhLoFhF ABxQ== ARC-Authentication-Results: i=2; mx.google.com; arc=pass (i=1 spf=pass spfdomain=lst.de); spf=pass (google.com: domain of linux-kernel+bounces-44753-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-44753-linux.lists.archive=gmail.com@vger.kernel.org" Return-Path: Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [139.178.88.99]) by mx.google.com with ESMTPS id b12-20020aa7870c000000b006ddcec3656dsi7552113pfo.251.2024.01.30.06.33.51 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 30 Jan 2024 06:33:51 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-44753-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) client-ip=139.178.88.99; Authentication-Results: mx.google.com; arc=pass (i=1 spf=pass spfdomain=lst.de); spf=pass (google.com: domain of linux-kernel+bounces-44753-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-44753-linux.lists.archive=gmail.com@vger.kernel.org" Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sv.mirrors.kernel.org (Postfix) with ESMTPS id 697CF285C86 for ; Tue, 30 Jan 2024 14:32:49 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 798DF6F070; Tue, 30 Jan 2024 14:32:35 +0000 (UTC) Received: from verein.lst.de (verein.lst.de [213.95.11.211]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id A83116DD03; Tue, 30 Jan 2024 14:32:32 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=213.95.11.211 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706625155; cv=none; b=V9YunkJ4tO+OOv/yTa1Zhuuw837XQ9paiYoIqK6f8XfupT7/HVZB/4YICbG/iSofAcEtPgq+lDS1iehvxOAWSz/Ynxrvc6rtnVYIq/D1nW1zf4mpwR8qApSoxVL1hZR7Vm8AUPLTqUu8qDUgbQrjBDXSjUpLC+rRUD1bPOUEBgI= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706625155; c=relaxed/simple; bh=Z7EH6XvVnLFGgUq3HBLgyE6pJaaNG87//RotfEpd5bM=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=ifoH5o1tVuASOM5QqI2waZ8QwGFV7bnRbyDR8/AE9QLOUlBVuoede/2NiCpUuylDZbueweAhAQH6sb/T+6W6hSfSppcAzG9C+HPBgq+bzLk1hg9rkLhekl9CE2H+An/pzLWvjCT3M03ZKkoMQGgpb4QxzhWZ61m/36FkaozHq2Q= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=lst.de; spf=pass smtp.mailfrom=lst.de; arc=none smtp.client-ip=213.95.11.211 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=lst.de Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=lst.de 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> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: 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) 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; }