From patchwork Mon Dec 18 15:35:47 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christoph Hellwig X-Patchwork-Id: 13497165 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 1B611C35274 for ; Mon, 18 Dec 2023 15:36:33 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 803CC8D0002; Mon, 18 Dec 2023 10:36:30 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 7B68E8D0001; Mon, 18 Dec 2023 10:36:30 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 67E3A8D0002; Mon, 18 Dec 2023 10:36:30 -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 5315F8D0001 for ; Mon, 18 Dec 2023 10:36:30 -0500 (EST) Received: from smtpin20.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay05.hostedemail.com (Postfix) with ESMTP id 2D80140B7A for ; Mon, 18 Dec 2023 15:36:30 +0000 (UTC) X-FDA: 81580340940.20.F196DCE Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) by imf24.hostedemail.com (Postfix) with ESMTP id 675BE18002D for ; Mon, 18 Dec 2023 15:36:28 +0000 (UTC) Authentication-Results: imf24.hostedemail.com; dkim=pass header.d=infradead.org header.s=bombadil.20210309 header.b=THuXRAhN; spf=none (imf24.hostedemail.com: domain of BATV+09f18f96a25a69770120+7421+infradead.org+hch@bombadil.srs.infradead.org has no SPF policy when checking 198.137.202.133) smtp.mailfrom=BATV+09f18f96a25a69770120+7421+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=1702913788; 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=3B9Hp+QAdQFWcqrQUPpFbTk6qvR0M5sjBup3lTEiqhs=; b=x/wQ94S6UuJyNP3jHllYFTD4TnYcLjGgaf25s394NnvB7dTJgbkULuog9Ovuht2yYJBdR1 YENYg5onIupGEtPPUxd/x9xw0TCCD/Iro/+FzEq46zdn6uPpXmuZvtV9eNU0rRe0BQD0gI d4RtFdJyDoLgsxyo2o0IdgVPamXKrEg= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1702913788; a=rsa-sha256; cv=none; b=v78Sx/VeAcbktPLWOANMfn8kxFpqS/hr79GxnQwhGHutcg+2ycuVpT1WFnTpfREqMaGYi2 r6CumGTIPHOysevinM3rmzInVaclEvI7nBT2y3KgMQaeJkugzeh444e1ALARzKAsrm5gXL v9f9hWJYudV8ecIa3kXTiqKtV6OCHNA= ARC-Authentication-Results: i=1; imf24.hostedemail.com; dkim=pass header.d=infradead.org header.s=bombadil.20210309 header.b=THuXRAhN; spf=none (imf24.hostedemail.com: domain of BATV+09f18f96a25a69770120+7421+infradead.org+hch@bombadil.srs.infradead.org has no SPF policy when checking 198.137.202.133) smtp.mailfrom=BATV+09f18f96a25a69770120+7421+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=3B9Hp+QAdQFWcqrQUPpFbTk6qvR0M5sjBup3lTEiqhs=; b=THuXRAhNeLCiO2K1fm6woSSF0o FKejSp1UwrESZMKns9PM7cdQ7F8P7vGO1leM/ItulT1ZAASbVhH3soffvn0yy2cYNQ7Db4BAOr9ku m7Aeco/LSG1tytEmmHRNB8t01Capsk3p3022lowatIGQS/92K5TIZZ50ORvE1uUbfbl5qTGihahCG t7RR7qRTsnt6rYpRX6/KmySAwqvvivwVdHHPiSnYv+ICCPdXwP4idam3OfER0xCEM1QDucjIIGYwL z3kxcpHeMwiL3Gk+EC3dtqn2BU8RvjxXmiBBSf79ujCTwihDzG75A4W/ShiFDKWGhEztFg+1o/gtd WL+ry0qg==; 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 1rFFfO-00BEUC-1y; Mon, 18 Dec 2023 15:36:27 +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 11/17] writeback: Use the folio_batch queue iterator Date: Mon, 18 Dec 2023 16:35:47 +0100 Message-Id: <20231218153553.807799-12-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> 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: 675BE18002D X-Rspam-User: X-Rspamd-Server: rspam11 X-Stat-Signature: qs1xf44a7f1eq3uub4nrupicce96srtu X-HE-Tag: 1702913788-192832 X-HE-Meta: U2FsdGVkX1/FGncAUKb36UV49VoCeVDx1ra3Cb0YtCFpNWdUTHezK+ZQ2PEbyoR+sx0p5swyyCDzRf10Cuxd2OkIOec+/uOQDK7twlKNTO3PCnmuXUQO17H5jRE1ZuaUGfOMUcSravXpjZniP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WyLBsPjS9vetPUMe+RLuaPgdqbEiY5Dm+9kRoJvaA2YOzyfMddMKq1YyLHcVpqz+yKJ5DiGko+s8sewzIgZ5RqLTKmf2rqcdtlc0udkioRr+zZAteBNCJf9UY1mW/K3i25HqsMJYHULQjk1UfQxuRJtimHj6Z94FZQ/jL0Ur3K1TajSxFInmxhWvnhAwWHmRg2bMWz7yWIpk3MGjJxoxsJlz2NmSV0SnJ1BIbGX95oMhrPAJx2cjnxD/P1RvFfstJEmaY8uwCuXY/tSLr0H+2MCLfXlZ70jfXsHRmqHsA= 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)" Instead of keeping our own local iterator variable, use the one just added to folio_batch. Signed-off-by: Matthew Wilcox (Oracle) Signed-off-by: Christoph Hellwig Reviewed-by: Jan Kara --- mm/page-writeback.c | 19 +++++++++---------- 1 file changed, 9 insertions(+), 10 deletions(-) diff --git a/mm/page-writeback.c b/mm/page-writeback.c index c7983ea3040be4..70f42fd9a95b5d 100644 --- a/mm/page-writeback.c +++ b/mm/page-writeback.c @@ -2397,13 +2397,19 @@ static pgoff_t wbc_end(struct writeback_control *wbc) return wbc->range_end >> PAGE_SHIFT; } -static void writeback_get_batch(struct address_space *mapping, +static struct folio *writeback_get_next(struct address_space *mapping, struct writeback_control *wbc) { + struct folio *folio = folio_batch_next(&wbc->fbatch); + + if (folio) + return folio; + folio_batch_release(&wbc->fbatch); cond_resched(); filemap_get_folios_tag(mapping, &wbc->index, wbc_end(wbc), wbc_to_tag(wbc), &wbc->fbatch); + return folio_batch_next(&wbc->fbatch); } static bool should_writeback_folio(struct address_space *mapping, @@ -2473,7 +2479,6 @@ int write_cache_pages(struct address_space *mapping, { int error; pgoff_t end; /* Inclusive */ - int i = 0; if (wbc->range_cyclic) { wbc->index = mapping->writeback_index; /* prev offset */ @@ -2489,18 +2494,12 @@ int write_cache_pages(struct address_space *mapping, wbc->err = 0; for (;;) { - struct folio *folio; + struct folio *folio = writeback_get_next(mapping, wbc); unsigned long nr; - if (i == wbc->fbatch.nr) { - writeback_get_batch(mapping, wbc); - i = 0; - } - if (wbc->fbatch.nr == 0) + if (!folio) break; - folio = wbc->fbatch.folios[i++]; - folio_lock(folio); if (!should_writeback_folio(mapping, wbc, folio)) { folio_unlock(folio);