From patchwork Sat Feb 3 07:11:45 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christoph Hellwig X-Patchwork-Id: 13543906 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 046FDC4828D for ; Sat, 3 Feb 2024 07:12:54 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 8BF276B0085; Sat, 3 Feb 2024 02:12:53 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 847236B0088; Sat, 3 Feb 2024 02:12:53 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 70F2F6B0089; Sat, 3 Feb 2024 02:12:53 -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 5F6356B0085 for ; Sat, 3 Feb 2024 02:12:53 -0500 (EST) Received: from smtpin18.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay08.hostedemail.com (Postfix) with ESMTP id 0337A1402FE for ; Sat, 3 Feb 2024 07:12:52 +0000 (UTC) X-FDA: 81749625426.18.F223922 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) by imf11.hostedemail.com (Postfix) with ESMTP id 5A80F4000B for ; Sat, 3 Feb 2024 07:12:51 +0000 (UTC) Authentication-Results: imf11.hostedemail.com; dkim=pass header.d=infradead.org header.s=bombadil.20210309 header.b=vH0hdIAp; spf=none (imf11.hostedemail.com: domain of BATV+a0ed29cff9639d748e7e+7468+infradead.org+hch@bombadil.srs.infradead.org has no SPF policy when checking 198.137.202.133) smtp.mailfrom=BATV+a0ed29cff9639d748e7e+7468+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=1706944371; 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=AnG5GvoJfhWPvqWiitfZqai2sD2FuEVxQzhAIrm6KaA=; b=VwGyq7XGTLJkAqvE1d2rhdhHwO7qBFKMK/JqLwnMdOAvatGNBiSkr1y+X/qStvwbS3glAq JyRd9G/elr1coC7YqYrl0i1MRp2kY42u/euUEdVB6nuwRy/eOLr8XLdeHyFrZgbbxk066Q p5Qd7Qzwu0Jhs4lIGKZkXNj9nD7Q5q4= ARC-Authentication-Results: i=1; imf11.hostedemail.com; dkim=pass header.d=infradead.org header.s=bombadil.20210309 header.b=vH0hdIAp; spf=none (imf11.hostedemail.com: domain of BATV+a0ed29cff9639d748e7e+7468+infradead.org+hch@bombadil.srs.infradead.org has no SPF policy when checking 198.137.202.133) smtp.mailfrom=BATV+a0ed29cff9639d748e7e+7468+infradead.org+hch@bombadil.srs.infradead.org; dmarc=none ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1706944371; a=rsa-sha256; cv=none; b=reLGxeRziXF3PJKC3h3+nlS1pLZhcAFbNYqBKi8KdLkWvA4UqjYBiaoNf5Li3GVBee0U08 cDzt/83x/mF29Pl4QOZH9iGIlnwKkHLIx/2c6Vs9TAnETkDDyRVg7J3bNuVHZQZWJvJvZR oiMwhZm6Qekmzqmm6MZJWVt8IgMkV4w= 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=AnG5GvoJfhWPvqWiitfZqai2sD2FuEVxQzhAIrm6KaA=; b=vH0hdIAp6gB22asQhHw8fV4fL7 t7SMPnQ6UOZ06eB6iUc6QRiRN2CHY9Hoa3/Qt6lKZZW+1cVc05CzNKKIfNtKfWXE9n/0DIqp9pM41 tUdkoZyp1A/VSO+XZuNI8/iD1snj2iILh49fiFClyMMSrDYvZwMScjIzwLgLCAtb95yYimLLC6kZs 3uYxfZ9w1waMc6giSV8N33kIOCeAyPZBqp55YBUwZiocSMqmbEkiaPrGEeU7UtVNwsyGwiGTQe5eA t3RXkIGbnjSxOrBklgbZ7FsjwDnYiDV06ODpVc/+M3iEChRzlwXXkIMS44L9k65uCSyfj+bQtgnTP OJ4GTRbA==; Received: from [89.144.222.32] (helo=localhost) by bombadil.infradead.org with esmtpsa (Exim 4.97.1 #2 (Red Hat Linux)) id 1rWACn-0000000FkIF-1VWY; Sat, 03 Feb 2024 07:12:50 +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 11/13] writeback: Move the folio_prepare_writeback loop out of write_cache_pages() Date: Sat, 3 Feb 2024 08:11:45 +0100 Message-Id: <20240203071147.862076-12-hch@lst.de> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20240203071147.862076-1-hch@lst.de> References: <20240203071147.862076-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: 5A80F4000B X-Rspam-User: X-Stat-Signature: aaphrpztp13mab1keerd6mdr4jjmousk X-Rspamd-Server: rspam01 X-HE-Tag: 1706944371-982538 X-HE-Meta: U2FsdGVkX18zVuTNp11qWw9QJCX5KM+1iaIv6DMIWNdASqsVxa3R3TCFJ0jNnpUpaVMbeW8v7x6E83lLK1HNG9ZxPg+KANKAuGo2qRNwecECr9fG+q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KVqYNh0jSeyI+VfobmfZ7xmF1vhafTUc1OBLrLKqLdLjw2w7gtd1ltReUXw79a1cndIs0tqELvJErDSS1q2oGkA0NUNUkW1s5nlIe5TWB/nAIuQ6iH5R7Uxak8H5qLccDKk8peZm6WDmr0U5puR+21Mdkq2xKlmiAg/2CQJHXBss2V0KdiU+fHo1ZKd4DnLlNUP0PgiwRqxdUJ+bX6o9F2fP93sjCgGHNUiDnLNgVaISft8/ftlinleNdqhP8pvuPAyNJzcAK/ALDqjMJozqfUjVPgE6IKaDFq/L5Eq2m7uQJrK7LIoTjOzfVKdNKcB0= 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 095ba4db9dcc17..3abb053e70580e 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);