From patchwork Thu Jan 25 08:57:46 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christoph Hellwig X-Patchwork-Id: 13530262 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 F0476C47258 for ; Thu, 25 Jan 2024 08:58:32 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 855806B007B; Thu, 25 Jan 2024 03:58:32 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 8050D6B0083; Thu, 25 Jan 2024 03:58:32 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 6A6926B0087; Thu, 25 Jan 2024 03:58:32 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0016.hostedemail.com [216.40.44.16]) by kanga.kvack.org (Postfix) with ESMTP id 4655C6B007B for ; Thu, 25 Jan 2024 03:58:32 -0500 (EST) Received: from smtpin14.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay01.hostedemail.com (Postfix) with ESMTP id EA0C51C08E6 for ; Thu, 25 Jan 2024 08:58:31 +0000 (UTC) X-FDA: 81717232422.14.676D35A Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) by imf14.hostedemail.com (Postfix) with ESMTP id 2BA4A10000B for ; Thu, 25 Jan 2024 08:58:29 +0000 (UTC) Authentication-Results: imf14.hostedemail.com; dkim=pass header.d=infradead.org header.s=bombadil.20210309 header.b=NYMtHn25; dmarc=none; spf=none (imf14.hostedemail.com: domain of BATV+b97a0fc658bf3e588113+7459+infradead.org+hch@bombadil.srs.infradead.org has no SPF policy when checking 198.137.202.133) smtp.mailfrom=BATV+b97a0fc658bf3e588113+7459+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=1706173110; 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=iMNdeEcqkHffoQV1X3XMHDmnGgKthKHMo1jJFViVMos=; b=5zV2+Ti7q2d/AnnHeZ2HuxTXh0o9YOBYZyWwYFpqwnEg5kGvl6jTpIiDeMiE0QBP9SY1oH uJzxWwE6wHGLYmaMqztusidwRNgffZT5YJowmpKITDH+SKddtMOfLicjWRfiC50JA+3Idm mw3NxClROQc6KbcBiTJKbKZ/ZW34UYE= ARC-Authentication-Results: i=1; imf14.hostedemail.com; dkim=pass header.d=infradead.org header.s=bombadil.20210309 header.b=NYMtHn25; dmarc=none; spf=none (imf14.hostedemail.com: domain of BATV+b97a0fc658bf3e588113+7459+infradead.org+hch@bombadil.srs.infradead.org has no SPF policy when checking 198.137.202.133) smtp.mailfrom=BATV+b97a0fc658bf3e588113+7459+infradead.org+hch@bombadil.srs.infradead.org ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1706173110; a=rsa-sha256; cv=none; b=GFc9OD5oXrGcZsjpcSSxUwTNdFxensikjZlecmLpJlraJRCSFVHKjD0LzCQ2X1bxpwN4AC uBkuko3ib7w5dRuZ1KXQlYrM98Lw4HJYJLFJ36Na1kS5b83EQ22uzktLZq5o4UJe1hIhnI VU/ulfxY5CaOEJVyjyIzrmYEMUFcVXQ= 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=iMNdeEcqkHffoQV1X3XMHDmnGgKthKHMo1jJFViVMos=; b=NYMtHn25QyrrlxJcgdmcd5wXPv Fs4iTu7Y92y79RyHoSjqnlwmQ9qOeHg2R71DOkpgcyJhscAmH6I4dNw4srUwkykfySn/hDJUXF9Mg xE1KHnNO/4TDKC1BnAC9r/zqcHfUmFdxMYmeWpb6mOQR7ikjQnudqE5vJzum+sNrz7WREHDLNDbt8 aOCRcmIL3e0neCp4yrhGF9cF/98FYoaUTHSoa9ags1lcADvlSMN2TLch/Y/7NVitDRie7WYJvj4ps 0BORVBVnBJbJe3aJ/25+/xzXccPHir5JNNB1eIiE4OgrV4nMlCA8nj6yVyW4d0PWkGM78le+KiEiS 8mHMHEEA==; 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 1rSvZ6-007QHR-2Y; Thu, 25 Jan 2024 08:58:29 +0000 From: Christoph Hellwig To: linux-mm@kvack.org Cc: Matthew Wilcox , Jan Kara , David Howells , Brian Foster , Christian Brauner , "Darrick J. Wong" , linux-xfs@vger.kernel.org, linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org, Jan Kara , Dave Chinner Subject: [PATCH 07/19] writeback: Factor writeback_get_batch() out of write_cache_pages() Date: Thu, 25 Jan 2024 09:57:46 +0100 Message-Id: <20240125085758.2393327-8-hch@lst.de> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20240125085758.2393327-1-hch@lst.de> References: <20240125085758.2393327-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: 2BA4A10000B X-Rspam-User: X-Rspamd-Server: rspam02 X-Stat-Signature: c4oskpwhwnxj5oe19igz6okab464dwbk X-HE-Tag: 1706173109-237881 X-HE-Meta: U2FsdGVkX19qOXrXA576WisulazHeGuhoqF4QSH4vgWqD8hiC6LcyKMYPi9ShwulqijC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ovfs9dqjMOzSwdbHhgkuNz1PYbLA3UU1dsSsqWdK3ABDOGV7DqTTaJU+mrMz+vuYwfp49nJzTbbSJ7OGBW2NOB0uFBBftrYPsi6u+HHLUw8Nrljap1Gx0R/4Qp3F+jCY7TnXP9i0lwhVUnsKMPpY5mK/YfSEeontD5Rv82Zn8hsR2eRiApPzAINtSp3AeZ/TWbIGe8w5QJiSLu4ZkYSPNELSj1EqGpWvE1srsfAYBbNs2R2uim0tOieM6pFcUc3xXxH9Qf6urfePaUmeHbU09E9NO4WfuVEbMjTUEVBPfiB4tRlFl8wH0NcEZzY+gILXIsLvaWtr93w9SVh7IYTtY8EXaU2QLfYq3tyLbLuZ+b31pS3VOTy5dHP6xKMjzFq6babNin1zWGoIh4ItZQ9GVcn1f+/jbvmGlGJG 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 Acked-by: Dave Chinner --- 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 7d60a68fa4ea47..a091817a5dba55 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 fcd90a176d806c..426d929741e46e 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);