From patchwork Mon Dec 18 15:35:51 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christoph Hellwig X-Patchwork-Id: 13497169 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 7DDC9C35274 for ; Mon, 18 Dec 2023 15:36:44 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 82AAD6B0088; Mon, 18 Dec 2023 10:36:43 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 7DADB6B0089; Mon, 18 Dec 2023 10:36:43 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 67BC96B0095; Mon, 18 Dec 2023 10:36:43 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0010.hostedemail.com [216.40.44.10]) by kanga.kvack.org (Postfix) with ESMTP id 4E1196B0088 for ; Mon, 18 Dec 2023 10:36:43 -0500 (EST) Received: from smtpin19.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay05.hostedemail.com (Postfix) with ESMTP id 249E840AB9 for ; Mon, 18 Dec 2023 15:36:43 +0000 (UTC) X-FDA: 81580341486.19.A46D515 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) by imf24.hostedemail.com (Postfix) with ESMTP id 6DBBF18002D for ; Mon, 18 Dec 2023 15:36:41 +0000 (UTC) Authentication-Results: imf24.hostedemail.com; dkim=pass header.d=infradead.org header.s=bombadil.20210309 header.b=wIxOQSPZ; spf=none (imf24.hostedemail.com: domain of BATV+09f18f96a25a69770120+7421+infradead.org+hch@bombadil.srs.infradead.org has no SPF policy when checking 198.137.202.133) smtp.mailfrom=BATV+09f18f96a25a69770120+7421+infradead.org+hch@bombadil.srs.infradead.org; dmarc=none ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1702913801; a=rsa-sha256; cv=none; b=bIqFBIgBfqVHrDHV3YbFzqL0ZTgRIt4o3gKyj8fd4RXN81mnueR24YCd8MIseRWhRQ6V7a hCHyuTeJST0qlqSUGO6MhUMXq9FX1fhogD6eW1TO7927hcdrh87Go2rVFPOtXmN6tZ/eGJ iKw1jkfS/sinH2gil5Ciq0QrX5YlDww= ARC-Authentication-Results: i=1; imf24.hostedemail.com; dkim=pass header.d=infradead.org header.s=bombadil.20210309 header.b=wIxOQSPZ; spf=none (imf24.hostedemail.com: domain of BATV+09f18f96a25a69770120+7421+infradead.org+hch@bombadil.srs.infradead.org has no SPF policy when checking 198.137.202.133) smtp.mailfrom=BATV+09f18f96a25a69770120+7421+infradead.org+hch@bombadil.srs.infradead.org; dmarc=none ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1702913801; 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=b65KMtlYAzH3EUkpAxud2ReFVr8IHYHtgd3wSTH/RNI=; b=PrK3LJFVq4ZvgUFQxVPL7x/G9d3bmJX4wusbz8fRrw2C2TZafD+aABji/ZlKn4sPAUWTE8 FKdVXomBvg9ZONFnWPeEdivbyI0A/sCt0CmCqaC31lzgH3HwiMBK/Yj6Jr7c4c0gz9ReRK PgUjTDBH+Koe8AC2GfRbfdN2atWTnX0= 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=b65KMtlYAzH3EUkpAxud2ReFVr8IHYHtgd3wSTH/RNI=; b=wIxOQSPZ9QaTybwrOD9nlYUkRM y+8Zb6dvZntvYiEKJllN8zuuGypcmjeu7cPyJWRRE+Fi8fVWQFfIPzfFljzQWA/7m7EebXSjpuGby ZxBT7WwEcpjYBrspB6z1WTQYVpyBXVdki2ccUQzksG71f2mGj6xHmzzSn29+2TiUT07EYabtmsSEA yjpaneMn2i1b5z0M+EWN6cvSKICP2g8eokXeawjJmIBfdsCN2ms6qC+WjksIXZgx/AY0iZWo/q1dc q1nJKDQPAPGC8P8DMR1Hb0mCPDuXhcA8+sfDzv9zFVilbUWOxiWUrz7F6UwF/edDUhPjfpeF9mZJg gxKIqiRg==; Received: from 2a02-8389-2341-5b80-39d3-4735-9a3c-88d8.cable.dynamic.v6.surfer.at ([2a02:8389:2341:5b80:39d3:4735:9a3c:88d8] helo=localhost) by bombadil.infradead.org with esmtpsa (Exim 4.96 #2 (Red Hat Linux)) id 1rFFfc-00BEaV-0K; Mon, 18 Dec 2023 15:36:40 +0000 From: Christoph Hellwig To: linux-mm@kvack.org Cc: "Matthew Wilcox (Oracle)" , Jan Kara , David Howells , Brian Foster , linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH 15/17] writeback: Add for_each_writeback_folio() Date: Mon, 18 Dec 2023 16:35:51 +0100 Message-Id: <20231218153553.807799-16-hch@lst.de> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20231218153553.807799-1-hch@lst.de> References: <20231218153553.807799-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-Rspamd-Server: rspam08 X-Rspamd-Queue-Id: 6DBBF18002D X-Stat-Signature: czyi5asrhoxzxys1e6qynncgqp9kkji7 X-Rspam-User: X-HE-Tag: 1702913801-244053 X-HE-Meta: U2FsdGVkX1/qGw6G+Sf1IXhff3JzB0ZXHfsaOhyY5qYcHqGbvdeGUYapgOGdkoAtcbo82ZSlY77svh0n3quW5ATMifzffhuLlRCBDiCfuP19DUM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KyARPsvPcPMeFqcss4l5Q62ZvEHaYSiWcUYhFuh/2c7qJU9+iMiZG84JfIgaYhMPiqUFVp4lSL94jaBaGeMEBSh0BlcdtPF1zsJgiu0U2haf0lzycmjd8ASzMUnGKvr8TejfHCzXqpQzm7dsowMb3phDqok2Qp507gmss0mmQkN6hSJl91ZEM+gpeGlLwyIRXFtXAC4YS8XxqtBu3K8Ffhnu5uPbeyOCqtma19/j5uR9q9afrR5eatq/hbYlCvoplBKKsg3byu5AhzM/tJmvfKtOlQDuHn1X0WVQzUupilaEwjONAa7/ZTwEoJ7xHz8qdPBOHABLM= 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 Reviewed-by: Jan Kara --- include/linux/writeback.h | 10 ++++++++++ mm/page-writeback.c | 8 +++----- 2 files changed, 13 insertions(+), 5 deletions(-) diff --git a/include/linux/writeback.h b/include/linux/writeback.h index 195393981ccb5c..1c1a543070c17b 100644 --- a/include/linux/writeback.h +++ b/include/linux/writeback.h @@ -368,6 +368,16 @@ 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); diff --git a/mm/page-writeback.c b/mm/page-writeback.c index 0771f19950081f..fbffd30a9cc93f 100644 --- a/mm/page-writeback.c +++ b/mm/page-writeback.c @@ -2463,7 +2463,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) @@ -2479,7 +2479,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); @@ -2557,9 +2557,7 @@ 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;