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: 180504 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7300:24d3:b0:fb:cd0c:d3e with SMTP id r19csp1329798dyi; Mon, 18 Dec 2023 07:42:05 -0800 (PST) X-Google-Smtp-Source: AGHT+IG0vYyGfZ21FcpX2NeZnTcbePlOHmIf/z08Ww2CV8yqbidxiq9xT7FwPQmaABcqGCo11/Fc X-Received: by 2002:a05:6a21:1a2:b0:194:8117:b36b with SMTP id le34-20020a056a2101a200b001948117b36bmr644853pzb.44.1702914125492; Mon, 18 Dec 2023 07:42:05 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1702914125; cv=none; d=google.com; s=arc-20160816; b=nTiO6bfW9QvNn1c4Vzd8C8lnkMDI+FBxiu5S4azJrlhxlJluIA2TVZhRgsxw0W3Sbk JxKGnqT/WHTB6E6+zyuNVeIWAIdXtqlX2fVb32tIcoxXNVzr3imjFuE4gBT+Uhg9bifd FSVWLOJtAQPsp7sdkGu7i/wkxm15m0ZGRWBeXPpM8KCc327as4LTE52gin5X8encp6cd EquDaLn2XpUimPDTs4GC268PQ0zByL7WxqHT/x0YCCDsRvpiBGvWsp1/idf1FQzm3Gnj q2qRaN8Urd70v4roUiXvmsTXL2w++6OeUtaR27BDZlWVP3AT+pEFfxBImqWRoFj606nT +mFA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :date:subject:cc:to:from:dkim-signature; bh=b65KMtlYAzH3EUkpAxud2ReFVr8IHYHtgd3wSTH/RNI=; fh=m0HBXuwgOCKat7wyuY7vstPypqMqxNmINnjBv5+EUjU=; b=Rbvv2vT2Hb04egVPFLp88HQoXCrv1AgVypYxJQjdf9qLQgpicSbUxaVFtqGyhmD1pN JzaO6SJ3lT6WatNPxVuBoD/UZENda9/Kuq2dxRQgJGJH/SKGGnRs5X75bAbB9kJFe9Kn FV0Ymor3gMo7BQKEmNwjTxR6TrrtNrnytkWJZoQmu/Du+tdhfqtgj4wdX3oeUQoNGRDF jWHQ/67NYbkU5iQ/MD6mSBj7uDrKAF5krJps52xDu1sWl0xS0pR15ey/v6l3XCr0OoJh 8IY0FW5buocjRgqHwc55cpi/V8S6opkY+IPjHlNWQ/A6JleXFviOUG0o39EqmXidUVVG ZtSQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@infradead.org header.s=bombadil.20210309 header.b=wIxOQSPZ; spf=pass (google.com: domain of linux-kernel+bounces-3958-ouuuleilei=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-3958-ouuuleilei=gmail.com@vger.kernel.org" Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [139.178.88.99]) by mx.google.com with ESMTPS id z5-20020a656645000000b005bd3da15474si17441577pgv.839.2023.12.18.07.42.05 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 18 Dec 2023 07:42:05 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-3958-ouuuleilei=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) client-ip=139.178.88.99; Authentication-Results: mx.google.com; dkim=pass header.i=@infradead.org header.s=bombadil.20210309 header.b=wIxOQSPZ; spf=pass (google.com: domain of linux-kernel+bounces-3958-ouuuleilei=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-3958-ouuuleilei=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 46428283A17 for ; Mon, 18 Dec 2023 15:42:05 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 7D36874E3C; Mon, 18 Dec 2023 15:36:51 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=infradead.org header.i=@infradead.org header.b="wIxOQSPZ" X-Original-To: linux-kernel@vger.kernel.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (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 82A7F74097; Mon, 18 Dec 2023 15:36:47 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=lst.de Authentication-Results: smtp.subspace.kernel.org; spf=none smtp.mailfrom=bombadil.srs.infradead.org 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> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-SRS-Rewrite: SMTP reverse-path rewritten from by bombadil.infradead.org. See http://www.infradead.org/rpr.html X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1785634882097667921 X-GMAIL-MSGID: 1785634882097667921 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;