From patchwork Sat Feb 3 07:11:36 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christoph Hellwig X-Patchwork-Id: 196255 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7301:9bc1:b0:106:209c:c626 with SMTP id op1csp987689dyc; Sat, 3 Feb 2024 04:20:12 -0800 (PST) X-Google-Smtp-Source: AGHT+IFxJPfPHS0TJjvbsQLwihDkziK+9UcwucmFAvIR8e/fTfUA2W4ReoQkNoEUZdeJO0wKWUGl X-Received: by 2002:a05:6214:1c4e:b0:68c:928e:a93d with SMTP id if14-20020a0562141c4e00b0068c928ea93dmr1350876qvb.25.1706962812665; Sat, 03 Feb 2024 04:20:12 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1706962812; cv=pass; d=google.com; s=arc-20160816; b=TAYwr2RTRB3u17LLJQjKVGjFd+m8DxodRiGZl22WK66ZvZ5Gqj3ymEpgcBl/PJ6r91 k9bDP/clMvNntqFYh+bqel3z17IaW4llvm7d9h5+sIoup7ZT/ahsQszzxsDGs7tJjqg4 EKJzrxhxGAjkDucXoahnJTyJq4t0yDJydWUm7lrFD3olFpOar7F7dgKHJv2KNVqFctV8 kk16rHZT5furWOPnWRyaaFEPkMgNhxKAnfmzNqfQlpzR6XGtEwUID/LbPljKAwrRTuiW W/Gt/03VB5CeoFmRqGKo8KQWEMLdCAIF+uc0hvsJx3mBEjvuh6iZGe8OcQEOugc9oy6y RBPA== 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=Ir6qdgwpiudHSGvIqZf3UZHrrrbsMgA9iIwYL6Ldf0U=; fh=xhaiu9dvUn4Wt+NSM8sF88dvyr0C0WIiBw5ptGmxj8I=; b=Bu10qxxXipwMhnT+W7uvgsTYhCY8ESZnIEpHfbphs7KYMNTBQKVqQpJ6LyJ6GJn6Jm ht0V+lrzCVYhdfxx/vdT/MOdY+BdK+uVnvrZSjg8x/xWgeNglXeHHBopRJ11R9TbkyVm d87T2U2S934CLXM1B7JkVCy28GnWDT/E5N/f805LcZ4EZp6En8LnqSTb+siv6pMZT2Xn IHFXXwN8PomOnqt4UKUCu5QERlWKLqX/GtvJhlzYXWSM4nj0YjL5u6jRtTozLrgdN6Ba OBAd32Sven5JxEmC+4xoOH/T9lF7vLOh7Glq1rsZ02NbO2J3mxUW99kEHyy6Jm9yzoT8 MIqw==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@infradead.org header.s=bombadil.20210309 header.b=iE2Qy9x6; arc=pass (i=1 dkim=pass dkdomain=infradead.org); spf=pass (google.com: domain of linux-kernel+bounces-50951-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-50951-ouuuleilei=gmail.com@vger.kernel.org" X-Forwarded-Encrypted: i=1; AJvYcCWkOnLo55MSzHmRI3rYMOA2Kf8Y4hBENj9Ma3p7k/7xvq1DLhzjREGc07Fa3hnp/WQ7aiew/bzQmiE6tI5/oMrZEG+f3w== Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [147.75.199.223]) by mx.google.com with ESMTPS id s2-20020ad44382000000b0068c461ae06fsi4158609qvr.258.2024.02.03.04.20.12 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 03 Feb 2024 04:20:12 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-50951-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) client-ip=147.75.199.223; Authentication-Results: mx.google.com; dkim=pass header.i=@infradead.org header.s=bombadil.20210309 header.b=iE2Qy9x6; arc=pass (i=1 dkim=pass dkdomain=infradead.org); spf=pass (google.com: domain of linux-kernel+bounces-50951-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-50951-ouuuleilei=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 ny.mirrors.kernel.org (Postfix) with ESMTPS id E7A6E1C23D4F for ; Sat, 3 Feb 2024 07:13:04 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 487104F212; Sat, 3 Feb 2024 07:12:16 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=infradead.org header.i=@infradead.org header.b="iE2Qy9x6" 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 450614E1D3; Sat, 3 Feb 2024 07:12:11 +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=1706944333; cv=none; b=h+tPRjH2v8Fly/Gt55zi2qHggBy5HccHjDs8mFFvW2H2UZKCKLibM8J9b/0jWd66+l1i1UOsSzB8uf/W8Vg+fv1/YKxdYOgoBg6zUpHwuLAg0MFuFU9lNROe+BK8vhncgYYRLGvNaR3y1W25WDDAhLEb6eRPAlLhsikH4PFFMY4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706944333; c=relaxed/simple; bh=fd5z2BBVNn++M9QyH8w4N0hNZ9EZndHdM9R5JVwzQgM=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=TTsqkzrAWpy99CaWv2HF8oVusngBsOWkQZIER+0e2AbEJ7RmrtIiFCYunBI9zRevuCNXXJi7MeiRWA4RxEXuRyeGVXrMWpCOTrdpSBbZe/iELgMo7bmLouYqIZAEbxYD6PP38dMcZPs1ThTrJU7zQ8+S7ccL7aC16Oqkohcc8FI= 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=iE2Qy9x6; 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=Ir6qdgwpiudHSGvIqZf3UZHrrrbsMgA9iIwYL6Ldf0U=; b=iE2Qy9x6Sg4y+wDEl3bj4dxn64 gCZM+M5CKCFy/pvjW1p2OkT8q39b+HPLnqpeQFtfQGA7LIQT455VsNCXAFevt/ZFQdlwY6+lV/T08 hi9wUOIqd5dzHOSzIBC2F2C1en3bkkET7N+8OxgSq2ZP6UymsXcY5AHMrDYarIBXr43S1FjEAqJwL tnWLV4DaRWtSn8qD6VOyT5NExzUXn7LolYKSrpLFNKsSD9ZMMwOWlGrlASjgnLrSgjA6/9i6nUia2 SO3m5CYQbkwfuUV+eCZiDRKzYLJuG2c9DuxAxC2a3HR2vl2ucCFG25/X7aUlQeXm0S5RF82fcXR7Y 9YjRd9ow==; Received: from [89.144.222.32] (helo=localhost) by bombadil.infradead.org with esmtpsa (Exim 4.97.1 #2 (Red Hat Linux)) id 1rWAC8-0000000Fjz1-3cgJ; Sat, 03 Feb 2024 07:12:09 +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 02/13] writeback: fix done_index when hitting the wbc->nr_to_write Date: Sat, 3 Feb 2024 08:11:36 +0100 Message-Id: <20240203071147.862076-3-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 X-SRS-Rewrite: SMTP reverse-path rewritten from by bombadil.infradead.org. See http://www.infradead.org/rpr.html X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1789880238503900174 X-GMAIL-MSGID: 1789880238503900174 When write_cache_pages finishes writing out a folio, it fails to update done_index to account for the number of pages in the folio just written. That means when range_cyclic writeback is restarted, it will be restarted at this folio instead of after it as it should. Fix that by updating done_index before breaking out of the loop. Signed-off-by: Christoph Hellwig Reviewed-by: Brian Foster Reviewed-by: Jan Kara Acked-by: Dave Chinner --- mm/page-writeback.c | 1 + 1 file changed, 1 insertion(+) diff --git a/mm/page-writeback.c b/mm/page-writeback.c index 02147b61712bc9..b4d978f77b0b69 100644 --- a/mm/page-writeback.c +++ b/mm/page-writeback.c @@ -2505,6 +2505,7 @@ int write_cache_pages(struct address_space *mapping, * keep going until we have written all the pages * we tagged for writeback prior to entering this loop. */ + done_index = folio->index + nr; wbc->nr_to_write -= nr; if (wbc->nr_to_write <= 0 && wbc->sync_mode == WB_SYNC_NONE) { From patchwork Sat Feb 3 07:11:37 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christoph Hellwig X-Patchwork-Id: 196310 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7301:9bc1:b0:106:209c:c626 with SMTP id op1csp1041381dyc; Sat, 3 Feb 2024 06:21:20 -0800 (PST) X-Google-Smtp-Source: AGHT+IHKFR0T+36zWv8AKmfv5mbIBF3GsDDSTL6SV9VvUN5zWM9CSt4e4mXc4T2frG5Nfes0RHQD X-Received: by 2002:a50:d59d:0:b0:55f:c4e9:60df with SMTP id v29-20020a50d59d000000b0055fc4e960dfmr1487300edi.20.1706970080196; Sat, 03 Feb 2024 06:21:20 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1706970080; cv=pass; d=google.com; s=arc-20160816; b=KUhUsuNz4Bu6uiLtc/oCJ6QRS67ue8Hkq5Un2mw3vwoPIubYZzDKoS+KXlSlMh06rl lwfGYu7phauJL7vYS7NlaERe25L5kseaqkSKPY9iAAnByHIHYK/KvUtIFz+vAMSBFmqN Q2vDwryE/6/2fQah6EohUT8nLxQMOTBpW8r20A+o1QPEhFbFYGOwnKZH9hV4aKqGAEu3 C3SVUwoddYuaEw7D36yqZjs6hthpt2IlswN2IxryWqTKoSx5gk+AJUx5GHxT6KlUfPQP 4TdxBmxhxgvWNygZs2WgoPtjeLq/dJer31AZFWjryuf4p1/AIHVQlzvJgzwtor99okyE 3m2A== 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=49fgiBCP04epsyHu4VZLFhJdGCRmLlr7ZEyZXKDtz3E=; fh=3RcM/WaoiZdJPBLsdLkSpJlGlSjNPivoQLqnWkUn4XQ=; b=fXPyJBVvhYqUQcaGHFZaSbwfhLp6Rk+AtrTMAeksOQFUFXItA+JC2k5JwyA6pMKg/6 WDQ/E1FUKE4cEcksxG3fMD7xHCPiuPRmcDPLeU4F6GqSMyEXgbYvyax/fuESKd+PkAB4 7IFJEvUaxg6kG5i35I27ZS+SteGX5l8NpPO8llOQgBCwxD/q5WSMJScByPnRpaLgGcdd Py1EX/nACe9VRV5uO0EGnqIWuCxambynAbU18vQ5MUPU1mQOo4tpGZ9K+Tug/L3JUAhG mpGSrQha8iWqCILqc1QYHAEpekhMjJGdipyD06dym2ADmhdQ6JeQHHfHHKzBOTchpyCi 7l3w==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@infradead.org header.s=bombadil.20210309 header.b=XlUtYVzv; arc=pass (i=1 dkim=pass dkdomain=infradead.org); spf=pass (google.com: domain of linux-kernel+bounces-50952-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-50952-ouuuleilei=gmail.com@vger.kernel.org" X-Forwarded-Encrypted: i=1; AJvYcCWtew1WclgAm4BvgIG0CwOGMuc4bTXG93wlPF3SCKEja6/mS7WHeHSNcK+6zRrFyR/QVEt4P9KT4oD5MVSC1mnVxFBOAw== Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [147.75.80.249]) by mx.google.com with ESMTPS id eg10-20020a056402288a00b0055729eed820si1850931edb.37.2024.02.03.06.21.20 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 03 Feb 2024 06:21:20 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-50952-ouuuleilei=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=XlUtYVzv; arc=pass (i=1 dkim=pass dkdomain=infradead.org); spf=pass (google.com: domain of linux-kernel+bounces-50952-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-50952-ouuuleilei=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 47FAD1F29788 for ; Sat, 3 Feb 2024 07:13:24 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id B443F4F885; Sat, 3 Feb 2024 07:12:21 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=infradead.org header.i=@infradead.org header.b="XlUtYVzv" 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 A1F3E4F21D; Sat, 3 Feb 2024 07:12:17 +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=1706944339; cv=none; b=XHXDnC2tMK6HkG9C9az0WgiuJVdQDDAP0UvLo+SMWNb/CtRg00SpZgFtpBBJnMwLSU/9wAkugPLrvHY6j/IuMuhfQJnTmUSDq8tI6Sx2hyN3+WorPT2fVde8pndQYX/+bM7SgnQ9yc/YGJj4r+SbhYzuM1zFnY7d/5YeaonGDRo= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706944339; c=relaxed/simple; bh=2Ra1DIMO+G/TyPfQxYqph8jYmrGnaJYGYnlhqWoTXnE=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=KGduLhuLAg/hS90YQqkMx2klUCmydvCIcksqcF8ni4TZTu3a48zxXi8WH2dtBM+0eYB2NQh5qedlzbTdw/zKS/F3khJdwGSvioqlBHJwLAAiRoeJ45VToSkSXkJ9rZ+gzOFmFp1wqpjNxGdJ9N3G9nAWv134SPtmILYBmA2RBig= 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=XlUtYVzv; 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=49fgiBCP04epsyHu4VZLFhJdGCRmLlr7ZEyZXKDtz3E=; b=XlUtYVzvEHslYCkKcXL+kLKkWh 9WTLKLOLzxgooVTG83weTxXHEkwnSz4ybyLAeTF63d9qpkg5/3QqKB1r0fiaxhUO3cVx09NH+5Eo5 QFGjAEPz/oAvFBpRtC9I0fpdDPAIDkdv9qsZ/o2Yk6jT1RW6Z8Qoa81kLjYtsh7/LoSy3GUxUHyIz MQ0OFbDNGbmshBa1RhuYyufJiFWc9kY5FoAub/R7AI5Ep+JcunFwqr5QsPuqV2eofrvNuVUc7kq0H mfFJrDAX6yoOt/HhTtIfyWWS9UVv6ptOAdSuTkYnPQpb3GhIL9zWe/+GHCh8en4saFjCp4gzKTqae RAaS1RPw==; Received: from [89.144.222.32] (helo=localhost) by bombadil.infradead.org with esmtpsa (Exim 4.97.1 #2 (Red Hat Linux)) id 1rWACE-0000000Fk0K-0UzU; Sat, 03 Feb 2024 07:12:14 +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 03/13] writeback: also update wbc->nr_to_write on writeback failure Date: Sat, 3 Feb 2024 08:11:37 +0100 Message-Id: <20240203071147.862076-4-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 X-SRS-Rewrite: SMTP reverse-path rewritten from by bombadil.infradead.org. See http://www.infradead.org/rpr.html X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1789887858754886389 X-GMAIL-MSGID: 1789887858754886389 When exiting write_cache_pages early due to a non-integrity write failure, wbc->nr_to_write currently doesn't account for the folio we just failed to write. This doesn't matter because the callers always ingore the value on a failure, but moving the update to common code will allow to simplify the code, so do it. Signed-off-by: Christoph Hellwig Reviewed-by: Brian Foster Reviewed-by: Jan Kara Acked-by: Dave Chinner --- mm/page-writeback.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mm/page-writeback.c b/mm/page-writeback.c index b4d978f77b0b69..ee9eb347890cd3 100644 --- a/mm/page-writeback.c +++ b/mm/page-writeback.c @@ -2473,6 +2473,7 @@ int write_cache_pages(struct address_space *mapping, trace_wbc_writepage(wbc, inode_to_bdi(mapping->host)); error = writepage(folio, wbc, data); nr = folio_nr_pages(folio); + wbc->nr_to_write -= nr; if (unlikely(error)) { /* * Handle errors according to the type of @@ -2506,7 +2507,6 @@ int write_cache_pages(struct address_space *mapping, * we tagged for writeback prior to entering this loop. */ done_index = folio->index + nr; - wbc->nr_to_write -= nr; if (wbc->nr_to_write <= 0 && wbc->sync_mode == WB_SYNC_NONE) { done = 1; From patchwork Sat Feb 3 07:11:38 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christoph Hellwig X-Patchwork-Id: 196235 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7301:9bc1:b0:106:209c:c626 with SMTP id op1csp955010dyc; Sat, 3 Feb 2024 02:50:20 -0800 (PST) X-Google-Smtp-Source: AGHT+IErNlu7ESek1dCeaipuTAxRnbu9HNNL24as2NXRqapA1Tz2idjaOssFZNnsMe1t03MaNZn1 X-Received: by 2002:ac8:7596:0:b0:42b:f01e:d9d5 with SMTP id s22-20020ac87596000000b0042bf01ed9d5mr914914qtq.62.1706957419878; Sat, 03 Feb 2024 02:50:19 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1706957419; cv=pass; d=google.com; s=arc-20160816; b=WbEtTPPVNyqm1KIux18r7mEN1ieZjj8wV2KnCmfJgmbPMtw88WlEp5iJEYcanDnpzR KkLH77pTCVj3J/Lq5ff7hUskAlgBXDKaurhBMBE9dTaB6Z/URE1as/TA39YEVHMUNd/q XKPZUqkcAooywPZcwQvH2Lg+B4mfqw1uqgnhrMA0RTUL16/ykiztUt+GYwc9ZUyY0+8L E4tCNHfaoUEc5rfbHbg3OOOj8jWFAkLzh4S5Lwo5pApsf9vk/zwNiLa5bvXJY0SjvaVy b9XHHiRZklwc9iho0OrVedgBZYojqRb6JUKJfitSLYZs9NXAVRdXpKiqX9/YO7El14T7 hOYw== 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=GhmEmGUPN5iqiwr7bHV2cU1PJLEobcTODedxESHF4Gc=; fh=AzMr/UYHDjellEUQFMeBv+4vXo4hDZmCoCiVtoR7mmg=; b=vrycJ8UzawPKURbid4TrNlKf8h5F0ZMb/rDSvDYj/uZN1rSoiTCUQ7Rf64wsS725s6 McO3oUYtuOtt/efeJ0hzL6QAj+5z3umTco2x9EJTPj+TOULsoD8OlRslZMLAvZpo0lju U0183O9bP6y+mzvLnBM/WYEVB+fHy9E+ORKuifzAPg76U6U5xWO9Lm2eJsguANadOAod hgNAUAl86UI4qjCcE7G/mZUfTUsWAmGshwy6uSgxH/N6krZRGmC7ZXdLKMQ3Zlkua3oC V458MkrcJwl8Tkt0NWWVcgqrPaqoU59Hk3cStw1W8cVM1XMRNoS9DxIAsBl1nhpcpNrE kByg==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@infradead.org header.s=bombadil.20210309 header.b=QH+FHNxv; arc=pass (i=1 dkim=pass dkdomain=infradead.org); spf=pass (google.com: domain of linux-kernel+bounces-50953-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-50953-ouuuleilei=gmail.com@vger.kernel.org" X-Forwarded-Encrypted: i=1; AJvYcCWSXF0Wl6oHPaw8nEu9ppgVZ6b2w3jiow1kpSddOqAk8DADfv0JMi+OWObXUXPOeNeLbXhFM2vqfe5taZFbT4c9MQlX+Q== Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [2604:1380:45d1:ec00::1]) by mx.google.com with ESMTPS id x20-20020a05622a001400b0042bee95c332si4024823qtw.557.2024.02.03.02.50.19 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 03 Feb 2024 02:50:19 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-50953-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) client-ip=2604:1380:45d1:ec00::1; Authentication-Results: mx.google.com; dkim=pass header.i=@infradead.org header.s=bombadil.20210309 header.b=QH+FHNxv; arc=pass (i=1 dkim=pass dkdomain=infradead.org); spf=pass (google.com: domain of linux-kernel+bounces-50953-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-50953-ouuuleilei=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 ny.mirrors.kernel.org (Postfix) with ESMTPS id 87B5B1C247B2 for ; Sat, 3 Feb 2024 07:13:41 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 6DA5650243; Sat, 3 Feb 2024 07:12:26 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=infradead.org header.i=@infradead.org header.b="QH+FHNxv" 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 7D75F4F891; Sat, 3 Feb 2024 07:12:22 +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=1706944343; cv=none; b=puDXNA3+xV8ZvPYj4orvSYi42v9fTSq4+vHBGocaYgXsfZYAQwDMNCWufmmwkehBYtZt3W1ih9IvC642hu44dTg32b9k+508lGFbUIPnF13017cuHzSCJ/2esn07dCLinX/OWgz2UyvrVPFWQKzxXgvncrJ4K4cLwY0DGaX2JNU= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706944343; c=relaxed/simple; bh=d7uAWRyCrrlyj0Ej5Or/Ih/519cz8DKV1v+etTcSbsg=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=lvIuULEv79ULms6iagWoZD6YS+K4ca8FBEl20XBsVy3/V5kCLcDCnkfZZIN1nqBh6Wo5qd0HJT4MRtk2fOmqLa5Lj2o9hGgfOF0BXP9Usf3SnKxr6f6SoO8X2pB27d5C5dO9pRn1BiAlVIFFDqQFhTshfak4kzivCgDVUdRZ0z4= 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=QH+FHNxv; 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=GhmEmGUPN5iqiwr7bHV2cU1PJLEobcTODedxESHF4Gc=; b=QH+FHNxvkAB6h4KM2iyT9Hyvsg AfE8Wt9IRK/c15fUAWzpoE0OtkarSrAESliln8xwuU91uqBJnw3VO1ZVOQoYwX84FrKLJob4M3jMF oRjd2HOh1Yp7g+s/i/D020aM/XNuc5Ou1E5OqSB+BoPXYnmXsysVl04sBQn+hyb0r/W9HefFlUQas cX5zi8ABK7rKKEQCa4O6ZDOWajvyMxkBX+pdPcVSoLre58AnwYKNwkfkYrngCfhD9mRSaR7RQeW3j +ZFwoC5ArTW4txv7BDS1lqNVD7QtwiapVkQzDgkl/LFVurH1ZDwJQeCF5Z4DWpsunH5mT9eRUoK2y SAl/WSOA==; Received: from [89.144.222.32] (helo=localhost) by bombadil.infradead.org with esmtpsa (Exim 4.97.1 #2 (Red Hat Linux)) id 1rWACJ-0000000Fk2d-1AV7; Sat, 03 Feb 2024 07:12:20 +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 04/13] writeback: only update ->writeback_index for range_cyclic writeback Date: Sat, 3 Feb 2024 08:11:38 +0100 Message-Id: <20240203071147.862076-5-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 X-SRS-Rewrite: SMTP reverse-path rewritten from by bombadil.infradead.org. See http://www.infradead.org/rpr.html X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1789874583288598074 X-GMAIL-MSGID: 1789874583288598074 mapping->writeback_index is only [1] used as the starting point for range_cyclic writeback, so there is no point in updating it for other types of writeback. [1] except for btrfs_defrag_file which does really odd things with mapping->writeback_index. But btrfs doesn't use write_cache_pages at all, so this isn't relevant here. Signed-off-by: Christoph Hellwig Reviewed-by: Brian Foster Reviewed-by: Jan Kara Acked-by: Dave Chinner --- mm/page-writeback.c | 24 ++++++++++++++---------- 1 file changed, 14 insertions(+), 10 deletions(-) diff --git a/mm/page-writeback.c b/mm/page-writeback.c index ee9eb347890cd3..c7c494526bc650 100644 --- a/mm/page-writeback.c +++ b/mm/page-writeback.c @@ -2403,7 +2403,6 @@ int write_cache_pages(struct address_space *mapping, pgoff_t index; pgoff_t end; /* Inclusive */ pgoff_t done_index; - int range_whole = 0; xa_mark_t tag; folio_batch_init(&fbatch); @@ -2413,8 +2412,6 @@ int write_cache_pages(struct address_space *mapping, } else { index = wbc->range_start >> PAGE_SHIFT; end = wbc->range_end >> PAGE_SHIFT; - if (wbc->range_start == 0 && wbc->range_end == LLONG_MAX) - range_whole = 1; } if (wbc->sync_mode == WB_SYNC_ALL || wbc->tagged_writepages) { tag_pages_for_writeback(mapping, index, end); @@ -2518,14 +2515,21 @@ int write_cache_pages(struct address_space *mapping, } /* - * If we hit the last page and there is more work to be done: wrap - * back the index back to the start of the file for the next - * time we are called. + * For range cyclic writeback we need to remember where we stopped so + * that we can continue there next time we are called. If we hit the + * last page and there is more work to be done, wrap back to the start + * of the file. + * + * For non-cyclic writeback we always start looking up at the beginning + * of the file if we are called again, which can only happen due to + * -ENOMEM from the file system. */ - if (wbc->range_cyclic && !done) - done_index = 0; - if (wbc->range_cyclic || (range_whole && wbc->nr_to_write > 0)) - mapping->writeback_index = done_index; + if (wbc->range_cyclic) { + if (done) + mapping->writeback_index = done_index; + else + mapping->writeback_index = 0; + } return ret; } From patchwork Sat Feb 3 07:11:39 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christoph Hellwig X-Patchwork-Id: 196236 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7301:9bc1:b0:106:209c:c626 with SMTP id op1csp955041dyc; Sat, 3 Feb 2024 02:50:28 -0800 (PST) X-Google-Smtp-Source: AGHT+IG4AxEIPtmBiOfeVSZekIIN9imJKz02xshF8HtP+jjv1B4Q8yi3Q49D9vi9O1hhrzbGvPdr X-Received: by 2002:a05:620a:248b:b0:785:3865:1c6e with SMTP id i11-20020a05620a248b00b0078538651c6emr5469712qkn.41.1706957428404; Sat, 03 Feb 2024 02:50:28 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1706957428; cv=pass; d=google.com; s=arc-20160816; b=NFdzhfNOT5jreZ4PcA96jSaBWFufjQn5EIAkWV6Lj45SUVG7sz8mUU2uJrQSjphv7c lWEaVoh6oS3U9jtGb/dh2k/t1ED12WIuS4U6a1FxPFjEYyBf4s/isbklOAi5UVYyXjeb HUC7epuvLSYgLsSzMoNcKDDt/EFXhUi6ZUDOisZ5bPHZbBPA4ctBnU/JGx8La0QU21B5 ESX8jrR1+8na7ZUycNhsp175oGKhbjR5EjOdj4RpMKn6KcDnbjo503twtPhH8yFQjy/F P1WYWBF12mVD+qZGNXBl+3Zh1FD5yJ45NuuYbyww3CrWsaUkLw8P5b6nDjmKkNAUYWaX S0Pg== 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=5NQ5foZwClGdjirNb4QF1J+mdWuoRYsiFuyY0APWPYw=; fh=ItFCWz9wxSSJfMJ4hpFktHVeyexOOH3HT5nr0C4wUkw=; b=BagWMek1wYPLTK1/7HkD6CEX399iWVm8jGLqK4GQci3VRGnopJeAVWQ4sgxqi4BrVu sbud84OiMoZeYBnuTxCaCTx1XSxG94h96YwUZ91fv+WoY0TNwLB15W+lSbvkmDccBSP0 7RjjilahMl6EbJ8SjshJ2KRSL56FPeh4hO0EbygpPI948m7kNVAsWJslIgrvW/A2L5IH czMvQJFFJAsxd4KvgC6Ll4yEvYEfUWJt3BW2ssO72fGZByCjlvMQuq8Nqao6JujVtRFk +vxAbJme9MG0v6yw6alOS1YdH7bsnZjGQJcmfYhZGpO9JMJuAnSY1pMPa9+/aXpJ8mdD EaYA==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@infradead.org header.s=bombadil.20210309 header.b=DB0SbFi6; arc=pass (i=1 dkim=pass dkdomain=infradead.org); spf=pass (google.com: domain of linux-kernel+bounces-50954-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-50954-ouuuleilei=gmail.com@vger.kernel.org" X-Forwarded-Encrypted: i=1; AJvYcCUppoT3B4dGcwISX3u+NH/Fehd030ldY6tmt4vmC5Ml02Y4CjD3IC4NYq78Gxh2btjc6+doTNNOyIT8y2ul0E3pLcGnrA== Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [2604:1380:45d1:ec00::1]) by mx.google.com with ESMTPS id g2-20020a05620a40c200b007850b2810cesi4513067qko.598.2024.02.03.02.50.28 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 03 Feb 2024 02:50:28 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-50954-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) client-ip=2604:1380:45d1:ec00::1; Authentication-Results: mx.google.com; dkim=pass header.i=@infradead.org header.s=bombadil.20210309 header.b=DB0SbFi6; arc=pass (i=1 dkim=pass dkdomain=infradead.org); spf=pass (google.com: domain of linux-kernel+bounces-50954-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-50954-ouuuleilei=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 ny.mirrors.kernel.org (Postfix) with ESMTPS id 5C36F1C23C9F for ; Sat, 3 Feb 2024 07:14:01 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 55F885026D; Sat, 3 Feb 2024 07:12:31 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=infradead.org header.i=@infradead.org header.b="DB0SbFi6" 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 DDC425024B; Sat, 3 Feb 2024 07:12:26 +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=1706944348; cv=none; b=H0gDXq1kUhgeDU1XqWwVTNqpy7jdlAm0V+Unwd6Hgb5yUYYPKqxCP96xHFQic4w903fmEahlWFUWR87kWrh/HzFxdu7Ctx4bv85e7s2U1UPfBn8JC1JUbB/cAMJZf4f1sXYrWvrrhzBrlT0VwIkJ9gVoLXdd0VC5nxJpMa4geJw= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706944348; c=relaxed/simple; bh=11+z648M91LOuAn70D5VUrpWYdA9g8PsbH50zJJGCu4=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=r5u+LLhxzZw3xdK+NeZSRWs/b/hzolAMeocimicWdKQ7wrA2a0LzGFDyb4rFClKj+IRsaAUVwldXxMbfLqvTG58MzEBAwhQj+CjBGG4rcruEtuFE+i/ozafOzENQjHenYLNjLXrc6YJioEkUx9cqZdVTK/2BaU5jZvnIFiNdP8U= 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=DB0SbFi6; 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=5NQ5foZwClGdjirNb4QF1J+mdWuoRYsiFuyY0APWPYw=; b=DB0SbFi6hUnk1R7j5iigmiLr5N wGakeqVDiyg/3UEtSiSGuXyTjawI0qc+3zilFXplt0yfm3V6765hxCRtqBaCEEbXRu6PmcijL0EwD ohFv1B6Ru53npud78X2mRjKDz+W8KfKClXbYz//sS9Rlej5EBI3FYmzdI0NGMiwddOLtapEwUWLxn xOakmAfp6pz1HZvZdZCjEVNJYQ8OON7wbu3bQautPLcydnJS0vvYHgPkMCCowSEe3fNMXKbop8vzO KCGYuP5WzsvA6ReigLFIw1MRl26nXVPe05zKKDjdM/xBnxIJJYynLn8OYg9q/pGoHyGTfCW9NxHyR jxtv/EuA==; Received: from [89.144.222.32] (helo=localhost) by bombadil.infradead.org with esmtpsa (Exim 4.97.1 #2 (Red Hat Linux)) id 1rWACN-0000000Fk4w-1KJm; Sat, 03 Feb 2024 07:12:23 +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 Subject: [PATCH 05/13] writeback: rework the loop termination condition in write_cache_pages Date: Sat, 3 Feb 2024 08:11:39 +0100 Message-Id: <20240203071147.862076-6-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 X-SRS-Rewrite: SMTP reverse-path rewritten from by bombadil.infradead.org. See http://www.infradead.org/rpr.html X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1789874592351415198 X-GMAIL-MSGID: 1789874592351415198 Rework the way we deal with the cleanup after the writepage call. First handle the magic AOP_WRITEPAGE_ACTIVATE separately from real error returns to get it out of the way of the actual error handling path. The split the handling on intgrity vs non-integrity branches first, and return early using a goto for the non-ingegrity early loop condition to remove the need for the done and done_index local variables, and for assigning the error to ret when we can just return error directly. Signed-off-by: Christoph Hellwig Reviewed-by: Jan Kara Reviewed-by: Brian Foster --- mm/page-writeback.c | 84 ++++++++++++++++++--------------------------- 1 file changed, 33 insertions(+), 51 deletions(-) diff --git a/mm/page-writeback.c b/mm/page-writeback.c index c7c494526bc650..88b2c4c111c01b 100644 --- a/mm/page-writeback.c +++ b/mm/page-writeback.c @@ -2396,13 +2396,12 @@ int write_cache_pages(struct address_space *mapping, void *data) { int ret = 0; - int done = 0; int error; struct folio_batch fbatch; + struct folio *folio; int nr_folios; pgoff_t index; pgoff_t end; /* Inclusive */ - pgoff_t done_index; xa_mark_t tag; folio_batch_init(&fbatch); @@ -2419,8 +2418,7 @@ int write_cache_pages(struct address_space *mapping, } else { tag = PAGECACHE_TAG_DIRTY; } - done_index = index; - while (!done && (index <= end)) { + while (index <= end) { int i; nr_folios = filemap_get_folios_tag(mapping, &index, end, @@ -2430,11 +2428,7 @@ int write_cache_pages(struct address_space *mapping, break; for (i = 0; i < nr_folios; i++) { - struct folio *folio = fbatch.folios[i]; - unsigned long nr; - - done_index = folio->index; - + folio = fbatch.folios[i]; folio_lock(folio); /* @@ -2469,45 +2463,32 @@ int write_cache_pages(struct address_space *mapping, trace_wbc_writepage(wbc, inode_to_bdi(mapping->host)); error = writepage(folio, wbc, data); - nr = folio_nr_pages(folio); - wbc->nr_to_write -= nr; - if (unlikely(error)) { - /* - * Handle errors according to the type of - * writeback. There's no need to continue for - * background writeback. Just push done_index - * past this page so media errors won't choke - * writeout for the entire file. For integrity - * writeback, we must process the entire dirty - * set regardless of errors because the fs may - * still have state to clear for each page. In - * that case we continue processing and return - * the first error. - */ - if (error == AOP_WRITEPAGE_ACTIVATE) { - folio_unlock(folio); - error = 0; - } else if (wbc->sync_mode != WB_SYNC_ALL) { - ret = error; - done_index = folio->index + nr; - done = 1; - break; - } - if (!ret) - ret = error; + wbc->nr_to_write -= folio_nr_pages(folio); + + if (error == AOP_WRITEPAGE_ACTIVATE) { + folio_unlock(folio); + error = 0; } /* - * We stop writing back only if we are not doing - * integrity sync. In case of integrity sync we have to - * keep going until we have written all the pages - * we tagged for writeback prior to entering this loop. + * For integrity writeback we have to keep going until + * we have written all the folios we tagged for + * writeback above, even if we run past wbc->nr_to_write + * or encounter errors. + * We stash away the first error we encounter in + * wbc->saved_err so that it can be retrieved when we're + * done. This is because the file system may still have + * state to clear for each folio. + * + * For background writeback we exit as soon as we run + * past wbc->nr_to_write or encounter the first error. */ - done_index = folio->index + nr; - if (wbc->nr_to_write <= 0 && - wbc->sync_mode == WB_SYNC_NONE) { - done = 1; - break; + if (wbc->sync_mode == WB_SYNC_ALL) { + if (error && !ret) + ret = error; + } else { + if (error || wbc->nr_to_write <= 0) + goto done; } } folio_batch_release(&fbatch); @@ -2524,14 +2505,15 @@ int write_cache_pages(struct address_space *mapping, * of the file if we are called again, which can only happen due to * -ENOMEM from the file system. */ - if (wbc->range_cyclic) { - if (done) - mapping->writeback_index = done_index; - else - mapping->writeback_index = 0; - } - + if (wbc->range_cyclic) + mapping->writeback_index = 0; return ret; + +done: + folio_batch_release(&fbatch); + if (wbc->range_cyclic) + mapping->writeback_index = folio->index + folio_nr_pages(folio); + return error; } EXPORT_SYMBOL(write_cache_pages); From patchwork Sat Feb 3 07:11:43 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christoph Hellwig X-Patchwork-Id: 196230 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7301:9bc1:b0:106:209c:c626 with SMTP id op1csp944658dyc; Sat, 3 Feb 2024 02:15:07 -0800 (PST) X-Google-Smtp-Source: AGHT+IEJaBVIs4cgTf3OPXEiGrWo7feQaV4HAkieCO4xlQhXcjR/DndKLttGVizv3SFZwDofrbc1 X-Received: by 2002:a05:620a:218d:b0:783:55af:9d5c with SMTP id g13-20020a05620a218d00b0078355af9d5cmr4655197qka.55.1706955307097; Sat, 03 Feb 2024 02:15:07 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1706955307; cv=pass; d=google.com; s=arc-20160816; b=MPeqoVkl0GtcqJiujlgDBNjsow8p2/+MOToffTF2tT8bIgodrJc/DSEj8Gdam4Sg8q L6phF3oSww8W8Rfjv2Z4thiFBTI+51bSlbJ5QpbyXokDHY2gf2f49cT2UXQNbF60nKUD jO7n/Olp3bDnEO5MTSUsJAybV3SsRygyNzB0Am0sa25zGWZDE1wIRIufmhFQ3JxDvYiV 96tsyYWyjbJXMq2tHhjbdKl0DbnXIdVHyVSArjjSdml0J+tUbs5ujSBfeOohJWp8WyyC SF8lsMTtjSBZcbuG3hw6E06zz//BIjjKOIganTEvVMtZMhxPYGpl6AbuNTFOtpj6K5uG +vjA== 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=M5Qvp5zNKGHXjXReg58hQjrWh/GgxzXP5maEkxrO/YI=; fh=TY3wz6kcoptQnUGOkpmDAyOteoMooHl0LcTQW4Xc2OA=; b=wmynSf12yKztQzOuvNddQA3SlWjSz6ev+aev3t91Y2zEEJEr4H3f+FGBs3HWZWhd7o 6RLr6yOREYyGfXzppzQDUFkCMTTHt8x1sfl3dGwbHSk00O8wrzCazrCp9ac6I28Qlx/F U+oWaoEw95mYFTQAoTRUC5y0GdQ63AAO4XWOotLm0di3lboLLtr0KyW4fRAD5z0pm0Sx 5Z/QNPIvKeBpkriWe5cG0A8X1g/XXYK4SfkTlRZhO94mnOwOH2IFYMvD52fjUdntNc0S Mc++XYhyB3/oy04J80M7gnawjASrpwwzU1N2brTtm5yMhMRIul3Vb/CmnHU+WWbI2zGb 2/IQ==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@infradead.org header.s=bombadil.20210309 header.b="0/r+7dmm"; arc=pass (i=1 dkim=pass dkdomain=infradead.org); spf=pass (google.com: domain of linux-kernel+bounces-50958-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-50958-ouuuleilei=gmail.com@vger.kernel.org" X-Forwarded-Encrypted: i=1; AJvYcCUeg56SnqedbyH8OE0ZIN7gI84z21pztFMqmbbF3v4OpNZ2woKbTCRK+G644teWKwvVED0BKsvwGekkVvkdouDN194lDg== Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [2604:1380:45d1:ec00::1]) by mx.google.com with ESMTPS id l19-20020a05620a211300b0078438018b61si3925147qkl.136.2024.02.03.02.15.06 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 03 Feb 2024 02:15:07 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-50958-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) client-ip=2604:1380:45d1:ec00::1; Authentication-Results: mx.google.com; dkim=pass header.i=@infradead.org header.s=bombadil.20210309 header.b="0/r+7dmm"; arc=pass (i=1 dkim=pass dkdomain=infradead.org); spf=pass (google.com: domain of linux-kernel+bounces-50958-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-50958-ouuuleilei=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 ny.mirrors.kernel.org (Postfix) with ESMTPS id 8B86C1C25B49 for ; Sat, 3 Feb 2024 07:15:18 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 41DDB54BDD; Sat, 3 Feb 2024 07:12:46 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=infradead.org header.i=@infradead.org header.b="0/r+7dmm" 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 5022853812; Sat, 3 Feb 2024 07:12:42 +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=1706944363; cv=none; b=ETCvOLdhlL9VCtJUvI3xZj4JQL+17KTC3v+xM66TzcbwePUD5wFkSREACWT1O0PcmLTd36yyXvlqi+nrxuFz5EVigP6wY/I4t+dWPZYVWKodJpzklIOMQq79RDXTsS3GtXfcF+Pzbucu/pnoL7KQEMstq62duXOVV8MqIGXvzcs= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706944363; c=relaxed/simple; bh=8YXecWRICYuMcNttDcOnWW490EjFn6keh2I4C8IPcyw=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=uIvJoH33sA4D3FKDBM4CFRm0itPyg4kiw0XXUc7vTM4FoBi7TnHJWZrR/SNi7ioLCV/WV6XoObo7ss3lTahpbpBdH/AnbAI8ceA0oAALxQNbLUUrKmeyTEr15vfqr1TFo72g8Yz95uIY7mb50va/UOgAR+IfXLCu0NfZmN/qjTw= 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=0/r+7dmm; 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=M5Qvp5zNKGHXjXReg58hQjrWh/GgxzXP5maEkxrO/YI=; b=0/r+7dmm43M5Dn9pI478JvAC/4 oMa4a8isH3iYu7/DiNuxK8ticsjuP9iB3tDFkuLLDpkg6dtFVtGZrup7ew7Rnn5OM2HIv9tS6RfwK LqawRXjuztB1xFtFVyxTQO1HlsxCukxD2MXQPsnIdK7arkvSvDEEZFNyL7beFqM3neAWYFUFJ2s1C rXejoAV9Dgdly36z5qeDNo2SknFWyn45vn2vzB7BwJXJaJ2MzKYi37Fk32ni74PE30b7+Rqi/uaDS AvC5hBjkd/pVjcP1eTjIgMojnI0ey9H2nma+pU9cepPu814Hc9/zTDPLloxTU4xB4yUYmcDRrLuB4 C+xJMSdQ==; Received: from [89.144.222.32] (helo=localhost) by bombadil.infradead.org with esmtpsa (Exim 4.97.1 #2 (Red Hat Linux)) id 1rWACd-0000000FkDE-0QIe; Sat, 03 Feb 2024 07:12:40 +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 09/13] pagevec: Add ability to iterate a queue Date: Sat, 3 Feb 2024 08:11:43 +0100 Message-Id: <20240203071147.862076-10-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 X-SRS-Rewrite: SMTP reverse-path rewritten from by bombadil.infradead.org. See http://www.infradead.org/rpr.html X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1789872368070897557 X-GMAIL-MSGID: 1789872368070897557 From: "Matthew Wilcox (Oracle)" Add a loop counter inside the folio_batch to let us iterate from 0-nr instead of decrementing nr and treating the batch as a stack. It would generate some very weird and suboptimal I/O patterns for page writeback to iterate over the batch as a stack. Signed-off-by: Matthew Wilcox (Oracle) Signed-off-by: Christoph Hellwig Reviewed-by: Brian Foster Reviewed-by: Jan Kara Acked-by: Dave Chinner --- include/linux/pagevec.h | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/include/linux/pagevec.h b/include/linux/pagevec.h index 87cc678adc850b..fcc06c300a72c3 100644 --- a/include/linux/pagevec.h +++ b/include/linux/pagevec.h @@ -27,6 +27,7 @@ struct folio; */ struct folio_batch { unsigned char nr; + unsigned char i; bool percpu_pvec_drained; struct folio *folios[PAGEVEC_SIZE]; }; @@ -40,12 +41,14 @@ struct folio_batch { static inline void folio_batch_init(struct folio_batch *fbatch) { fbatch->nr = 0; + fbatch->i = 0; fbatch->percpu_pvec_drained = false; } static inline void folio_batch_reinit(struct folio_batch *fbatch) { fbatch->nr = 0; + fbatch->i = 0; } static inline unsigned int folio_batch_count(struct folio_batch *fbatch) @@ -75,6 +78,21 @@ static inline unsigned folio_batch_add(struct folio_batch *fbatch, return folio_batch_space(fbatch); } +/** + * folio_batch_next - Return the next folio to process. + * @fbatch: The folio batch being processed. + * + * Use this function to implement a queue of folios. + * + * Return: The next folio in the queue, or NULL if the queue is empty. + */ +static inline struct folio *folio_batch_next(struct folio_batch *fbatch) +{ + if (fbatch->i == fbatch->nr) + return NULL; + return fbatch->folios[fbatch->i++]; +} + void __folio_batch_release(struct folio_batch *pvec); static inline void folio_batch_release(struct folio_batch *fbatch) 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: 196250 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7301:9bc1:b0:106:209c:c626 with SMTP id op1csp979597dyc; Sat, 3 Feb 2024 04:01:46 -0800 (PST) X-Google-Smtp-Source: AGHT+IFs3MXkI7gethONExdSHzdmy694eRi2jB4MpYUCGOW9RLj+aFnOfYzdkLP0c94pSNWUtBQX X-Received: by 2002:a17:906:31c3:b0:a36:f480:40e5 with SMTP id f3-20020a17090631c300b00a36f48040e5mr3333227ejf.46.1706961706403; Sat, 03 Feb 2024 04:01:46 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1706961706; cv=pass; d=google.com; s=arc-20160816; b=fe6N7HaaAf/LxXPYeZFYzUkA/nuCxRD7Ip2d3efqrluLKNH7woRysUWcY/Wxb5TqJj 9ZBonBg9hPXCe0dPrc4os+ip+RWasL+jfbP5zZvOnEW2Epma5HQzC5FJvSiodBOHkYUZ Is7N/SYqem62dDfOzfjHJgIrHFLI0Dq3YNfFxiLBqhV6/jiI536W5S8CI3q8uzdCmypH jDp6bfv9S/X7cr0q71J6GbNBDa3y5fLRpbt8KMAVDCCrfRtmZvz8FzP9pjhM4pAmdSjb wUfDMZ9VFhw0W1wvYOM208n71/E08kv+O3HhOiFBBQV2uBsj/Wu3B2jBxX4yW74zSXqC VSEw== 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=ngOuRDn+1bPTAtNgsxtv1r0sRWlRTsxkU/k4q+ARRKo=; b=IWz4DXYk6FpILb9VVl1j8cePXGGOsRiy6vVkOYeoaW3nlM1tGluB7lqyd5q17HMIVY QiMZmtkUS96LiqUhq0dJJAVDUbyDfk2v1TXLr//xDPIeAKnAc4vOSdFYBLdZ2PY7HT7Y +PGYk8Mv9MEZ3T73eEDQHgEQwToT41UAXguyfUYDUyFXbU7LHn8ifVTUxx6spVLR73pT oBgdW20D3r3JBCDTh1sK+exrfxxnoeuWPLz2JI4xqaiuFNtgvvVAoiSL4GtuUFAzj+mD z/xJMm+8eWjxqay6Wc0lnCLvsZlafv92jEUYN6F81DaJk6uaRA2mkbFC6AIgtI/yzN3d 6VCA==; 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-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-50960-ouuuleilei=gmail.com@vger.kernel.org" X-Forwarded-Encrypted: i=1; AJvYcCW1IdFJGfArFNdYP1k0S6wNl+hVYZUeCFSEToi4iG64+xtlxVhbTyTf1p4Eo7L8oDqEXSuWr3+9SI2A1dLolTELI0vXJA== Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [147.75.80.249]) by mx.google.com with ESMTPS id v13-20020a170906564d00b00a372ac5cee5si1112160ejr.850.2024.02.03.04.01.46 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 03 Feb 2024 04:01:46 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-50960-ouuuleilei=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=vH0hdIAp; arc=pass (i=1 dkim=pass dkdomain=infradead.org); spf=pass (google.com: domain of linux-kernel+bounces-50960-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-50960-ouuuleilei=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 633CD1F2B580 for ; Sat, 3 Feb 2024 07:15:58 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id DF36856B6B; Sat, 3 Feb 2024 07:12:57 +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 X-SRS-Rewrite: SMTP reverse-path rewritten from by bombadil.infradead.org. See http://www.infradead.org/rpr.html X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1789879078205631833 X-GMAIL-MSGID: 1789879078205631833 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); From patchwork Sat Feb 3 07:11: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: 196247 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7301:9bc1:b0:106:209c:c626 with SMTP id op1csp969814dyc; Sat, 3 Feb 2024 03:31:26 -0800 (PST) X-Google-Smtp-Source: AGHT+IECbGm7bI+3TCGvGmGPq7DklRR+jy9+l7fIKjhV/5w1H7jt2aAIKdI9vnBWyk8jlyM1fnLn X-Received: by 2002:a05:6402:745:b0:55f:99:c895 with SMTP id p5-20020a056402074500b0055f0099c895mr1497752edy.20.1706959886050; Sat, 03 Feb 2024 03:31:26 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1706959886; cv=pass; d=google.com; s=arc-20160816; b=DDcv+MmiMO1ezAOnUMGRo591b4rnkjrphLZlKUP2/25I8KXt3cxm8gRdbPL4eQi8di gdwaDu7U9SiTk75X3h85Qj7Kp4XbgrN1W+tZ5VY7O7ODY07E98sAYX0FI4ShpkaB4Jp+ Pwb38KsCGFPhNgHHvRWpLtBqXl0pDYMyu5Jp+0eI2pNiU+StoR85xTZsQdGoz8C+ie2E kCfE2Cu1g75rX8rPdJPCp+qVKn/COUZYNmEE4GPUNMC0ZVahcyb8yjCucXZDwKGsnPwy oHgXqO0lGUiTjf8dM0TA5OU4H9waB8aUUbhi62QDjfjYP/g8gRMmU8kS7tKE+hBCUsfk M1jg== 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=GezxIWW+q+u2zC46RjSY4N2DxF7mdi1d7/13SlWu4e0=; fh=f3j10iH9SSRVqqXLttr/IBIJdxXP0jueLusndekKbPE=; b=saxhqXPSyJdDJrpuGJSC2CW32rrOvmNWlwQ4hMd9MVS+oVxEduCg9yKlNqJ2NocoJG v4ObEW7KjECcLO0az3WVisUiMsTRYk5bNC1IfGhQLNVwMvWQhxunhb/fQ1irZ1IZ8ZRT hFLioL2FuZ4R5x66AlnbczR5G0i26fGigPS7rLivEoqLkPCfNFSRn2Wqp9VrckrGtHiT s3eBr3dSOjdLS21aVr19aDmWtckOOqh8lzWEOH+t4JHWDcS4zaxWFF2Y0uW6Mp5eu6fT 7nofzl76ebQj8jKytaWB97GIyYhuGwESBQykkoheEjWVPJOReEqMFYgu/6517eCUzIkj IM5Q==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@infradead.org header.s=bombadil.20210309 header.b=0fuITZBJ; arc=pass (i=1 dkim=pass dkdomain=infradead.org); spf=pass (google.com: domain of linux-kernel+bounces-50961-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-50961-ouuuleilei=gmail.com@vger.kernel.org" X-Forwarded-Encrypted: i=1; AJvYcCWQgnpaEBcvVvjcCmVkYfJJXxyVnXvEa2stljRWOWWRoMB4/E0gzmJQpoIY9hdkt2WWvm/wRT7ANSIsbcWs3U4zr5VE9Q== Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [2604:1380:4601:e00::3]) by mx.google.com with ESMTPS id e21-20020a056402149500b0055edc435176si1711596edv.105.2024.02.03.03.31.25 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 03 Feb 2024 03:31:26 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-50961-ouuuleilei=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=0fuITZBJ; arc=pass (i=1 dkim=pass dkdomain=infradead.org); spf=pass (google.com: domain of linux-kernel+bounces-50961-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-50961-ouuuleilei=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 066461F2C2C0 for ; Sat, 3 Feb 2024 07:16:19 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id D333157316; Sat, 3 Feb 2024 07:13:02 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=infradead.org header.i=@infradead.org header.b="0fuITZBJ" 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 F252D5677A; Sat, 3 Feb 2024 07:12:56 +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=1706944378; cv=none; b=h92DZM9xyTDYt/QJHscNk3jBkskR0jvV/OPiYqGjzXH2+1ElcZjY890Hrpz74B1IAmojaAOld8F9lTEPsoa6Y/Nhh/hb9dlK/4dL790qqhTRQh7WD4eKaWbWwQwIYSplmeW+l00p2+jQ0b2M7P/F12hKN45Bst8041C4uLXAxwc= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706944378; c=relaxed/simple; bh=m4giqPV84816CByeyXTh7r2sIblFSun4/FcDAG8GeJM=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=UPrJk4nMCYVctVv2+QA0ahm2+YFmr+A6TSL7JAsPwKIyvpss1Nrya2YmhaIcD4SUi/4jyLy2d0UyoCDeNZdDCrXV88W66y5hBnZESD6j6/AR5VNdsXF/sl441tbB8n37ZKUBuNT/GtBw6Rxk/RYBHb9l9cckmARFhvRqhDkKq4E= 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=0fuITZBJ; 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=GezxIWW+q+u2zC46RjSY4N2DxF7mdi1d7/13SlWu4e0=; b=0fuITZBJrufOpvkZIZVTWLsXDG Tb1yRAHTRSZM10wbA9mMQmPVY7Dc/QPRmF7qOsXh9cUUf9u8BZ4kCuh0PsgskRbJvPn1EXAWIHPo/ 2lUsRZffOvsZzX/H8/b9ym45gzAp3Xs0w0hhnCArnihPgDVLNKiYo/O+eRsH5bw/DH4TgV9psc3II Ri+1RmASwfnAIZaowi8VPt9u+QXKPsK7mH9qI+9Bnz/jojbY9mOU/Z1FWHmh4z/tvtaZZmu7dVmrK mTYhghZYwghLpblIlUFbA1bxNC9ycEhtE3cNU/inSmeuTiqmjjbnkEOFTaPl0XNmjuDmFeuE1ihUx NqEc+Dew==; Received: from [89.144.222.32] (helo=localhost) by bombadil.infradead.org with esmtpsa (Exim 4.97.1 #2 (Red Hat Linux)) id 1rWACr-0000000FkKP-28zg; Sat, 03 Feb 2024 07:12:54 +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 Subject: [PATCH 12/13] writeback: add a writeback iterator Date: Sat, 3 Feb 2024 08:11:46 +0100 Message-Id: <20240203071147.862076-13-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 X-SRS-Rewrite: SMTP reverse-path rewritten from by bombadil.infradead.org. See http://www.infradead.org/rpr.html X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1789877169403570371 X-GMAIL-MSGID: 1789877169403570371 Refactor the code left in write_cache_pages into an iterator that the file system can call to get the next folio for a writeback operation: struct folio *folio = NULL; while ((folio = writeback_iter(mapping, wbc, folio, &error))) { error = ; } The twist here is that the error value is passed by reference, so that the iterator can restore it when breaking out of the loop. Handling of the magic AOP_WRITEPAGE_ACTIVATE value stays outside the iterator and needs is just kept in the write_cache_pages legacy wrapper. in preparation for eventually killing it off. Heavily based on a for_each* based iterator from Matthew Wilcox. Signed-off-by: Christoph Hellwig Reviewed-by: Jan Kara Reviewed-by: Brian Foster --- include/linux/writeback.h | 4 + mm/page-writeback.c | 192 ++++++++++++++++++++++---------------- 2 files changed, 118 insertions(+), 78 deletions(-) diff --git a/include/linux/writeback.h b/include/linux/writeback.h index f67b3ea866a0fb..9845cb62e40b2d 100644 --- a/include/linux/writeback.h +++ b/include/linux/writeback.h @@ -82,6 +82,7 @@ struct writeback_control { /* internal fields used by the ->writepages implementation: */ struct folio_batch fbatch; pgoff_t index; + int saved_err; #ifdef CONFIG_CGROUP_WRITEBACK struct bdi_writeback *wb; /* wb this writeback is issued under */ @@ -366,6 +367,9 @@ int balance_dirty_pages_ratelimited_flags(struct address_space *mapping, bool wb_over_bg_thresh(struct bdi_writeback *wb); +struct folio *writeback_iter(struct address_space *mapping, + struct writeback_control *wbc, struct folio *folio, int *error); + typedef int (*writepage_t)(struct folio *folio, struct writeback_control *wbc, void *data); diff --git a/mm/page-writeback.c b/mm/page-writeback.c index 3abb053e70580e..5fe4cdb7dbd61a 100644 --- a/mm/page-writeback.c +++ b/mm/page-writeback.c @@ -2325,18 +2325,18 @@ void __init page_writeback_init(void) } /** - * tag_pages_for_writeback - tag pages to be written by write_cache_pages + * tag_pages_for_writeback - tag pages to be written by writeback * @mapping: address space structure to write * @start: starting page index * @end: ending page index (inclusive) * * This function scans the page range from @start to @end (inclusive) and tags - * all pages that have DIRTY tag set with a special TOWRITE tag. The idea is - * that write_cache_pages (or whoever calls this function) will then use - * TOWRITE tag to identify pages eligible for writeback. This mechanism is - * used to avoid livelocking of writeback by a process steadily creating new - * dirty pages in the file (thus it is important for this function to be quick - * so that it can tag pages faster than a dirtying process can create them). + * all pages that have DIRTY tag set with a special TOWRITE tag. The caller + * can then use the TOWRITE tag to identify pages eligible for writeback. + * This mechanism is used to avoid livelocking of writeback by a process + * steadily creating new dirty pages in the file (thus it is important for this + * function to be quick so that it can tag pages faster than a dirtying process + * can create them). */ void tag_pages_for_writeback(struct address_space *mapping, pgoff_t start, pgoff_t end) @@ -2434,69 +2434,68 @@ static struct folio *writeback_get_folio(struct address_space *mapping, } /** - * write_cache_pages - walk the list of dirty pages of the given address space and write all of them. + * writeback_iter - iterate folio of a mapping for writeback * @mapping: address space structure to write - * @wbc: subtract the number of written pages from *@wbc->nr_to_write - * @writepage: function called for each page - * @data: data passed to writepage function + * @wbc: writeback context + * @folio: previously iterated folio (%NULL to start) + * @error: in-out pointer for writeback errors (see below) * - * If a page is already under I/O, write_cache_pages() skips it, even - * if it's dirty. This is desirable behaviour for memory-cleaning writeback, - * but it is INCORRECT for data-integrity system calls such as fsync(). fsync() - * and msync() need to guarantee that all the data which was dirty at the time - * the call was made get new I/O started against them. If wbc->sync_mode is - * WB_SYNC_ALL then we were called for data integrity and we must wait for - * existing IO to complete. - * - * To avoid livelocks (when other process dirties new pages), we first tag - * pages which should be written back with TOWRITE tag and only then start - * writing them. For data-integrity sync we have to be careful so that we do - * not miss some pages (e.g., because some other process has cleared TOWRITE - * tag we set). The rule we follow is that TOWRITE tag can be cleared only - * by the process clearing the DIRTY tag (and submitting the page for IO). - * - * To avoid deadlocks between range_cyclic writeback and callers that hold - * pages in PageWriteback to aggregate IO until write_cache_pages() returns, - * we do not loop back to the start of the file. Doing so causes a page - * lock/page writeback access order inversion - we should only ever lock - * multiple pages in ascending page->index order, and looping back to the start - * of the file violates that rule and causes deadlocks. + * This function returns the next folio for the writeback operation described by + * @wbc on @mapping and should be called in a while loop in the ->writepages + * implementation. * - * Return: %0 on success, negative error code otherwise + * To start the writeback operation, %NULL is passed in the @folio argument, and + * for every subsequent iteration the folio returned previously should be passed + * back in. + * + * If there was an error in the per-folio writeback inside the writeback_iter() + * loop, @error should be set to the error value. + * + * Once the writeback described in @wbc has finished, this function will return + * %NULL and if there was an error in any iteration restore it to @error. + * + * Note: callers should not manually break out of the loop using break or goto + * but must keep calling writeback_iter() until it returns %NULL. + * + * Return: the folio to write or %NULL if the loop is done. */ -int write_cache_pages(struct address_space *mapping, - struct writeback_control *wbc, writepage_t writepage, - void *data) +struct folio *writeback_iter(struct address_space *mapping, + struct writeback_control *wbc, struct folio *folio, int *error) { - int ret = 0; - int error; - struct folio *folio; - pgoff_t end; /* Inclusive */ - - if (wbc->range_cyclic) { - wbc->index = mapping->writeback_index; /* prev offset */ - end = -1; - } else { - wbc->index = wbc->range_start >> PAGE_SHIFT; - end = wbc->range_end >> PAGE_SHIFT; - } - if (wbc->sync_mode == WB_SYNC_ALL || wbc->tagged_writepages) - tag_pages_for_writeback(mapping, wbc->index, end); - - folio_batch_init(&wbc->fbatch); + if (!folio) { + folio_batch_init(&wbc->fbatch); + wbc->saved_err = *error = 0; - for (;;) { - folio = writeback_get_folio(mapping, wbc); - if (!folio) - break; + /* + * For range cyclic writeback we remember where we stopped so + * that we can continue where we stopped. + * + * For non-cyclic writeback we always start at the beginning of + * the passed in range. + */ + if (wbc->range_cyclic) + wbc->index = mapping->writeback_index; + else + wbc->index = wbc->range_start >> PAGE_SHIFT; - error = writepage(folio, wbc, data); + /* + * To avoid livelocks when other processes dirty new pages, we + * first tag pages which should be written back and only then + * start writing them. + * + * For data-integrity writeback we have to be careful so that we + * do not miss some pages (e.g., because some other process has + * cleared the TOWRITE tag we set). The rule we follow is that + * TOWRITE tag can be cleared only by the process clearing the + * DIRTY tag (and submitting the page for I/O). + */ + if (wbc->sync_mode == WB_SYNC_ALL || wbc->tagged_writepages) + tag_pages_for_writeback(mapping, wbc->index, + wbc_end(wbc)); + } else { wbc->nr_to_write -= folio_nr_pages(folio); - if (error == AOP_WRITEPAGE_ACTIVATE) { - folio_unlock(folio); - error = 0; - } + WARN_ON_ONCE(*error > 0); /* * For integrity writeback we have to keep going until we have @@ -2510,33 +2509,70 @@ int write_cache_pages(struct address_space *mapping, * wbc->nr_to_write or encounter the first error. */ if (wbc->sync_mode == WB_SYNC_ALL) { - if (error && !ret) - ret = error; + if (*error && !wbc->saved_err) + wbc->saved_err = *error; } else { - if (error || wbc->nr_to_write <= 0) + if (*error || wbc->nr_to_write <= 0) goto done; } } - /* - * For range cyclic writeback we need to remember where we stopped so - * that we can continue there next time we are called. If we hit the - * last page and there is more work to be done, wrap back to the start - * of the file. - * - * For non-cyclic writeback we always start looking up at the beginning - * of the file if we are called again, which can only happen due to - * -ENOMEM from the file system. - */ - folio_batch_release(&wbc->fbatch); - if (wbc->range_cyclic) - mapping->writeback_index = 0; - return ret; + folio = writeback_get_folio(mapping, wbc); + if (!folio) { + /* + * To avoid deadlocks between range_cyclic writeback and callers + * that hold pages in PageWriteback to aggregate I/O until + * the writeback iteration finishes, we do not loop back to the + * start of the file. Doing so causes a page lock/page + * writeback access order inversion - we should only ever lock + * multiple pages in ascending page->index order, and looping + * back to the start of the file violates that rule and causes + * deadlocks. + */ + if (wbc->range_cyclic) + mapping->writeback_index = 0; + + /* + * Return the first error we encountered (if there was any) to + * the caller. + */ + *error = wbc->saved_err; + } + return folio; done: folio_batch_release(&wbc->fbatch); if (wbc->range_cyclic) mapping->writeback_index = folio->index + folio_nr_pages(folio); + return NULL; +} + +/** + * write_cache_pages - walk the list of dirty pages of the given address space and write all of them. + * @mapping: address space structure to write + * @wbc: subtract the number of written pages from *@wbc->nr_to_write + * @writepage: function called for each page + * @data: data passed to writepage function + * + * Return: %0 on success, negative error code otherwise + * + * Note: please use writeback_iter() instead. + */ +int write_cache_pages(struct address_space *mapping, + struct writeback_control *wbc, writepage_t writepage, + void *data) +{ + struct folio *folio = NULL; + int error; + + while ((folio = writeback_iter(mapping, wbc, folio, &error))) { + error = writepage(folio, wbc, data); + if (error == AOP_WRITEPAGE_ACTIVATE) { + folio_unlock(folio); + error = 0; + } + } + return error; } EXPORT_SYMBOL(write_cache_pages); From patchwork Sat Feb 3 07:11:47 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christoph Hellwig X-Patchwork-Id: 196218 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7301:9bc1:b0:106:209c:c626 with SMTP id op1csp927224dyc; Sat, 3 Feb 2024 01:19:50 -0800 (PST) X-Google-Smtp-Source: AGHT+IHhBardEmsPjKI8OSERKjDAv7L3v2nokBxuE89uEWdKLXogBWVeYiBhhQL5JUEoSIajmnxH X-Received: by 2002:aa7:8298:0:b0:6db:cdfd:af6 with SMTP id s24-20020aa78298000000b006dbcdfd0af6mr9678045pfm.31.1706951990090; Sat, 03 Feb 2024 01:19:50 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1706951990; cv=pass; d=google.com; s=arc-20160816; b=zAwNZmkgUeLMQq2xQQXOmff9ktCDvEFYFFPuzvUry9SF97ptsfDMjlrQqak20K7oF1 58KQRJCLqaHaHZKylJwWy/OXV55JfYEhhSjDinWDvuv6pAYznpGtmsmE7PlN3aE5v9u9 KW3oy9H9kAxT8Tlv5u3hJFjMuUZzVoEeeA3ojWav9lgmEJ8U9liRUKtFkTL02o4M1042 pb+Pmp+soeoGQhBZqsh5MugVcPTCdXUGybS7FcaaorYgemOR88jf6Xv58PhNsBFB4ZKi BVgMJfAJUUQCHy/M+du4q2kxXwEbsmsvNasLZWZGXsH/fBTvVxNtE4uN2iQ06vVxQ2ok OAvQ== 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=aBLx8GrPTTpnrFrYwat6koWXvCPglp7/mI2LOOfVaJQ=; fh=aHHlzGX7hJOH06qLZuYGi9mzwCV+luBTFYe9Oa2XCU0=; b=ML65kcxREoYrehk5xE94oldTBvjkWXkDuXUlvvf3H6GloQ5+P0ojod/XXAALHs6B8U 6ESP2AAQn9lbz73nCkELNuZJ5ZEJc9/pFnc4ernJQDDidq9Ldj39nEhlD5gufXCgk5gZ MCSjPE4Rx3a7+TTvCetGwcInkh/gqBwi655bCoDwZ0xKglYzjaLcvDz+sGdBM50hyN+7 +j8ONrFVDiBUL9a46vmhEKrc3bpNtE7pZqOSKGhoNIBzUf2LTvtDnAjNr5k9jVi/Fjxs SLuWRACYPlmhzoRhyM5dwNWccwgikRMz0BE9gPi9d6z6c3uBl0IrAlWGQihMpWJLXMLJ BXIg==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@infradead.org header.s=bombadil.20210309 header.b=FDgMugVo; arc=pass (i=1 dkim=pass dkdomain=infradead.org); spf=pass (google.com: domain of linux-kernel+bounces-50962-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-50962-ouuuleilei=gmail.com@vger.kernel.org" X-Forwarded-Encrypted: i=1; AJvYcCX3J8p/2Yx/C4EuJOXIZQzJv+A9ONNvnNS81KdMVTidDfxxSC3GwGN6JQ0lJ6JhGQufSZPtTd5YbNtR1Z56KYE2PUTVJA== Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [2604:1380:45e3:2400::1]) by mx.google.com with ESMTPS id t23-20020a656097000000b005d8b8c4cc37si2828088pgu.295.2024.02.03.01.19.49 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 03 Feb 2024 01:19:50 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-50962-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) client-ip=2604:1380:45e3:2400::1; Authentication-Results: mx.google.com; dkim=pass header.i=@infradead.org header.s=bombadil.20210309 header.b=FDgMugVo; arc=pass (i=1 dkim=pass dkdomain=infradead.org); spf=pass (google.com: domain of linux-kernel+bounces-50962-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-50962-ouuuleilei=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 sv.mirrors.kernel.org (Postfix) with ESMTPS id 52CF628C209 for ; Sat, 3 Feb 2024 07:16:37 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id F06D958122; Sat, 3 Feb 2024 07:13:05 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=infradead.org header.i=@infradead.org header.b="FDgMugVo" 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 F12DB57312; Sat, 3 Feb 2024 07:13:01 +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=1706944383; cv=none; b=r5Oyem+7ZgE1WWROLkNvCGkgY4dZucBYmiRCsY4LIa5QoHf5zW/Y8wWEPAF59CKTlyTx80goUK7AaM7pQ8R/Ct/SvwZIZPQtwSUy8BkdKJ/hcsg5hO2c+LWq9+DyTD3snoB1Gw35yKgs50Ywaw5l+JmdxpAeaFU9dD8y+p33jRA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706944383; c=relaxed/simple; bh=tYS0fAOiFIhd5iBGGom3yizrN/cdEhJ6ynoZIQ4dwCQ=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=GszER4YpHFfc30E+kaH4bydwNtrmHGRKiNv8irYRfiAWJMamf/4gqbgu7HuaIZAcPqqdvk8seGpCXf9sMJGGFvG2I5oxyL5XGmcv5oxotL+zwbpdZyMPK5CUTu/nra9sgmMyXmtlCFq/3AqlT4SRV3Z4G+lC0JVaHqr4RYYbtYA= 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=FDgMugVo; 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=aBLx8GrPTTpnrFrYwat6koWXvCPglp7/mI2LOOfVaJQ=; b=FDgMugVoB7MSUNHernp01Fwg/x MO+pR9JFMoCL9rwCqYotraUCpxDX06NW4fyeZ6vX5JPS0X8tpbgo7moefxhXVI67QAr0Xxmzp5E37 psFmoZYeys27ykwrnviTUvz/SmbokAZR4N9bZEyFSFJOJlxuJ2QZbK1SuEFbb8Vdsk7p/XGeR7TL8 +XGOB5d0OGem8uOS4FN4sM1iYvLyTDpZ+wlMffmwZiv2yPxszrIZH53rlSPctCCQy5qXCcVdpqrYW 3kZ1BMlFOw32O9rX7U/qB7G4p6dLZExzOJuw2VLdjcwXSgL2j1i6HzWGmXtoS3nBfwUSXDi/FI0fc ndPdGBiw==; Received: from [89.144.222.32] (helo=localhost) by bombadil.infradead.org with esmtpsa (Exim 4.97.1 #2 (Red Hat Linux)) id 1rWACv-0000000FkMz-41QH; Sat, 03 Feb 2024 07:12:59 +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 Subject: [PATCH 13/13] writeback: Remove a use of write_cache_pages() from do_writepages() Date: Sat, 3 Feb 2024 08:11:47 +0100 Message-Id: <20240203071147.862076-14-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 X-SRS-Rewrite: SMTP reverse-path rewritten from by bombadil.infradead.org. See http://www.infradead.org/rpr.html X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1789868889953121459 X-GMAIL-MSGID: 1789868889953121459 From: "Matthew Wilcox (Oracle)" Use the new writeback_iter() directly instead of indirecting through a callback. Signed-off-by: Matthew Wilcox (Oracle) [hch: ported to the while based iter style] Signed-off-by: Christoph Hellwig Reviewed-by: Jan Kara Reviewed-by: Brian Foster --- mm/page-writeback.c | 31 +++++++++++++++++++------------ 1 file changed, 19 insertions(+), 12 deletions(-) diff --git a/mm/page-writeback.c b/mm/page-writeback.c index 5fe4cdb7dbd61a..53ff2d8219ddb6 100644 --- a/mm/page-writeback.c +++ b/mm/page-writeback.c @@ -2577,13 +2577,25 @@ int write_cache_pages(struct address_space *mapping, } EXPORT_SYMBOL(write_cache_pages); -static int writepage_cb(struct folio *folio, struct writeback_control *wbc, - void *data) +static int writeback_use_writepage(struct address_space *mapping, + struct writeback_control *wbc) { - struct address_space *mapping = data; - int ret = mapping->a_ops->writepage(&folio->page, wbc); - mapping_set_error(mapping, ret); - return ret; + struct folio *folio = NULL; + struct blk_plug plug; + int err; + + blk_start_plug(&plug); + while ((folio = writeback_iter(mapping, wbc, folio, &err))) { + err = mapping->a_ops->writepage(&folio->page, wbc); + mapping_set_error(mapping, err); + if (err == AOP_WRITEPAGE_ACTIVATE) { + folio_unlock(folio); + err = 0; + } + } + blk_finish_plug(&plug); + + return err; } int do_writepages(struct address_space *mapping, struct writeback_control *wbc) @@ -2599,12 +2611,7 @@ int do_writepages(struct address_space *mapping, struct writeback_control *wbc) if (mapping->a_ops->writepages) { ret = mapping->a_ops->writepages(mapping, wbc); } else if (mapping->a_ops->writepage) { - struct blk_plug plug; - - blk_start_plug(&plug); - ret = write_cache_pages(mapping, wbc, writepage_cb, - mapping); - blk_finish_plug(&plug); + ret = writeback_use_writepage(mapping, wbc); } else { /* deal with chardevs and other special files */ ret = 0;