From patchwork Thu Jan 25 08:57:52 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christoph Hellwig X-Patchwork-Id: 13530268 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 23587C47258 for ; Thu, 25 Jan 2024 08:58:56 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id AA0BF280007; Thu, 25 Jan 2024 03:58:55 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id A4FDB280001; Thu, 25 Jan 2024 03:58:55 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 8A248280007; Thu, 25 Jan 2024 03:58:55 -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 7AD01280001 for ; Thu, 25 Jan 2024 03:58:55 -0500 (EST) Received: from smtpin27.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay07.hostedemail.com (Postfix) with ESMTP id 589F6160D46 for ; Thu, 25 Jan 2024 08:58:55 +0000 (UTC) X-FDA: 81717233430.27.0B428FE Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) by imf26.hostedemail.com (Postfix) with ESMTP id DB086140008 for ; Thu, 25 Jan 2024 08:58:53 +0000 (UTC) Authentication-Results: imf26.hostedemail.com; dkim=pass header.d=infradead.org header.s=bombadil.20210309 header.b=ZQE+aY4V; spf=none (imf26.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; dmarc=none ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1706173133; 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=ukNtwPf12oSRUA3UJBplrrlZ3BMhuvUNPapQ7zi0Hu0=; b=zutLYZIIYZfCCmSsZMkPZ9g5udN+khX39ni1LNUg+5bTRBStKJrG3cMg5CMp0NmZQZ60Kk uhIFg1Pe48qruhw2p6FTWfB/uwwh2nxU2tE/PSeVIfwaL7nmYV2dwJcDxAfJAQgwhbpYe2 7Nyf5eHP72RPSj3WHBvj2LQbtoCdFq0= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1706173133; a=rsa-sha256; cv=none; b=Ci+1MXAkor3hCy/vIB2VUcaKyQfFtPfN9ulyBbu48prpDmVA5YseUH9965feECEs4I6mcV GjBzjn70T4bwE+KsWI1l7pkVefD0nLUcuF96/HPdGzqr6g/+lsjvLeSx/NqRoH7HaD5W2c WtZ5KshkW7b7OTvYfOBLD9uKVpHEmpM= ARC-Authentication-Results: i=1; imf26.hostedemail.com; dkim=pass header.d=infradead.org header.s=bombadil.20210309 header.b=ZQE+aY4V; spf=none (imf26.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; 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=ukNtwPf12oSRUA3UJBplrrlZ3BMhuvUNPapQ7zi0Hu0=; b=ZQE+aY4VeQqULr6kd1ufkmZyCm g9XFXD48FdWm/3mGFDF270b4JWx4OZ1Vd/zauFYola5nkSWISmgToauOt+vPrpv0elJ11E7fycDW+ uOi2DFdCMSO/ZX0oeqLzF1JI8vL3pIexWD13RQ4jUekhoCKohpXznMGe5Uyou0O9KuF8gj5CUJEOF o7nEL9nQYx8FhnMMg3ZBtuM0yJyPDXOrqiutn+GUZRX+HAT/TooxYxn9uecwIuNBUADX/fGtI9kYl EMbhh8TGKk2tqfPi8Nb9f4CirptF/P969fIdg3CJ31Oh3webS++wJM9TVQQJOU/AFldl7RgCJIO+4 /gpbjwIA==; 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 1rSvZU-007QRY-1i; Thu, 25 Jan 2024 08:58:53 +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 13/19] writeback: Move the folio_prepare_writeback loop out of write_cache_pages() Date: Thu, 25 Jan 2024 09:57:52 +0100 Message-Id: <20240125085758.2393327-14-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-Stat-Signature: yjaqaoiypgjgsfe5houn4r4n8u3sqo4c X-Rspamd-Server: rspam10 X-Rspamd-Queue-Id: DB086140008 X-Rspam-User: X-HE-Tag: 1706173133-497357 X-HE-Meta: U2FsdGVkX1/wJxSrHAtiDJjVIW/6PRS0fSiSSCGIFJRDocThg3jXMRuup0U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/PpoVhjuA8U5x+NL2Tw0stK+Ncc3Dl2XTS99tTUcahX4X2hcAhoy/V86gPw== 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 ae9f659e6796ac..d170dab07402ce 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;