From patchwork Thu Dec 14 13:25:40 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christoph Hellwig X-Patchwork-Id: 13493160 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 AC3A0C4332F for ; Thu, 14 Dec 2023 14:54:13 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id DC4828D00B1; Thu, 14 Dec 2023 09:54:12 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id D4C458D00C7; Thu, 14 Dec 2023 09:54:12 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id B525B8D00B1; Thu, 14 Dec 2023 09:54:12 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0017.hostedemail.com [216.40.44.17]) by kanga.kvack.org (Postfix) with ESMTP id 91A8F6B051C for ; Thu, 14 Dec 2023 09:54:12 -0500 (EST) Received: from smtpin18.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay08.hostedemail.com (Postfix) with ESMTP id 464E5140CFC for ; Thu, 14 Dec 2023 14:54:12 +0000 (UTC) X-FDA: 81565719144.18.6BF7E17 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) by imf29.hostedemail.com (Postfix) with ESMTP id 63765120017 for ; Thu, 14 Dec 2023 14:54:09 +0000 (UTC) Authentication-Results: imf29.hostedemail.com; dkim=pass header.d=infradead.org header.s=bombadil.20210309 header.b="SFp/hA0f"; spf=none (imf29.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; dmarc=none ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1702565650; 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=Rss8E0TEJ5ZWP+w65Q90ToBr5MzQatBIEX9ecM3F1aY=; b=ZUqZlwoNCrvSRhL4aKWoQNXrgSAtDJNHeO5pVDbAFlfUp0aMvae0uB8OaUildgl/n7D+vn BYIxCOaqawEzBy1Q4ryV30I9jLf6sUzIiz5CB08I5GBA74m87qqJqj06E7msiEUpqWrbLt MRY0ItTQc7IaVgsNbkxt6DMv3zNs1tc= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1702565650; a=rsa-sha256; cv=none; b=GX6lnArhhEpuSVW6c8BQJW3D92qz+Mp7Bj2+OZ7eZfxmhaF7EN5pnalNoLok0GxDr6hGYY 8diiq7RTQ+rRfwe4tyYkt5dxpd1XAiaXlHQCd1Blye9Df21Ln87daBlZbIFRqrg7rEEjDi 2ss4CIrmrn3TAIRVOBmerUuP3Z/C7+0= ARC-Authentication-Results: i=1; imf29.hostedemail.com; dkim=pass header.d=infradead.org header.s=bombadil.20210309 header.b="SFp/hA0f"; spf=none (imf29.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; 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=Rss8E0TEJ5ZWP+w65Q90ToBr5MzQatBIEX9ecM3F1aY=; b=SFp/hA0fghmYHxPZK8RDs0mSUs 2dvs2+f6lfbzUR4ZepQ8+lOvHkqOAptEtwte/LyANyBKUX+HZd6mcog/IExGHXKJfcdRoQzhSEDVK 9gl9L8NnOfFLsnDEvkTsvZZbvnfcHT60084SRlecI7C6UAQf90dwmCWmioA0g1syVyRezuHE2J+eF 21bWWbXPoewfgvDtZgt262UOaoMZWqrFo31EMV17CZ/D0kysdzJ+M4j1lDjO8XJ42vlch6Vq549hE 9UltZjPeJfE+jhxELs1O90Wb3pPSZRv3o+5Fg2ZUJ9i5WA/JSVcNZOnJTj+4nH5Fs+BxSmPDf0wae I2w0fc9g==; Received: from [88.128.88.27] (helo=localhost) by bombadil.infradead.org with esmtpsa (Exim 4.96 #2 (Red Hat Linux)) id 1rDljF-000N9J-2g; Thu, 14 Dec 2023 13:26:18 +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 07/11] writeback: Factor writeback_iter_init() out of write_cache_pages() Date: Thu, 14 Dec 2023 14:25:40 +0100 Message-Id: <20231214132544.376574-8-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-Stat-Signature: haiykttahwm6sng3p1qfesmjg7h8j5ce X-Rspamd-Server: rspam10 X-Rspamd-Queue-Id: 63765120017 X-Rspam-User: X-HE-Tag: 1702565649-535965 X-HE-Meta: U2FsdGVkX19ZguZmEO7PWoD5rbZ/WBogkWceWnNVkEtTN5gd/baK4Ka/zCA4QtXDIySq1XLji81JV+gD6vp/shEXt762z7xkUvvkohtwSOCssgOR63bBssKHnvlx0p6qJ44+QhAohNqMaGkUe80uWa6SgWx8BYxQCzFzm77sMwnO5w3aow7vGt82MmO982W+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a7SpM2drJeOs1vc29ehzRcBu3gJChPflcIEIy/M9Gf8me3hTb+FtbAgE/kG8zrRdeW3lKV/I6zQOUaVGoG7idRxXS2OrvuPxg4cgujx1RHKM4rZm2fXZjkLeimxXM/+MgMoUib/R8gIkaO/OuSVdjqyBN6tHKtcRDBRzWJPkxeK/I4VCwCuNkI6NLvtS7yZFGblaiUaWzcOU+sNpGsuNq7gyVDZg== 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 --- mm/page-writeback.c | 47 +++++++++++++++++++++++++-------------------- 1 file changed, 26 insertions(+), 21 deletions(-) diff --git a/mm/page-writeback.c b/mm/page-writeback.c index 2243a0d1b2d3c7..8c220c6a7f824d 100644 --- a/mm/page-writeback.c +++ b/mm/page-writeback.c @@ -2429,6 +2429,28 @@ static bool should_writeback_folio(struct address_space *mapping, return true; } +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 */ + wbc->end = -1; + } else { + wbc->index = wbc->range_start >> PAGE_SHIFT; + wbc->end = wbc->range_end >> PAGE_SHIFT; + if (wbc->range_start == 0 && wbc->range_end == LLONG_MAX) + wbc->range_whole = 1; + } + if (wbc->sync_mode == WB_SYNC_ALL || wbc->tagged_writepages) + tag_pages_for_writeback(mapping, wbc->index, wbc->end); + + wbc->done_index = wbc->index; + folio_batch_init(&wbc->fbatch); + wbc->err = 0; + + return writeback_get_next(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 @@ -2464,31 +2486,14 @@ int write_cache_pages(struct address_space *mapping, struct writeback_control *wbc, writepage_t writepage, void *data) { + struct folio *folio; int error; - if (wbc->range_cyclic) { - wbc->index = mapping->writeback_index; /* prev offset */ - wbc->end = -1; - } else { - wbc->index = wbc->range_start >> PAGE_SHIFT; - wbc->end = wbc->range_end >> PAGE_SHIFT; - if (wbc->range_start == 0 && wbc->range_end == LLONG_MAX) - wbc->range_whole = 1; - } - if (wbc->sync_mode == WB_SYNC_ALL || wbc->tagged_writepages) - tag_pages_for_writeback(mapping, wbc->index, wbc->end); - - wbc->done_index = wbc->index; - folio_batch_init(&wbc->fbatch); - wbc->err = 0; - - for (;;) { - struct folio *folio = writeback_get_next(mapping, wbc); + for (folio = writeback_iter_init(mapping, wbc); + folio; + folio = writeback_get_next(mapping, wbc)) { unsigned long nr; - if (!folio) - break; - wbc->done_index = folio->index; folio_lock(folio);