From patchwork Thu Feb 15 06:36:47 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christoph Hellwig X-Patchwork-Id: 13557446 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 B3570C4829E for ; Thu, 15 Feb 2024 06:37:44 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id BACB96B00B8; Thu, 15 Feb 2024 01:37:30 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id B0C316B00B9; Thu, 15 Feb 2024 01:37:30 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 95E266B00BA; Thu, 15 Feb 2024 01:37:30 -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 791C46B00B8 for ; Thu, 15 Feb 2024 01:37:30 -0500 (EST) Received: from smtpin20.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay04.hostedemail.com (Postfix) with ESMTP id 55EEF1A0DA7 for ; Thu, 15 Feb 2024 06:37:30 +0000 (UTC) X-FDA: 81793081860.20.99CBB90 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) by imf02.hostedemail.com (Postfix) with ESMTP id A61A280016 for ; Thu, 15 Feb 2024 06:37:28 +0000 (UTC) Authentication-Results: imf02.hostedemail.com; dkim=pass header.d=infradead.org header.s=bombadil.20210309 header.b=IE6GYCQF; spf=none (imf02.hostedemail.com: domain of BATV+a252b21bd4a653ddb6e6+7480+infradead.org+hch@bombadil.srs.infradead.org has no SPF policy when checking 198.137.202.133) smtp.mailfrom=BATV+a252b21bd4a653ddb6e6+7480+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=1707979048; 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=dpEY7SmyA34rLmNMjZVpGv1HVhFTICw5Hhe2kQSv81M=; b=HLkO0tPSCRmC1BGFBOGJEiWc6zP8DexZx43ZX5g7sfDtnqpVuv2LHQ8W+eDcs+9SAuLZiG wZtadC+wheSwXk+ocbsWgvXbp+5y/vgPCW+HJg8hF8xxB+dThy7HqKgsM5xk5h8VVaEOkj 0+XjLeDYjbcAHeqm524Dgpu+ke2s3GE= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1707979048; a=rsa-sha256; cv=none; b=TGXR89KJ7DgTgAsqwYwuk1nU90PWGO1jBnk2FS375fCXFEWLRUHiEkAV+y6jtEXwUrpgFI IPN2F/H4121okO24sb7u0Lm3LLCFAoHaaU7Z5IcwUT1nE1nKhBzsbTK/8i/gjsH1qlYEMC MUP3xHDnXOWG/uAZvF0NWGTnAmTyVCU= ARC-Authentication-Results: i=1; imf02.hostedemail.com; dkim=pass header.d=infradead.org header.s=bombadil.20210309 header.b=IE6GYCQF; spf=none (imf02.hostedemail.com: domain of BATV+a252b21bd4a653ddb6e6+7480+infradead.org+hch@bombadil.srs.infradead.org has no SPF policy when checking 198.137.202.133) smtp.mailfrom=BATV+a252b21bd4a653ddb6e6+7480+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=dpEY7SmyA34rLmNMjZVpGv1HVhFTICw5Hhe2kQSv81M=; b=IE6GYCQF3eV3lxuP59icZOXmbS +ZieiZz134xt6WwJJzwEPn739abiFT+QYhRmHkAw32tujHIHQHYaTqWK18UROqd9WFjuRrPe7e2tx gpFYSFBSmWjzvOzbpp4+OvsrWEKz3fKWswV/Zrm4Asux3Z2NCPWYpQ7gOdOlLV0EHf56ssi9QFmsK q7iPT2U8FwRCMtBDr7GcdQx219YFW7DS0GggsGgV2i/XgHXQnLt55fDdUF0bbhStSOweF6LucJ4bh eNFNVP2TLPuzZqh7+r2s7SHtmBzkiSMfVkTncMGSxRQLPZJFmcRiKLXjcQQLItfXLoMJfU/8tkReR qNWH7rHA==; 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.97.1 #2 (Red Hat Linux)) id 1raVN9-0000000F71D-1Lq2; Thu, 15 Feb 2024 06:37:27 +0000 From: Christoph Hellwig To: linux-mm@kvack.org Cc: Matthew Wilcox , Jan Kara , David Howells , Brian Foster , Christian Brauner , linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org, Jan Kara , Dave Chinner Subject: [PATCH 12/14] writeback: Move the folio_prepare_writeback loop out of write_cache_pages() Date: Thu, 15 Feb 2024 07:36:47 +0100 Message-Id: <20240215063649.2164017-13-hch@lst.de> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20240215063649.2164017-1-hch@lst.de> References: <20240215063649.2164017-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: A61A280016 X-Rspam-User: X-Stat-Signature: nx3nzp51i5mhkyc9qngatgxfmeq4j4uf X-Rspamd-Server: rspam03 X-HE-Tag: 1707979048-367428 X-HE-Meta: U2FsdGVkX1+ZCjDk9vJfrjKtzGxs1UsGhnWbc9I+z77p+p/Juyd19SPAcgL7sLoc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dAHBRhMl75Ts3yma5wUERSTL4eSVRwA4q/engVUSfuM+QDRGc8m+ntYntneXONqLPVcqGniSQ6qW0JCx2bKgCf4sq4iMk5YbXogO5Hx0lgazGtwAvWHGVRrDlCiLnLbiSeevEgi2JyU37+bkT+TB7t3tIYJN7yQMwoNGX4N3OVTj2GsInduPH3u3Us6vd/xOJvienrIM3epShla+J3tDHoiLDx+f8gpdqnC/cSgemAe/VBWHJaXEhI1o8XmB9VUK9TDDNJTflmw9SIgDTpFkFybcAW28vk63SVlwqgonme2IHlcBKdoJOx17Yrtdd0d51m0SCv5JBn3pzhr1YDoGKcXsCrwBBilD4tUtQFcMI/UUupK7md5fVoJkAMkB9ebKJkKtZ 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: Brian Foster 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 3cbe4a7daa357c..fc421402f81881 100644 --- a/mm/page-writeback.c +++ b/mm/page-writeback.c @@ -2411,6 +2411,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); @@ -2418,8 +2419,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; } @@ -2480,14 +2490,6 @@ int write_cache_pages(struct address_space *mapping, if (!folio) break; - 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); wbc->nr_to_write -= folio_nr_pages(folio);