From patchwork Fri Dec 22 15:08:23 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christoph Hellwig X-Patchwork-Id: 13503421 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 2E3C9C41535 for ; Fri, 22 Dec 2023 15:09:09 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 4FC968D0007; Fri, 22 Dec 2023 10:09:03 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 45C7D8D0003; Fri, 22 Dec 2023 10:09:03 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 2D6F78D0007; Fri, 22 Dec 2023 10:09:03 -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 1E0B98D0003 for ; Fri, 22 Dec 2023 10:09:03 -0500 (EST) Received: from smtpin15.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay03.hostedemail.com (Postfix) with ESMTP id D87B6A0EDA for ; Fri, 22 Dec 2023 15:09:02 +0000 (UTC) X-FDA: 81594786924.15.DDB27B2 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) by imf20.hostedemail.com (Postfix) with ESMTP id 111581C0030 for ; Fri, 22 Dec 2023 15:09:00 +0000 (UTC) Authentication-Results: imf20.hostedemail.com; dkim=pass header.d=infradead.org header.s=bombadil.20210309 header.b=fsTEpZhG; spf=none (imf20.hostedemail.com: domain of BATV+af923ccb694ecd533eae+7425+infradead.org+hch@bombadil.srs.infradead.org has no SPF policy when checking 198.137.202.133) smtp.mailfrom=BATV+af923ccb694ecd533eae+7425+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=1703257741; 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=nwSb0aQ6WVWAqtAF+HdyJ3HlPU1688MOnHDS98Pt7+A=; b=SHudDDpyUhT86lgOV11EO+tiqhVP/t4PiuSYPUhDbJ9G9LKqKcqLZrEMfZoAGyPTTgIJQu 1HBuga32oqJG3tzSv47mE9affnTHGeVQc2e3L5xCciqIh1ojCPaHxfABX+SYBFFzfmaAO4 4Ubj9ARFB85n5oI0g7lsH7sip2pyJUc= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1703257741; a=rsa-sha256; cv=none; b=k8RIsebGQVLoWafvBGGWN0VPdA4XJk3wGMnaCcR8CzrBQ3TEcAlXJHK1snIp2R8N2M5zeS VzLitrD6uSZUcYNiSVS8zhOi+2V7x/LMwP34+QoA6Yrvo2Yf5uQmhBdd3z3qsYVwj7V7Ic oHJ8oPPz/jnxhTcVS2O328ygw0zeM+U= ARC-Authentication-Results: i=1; imf20.hostedemail.com; dkim=pass header.d=infradead.org header.s=bombadil.20210309 header.b=fsTEpZhG; spf=none (imf20.hostedemail.com: domain of BATV+af923ccb694ecd533eae+7425+infradead.org+hch@bombadil.srs.infradead.org has no SPF policy when checking 198.137.202.133) smtp.mailfrom=BATV+af923ccb694ecd533eae+7425+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=nwSb0aQ6WVWAqtAF+HdyJ3HlPU1688MOnHDS98Pt7+A=; b=fsTEpZhGkE4khH8MXT4PtBYhdo ZQgp/dXeIGwyn7s3VuOqu6GmTRUxeSslau35ljaEbUfRgqA0ZEAH8JVNUJqryffLuZ1tiX++MxAHy Nq+T9gs+7AeBOpWiNijbKLhyOEzHiXCvYJyQBKAzyR6Jx96R9RLRtpKuVe/PAuijSu2MSVEHhsx60 po2QLtX1ruHagJovmBJr49HjCGb76ply2cGzBN7tNen/Y7LvzOWkGILqJzTcP2VcgfasfyxRa/YLB CMyztaZTGjFje4ZGqnH7q15JeaxPgTH5DZcug+qDAWvVZPH+wM4/3FoVMrbM3vDe1Jt7WqAsXg8ta 7O6j3/7A==; 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 1rGh91-006BYP-2j; Fri, 22 Dec 2023 15:09:00 +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, Jan Kara , Dave Chinner Subject: [PATCH 13/17] writeback: Move the folio_prepare_writeback loop out of write_cache_pages() Date: Fri, 22 Dec 2023 16:08:23 +0100 Message-Id: <20231222150827.1329938-14-hch@lst.de> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20231222150827.1329938-1-hch@lst.de> References: <20231222150827.1329938-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: 53zpjeyaeo39eztt1pjx15cr1d8q6m6e X-Rspamd-Server: rspam10 X-Rspamd-Queue-Id: 111581C0030 X-Rspam-User: X-HE-Tag: 1703257740-661106 X-HE-Meta: U2FsdGVkX18pKxll+CYcCYYaQD34y6lhjXjORrlgKVUYn1Aa2yjFBnkVyO4eHjWnuu2Jmp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uXGyR1tLBLXbZ5GzoDgtMLZFPIS8/qpiUniEXDKGC4o+TkCXNuhOuu6mPh9s39Ik/PPQiVTZzbXXvAiYGVMysdmCKmj6aRsi7C87NxK4OwR342eBGqJ1hyrSmISA3f3cK4LROYxSNlSjvrXYFBdq/uJFB36oFhMZ/mF263Fx0NFKI9XEIU0W91XnGdXM9mG8mMfAVBDh7YYH6OOS6mWYF0z81185XqK7QJfpFLtSbqzbORWL+zOxkk9VB+scqWFy5kaO11hfTPfuCWdClUF+STjwz5UaBjADfrV1E6U1afQnPcjPEQeqt54hwPcW4/BMHW59m0upjTXSpfKh708WeCXG+AQ6mGqdmkYIQdARF9prgtZPvvcJTpgLzoC1ykynrdX0d 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)" Move the loop for should-we-write-this-folio to writeback_get_folio. Signed-off-by: Matthew Wilcox (Oracle) [hch: folded the loop into the existing helper instead of a separate one as suggested by Jan Kara] Signed-off-by: Christoph Hellwig Reviewed-by: Jan Kara Acked-by: Dave Chinner --- mm/page-writeback.c | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/mm/page-writeback.c b/mm/page-writeback.c index f85145f330bb36..b6048c14748fdb 100644 --- a/mm/page-writeback.c +++ b/mm/page-writeback.c @@ -2434,6 +2434,7 @@ static struct folio *writeback_get_folio(struct address_space *mapping, { struct folio *folio; +retry: folio = folio_batch_next(&wbc->fbatch); if (!folio) { folio_batch_release(&wbc->fbatch); @@ -2441,8 +2442,17 @@ static struct folio *writeback_get_folio(struct address_space *mapping, filemap_get_folios_tag(mapping, &wbc->index, wbc_end(wbc), wbc_to_tag(wbc), &wbc->fbatch); folio = folio_batch_next(&wbc->fbatch); + if (!folio) + return NULL; } + folio_lock(folio); + if (unlikely(!folio_prepare_writeback(mapping, wbc, folio))) { + folio_unlock(folio); + goto retry; + } + + trace_wbc_writepage(wbc, inode_to_bdi(mapping->host)); return folio; } @@ -2505,14 +2515,6 @@ int write_cache_pages(struct address_space *mapping, folio = writeback_get_folio(mapping, wbc)) { unsigned long nr; - folio_lock(folio); - if (!folio_prepare_writeback(mapping, wbc, folio)) { - folio_unlock(folio); - continue; - } - - trace_wbc_writepage(wbc, inode_to_bdi(mapping->host)); - error = writepage(folio, wbc, data); nr = folio_nr_pages(folio); wbc->nr_to_write -= nr;