From patchwork Thu Dec 14 13:25:39 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christoph Hellwig X-Patchwork-Id: 13493126 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 3203BC4332F for ; Thu, 14 Dec 2023 14:22:50 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id A78EF6B06AF; Thu, 14 Dec 2023 09:22:49 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id A296B6B06B0; Thu, 14 Dec 2023 09:22:49 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 8F1E56B06B1; Thu, 14 Dec 2023 09:22:49 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0014.hostedemail.com [216.40.44.14]) by kanga.kvack.org (Postfix) with ESMTP id 7BBDC6B06AF for ; Thu, 14 Dec 2023 09:22:49 -0500 (EST) Received: from smtpin09.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay09.hostedemail.com (Postfix) with ESMTP id 4647880CA6 for ; Thu, 14 Dec 2023 14:22:49 +0000 (UTC) X-FDA: 81565640058.09.D4BB4FE Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) by imf01.hostedemail.com (Postfix) with ESMTP id 594EF4001D for ; Thu, 14 Dec 2023 14:22:46 +0000 (UTC) Authentication-Results: imf01.hostedemail.com; dkim=pass header.d=infradead.org header.s=bombadil.20210309 header.b=D9YSNoUn; dmarc=none; spf=none (imf01.hostedemail.com: domain of BATV+55581d165dda9d0af87b+7417+infradead.org+hch@bombadil.srs.infradead.org has no SPF policy when checking 198.137.202.133) smtp.mailfrom=BATV+55581d165dda9d0af87b+7417+infradead.org+hch@bombadil.srs.infradead.org ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1702563767; a=rsa-sha256; cv=none; b=NM9Nu3LXh0E7KlIFX+tU66FL+pVya330ly1Og1QpCvyXT7YcqUDvTFJd4Bnd1GpNxipcNg WWwi/lOKHRpUOBIciUYCyPF8EuRcgO6uXFVXKif7S54iBj4mpX4yuN5tP09mqR9uwCCzpq tp7SzHCaoRcFyYrlJ61/ZOaf492j0Q8= ARC-Authentication-Results: i=1; imf01.hostedemail.com; dkim=pass header.d=infradead.org header.s=bombadil.20210309 header.b=D9YSNoUn; dmarc=none; spf=none (imf01.hostedemail.com: domain of BATV+55581d165dda9d0af87b+7417+infradead.org+hch@bombadil.srs.infradead.org has no SPF policy when checking 198.137.202.133) smtp.mailfrom=BATV+55581d165dda9d0af87b+7417+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=1702563767; 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=MxYyShLiRKm/b2kgWMNr7J68lt6H7F1PYCAdmGQu21k=; b=WIhl1fyGcPoioMxfk7W7GZJ3eTszreLo4SZ8LWXXiQKrtg3quKSBu+yvYDvc55pVwDULNV luDWQ+2Ba30I1KnWNUx6sirlEWF4wP8rQaunnUFsY9UhKd0c4Spxxgj6ZYDJ96ako2eQQ/ 029VU9OcIBPJ4Aay7oWzsJad+u+JDNA= 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=MxYyShLiRKm/b2kgWMNr7J68lt6H7F1PYCAdmGQu21k=; b=D9YSNoUndTNHZOJBIIstgZm299 fqPapOf+sTH1GXW0IqUNd0YqzZtYfAXncK2PeCKGRRHmhuG09goKRpeMQWwnoW7FXknQOalV4l2fH uMjwqwUUmCi3br7beZe20CmuYsuPnXaM6VvFGr0zv6SNQZqvI5wZ9sv1+odmLUM63q3Fu85vAG2gf s/8DG9HAvLdUTA+2GNHp/WSl9Y/MqL5YMQytvl73whfVH0xPfqs91rWMXyaWVagm/AxS13FvHlweg mjFa5QkB005ny4hVt62BETy702qH2PMBV67OIuknvVwncXTerzZRoIe+aF+KZ8szfS1i+JuPt8KvI m8mTW8UA==; Received: from [88.128.88.27] (helo=localhost) by bombadil.infradead.org with esmtpsa (Exim 4.96 #2 (Red Hat Linux)) id 1rDljB-000N7L-0i; Thu, 14 Dec 2023 13:26:14 +0000 From: Christoph Hellwig 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 06/11] writeback: Use the folio_batch queue iterator Date: Thu, 14 Dec 2023 14:25:39 +0100 Message-Id: <20231214132544.376574-7-hch@lst.de> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20231214132544.376574-1-hch@lst.de> References: <20231214132544.376574-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-Rspam-User: X-Rspamd-Server: rspam06 X-Rspamd-Queue-Id: 594EF4001D X-Stat-Signature: 41fbamnbpwf7kok49sof4qmd9gag5tey X-HE-Tag: 1702563766-752141 X-HE-Meta: U2FsdGVkX1+AjZ8IBdJjsEtSB26chofMmFgx156eNQkyEwPslnC0qtwCB75xiS3gcR0p3NbFf0wB9ty2l0EDenM2neRZAomfW3EqlmlUJTcCc0BQTxoVsQd9xxAGsWEKEhe5NkI+ljGejgt22ARJbnvqTQ82G0KXEddnYnKHoEC0ttfMPxWUrkuTX96dYDxbVqI11FevYW1tVh27l7qV4D7b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7oVDfXISH8jNW5pyuhc0Ag49ib0X9HLTBMWzi6H4o1SIjd3oyf3Uw54bes8QkDdxBaPk7nYf5ilJzIg/SXMlJfewrzx7VyUlxn3ipQ0QIvVKfracC9F2kGGR0EPMnThl+WVU3BluuDSUigq9ZoVeh6NxfTDubhTNjwb2KIU0OYNCgAuQ1xXx4lZilc1w== 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 --- mm/page-writeback.c | 18 ++++++++---------- 1 file changed, 8 insertions(+), 10 deletions(-) diff --git a/mm/page-writeback.c b/mm/page-writeback.c index 2087d16115710e..2243a0d1b2d3c7 100644 --- a/mm/page-writeback.c +++ b/mm/page-writeback.c @@ -2378,11 +2378,15 @@ static int writeback_finish(struct address_space *mapping, return wbc->err; } -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); xa_mark_t tag; + if (folio) + return folio; + if (wbc->sync_mode == WB_SYNC_ALL || wbc->tagged_writepages) tag = PAGECACHE_TAG_TOWRITE; else @@ -2392,6 +2396,7 @@ static void writeback_get_batch(struct address_space *mapping, cond_resched(); filemap_get_folios_tag(mapping, &wbc->index, wbc->end, tag, &wbc->fbatch); + return folio_batch_next(&wbc->fbatch); } static bool should_writeback_folio(struct address_space *mapping, @@ -2460,7 +2465,6 @@ int write_cache_pages(struct address_space *mapping, void *data) { int error; - int i = 0; if (wbc->range_cyclic) { wbc->index = mapping->writeback_index; /* prev offset */ @@ -2479,18 +2483,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++]; - wbc->done_index = folio->index; folio_lock(folio);