Received: by 2002:a05:7412:8d10:b0:f3:1519:9f41 with SMTP id bj16csp5981005rdb; Thu, 14 Dec 2023 05:26:46 -0800 (PST) X-Google-Smtp-Source: AGHT+IEawVp+f9rdf9jbirDUa9VETkdyto8nmKMb3UvCINCZ0VnBqXXwhL9e8HVaQS6zFSn2s8io X-Received: by 2002:a05:6830:a55:b0:6da:aa8:5c0e with SMTP id g21-20020a0568300a5500b006da0aa85c0emr8248290otu.34.1702560406223; Thu, 14 Dec 2023 05:26:46 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1702560406; cv=none; d=google.com; s=arc-20160816; b=k4rS+PyaJRgUmOY1bYtGxzK9iQhWJLC3fu8e/pgZJZWReEqHCuxhvtuJyQKijYBZOL UrDA3pTICCWKng3jrgDHCkHTps4OYJIO5U3RamqM0zclU6/3ZtgtEc3jwZuzguTukley 6Mp6DF9V4/i7QZPqHgXqzMamdvSYuY2Mi4ocYYf/8j4nvI/lr9eU0eNe0nrNuEmz9sZk Lj4BzQ8/pQVudxdzFdWVh+m5euP7ES5EtYrz+uAdcwaZEIBBXNRzTuwjenoV4r1EnZa3 7b+1K5RHewwsVSbPwS2s47JtOzuRSPMPYmo2dAnqPtI577/pcdjeaYWfs3rHV59BQWa2 /JZw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=+EjBTTu0WiLV+Q73nxsWHktHLf8xanuJ2SDeP86Fuu8=; fh=s6qbYcpKmY0AEsK/gKDpT3qiaGyyaU+hQ5h16uVwDEk=; b=OD0HaIFnLv+ByVlPozS+qQq1B9nsWOy6AP7k8dIVgM5Xgw6D47ONtvQZRrPScJb0dD Ec9ILNEhO9z23fU4+RBPSRu+uGvs6By8Xcd5foSK1K7EEjf2IfpIPXGbMvj8NS61adTK BEThPvtE1q0KEH75uwhdQqAj5yUGdVhZhvgWfwXEpBCnGWNt1vnCVmEu8dM9iIkBgj14 brk0yky5J275nyQ2gIJtz8Ug8dTaS15SRRftfUainiCgtVGyT89Ty0TCsGHgj31r6oUU 25zkj6E6UFw22yInc89ZzzQIPja6o1R2DWkWMZychuB/FMJmj/3kgnzhjJrni7YdcixT +Uzg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@infradead.org header.s=bombadil.20210309 header.b=FpcH5Bmf; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.37 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from snail.vger.email (snail.vger.email. [23.128.96.37]) by mx.google.com with ESMTPS id c32-20020a634e20000000b005b95ccd1b4dsi11115038pgb.82.2023.12.14.05.26.45 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 14 Dec 2023 05:26:46 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.37 as permitted sender) client-ip=23.128.96.37; Authentication-Results: mx.google.com; dkim=pass header.i=@infradead.org header.s=bombadil.20210309 header.b=FpcH5Bmf; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.37 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by snail.vger.email (Postfix) with ESMTP id DFBC68025729; Thu, 14 Dec 2023 05:26:44 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at snail.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1573324AbjLNN0c (ORCPT + 99 others); Thu, 14 Dec 2023 08:26:32 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57844 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1573314AbjLNN0W (ORCPT ); Thu, 14 Dec 2023 08:26:22 -0500 Received: from bombadil.infradead.org (bombadil.infradead.org [IPv6:2607:7c80:54:3::133]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 3077E10F; Thu, 14 Dec 2023 05:26:28 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=bombadil.20210309; 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=+EjBTTu0WiLV+Q73nxsWHktHLf8xanuJ2SDeP86Fuu8=; b=FpcH5BmfnsmbIgWMunX3/hZPox tLAIZ4W/GC6ayMAPNn5BY589vQNYhvpCUHsur984ldcZbvmNVmyABftvrU8KE0pxTLjrF/LT/lF6h SiflrOMvjG+E1PERscpCGlpvsObop7COIxi6gE91+X0cch22c4DoY7nQHyHRL1yFc2u2hfZZOFomB HXmpsS0q7VhQuYxeu8rRNY+C/aQRPGP9bmc3cMhWDWqkkF3gpfPUI9+2H4YOMkDdjkx2ZMV1YtHbc yBPNNlsuIhZzoQYxOnc6gtiz5hY+BMwSY0GP/N1RdxH7A7pmUVX/bJlYXECIOQmgGJr+9r7+K2c92 Wog0fx2Q==; Received: from [88.128.88.27] (helo=localhost) by bombadil.infradead.org with esmtpsa (Exim 4.96 #2 (Red Hat Linux)) id 1rDljP-000NEm-28; Thu, 14 Dec 2023 13:26:28 +0000 From: Christoph Hellwig To: linux-mm@kvack.org Cc: "Matthew Wilcox (Oracle)" , linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org, Jan Kara , David Howells Subject: [PATCH 10/11] writeback: Add for_each_writeback_folio() Date: Thu, 14 Dec 2023 14:25:43 +0100 Message-Id: <20231214132544.376574-11-hch@lst.de> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20231214132544.376574-1-hch@lst.de> References: <20231214132544.376574-1-hch@lst.de> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-SRS-Rewrite: SMTP reverse-path rewritten from by bombadil.infradead.org. See http://www.infradead.org/rpr.html X-Spam-Status: No, score=-1.8 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_EF,HEADER_FROM_DIFFERENT_DOMAINS, RCVD_IN_DNSWL_BLOCKED,SPF_HELO_NONE,SPF_NONE,T_SCC_BODY_TEXT_LINE autolearn=no autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (snail.vger.email [0.0.0.0]); Thu, 14 Dec 2023 05:26:45 -0800 (PST) From: "Matthew Wilcox (Oracle)" Wrap up the iterator with a nice bit of syntactic sugar. Now the caller doesn't need to know about wbc->err and can just return error, not knowing that the iterator took care of storing errors correctly. Signed-off-by: Matthew Wilcox (Oracle) Signed-off-by: Christoph Hellwig --- include/linux/writeback.h | 14 +++++++++++--- mm/page-writeback.c | 11 ++++------- 2 files changed, 15 insertions(+), 10 deletions(-) diff --git a/include/linux/writeback.h b/include/linux/writeback.h index be960f92ad9dbd..b5fcf91cf18bdd 100644 --- a/include/linux/writeback.h +++ b/include/linux/writeback.h @@ -371,14 +371,22 @@ int balance_dirty_pages_ratelimited_flags(struct address_space *mapping, bool wb_over_bg_thresh(struct bdi_writeback *wb); +struct folio *writeback_iter_init(struct address_space *mapping, + struct writeback_control *wbc); +struct folio *writeback_iter_next(struct address_space *mapping, + struct writeback_control *wbc, struct folio *folio, int error); + +#define for_each_writeback_folio(mapping, wbc, folio, error) \ + for (folio = writeback_iter_init(mapping, wbc); \ + folio || ((error = wbc->err), false); \ + folio = writeback_iter_next(mapping, wbc, folio, error)) + typedef int (*writepage_t)(struct folio *folio, struct writeback_control *wbc, void *data); - -void tag_pages_for_writeback(struct address_space *mapping, - pgoff_t start, pgoff_t end); int write_cache_pages(struct address_space *mapping, struct writeback_control *wbc, writepage_t writepage, void *data); + int do_writepages(struct address_space *mapping, struct writeback_control *wbc); void writeback_set_ratelimit(void); void tag_pages_for_writeback(struct address_space *mapping, diff --git a/mm/page-writeback.c b/mm/page-writeback.c index 4fae912f7a86e2..e4a1444502ccd4 100644 --- a/mm/page-writeback.c +++ b/mm/page-writeback.c @@ -2450,7 +2450,7 @@ static struct folio *writeback_get_folio(struct address_space *mapping, return folio; } -static struct folio *writeback_iter_init(struct address_space *mapping, +struct folio *writeback_iter_init(struct address_space *mapping, struct writeback_control *wbc) { if (wbc->range_cyclic) { @@ -2472,7 +2472,7 @@ static struct folio *writeback_iter_init(struct address_space *mapping, return writeback_get_folio(mapping, wbc); } -static struct folio *writeback_iter_next(struct address_space *mapping, +struct folio *writeback_iter_next(struct address_space *mapping, struct writeback_control *wbc, struct folio *folio, int error) { unsigned long nr = folio_nr_pages(folio); @@ -2551,13 +2551,10 @@ int write_cache_pages(struct address_space *mapping, struct folio *folio; int error; - for (folio = writeback_iter_init(mapping, wbc); - folio; - folio = writeback_iter_next(mapping, wbc, folio, error)) { + for_each_writeback_folio(mapping, wbc, folio, error) error = writepage(folio, wbc, data); - } - return wbc->err; + return error; } EXPORT_SYMBOL(write_cache_pages); -- 2.39.2