From patchwork Mon Feb 12 07:13: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: 13552753 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 8C1DDC4829E for ; Mon, 12 Feb 2024 07:14:35 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 233AD6B0088; Mon, 12 Feb 2024 02:14:35 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 196506B0089; Mon, 12 Feb 2024 02:14:35 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id F024E6B008A; Mon, 12 Feb 2024 02:14:34 -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 DF1A56B0088 for ; Mon, 12 Feb 2024 02:14:34 -0500 (EST) Received: from smtpin14.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay10.hostedemail.com (Postfix) with ESMTP id B5B89C08C1 for ; Mon, 12 Feb 2024 07:14:34 +0000 (UTC) X-FDA: 81782288868.14.9255A77 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) by imf22.hostedemail.com (Postfix) with ESMTP id F290BC0017 for ; Mon, 12 Feb 2024 07:14:32 +0000 (UTC) Authentication-Results: imf22.hostedemail.com; dkim=pass header.d=infradead.org header.s=bombadil.20210309 header.b=XbHX1mZC; dmarc=none; spf=none (imf22.hostedemail.com: domain of BATV+56c964bc8172c8a9ee6e+7477+infradead.org+hch@bombadil.srs.infradead.org has no SPF policy when checking 198.137.202.133) smtp.mailfrom=BATV+56c964bc8172c8a9ee6e+7477+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=1707722073; 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=hDwf/sJTGlPIwBTRyPln6Zb1s+XpptYYA785c3w7vC4=; b=l3oGCSrX1lccxdtF6HdnLNjDIStEsTkHHoN8AwBx2WeqvwDUfJQ7uSLZlfZwhZbukpYfiI zZMcqKvYU1q5ptSL5t5HvRM6DpKJLVKpmePIoKuZKTt+EG9oQAYxuNnDpzjxCNOUk2BnPG NNAOMM7iORoFSjP4YRHKCamZOyKubac= ARC-Authentication-Results: i=1; imf22.hostedemail.com; dkim=pass header.d=infradead.org header.s=bombadil.20210309 header.b=XbHX1mZC; dmarc=none; spf=none (imf22.hostedemail.com: domain of BATV+56c964bc8172c8a9ee6e+7477+infradead.org+hch@bombadil.srs.infradead.org has no SPF policy when checking 198.137.202.133) smtp.mailfrom=BATV+56c964bc8172c8a9ee6e+7477+infradead.org+hch@bombadil.srs.infradead.org ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1707722073; a=rsa-sha256; cv=none; b=6EISi8/efjLKEKtBLEqhOclKuuASaWulN0+ERdNVbOzpBr+WDZ/7GwCUMA5qqGHW9e98Xt RR28YN1gXsYfTpq/X4mL0uZl1wIvLEE5oNE0K+dBQA1lEq0TwMBZWz67LK+I83gBQ+ZPfD XFDbrlIECRCrDswh/J+KzV2ePf8wPL8= 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=hDwf/sJTGlPIwBTRyPln6Zb1s+XpptYYA785c3w7vC4=; b=XbHX1mZCM5Mo7rShucMVsPQybi QYfeqa4nFaBzcM/DsAKy72s4D9gnZOQ+eZo15yg3xEHI7qigOLDFMavU0ZQlm8qdIdV8CBLgIYtNM gHhvHVUsTtsNGL+zE1jQLwkYVCj1Ruag3QbLwJ6Ta838iRkgnS1Lg6mE0P8nW/ZpIDmOytDpBIi4n yCMmI5JnIJvd0PcT1ZiaClUiaUlPN6MlYprQswFXIjkP/LX0Uli5B5o6UES3k6xUM87eJrAHtae9O FQP2lx8hKziZv9DQcZadgvj3xcrZEzcT3dQju6kWLLYmqNYz0W+KfaI8gVzCyx93dbRKa1wcqdpG3 r9C4E0cQ==; Received: from [2001:4bb8:190:6eab:75e9:7295:a6e3:c35d] (helo=localhost) by bombadil.infradead.org with esmtpsa (Exim 4.97.1 #2 (Red Hat Linux)) id 1rZQWN-00000004T3G-2raf; Mon, 12 Feb 2024 07:14:32 +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: Mon, 12 Feb 2024 08:13:46 +0100 Message-Id: <20240212071348.1369918-13-hch@lst.de> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20240212071348.1369918-1-hch@lst.de> References: <20240212071348.1369918-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-Rspamd-Server: rspam12 X-Rspamd-Queue-Id: F290BC0017 X-Stat-Signature: k1ijp36axur8fj4ifgfe9srgz3yxnz8i X-HE-Tag: 1707722072-284792 X-HE-Meta: U2FsdGVkX18fCiIQer6Fz6UPliVxtk3sGqKZwXoxEU4a1yrBjNvaKWZv5+pnb1vBJvOxgSHloKc6bgZibMM3GNT7WSQ+QU/Fg9QyeRbCohgGT7nUebly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ZO5dnKkPhfXpZVrPpK68iJWeEKOOVRoKEQY5CkDxPNMhVlAt9XAvB7ce9eYZynYNneuq5kjpv05xy1XJoec98GYxKUpZmFRD2u+c2iEcHoKo2V5opcwkEuwOSKO9GgDxHyMJ/+zoF/7QOQfwtpkHvWHF0NmqRxQ0/nH6VIBDwdTtIwcYdzMBDQBuo3XtkaZ9iB4xwJ3LKaffzm1WGqYXMWteXkL0IhKIkyMLoHcyr7q55GOy74XJ/lO29OCWpOZMnm2rGEkhPFsnn3HjtVM7pe7Td/dSInCg2kiI4rbNbH/zfEZQBF553Lzy20uYzXgZS4R6rAV 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 62b663debe713b..01f076db4f2118 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);