From patchwork Thu Dec 14 13:25:35 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christoph Hellwig X-Patchwork-Id: 13493056 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 2F36BC4167B for ; Thu, 14 Dec 2023 13:26:03 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id B88288D00B5; Thu, 14 Dec 2023 08:26:02 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id B39EC8D00B1; Thu, 14 Dec 2023 08:26:02 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 98B2F8D00B5; Thu, 14 Dec 2023 08:26:02 -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 8334D8D00B1 for ; Thu, 14 Dec 2023 08:26:02 -0500 (EST) Received: from smtpin19.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay04.hostedemail.com (Postfix) with ESMTP id 64D601A0BF7 for ; Thu, 14 Dec 2023 13:26:02 +0000 (UTC) X-FDA: 81565496964.19.3D3E0C7 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) by imf04.hostedemail.com (Postfix) with ESMTP id A715440005 for ; Thu, 14 Dec 2023 13:26:00 +0000 (UTC) Authentication-Results: imf04.hostedemail.com; dkim=pass header.d=infradead.org header.s=bombadil.20210309 header.b=iaO3zrW7; dmarc=none; spf=none (imf04.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=1702560360; 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=gFAfQ8RI4NZqa/9LCD+jS3TStiD980ne3/Qcf1aEZzA=; b=0FM5pNgVtavPvDwC864rgg6WuPNd9662pqzIbAZJMEhvDitXJVFuvfiZaV4DRqfXQlBHkW EEhxuDZp7SewNr+hMfCTfKuN76XnDWok51LvS7cgqOx0GwOTIrTKyWZfsMwk/ZKcruoxDw U9QU2INFqbCuWAXRYpiytWbHlkFfCjc= ARC-Authentication-Results: i=1; imf04.hostedemail.com; dkim=pass header.d=infradead.org header.s=bombadil.20210309 header.b=iaO3zrW7; dmarc=none; spf=none (imf04.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=1702560360; a=rsa-sha256; cv=none; b=ay/xzDW1ZNMWeKki+fOfzzbzCcoBPwmf0gklAqBNL+CAbezNRSUs5S4scmc2vEb3DjUV8w KE7yaLVK37aGFct9drIjbzXC7LcrhoYMQjdYVNO2ctvz8YBqKtAdbCpWprvdxI8SlCtX2a zAICBcYKedCSRP25T8HjCSfgfMsYXE0= 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=gFAfQ8RI4NZqa/9LCD+jS3TStiD980ne3/Qcf1aEZzA=; b=iaO3zrW79MSicmR2sZYKfRcxiH i6dP0SWuEvOwauQFGQNX6drc20R0mQporbqJK9Ae/EpSzZ2URWntRpkaHP0xigV0iDY5QuSJHIiCQ Mo7Rto/vqm0//OV5Akxwqp+GKF4VnjeKJIRrzyZvhXp1nfFHZo6clA6Ms2vyByRzAuCo5P769hI0E uuu0EStnwmU0hmRpVyXiiEKSAQSDbPs5OhXxok9vD7vVpTfFx0OyvSabAZzyGs9vLoBYXlH08ZvZw 9amAcoVDpwtwFO+Pq43XGabNC9cEhu43saMRnC8Zp09eKvIPBlEOZtG6iQCulLeEvzO1jHG5Xn8O+ yftaE4YA==; Received: from [88.128.88.27] (helo=localhost) by bombadil.infradead.org with esmtpsa (Exim 4.96 #2 (Red Hat Linux)) id 1rDlix-000N1N-1b; Thu, 14 Dec 2023 13:25:59 +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 02/11] writeback: Factor writeback_get_batch() out of write_cache_pages() Date: Thu, 14 Dec 2023 14:25:35 +0100 Message-Id: <20231214132544.376574-3-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-Stat-Signature: 7u4rn439r5onuyc7fa6g476xysws4ar7 X-Rspamd-Server: rspam07 X-Rspamd-Queue-Id: A715440005 X-HE-Tag: 1702560360-195031 X-HE-Meta: U2FsdGVkX1+cGIXiBk4DCl6YNjIjN30qaw+NohO9CeMy+pGniKLgSCHRX0NGWLeUXspyyU//I6WLDdlSFa+5TYSMx03/rm4nTPt36vGOA2DLhvBJDXLBHa5ak+A6hxS8zIbw9ijFCZrS2ZosIGr3GIlGSa5Mu5/IafA6AcJa4bXmBBLli9UnT8oEeW8Jjbg24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D4T3V1R6mAEbI8vm/STUKtArhUg7CmmQ370UGinsXl+8WM+JBRAglpchSbSE6bk4BpfTVcQ6/tXz+GA0ofAMz19b62bxwjWmVBMWe45OlV4bPDUJ+0FgLngDdvA3WHAqgQDINa/E2cnVAfx+JHRvMj7soQ0XaHS+kJINTL+Ju+auWfUCnUYRznarL4X9PyZO7Dpw3FFaMzNOBkhPzfRfEcOdQ5g== 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) Signed-off-by: Christoph Hellwig --- include/linux/writeback.h | 2 ++ mm/page-writeback.c | 49 +++++++++++++++++++++------------------ 2 files changed, 29 insertions(+), 22 deletions(-) diff --git a/include/linux/writeback.h b/include/linux/writeback.h index 05e8add4b5ae3c..be960f92ad9dbd 100644 --- a/include/linux/writeback.h +++ b/include/linux/writeback.h @@ -81,6 +81,8 @@ struct writeback_control { /* internal fields used by the ->writepages implementation: */ struct folio_batch fbatch; + pgoff_t index; + pgoff_t end; /* inclusive */ pgoff_t done_index; int err; unsigned range_whole:1; /* entire file */ diff --git a/mm/page-writeback.c b/mm/page-writeback.c index 45309f3b8193f8..5d33e7b468e2cc 100644 --- a/mm/page-writeback.c +++ b/mm/page-writeback.c @@ -2378,6 +2378,22 @@ static int writeback_finish(struct address_space *mapping, return wbc->err; } +static void writeback_get_batch(struct address_space *mapping, + struct writeback_control *wbc) +{ + xa_mark_t tag; + + if (wbc->sync_mode == WB_SYNC_ALL || wbc->tagged_writepages) + tag = PAGECACHE_TAG_TOWRITE; + else + tag = PAGECACHE_TAG_DIRTY; + + folio_batch_release(&wbc->fbatch); + cond_resched(); + filemap_get_folios_tag(mapping, &wbc->index, wbc->end, tag, + &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 @@ -2414,41 +2430,32 @@ 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 */ - end = -1; + wbc->index = mapping->writeback_index; /* prev offset */ + wbc->end = -1; } else { - index = wbc->range_start >> PAGE_SHIFT; - end = wbc->range_end >> PAGE_SHIFT; + 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, 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, wbc->end); - wbc->done_index = index; + wbc->done_index = wbc->index; folio_batch_init(&wbc->fbatch); wbc->err = 0; - while (index <= end) { + while (wbc->index <= wbc->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; @@ -2526,8 +2533,6 @@ int write_cache_pages(struct address_space *mapping, wbc->sync_mode == WB_SYNC_NONE) return writeback_finish(mapping, wbc, true); } - folio_batch_release(&wbc->fbatch); - cond_resched(); } return writeback_finish(mapping, wbc, false);