From patchwork Thu Jan 25 08:57:54 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christoph Hellwig X-Patchwork-Id: 13530270 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 96EC6C47258 for ; Thu, 25 Jan 2024 08:59:02 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 266C628000A; Thu, 25 Jan 2024 03:59:02 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 1EA80280001; Thu, 25 Jan 2024 03:59:02 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 0645228000A; Thu, 25 Jan 2024 03:59:01 -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 E82A1280001 for ; Thu, 25 Jan 2024 03:59:01 -0500 (EST) Received: from smtpin14.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay05.hostedemail.com (Postfix) with ESMTP id C902940D68 for ; Thu, 25 Jan 2024 08:59:01 +0000 (UTC) X-FDA: 81717233682.14.0A98226 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) by imf28.hostedemail.com (Postfix) with ESMTP id 392B7C001C for ; Thu, 25 Jan 2024 08:59:00 +0000 (UTC) Authentication-Results: imf28.hostedemail.com; dkim=pass header.d=infradead.org header.s=bombadil.20210309 header.b=CWZJKe+f; spf=none (imf28.hostedemail.com: domain of BATV+b97a0fc658bf3e588113+7459+infradead.org+hch@bombadil.srs.infradead.org has no SPF policy when checking 198.137.202.133) smtp.mailfrom=BATV+b97a0fc658bf3e588113+7459+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=1706173140; 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=hycX01++9KfrQWd9zJFSZD7mlFdT083LhSglCnbjIfA=; b=sVV7bJVmWtO/or412IFQTEK5DUz7nPinCk76MWM7/DH9nbbmRe8NsFwfTR11ljicDvDnYf BtqF07GaTs9kzyqxuQHI3Qw1BZFt5/JDGVoXF84/anfraFLpumSVhYuK8j7pQ7xAoXLZuQ AHhSAmSfRL71ssceTrI+zUqJlej2OoM= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1706173140; a=rsa-sha256; cv=none; b=m9Fq8iKeY5djcOmRX5FLP5C8m8C83kd5r/rXYExGmnPDGSbc6duSG+FsV7lnhXll1jVpX5 qdKo4d8JPTOAXQvfFthrYCc2eYiN8Wmnl8TCzNJ4MkN1Rng5x91R2kXnQqPA58e+9qPDdy Z6qqKw+aE1R5ayxK+gU7SeUL4s5dOW8= ARC-Authentication-Results: i=1; imf28.hostedemail.com; dkim=pass header.d=infradead.org header.s=bombadil.20210309 header.b=CWZJKe+f; spf=none (imf28.hostedemail.com: domain of BATV+b97a0fc658bf3e588113+7459+infradead.org+hch@bombadil.srs.infradead.org has no SPF policy when checking 198.137.202.133) smtp.mailfrom=BATV+b97a0fc658bf3e588113+7459+infradead.org+hch@bombadil.srs.infradead.org; dmarc=none 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=hycX01++9KfrQWd9zJFSZD7mlFdT083LhSglCnbjIfA=; b=CWZJKe+fYMpoyNJTzLY6dZJyZA QYOX3JkYnjQSNZqRqWnV5LQJ5dcHTdNCtbSFBLQVS8uFpIHzJkuyQOnqlCRSH9/Eik0Bxh7kCd5tC Ophi8cnF1+hC+jcY4nHJOrBS7Qg+ajDD1z3M4DNxObV8/o2aB9ULuQQYqrNeBPF8ytfbSumetEYcw dhxh/yWN1eZFv6zTFaNHQ9tpiHLZN82AuIZh7cXSqcXBA3i6psFH+Rp7ifIufSFmF8k5C2ygBq3gs Na1eRG+Erd+ijYZb6gNByZXQaa+TTVlviqmjmiGIUDafwuHIG2zLEXmLPlciRMF1l1+yptTWAiy10 5WmAk/pw==; 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 1rSvZa-007QUh-2Y; Thu, 25 Jan 2024 08:58:59 +0000 From: Christoph Hellwig To: linux-mm@kvack.org Cc: Matthew Wilcox , Jan Kara , David Howells , Brian Foster , Christian Brauner , "Darrick J. Wong" , linux-xfs@vger.kernel.org, linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org, Jan Kara , Dave Chinner Subject: [PATCH 15/19] writeback: Add for_each_writeback_folio() Date: Thu, 25 Jan 2024 09:57:54 +0100 Message-Id: <20240125085758.2393327-16-hch@lst.de> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20240125085758.2393327-1-hch@lst.de> References: <20240125085758.2393327-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: 392B7C001C X-Rspam-User: X-Rspamd-Server: rspam11 X-Stat-Signature: e87ixdcaw6j7e45g5rn1f1fw5fqtuxpk X-HE-Tag: 1706173140-583018 X-HE-Meta: U2FsdGVkX18BzobK2zokV5ysSGi7kJ5ehDU5qHP65sWpoQ3nSf7pWI4Y50zcdwtsXEEOGhQ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WnfEEeKHNm+62HzWRr04ilJt38gOgPHiKQEffj8GLn7ttFYO8tKDzS5QGITKxT8iJkr1V5XvAkN8XNwTz5TdKuoe2ObBi1sO3KXeGcxn7wxE1ZUDwFT3vpsmd5+4BqGEdVTHtqEYjEtznxuebg0Bpv7kfRHzpUn8J6jyyWhi6Z9XirfWRD6F7Xcmta2hhN2SZmG9eNDB6djnUWkyMhWEIvmNWwGBLk4hpwbB1nn1hBFMNo0Oqa3uQxl7+UyzNgFxmmY1acWKKSKw+j9g8OX8O0fDiO1OvVVIR/0AMke9860+b5e9Q15dd7qwDv85zOfcBaPDWGu/BGVI+vX8lZkekH3fkmiGDaFiom3L2ladn50h7GkFXgdV7fj3y70JL52boi5 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 a091817a5dba55..2416da933440e2 100644 --- a/include/linux/writeback.h +++ b/include/linux/writeback.h @@ -367,6 +367,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 d5815237fbec29..aca0f43021a20c 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;