Received: by 2002:a05:7412:bbc7:b0:fc:a2b0:25d7 with SMTP id kh7csp1304051rdb; Sat, 3 Feb 2024 00:31:38 -0800 (PST) X-Google-Smtp-Source: AGHT+IEwXNSqn9IFRTflGvKrg+ebJw1NJbfKiGxPV+s0ue2ArwJbJgI6mz+ssqd0q5Ftfyrg2oYO X-Received: by 2002:a17:906:22d6:b0:a36:c845:86c2 with SMTP id q22-20020a17090622d600b00a36c84586c2mr4408384eja.51.1706949098211; Sat, 03 Feb 2024 00:31:38 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1706949098; cv=pass; d=google.com; s=arc-20160816; b=lbM9O/g4vV8RgL6ZeiZ4pAsM+UcVYT3hW+w6H/5QhWbZKhXmlFtwfifD1rpeswzHdN jKFRYJYD6UvMiw5VVzdo+vpt7jXambf7awRrIQgYyaB9bMirr2Ew4bTaZrXE6J5J3kTZ hHJpMDUAOe2bXnNFVSYMRdu79nctKHEzSrMjHb2Jdmrl/hZheJEHjDQLiEEeW48uPeUp ZXU+wn4F/rTU47Dtiasoo/cIENHKjb92jTGNaHds9uj+NOZ9F0yoY0Io62bza0ljYhzj b8sHNQxY/+HSYZUsUy+2zgSJECUvrjP0Cs2rwpfoA43AEeNT9hA/LH9HS0p29236v51P /MCg== ARC-Message-Signature: i=2; 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=AnG5GvoJfhWPvqWiitfZqai2sD2FuEVxQzhAIrm6KaA=; fh=cK5T75WwXSuha+CFUwcBvmkUAUA+qvoMmYRaTJLuDvw=; b=izd96i/4Rnp4jyzxlUMIsCqe9EihkEZlnic0yqFQOCXY9iyZn7NtaqqMMTfbDoEaS9 efUd1j1QnR3qxJZAkRT7VuKhtqnuIE0/68bqfYteqR0U0buFFZXSqQkTZRpqpbhDZxOq 7JCE83ed5HDfjMNFF5gkmuFqENOEWbzoVclZV6xA41YhcKS9rw3FbqqqPNED7Q7DPS4G 7+Gj8U6atF3Y3oY477umsNO21Jo70If+gD4dD0LMkSXAfTObvdSMLSUaTox9FlTwYLSF 9bsO1lP9MoSCOQWaHCjbQvPd2Ul2Kx5VlkKY496w+WS/Non4rnhXUG/Fn7TRD3bmaAOr 2TnA==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@infradead.org header.s=bombadil.20210309 header.b=vH0hdIAp; arc=pass (i=1 dkim=pass dkdomain=infradead.org); spf=pass (google.com: domain of linux-kernel+bounces-50960-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-50960-linux.lists.archive=gmail.com@vger.kernel.org" X-Forwarded-Encrypted: i=1; AJvYcCXPWq7Vzpae/T2AQ47RofsSDo+b2Cs+ZZCParmEz9/Y1bgv2k+I2Ymn/3B7I97p8LbFtEfuA8GuXzMuCt8dWiJAfJ9t+GY7hq14qVtvBQ== Return-Path: Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [2604:1380:4601:e00::3]) by mx.google.com with ESMTPS id r6-20020a1709067fc600b00a28fe2b3ad5si1624358ejs.1015.2024.02.03.00.31.38 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 03 Feb 2024 00:31:38 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-50960-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) client-ip=2604:1380:4601:e00::3; Authentication-Results: mx.google.com; dkim=pass header.i=@infradead.org header.s=bombadil.20210309 header.b=vH0hdIAp; arc=pass (i=1 dkim=pass dkdomain=infradead.org); spf=pass (google.com: domain of linux-kernel+bounces-50960-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-50960-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 B3EE91F2BDED for ; Sat, 3 Feb 2024 07:15:49 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 19F4E5676E; Sat, 3 Feb 2024 07:12:56 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=infradead.org header.i=@infradead.org header.b="vH0hdIAp" 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 41C345674D; Sat, 3 Feb 2024 07:12:53 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=198.137.202.133 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706944375; cv=none; b=WgDO1cNXuU0mWvLO2zjZ7Y2Nc2abdsCUgXs61hCE0AQBcbSxaSMXOyUnt1G8asDqpSSiZDfJCOLkL6z+ZvXSokbvFc4hJ3EynG1PCiWST9hQnkT3cgkzbPb9rSUzYyCRIe0OwolJy0MXqdlphyRc1EzuC6phxnUXpdoM9FvzacA= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706944375; c=relaxed/simple; bh=BEzYiGhNCPidNvLvQLhLK2U2cZcI03nhea82PoTH56s=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=qwTrdoNCgKMGcfy+qax7TpF0QaTvX8IW9Mm+MuGyEd1oNJAhUJwzyi6UaDOwiMqRYBjr0JZoNBe9QougMhh4v7NJSTGNoW8uLRh0CYDXN5HwOSG3OBzJsERNAJzMsbihP4/oaaVPsZVxZWyBDY4RlSU74ioZzQxFIkaoo0VGTUk= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=lst.de; spf=none smtp.mailfrom=bombadil.srs.infradead.org; dkim=pass (2048-bit key) header.d=infradead.org header.i=@infradead.org header.b=vH0hdIAp; arc=none smtp.client-ip=198.137.202.133 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=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> 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: 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); -- 2.39.2