From patchwork Fri Dec 22 15:08:25 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christoph Hellwig X-Patchwork-Id: 13503423 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 96050C41535 for ; Fri, 22 Dec 2023 15:09:15 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 08FF78D0009; Fri, 22 Dec 2023 10:09:08 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id F32448D0003; Fri, 22 Dec 2023 10:09:07 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id D5EC48D0009; Fri, 22 Dec 2023 10:09:07 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0015.hostedemail.com [216.40.44.15]) by kanga.kvack.org (Postfix) with ESMTP id C6B078D0003 for ; Fri, 22 Dec 2023 10:09:07 -0500 (EST) Received: from smtpin06.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay02.hostedemail.com (Postfix) with ESMTP id 95FA4120998 for ; Fri, 22 Dec 2023 15:09:07 +0000 (UTC) X-FDA: 81594787134.06.416CAA0 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) by imf17.hostedemail.com (Postfix) with ESMTP id B544440019 for ; Fri, 22 Dec 2023 15:09:05 +0000 (UTC) Authentication-Results: imf17.hostedemail.com; dkim=pass header.d=infradead.org header.s=bombadil.20210309 header.b=QcpTyTJu; spf=none (imf17.hostedemail.com: domain of BATV+af923ccb694ecd533eae+7425+infradead.org+hch@bombadil.srs.infradead.org has no SPF policy when checking 198.137.202.133) smtp.mailfrom=BATV+af923ccb694ecd533eae+7425+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=1703257745; 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=Cpsd8l7OUn8C5bZQLGYGz9qCV/TqxduSbkyPfu2Mjvk=; b=I3gvaURniukuUV92pby/zsVlHM542T3uov18uefedYniDBi5CFTIZa93F7fRrVIlGLYz47 Rkabh+1QXawDRJq7B7tZNv42hrDMB63hKD0YTLHucA/2i/0swQIiNCQC5fpjD4Mx0WvwMG 56C8+KNoax/4f38lGgMceVeV86p22e4= ARC-Authentication-Results: i=1; imf17.hostedemail.com; dkim=pass header.d=infradead.org header.s=bombadil.20210309 header.b=QcpTyTJu; spf=none (imf17.hostedemail.com: domain of BATV+af923ccb694ecd533eae+7425+infradead.org+hch@bombadil.srs.infradead.org has no SPF policy when checking 198.137.202.133) smtp.mailfrom=BATV+af923ccb694ecd533eae+7425+infradead.org+hch@bombadil.srs.infradead.org; dmarc=none ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1703257745; a=rsa-sha256; cv=none; b=rul4/UI2D3CDxanu2zWICJ3rO79ZNWz352zkQi16Wl6vMqY6DUFZTy0wHXqy1BMpAxGL8S byiZLZWldu9Y6WU56nWuLCH6CFafB2s0R1difyswy4C7bXQoPQRGWcKjYx6ucm0G5AZcyz P+lmQI34tFbMP/keuXX/efcOI8+Zxzk= 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=Cpsd8l7OUn8C5bZQLGYGz9qCV/TqxduSbkyPfu2Mjvk=; b=QcpTyTJuJ95zy8zQxfBVMOoGDn sw2GJk7mt4gkoe22EcMVpN5zoyxcTZ73p+PdkX60CZgHZeUAuIUr2oVe8FRVmI8/vAcpKnpluXuEu TUUZxssJV21oSRM3MQ9FjEgkhDo2BKBvRLib0rucgP+qyhWCD0t6FBI8QvgXSiu3rZjMwYBrflf0M uoIruyUMiuNMWZXyPdg5PqtA3L2CzyA4EIAD0M+B5pGflz0iEsiuxw8YZ2tO6wp2UnPyPwLrtqOIi L2C1oIjxnOjwUKsQO/pO4H+bWqA1WGkCM7vItyfaVkeb+MtDYyqFpiRj3tcKyxP2vT3yQKv8ByTNA uje57PSw==; 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 1rGh96-006Bb2-1Z; Fri, 22 Dec 2023 15:09:04 +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, Jan Kara , Dave Chinner Subject: [PATCH 15/17] writeback: Add for_each_writeback_folio() Date: Fri, 22 Dec 2023 16:08:25 +0100 Message-Id: <20231222150827.1329938-16-hch@lst.de> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20231222150827.1329938-1-hch@lst.de> References: <20231222150827.1329938-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-Queue-Id: B544440019 X-Rspam-User: X-Stat-Signature: oe5j3tnpdscgyhu94wfdfcz3haq38ja9 X-Rspamd-Server: rspam01 X-HE-Tag: 1703257745-554477 X-HE-Meta: U2FsdGVkX1/oYwS5O9TjhRqbBf42npixtOgASB+v6RpXJSMGtmtBiQB1y8BVf1UK4Z9eAB69gwExMYYPd/FxncILctyzrieb6CV1FPBMP4PKBGYB4nGqRkj2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0/v3iC2utUpDF+RNMrtU7YKYP/Rxi8VEjUbN0UeneqfdXct3Z5sTKbHK/aTszKmwABL4scCxl+E39Oe9DPfab2HU6i62p5lTis/kU59QXJtjwOBIUyvVcIUU2L5HAeiNYD7SURfhhpkyph7mowzIFiwIX186BZPOYSQAYtLJCR1xwMWJmfYNFARP2cHkB8g5yiJlCWEg9vdpJDPaA3L4+Upnbd28KliK9WpRueJ2wh0TNx/m2D/B2bNz69KlJ2jgGyZb4Q7LhSSc0lv3YBZQzdwypUOGtTr5mokM954ikIhycemGXZOK0Wp/osfSEUTIrWDrA/U99S 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 Acked-by: Dave Chinner --- 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 a041cc563762ae..5c33a4a527b3fa 100644 --- a/mm/page-writeback.c +++ b/mm/page-writeback.c @@ -2458,7 +2458,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) @@ -2474,7 +2474,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); @@ -2552,9 +2552,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;