Received: by 2002:a05:7412:b995:b0:f9:9502:5bb8 with SMTP id it21csp861293rdb; Fri, 22 Dec 2023 07:13:46 -0800 (PST) X-Google-Smtp-Source: AGHT+IEBhYTsfGvgHrSbxIoVU42FC4kVYYyuizUFAF1hVhBNnXg/1f0UjnfL+aqFZAb5vDdrWL2q X-Received: by 2002:a17:907:9056:b0:a26:cac5:b39b with SMTP id az22-20020a170907905600b00a26cac5b39bmr50418ejc.124.1703258026289; Fri, 22 Dec 2023 07:13:46 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1703258026; cv=none; d=google.com; s=arc-20160816; b=wZE4c6mmpqsH8uZQ7k2ZmWlKp5BpdvIf+odSx9N6znWx0duSpwxFYZy++tB516onh+ GylK+hzAbOPPXPNHnWFE5wEnhVkufzDvXd0c2NuFG+1jRJXKetw6VC2NPazKkAVmQTuo 6EP8g0JnGMsOCzwB88r9kQGI2/TbX1x5X48cISUfudJ6h6uZzg53CSiEDxd0WYU7GZsl 2NvHAbquO2z8bmhOZv3nhpuoJTU7ZEznclqk2X04ND0vkk0kkSPMzG3LzhXCf8RNEahE E/Kfshc5LzJT9SR2iAEv2cZgQNug3Gi3N78LUF0YO60K8//ltzz5Q8SF1VY9bDyDZzrV BcvQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :date:subject:cc:to:from:dkim-signature; bh=nwSb0aQ6WVWAqtAF+HdyJ3HlPU1688MOnHDS98Pt7+A=; fh=hzpEVxJ05G9gyZL9WVyKgOEGxITvmFSuTcKyr2ByStg=; b=gm+xch9t4yWKbnAFICZl5agQaojl1uE8OtP2MoMuBB1OQs1khV//26qM/nUfpJKTMp o7e1QBNaMXxR39txeoIzW+RWLxmaZz3E5XrZIYE5wGhRn2Fp8d0h2ZbLMldrooBk2x8C nq60+I6AiTGV/15Ph8LJwPEnifGT/CLgeDFOuqLZhv/29yN7pnWk/6gV0uw3zTbBNdbt jRy5JE+SJyHS5WnkEBmHUgdnoAUUjdm6mJkF1owL53j0M7xmmbJjUSwSniM/Pb3cDn28 7fgleN7ZgCVcdy649NLByE1s4Q7t9l/vvmwfl0koI0B+zN/X6/hqhaH1XbgB/69Za1BQ 0njg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@infradead.org header.s=bombadil.20210309 header.b=fsTEpZhG; spf=pass (google.com: domain of linux-kernel+bounces-9825-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-9825-linux.lists.archive=gmail.com@vger.kernel.org" Return-Path: Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [147.75.80.249]) by mx.google.com with ESMTPS id a6-20020a170906468600b00a235ce4851bsi1865002ejr.796.2023.12.22.07.13.46 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 22 Dec 2023 07:13:46 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-9825-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) client-ip=147.75.80.249; Authentication-Results: mx.google.com; dkim=pass header.i=@infradead.org header.s=bombadil.20210309 header.b=fsTEpZhG; spf=pass (google.com: domain of linux-kernel+bounces-9825-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-9825-linux.lists.archive=gmail.com@vger.kernel.org" Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by am.mirrors.kernel.org (Postfix) with ESMTPS id 67B1E1F225F5 for ; Fri, 22 Dec 2023 15:12:53 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 221572E85E; Fri, 22 Dec 2023 15:09:05 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=infradead.org header.i=@infradead.org header.b="fsTEpZhG" X-Original-To: linux-kernel@vger.kernel.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 3582E2E837; Fri, 22 Dec 2023 15:09:02 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=lst.de Authentication-Results: smtp.subspace.kernel.org; spf=none smtp.mailfrom=bombadil.srs.infradead.org 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> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-SRS-Rewrite: SMTP reverse-path rewritten from by bombadil.infradead.org. See http://www.infradead.org/rpr.html 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; -- 2.39.2