From patchwork Thu Dec 14 13:25:43 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christoph Hellwig X-Patchwork-Id: 13493146 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 2F083C4332F for ; Thu, 14 Dec 2023 14:39:19 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 972D66B0487; Thu, 14 Dec 2023 09:39:18 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 8FBD86B0488; Thu, 14 Dec 2023 09:39:18 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 79C976B048A; Thu, 14 Dec 2023 09:39:18 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0012.hostedemail.com [216.40.44.12]) by kanga.kvack.org (Postfix) with ESMTP id 6399A6B0487 for ; Thu, 14 Dec 2023 09:39:18 -0500 (EST) Received: from smtpin28.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay08.hostedemail.com (Postfix) with ESMTP id 2F18F1403D6 for ; Thu, 14 Dec 2023 14:39:18 +0000 (UTC) X-FDA: 81565681596.28.590A4C1 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) by imf15.hostedemail.com (Postfix) with ESMTP id 886D1A0023 for ; Thu, 14 Dec 2023 14:39:15 +0000 (UTC) Authentication-Results: imf15.hostedemail.com; dkim=pass header.d=infradead.org header.s=bombadil.20210309 header.b=FpcH5Bmf; dmarc=none; spf=none (imf15.hostedemail.com: domain of BATV+55581d165dda9d0af87b+7417+infradead.org+hch@bombadil.srs.infradead.org has no SPF policy when checking 198.137.202.133) smtp.mailfrom=BATV+55581d165dda9d0af87b+7417+infradead.org+hch@bombadil.srs.infradead.org ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1702564755; 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-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=+EjBTTu0WiLV+Q73nxsWHktHLf8xanuJ2SDeP86Fuu8=; b=jogn37ChvIjQFoosKi0qlUMa8BgQYem/wFYcgmHv1P2+rj+tbuoRZPpFo38JJxzotZaRN5 qfJ+v8Yl/nHGgBG/hsYjE7ChyH6s1i7rAUZSPJjc6Hrys4fHZltJ9o7raBm8Iq1ONi0j5G hoC5B6NpJVYFLQkqGUQu03iOX3BlAkc= ARC-Authentication-Results: i=1; imf15.hostedemail.com; dkim=pass header.d=infradead.org header.s=bombadil.20210309 header.b=FpcH5Bmf; dmarc=none; spf=none (imf15.hostedemail.com: domain of BATV+55581d165dda9d0af87b+7417+infradead.org+hch@bombadil.srs.infradead.org has no SPF policy when checking 198.137.202.133) smtp.mailfrom=BATV+55581d165dda9d0af87b+7417+infradead.org+hch@bombadil.srs.infradead.org ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1702564755; a=rsa-sha256; cv=none; b=5mdmsqw7vdMR+6ROLNvQLOXailmS6uXFUoStfOV4gdG38opP1yuXAfAfIJ9pmtLU8TDPrZ +7PApIvJeBo7CbdmoQ3G54Bt4IULpSyoS2EA7VW6/H2LDxk6QiENRCZ4QCflVQeHamRAo7 TZWKvtvOy+qHTsr4AGsUQuabqI6L5gU= 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 X-SRS-Rewrite: SMTP reverse-path rewritten from by bombadil.infradead.org. See http://www.infradead.org/rpr.html X-Rspam-User: X-Rspamd-Server: rspam12 X-Rspamd-Queue-Id: 886D1A0023 X-Stat-Signature: fex7kw3z6g5i9ipx8qgamygssw8zxb4f X-HE-Tag: 1702564755-144497 X-HE-Meta: U2FsdGVkX1/srQw0rOf7c5zsVyBSk+EdU5Au/buUyx4Wh/PoNpXTSkJthKqlPUhzO+4CVVJdA5mJ1sUOr7SxX9i79Fa2AhRyWW/SMvXzDA3LDyboGZDNLydBfQDiHRgSJ26rO//n5znM0ejIS55G/SOmm2M/IFqjOjizTHQ75amaWycCALzPJppX182oJ1jvQs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x0IJ93PtZJT3yCJUfvTssoWsUAxYFbXGkp/6lBItOW52tsMaaFeIMUIy2UPAUq7T2MRQ2M0uQBXq1UcoRMo7PHsBNslO+dmUbIRRpbtrR4Kos/AzKbRaOHRKc7yq4WHYsQtBMUGlzzJW+AYBctPkPC/XGhVwSHv24F3wypTynPMxaT5rQAS11buLSU8ddiDirm9N7NI3F71i8TdPaDhoSYdvA== 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: 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);