From patchwork Fri Dec 22 15:08:22 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christoph Hellwig X-Patchwork-Id: 13503420 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 34872C46CD2 for ; Fri, 22 Dec 2023 15:09:06 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 9DD5A8D0006; Fri, 22 Dec 2023 10:09:00 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 9685F8D0003; Fri, 22 Dec 2023 10:09:00 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 71CBE8D0006; Fri, 22 Dec 2023 10:09:00 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0011.hostedemail.com [216.40.44.11]) by kanga.kvack.org (Postfix) with ESMTP id 611D48D0003 for ; Fri, 22 Dec 2023 10:09:00 -0500 (EST) Received: from smtpin26.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay04.hostedemail.com (Postfix) with ESMTP id 436A81A0E9E for ; Fri, 22 Dec 2023 15:09:00 +0000 (UTC) X-FDA: 81594786840.26.12E85D9 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) by imf26.hostedemail.com (Postfix) with ESMTP id 7FE41140012 for ; Fri, 22 Dec 2023 15:08:58 +0000 (UTC) Authentication-Results: imf26.hostedemail.com; dkim=pass header.d=infradead.org header.s=bombadil.20210309 header.b=yfQSDflm; dmarc=none; spf=none (imf26.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 ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1703257738; 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=uhQwu0XzlF9g6tYMy5v46u1+umuzBvOukQsb3rulW5U=; b=wFEU/+xS3/5inJB0irGcAFhmzYmnr838SixN/IhUWgjW1GJFaCjm4org6dcTRKsF7SbwyL 2nB/P1lnngRL51M1bosEbghYipdNi3MA0CXGq7wNo7dscVqSigwW+vDGu6eiUBIwvcA5q2 L+fXsdlpG/0IJGvquZQ6ShNVT6hHkmc= ARC-Authentication-Results: i=1; imf26.hostedemail.com; dkim=pass header.d=infradead.org header.s=bombadil.20210309 header.b=yfQSDflm; dmarc=none; spf=none (imf26.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 ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1703257738; a=rsa-sha256; cv=none; b=X8DmA5U5ZmxJu7waTyIAjChrz4ysdDCbax/6aKGmzwKTqXdwDAzkX9/1zn8+GkaKm4BIWI z5IZSThwgidenWKwE5AQRmZS5voZqe8DLPg4ZXz/m1oGnUuEcDCkA81jNW2LFz0YXCRZIo EZgRHoSJ96P2PYzoxyy4LkxLWyq+dqU= 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=uhQwu0XzlF9g6tYMy5v46u1+umuzBvOukQsb3rulW5U=; b=yfQSDflmOsFoQUBv7S0oxf31Lt bA8UjbacePhce939zrO4Ir44tqLbrgyX1i5WWUPFn1Dh+11PMGev7lVY8wnZureYjbZsYuESrU/5W 7r7TRMZJi1BVUw35tzYKJsGhRRphnMJlwuQRlfFG7hoKMPvs2RHHddSnKmZ5Zo6xy79keEUFELCWb di7aVlxzJVcxNMi/KVCgAn/kv4q2J3SRszZOCJqDD9t8X6NkbjyqzvwY30OmTwG+hrdVwHprkayFJ byFe+UZ+5u414GPfeJPQCofOizDxVA0C4ZgEqEEGUVbFOp5tujEidQTo2hVAYbvVDVsV6qignOnCn L7ZBVhGw==; 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 1rGh8z-006BXA-0y; Fri, 22 Dec 2023 15:08:57 +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 12/17] writeback: Factor writeback_iter_init() out of write_cache_pages() Date: Fri, 22 Dec 2023 16:08:22 +0100 Message-Id: <20231222150827.1329938-13-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-Server: rspam09 X-Rspamd-Queue-Id: 7FE41140012 X-Stat-Signature: k8918x6t31rw739xbcrd4eqs4fh3fw74 X-Rspam-User: X-HE-Tag: 1703257738-966271 X-HE-Meta: U2FsdGVkX1+dgAeWmfzSiMccsCsdzIqaD/ajr2yRZVyBMeu/3l5GeURep5rDD2y0f8nj6dpW7OQQ4uy03aNYL1NQiB7FEpzPN7mOLY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9Q1gDSI4QEX7h7paJC84LOV4mnFcsUEoiYTvX6L50KfjatDtpHdvHvfZlKee9bMbUAaXCMl1wUaWnfn1wiLes/AVGJbFez3rYcZ0vwdV4EuP9SDlNEuY6MXMijv2Pr4Qr2b+Cp+enTqJX6F93nyZRFKcJmSkmfO9H2+rW9Rb45UMQJos/P1VJYvyMxyHNbYtAYtQSmh5zWhtB+LCqAKiF3P/UNl7bILFAt5gnd7jOcq/9zgxTB1b8Zl8Q2Mh0CkAansKxNxWkuwKWGIoWxetRxWz1c7nVH5VImxP+3V2ZFdG7hDbOeqMfKNKISQLIIT3xf+SLjJbiGEpU6g2aDVkklAuBasxWJq2A4U53J 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)" Make it return the first folio in the batch so that we can use it in a typical for() pattern. Signed-off-by: Matthew Wilcox (Oracle) Signed-off-by: Christoph Hellwig Reviewed-by: Jan Kara Acked-by: Dave Chinner --- mm/page-writeback.c | 39 ++++++++++++++++++++------------------- 1 file changed, 20 insertions(+), 19 deletions(-) diff --git a/mm/page-writeback.c b/mm/page-writeback.c index 47457895891221..f85145f330bb36 100644 --- a/mm/page-writeback.c +++ b/mm/page-writeback.c @@ -2446,6 +2446,22 @@ static struct folio *writeback_get_folio(struct address_space *mapping, return folio; } +static struct folio *writeback_iter_init(struct address_space *mapping, + struct writeback_control *wbc) +{ + if (wbc->range_cyclic) + wbc->index = mapping->writeback_index; /* prev offset */ + else + wbc->index = wbc->range_start >> PAGE_SHIFT; + + if (wbc->sync_mode == WB_SYNC_ALL || wbc->tagged_writepages) + tag_pages_for_writeback(mapping, wbc->index, wbc_end(wbc)); + + wbc->err = 0; + folio_batch_init(&wbc->fbatch); + return writeback_get_folio(mapping, wbc); +} + /** * write_cache_pages - walk the list of dirty pages of the given address space and write all of them. * @mapping: address space structure to write @@ -2481,29 +2497,14 @@ int write_cache_pages(struct address_space *mapping, struct writeback_control *wbc, writepage_t writepage, void *data) { + struct folio *folio; int error; - pgoff_t end; /* Inclusive */ - if (wbc->range_cyclic) { - wbc->index = mapping->writeback_index; /* prev offset */ - end = -1; - } else { - wbc->index = wbc->range_start >> PAGE_SHIFT; - end = wbc->range_end >> PAGE_SHIFT; - } - if (wbc->sync_mode == WB_SYNC_ALL || wbc->tagged_writepages) - tag_pages_for_writeback(mapping, wbc->index, end); - - folio_batch_init(&wbc->fbatch); - wbc->err = 0; - - for (;;) { - struct folio *folio = writeback_get_folio(mapping, wbc); + for (folio = writeback_iter_init(mapping, wbc); + folio; + folio = writeback_get_folio(mapping, wbc)) { unsigned long nr; - if (!folio) - break; - folio_lock(folio); if (!folio_prepare_writeback(mapping, wbc, folio)) { folio_unlock(folio);