From patchwork Mon Dec 18 15:35:43 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christoph Hellwig X-Patchwork-Id: 13497161 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 A6905C35274 for ; Mon, 18 Dec 2023 15:36:20 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 9986B8D000E; Mon, 18 Dec 2023 10:36:17 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 939F08D0009; Mon, 18 Dec 2023 10:36:17 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 7DAE78D000E; Mon, 18 Dec 2023 10:36:17 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0013.hostedemail.com [216.40.44.13]) by kanga.kvack.org (Postfix) with ESMTP id 6B8668D0009 for ; Mon, 18 Dec 2023 10:36:17 -0500 (EST) Received: from smtpin07.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay08.hostedemail.com (Postfix) with ESMTP id 4C02B140224 for ; Mon, 18 Dec 2023 15:36:17 +0000 (UTC) X-FDA: 81580340394.07.BDCDC64 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) by imf14.hostedemail.com (Postfix) with ESMTP id BAB68100012 for ; Mon, 18 Dec 2023 15:36:15 +0000 (UTC) Authentication-Results: imf14.hostedemail.com; dkim=pass header.d=infradead.org header.s=bombadil.20210309 header.b="Fx9/cCVV"; dmarc=none; spf=none (imf14.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 ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1702913775; 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=aHXKO1UbJHXuqoP1fMOkKbpvbuANBll89l/hQyqHhR4=; b=IM7MEllU9yE5AV3b1hxwe0Aoi1G2XPCfNd6Y0Cc8HbhXrcNHLfxgVFapBS3aYtMIsmMqHT 1EaEnCY4NJnHSQIOHvIRwEORyjgaQO17ySIcbfCKP2f7wPRzF/lPdKvxNndByIhvee6SHl eXM8n98Bev+O3M4hB7M8ymHhmkc9yk0= ARC-Authentication-Results: i=1; imf14.hostedemail.com; dkim=pass header.d=infradead.org header.s=bombadil.20210309 header.b="Fx9/cCVV"; dmarc=none; spf=none (imf14.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 ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1702913775; a=rsa-sha256; cv=none; b=hGC+hyWC354BVbm7D1fqrY9WazaZiUr39ftixD5atKkb1MrPZwh0na10NvPAdoRbQ8A0px B7AFaYxsEIKuuFa2GCo9q6Xiwh6tJVrdIXec7sQL7GE9D/6oA+Ih2BQ2KlJyhUAfii0qYt 1Nnal5/99kuAEahGDUVA+9FqmKnLx1U= 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=aHXKO1UbJHXuqoP1fMOkKbpvbuANBll89l/hQyqHhR4=; b=Fx9/cCVVlwYOnhe/PSU89cDqVD NI/Css67r/FlsYc8NmCfniGg54QHQxgHsspAS57gDul5cTzL0hn1ZYeRU9gC8qFIq//ZJLH1vTyTT NkYZETzb+w26apnFjyIKLapIGMmBHyHAabMX4hk9cvfq0clnn+uyJpYeekVoYtCuTYVUNQFlPatrZ SSsp/9CpzQ3RKUCNPWaBU4OgSu7Wl1+hiqb+XWiQ2Uv+YBGT9sPgftDPPkSwJXycLm4D/AKXvHjus 0HFC0kopXSnEv2BVLjCG4hwfCCGuT9gt5VWusTok0xcANlH5KBh8QDWOzHVEd1W+MU2o0JryEnPBY gQ5ZhBvA==; 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 1rFFfC-00BENM-0x; Mon, 18 Dec 2023 15:36:14 +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 07/17] writeback: Factor writeback_get_batch() out of write_cache_pages() Date: Mon, 18 Dec 2023 16:35:43 +0100 Message-Id: <20231218153553.807799-8-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: BAB68100012 X-Rspam-User: X-Rspamd-Server: rspam04 X-Stat-Signature: pqfiq4sim3cc6pcwzsqqwtedqqns5tr7 X-HE-Tag: 1702913775-306425 X-HE-Meta: U2FsdGVkX183RCOBl1KzO4pXxVK3suinXqoi/Tdp6ReyTCZu4DtFw1GT+UcJV8MaRxNj/vE+GlUVKxeiwZh5xM7YDGDnbiXkuGs+xJ9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KXAp7P7aCt5KlOSWolQzA6wprhchw== 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)" This simple helper will be the basis of the writeback iterator. To make this work, we need to remember the current index and end positions in writeback_control. Signed-off-by: Matthew Wilcox (Oracle) [hch: heavily rebased, add helpers to get the tag and end index, don't keep the end index in struct writeback_control] Signed-off-by: Christoph Hellwig Reviewed-by: Jan Kara --- include/linux/writeback.h | 1 + mm/page-writeback.c | 49 +++++++++++++++++++++++++-------------- 2 files changed, 32 insertions(+), 18 deletions(-) diff --git a/include/linux/writeback.h b/include/linux/writeback.h index 390f2dd03cf27e..195393981ccb5c 100644 --- a/include/linux/writeback.h +++ b/include/linux/writeback.h @@ -81,6 +81,7 @@ struct writeback_control { /* internal fields used by the ->writepages implementation: */ struct folio_batch fbatch; + pgoff_t index; int err; #ifdef CONFIG_CGROUP_WRITEBACK diff --git a/mm/page-writeback.c b/mm/page-writeback.c index 564d5faf562ba7..798e5264dc0353 100644 --- a/mm/page-writeback.c +++ b/mm/page-writeback.c @@ -2383,6 +2383,29 @@ static void writeback_finish(struct address_space *mapping, } } +static xa_mark_t wbc_to_tag(struct writeback_control *wbc) +{ + if (wbc->sync_mode == WB_SYNC_ALL || wbc->tagged_writepages) + return PAGECACHE_TAG_TOWRITE; + return PAGECACHE_TAG_DIRTY; +} + +static pgoff_t wbc_end(struct writeback_control *wbc) +{ + if (wbc->range_cyclic) + return -1; + return wbc->range_end >> PAGE_SHIFT; +} + +static void writeback_get_batch(struct address_space *mapping, + struct writeback_control *wbc) +{ + folio_batch_release(&wbc->fbatch); + cond_resched(); + filemap_get_folios_tag(mapping, &wbc->index, wbc_end(wbc), + wbc_to_tag(wbc), &wbc->fbatch); +} + /** * 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 @@ -2419,38 +2442,30 @@ int write_cache_pages(struct address_space *mapping, void *data) { int error; - int nr_folios; - pgoff_t index; pgoff_t end; /* Inclusive */ - xa_mark_t tag; if (wbc->range_cyclic) { - index = mapping->writeback_index; /* prev offset */ + wbc->index = mapping->writeback_index; /* prev offset */ end = -1; } else { - index = wbc->range_start >> PAGE_SHIFT; + 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, index, end); - tag = PAGECACHE_TAG_TOWRITE; - } else { - tag = PAGECACHE_TAG_DIRTY; - } + 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; - while (index <= end) { + while (wbc->index <= end) { int i; - nr_folios = filemap_get_folios_tag(mapping, &index, end, - tag, &wbc->fbatch); + writeback_get_batch(mapping, wbc); - if (nr_folios == 0) + if (wbc->fbatch.nr == 0) break; - for (i = 0; i < nr_folios; i++) { + for (i = 0; i < wbc->fbatch.nr; i++) { struct folio *folio = wbc->fbatch.folios[i]; unsigned long nr; @@ -2525,8 +2540,6 @@ int write_cache_pages(struct address_space *mapping, return error; } } - folio_batch_release(&wbc->fbatch); - cond_resched(); } writeback_finish(mapping, wbc, 0);