From patchwork Mon Jun 26 17:35:19 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Matthew Wilcox X-Patchwork-Id: 113075 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:994d:0:b0:3d9:f83d:47d9 with SMTP id k13csp7653978vqr; Mon, 26 Jun 2023 10:55:03 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ6qfZDv0thHxFepVanI6sv5LziTmNwWamdGlN8oqMk6bC3Ahs84zluAJ2dKMZywefHU4KFs X-Received: by 2002:a2e:9c56:0:b0:2b5:93c0:bbb with SMTP id t22-20020a2e9c56000000b002b593c00bbbmr6853749ljj.26.1687802102690; Mon, 26 Jun 2023 10:55:02 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1687802102; cv=none; d=google.com; s=arc-20160816; b=WH0MxIJP6Pq3GT5/JcrZM6J+Vlz6NZcV8yuB6lTA49i4+jd8Ld77JQFsXaqZkCpwZ1 CiR9SBaDNy4Ms2VOamalDv5Mgmtp0LrR1WJX9PZaEgZrnG1tG8XzBkc6vrFegyUQjdja FbSPRtavlisz0jI4qJCeL8QTZrIh06CPYo9XR76ft7mpfawUZI/alNuZ17BoLpntrm4n j7sqQznWsYhr+eZ3lfPa9yc9B9e/xrIeuIQIXo3x+2LIffRP+fMuUnc35qR+nxhLrmxV gJ0QWBjg4UadyW2BcgI1xi4ipJTO19LsnutjCnInjKa73e0vL1E+Sqm5npYGtWNPVlU0 D6zg== 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=DbRDOwy4aGYzGm5HeqIsIhOnoGhV3uqwtbzHnV71lmw=; fh=s6qbYcpKmY0AEsK/gKDpT3qiaGyyaU+hQ5h16uVwDEk=; b=irYENTFCQzcOqKF5LLYArmXT6r9IhHUV/36KCNw2kBlJqIok8NEwfnWUID+kffTNnV EKDShabbIj4idM4o5mAklORfx/myJm3Fqa5QuT96D8AhwRnzOpCM06u1M1aJwqDZ4WoM 7Tanchm1ubp61dySrKsXiOeXos6Ef1OVgTHUra8/IG8pszSmIVOy9nivmypULYox3iVk MXZlPxcXkzNf3LE9jNtRrrWY+Z9tyJnslI948lfJsonzoEIUI00Y983+oPh4xfCi+mGu SYx2aiGfr3Xe1lNFUTE/JlETBQaQQ8M/hllb+ayvb8jpdR3MlaNUS/saDqr/U1lIpy5m 7UcQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@infradead.org header.s=casper.20170209 header.b="W1PA+/Bi"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id jp18-20020a170906f75200b00991db88c470si896308ejb.184.2023.06.26.10.54.38; Mon, 26 Jun 2023 10:55:02 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@infradead.org header.s=casper.20170209 header.b="W1PA+/Bi"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229780AbjFZRgm (ORCPT + 99 others); Mon, 26 Jun 2023 13:36:42 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35964 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231682AbjFZRgB (ORCPT ); Mon, 26 Jun 2023 13:36:01 -0400 Received: from casper.infradead.org (casper.infradead.org [IPv6:2001:8b0:10b:1236::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 75E542955; Mon, 26 Jun 2023 10:35:32 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=casper.20170209; 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=DbRDOwy4aGYzGm5HeqIsIhOnoGhV3uqwtbzHnV71lmw=; b=W1PA+/Bi8v1fqLdsB7yl772V0f RgwlNsF3bvGRmX6GeWkooNi1wYpT1f3iUIzX4l7MUM38mQ9Zw5s7SQOuMEMB53KdS5tSL+OHJSisS K87JMB2fNoyImDp7TG+shhEPLoq4/BISTARhOn43kcMebEMFO3G44dQ5TWC3FZLmULKJjwLPoTUNq WUIpgwde5+sWTO8N2dyN3HIV4wxNNuQ+5Pvpm5cCn3mV9Sxw1bvQhXNl0ETOjQa+6UJarTN7j2N2A ahz+Xz2UCRm0wunSNn5GNma/A151vXBBaymuvJ4fLZ0+HcnPGNDiVY6mFsk/ZzC0yxz2xPztK9RUp bM2BXbXg==; Received: from willy by casper.infradead.org with local (Exim 4.94.2 #2 (Red Hat Linux)) id 1qDq7Y-001vVI-28; Mon, 26 Jun 2023 17:35:24 +0000 From: "Matthew Wilcox (Oracle)" 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/12] writeback: Add for_each_writeback_folio() Date: Mon, 26 Jun 2023 18:35:19 +0100 Message-Id: <20230626173521.459345-11-willy@infradead.org> X-Mailer: git-send-email 2.37.1 In-Reply-To: <20230626173521.459345-1-willy@infradead.org> References: <20230626173521.459345-1-willy@infradead.org> MIME-Version: 1.0 X-Spam-Status: No, score=-4.4 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_MED,SPF_HELO_NONE, SPF_NONE,T_SCC_BODY_TEXT_LINE autolearn=ham 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-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1769788777614936690?= X-GMAIL-MSGID: =?utf-8?q?1769788777614936690?= 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) --- 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 7dd050b40e4b..84d5306ef045 100644 --- a/include/linux/writeback.h +++ b/include/linux/writeback.h @@ -369,14 +369,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 ef61d7006c5e..245d6318dfb2 100644 --- a/mm/page-writeback.c +++ b/mm/page-writeback.c @@ -2451,7 +2451,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) { @@ -2473,7 +2473,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) { if (unlikely(error)) { @@ -2550,13 +2550,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);