Received: by 2002:a05:7412:b995:b0:f9:9502:5bb8 with SMTP id it21csp861203rdb; Fri, 22 Dec 2023 07:13:36 -0800 (PST) X-Google-Smtp-Source: AGHT+IE44L9ZriYWAbSNiyNQv9JNV3ki/8P0WAFIVDnKbvsHAi0wY/g7GxG/t3/zilH8jhdolSSv X-Received: by 2002:a2e:8709:0:b0:2cc:652d:343e with SMTP id m9-20020a2e8709000000b002cc652d343emr800014lji.44.1703258016479; Fri, 22 Dec 2023 07:13:36 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1703258016; cv=none; d=google.com; s=arc-20160816; b=QkO3oDsupmAPaqyqGJJE95RGjCBBXSnpk7MJbKMYGFFAT0l2yq6jwEkXYmTrK5jSua 51r1wttEMdtgdSyNEMOcgBedw+Jn6fXGBME6dzZ6Y+wpwRWU3JXfGe3qS41dIOZV2RKH TptrqLUj+zM86h7Q4uhgGM6TfkFfOBBbGbvK0nzn/ruxiAeulZFx3YPbkCWSUj5vqjOL 5vkiwnmIL8eV6W4J74HS7PUbxEj+8PKvwL66xSXN5fA7fW7ylosrQdoc5O95GdUPgXuc Ju/JA+ExPe5HL+A2MPrxJdDbxQ/VJnrbptAQPZBR3bEJsNCglnWwcjMXplGzJ18bVWJ9 7uZA== 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=uhQwu0XzlF9g6tYMy5v46u1+umuzBvOukQsb3rulW5U=; fh=hzpEVxJ05G9gyZL9WVyKgOEGxITvmFSuTcKyr2ByStg=; b=eny0KFMD3L1HWwjRDrgkH3bt6vqVl0WrZ+qNdwpCcdZ1dTtsGSR/2Saz9QnJpg53sJ 7MhjXQJDx+buGmzo0PyucxlTPPz+qSfjLZrTDjIzCMf/uzAMi7QMwwB5+bFOrlH7EIv2 kfAyGtV258DPfpiSw4m9XcjfZZUTlCHc6eOxH4fQAVN4tx/G7mtX2uJmE7qt3MSsMEbx edsgLhTIa+uMaCMQGxL+q3KtA3UcV5+Q78FlD/L9EzTOdr1X/aqaWNSh8+AvkJcIwjS+ Id9xRxkSF250husv/XLv1KG3mB58z2GXkCKHDhG26ouBTby6e6y6OHb31XaPPbcsQCkT 5xGA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@infradead.org header.s=bombadil.20210309 header.b=yfQSDflm; spf=pass (google.com: domain of linux-kernel+bounces-9824-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-9824-linux.lists.archive=gmail.com@vger.kernel.org" Return-Path: Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [147.75.80.249]) by mx.google.com with ESMTPS id f10-20020a50a6ca000000b00551f54c680bsi1887892edc.315.2023.12.22.07.13.36 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 22 Dec 2023 07:13:36 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-9824-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) client-ip=147.75.80.249; Authentication-Results: mx.google.com; dkim=pass header.i=@infradead.org header.s=bombadil.20210309 header.b=yfQSDflm; spf=pass (google.com: domain of linux-kernel+bounces-9824-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-9824-linux.lists.archive=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 am.mirrors.kernel.org (Postfix) with ESMTPS id 875491F249EB for ; Fri, 22 Dec 2023 15:12:35 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 7BD1A2E82F; Fri, 22 Dec 2023 15:09:02 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=infradead.org header.i=@infradead.org header.b="yfQSDflm" 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 8DAF02E643; Fri, 22 Dec 2023 15:09:00 +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=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> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-SRS-Rewrite: SMTP reverse-path rewritten from by bombadil.infradead.org. See http://www.infradead.org/rpr.html 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); -- 2.39.2