From patchwork Thu Jan 25 08:57:40 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christoph Hellwig X-Patchwork-Id: 13530234 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id B2D3AC48260 for ; Thu, 25 Jan 2024 08:58:11 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 45E328D000C; Thu, 25 Jan 2024 03:58:11 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 40ED1280001; Thu, 25 Jan 2024 03:58:11 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 265878D0021; Thu, 25 Jan 2024 03:58:11 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0013.hostedemail.com [216.40.44.13]) by kanga.kvack.org (Postfix) with ESMTP id 10F478D000C for ; Thu, 25 Jan 2024 03:58:11 -0500 (EST) Received: from smtpin06.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay02.hostedemail.com (Postfix) with ESMTP id BD499120DC8 for ; Thu, 25 Jan 2024 08:58:10 +0000 (UTC) X-FDA: 81717231540.06.A534A89 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) by imf26.hostedemail.com (Postfix) with ESMTP id 40532140002 for ; Thu, 25 Jan 2024 08:58:09 +0000 (UTC) Authentication-Results: imf26.hostedemail.com; dkim=pass header.d=infradead.org header.s=bombadil.20210309 header.b=kPX9xF5+; dmarc=none; spf=none (imf26.hostedemail.com: domain of BATV+b97a0fc658bf3e588113+7459+infradead.org+hch@bombadil.srs.infradead.org has no SPF policy when checking 198.137.202.133) smtp.mailfrom=BATV+b97a0fc658bf3e588113+7459+infradead.org+hch@bombadil.srs.infradead.org ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1706173089; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=pITNTbiyepqtlo8jP3CXnxlwUzR/Qf7OVM31pgQXB2c=; b=ZllVJEmANYw277TI4IfBDZhhG/7ssfTAIkyFoiICBdUMFhWAmEEIQeAGbJTD4na1Vv7ucE KJ4t1uqEoZuPLbPiAxv2zfR+Hc/h1f6qWVBt/+93+I99CsCaRPYgn66FO9qrnFKHVf718y 09JsvllGBAXDU9vWxktRnXZe1iUMP2o= ARC-Authentication-Results: i=1; imf26.hostedemail.com; dkim=pass header.d=infradead.org header.s=bombadil.20210309 header.b=kPX9xF5+; dmarc=none; spf=none (imf26.hostedemail.com: domain of BATV+b97a0fc658bf3e588113+7459+infradead.org+hch@bombadil.srs.infradead.org has no SPF policy when checking 198.137.202.133) smtp.mailfrom=BATV+b97a0fc658bf3e588113+7459+infradead.org+hch@bombadil.srs.infradead.org ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1706173089; a=rsa-sha256; cv=none; b=GgAPQ5RPpbm5tC5Swed+Eu7wKrhs2ByN6pr2I6ZG1h8WInhABuloFKPd/x0VIw6tGUuquF RgQALEhlU14uaKMDWlF0RIt0doOn+4pjHR/MxycLANQrsfI6aCErQOojXfTY/zoBUE2kPl htg544JiVaC19mZFPJ+EWipmtJ6uOrA= 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=pITNTbiyepqtlo8jP3CXnxlwUzR/Qf7OVM31pgQXB2c=; b=kPX9xF5+9DOPdosYkrB4Gr7OOk 5ZlGLcIDUkax96vrJCDbY/nuuyGiD6tZpyCwUUKBzMPUI5/FUH27SCTQnbKcPPH6k4pfwzuHB/NnW KiUHwflreZCIKmAfCsS//LnMJoJ4efOoi4Qk90nWwqnrKIFkYhMKyCywz/0/wE6Blsoboh4A0cXJL 6rZJlpqo6dJ1An7vfDAsSIWlqBdbYK5cAWqxNG+L+GTNFn5/gxRkOYOy0Of9iCKTXkeoH3GsUQFFG eugtxQofw3oW8cB3zk7+g7AX/EXuuPLtVV0s+b0Rb59uTXlN7SZWMh2Qq65VBgLd7ux0QqVdjPwWF WTjSr3mQ==; 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 1rSvYl-007Q8L-2u; Thu, 25 Jan 2024 08:58:08 +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 01/19] writeback: fix done_index when hitting the wbc->nr_to_write Date: Thu, 25 Jan 2024 09:57:40 +0100 Message-Id: <20240125085758.2393327-2-hch@lst.de> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20240125085758.2393327-1-hch@lst.de> References: <20240125085758.2393327-1-hch@lst.de> MIME-Version: 1.0 X-SRS-Rewrite: SMTP reverse-path rewritten from by bombadil.infradead.org. See http://www.infradead.org/rpr.html X-Rspam-User: X-Rspamd-Server: rspam12 X-Rspamd-Queue-Id: 40532140002 X-Stat-Signature: zihmthx1dekdixnjyq6mqyfok99msedz X-HE-Tag: 1706173089-38019 X-HE-Meta: U2FsdGVkX1/EZ/rOBpaSyhA3AS1VGriPnXCnMGGw7+biv1KBPepl2KXFT97zMSnyAtChQbxKs9wudvn8yP3Qxy9887lbDGNDpWnsSZzIZEc2gvAFBwdkmyDJLG5fU+t/zo+DEuDNuOGpQ4e8O8aZ5oXededEX5l7tVuGGi0Bf/nTJgaBb2Lmdougvx7x4i5z9ZBzAVTCbWLPI6Fp7gMrXn77P2cUvgPzcU88UBFDksC2mmI3bJEXh1Hom/hct95MMJvVBjAXGZxxUELxhW4sPmZv0ziOx+A+HrQMMnl2UFiBSFG5ePE5X8I9XA2A22kXilvH7ky/oUu26kfCrvNFvnGSrwJcH8o76lcX+38VxUzrABHDmTvFKfUjrvCHCIRarFVrtZRis+xDpCCCd6v0TYaECPQCMj4bJAVYS/XN54/WE+CkjsfVPb7ZWhNaYBpwvdype1wKAo+ZlwREB6QUzYxPlrH1ZrdWAPzKhtz3UPdAWaXVn5saGXSior11g/gzeleXGo4XkpYPjyCrEKTC8d9QEHadCfGun62nsyR4EtNt/wYbu2N8CrLY8Evc3iBShWi88HiifsaDKgyzTFMNWNbtm9mqPvx3Cyo231GS/0VSHGAR+oHzfWKqnntm2r/cAmTLe88kLepQjX4bSHvgGKsp/IpDhP8ajPzczfeWEzBdtRgrgWBQ10KV8ET5DfRoZ+yNQ3Cg/mqcylO7eYoykdCl9KmwOxSvpd4/00m3q+hyORRrfMp2IvJqpp5UFEIi1wg2UVT7xe+eAyPoVlE3D4f3c67vn8hyUWy/bwC0A+R8pIElQVLlmmyJjkrOBdfyiWcuGa5bpTtFsu/vPM2oN1uX/6xu7pHZTbcwps84XBWL1SDlra1EwpIs0/LiCjTlhs9CRA0fD6yqjjBpu1W9fDgEmw1vm1ngqfHLWlYS+KgiS62ucli3xDn/Ye+5A/DX28JGXuhIbIOilV3joLJ nM+dz3O1 BbcTnJST7eW+FvWGKPeDspEOpmbG1vf3O8mRswGcy30VYHkcglvaWh62EPYuGdmW8cu4McTvAEDiLytDeGBGCrqNvGbMxtwi9AvulElQbIVGT9j3TEqintOxI57yLGtog8MdbqWAeUDIL2OY30ufnzTyvlnOJ8Fgn3PwuxWKVK1EsFYINp8YxUTd768bH2Qr8nlUfeVezYKBwLYQufADrzcc+HQ== X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: 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: 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 cd4e4ae77c40ae..ef2334291a7270 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 Thu Jan 25 08:57:41 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christoph Hellwig X-Patchwork-Id: 13530235 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 1B83BC47422 for ; Thu, 25 Jan 2024 08:58:15 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id A79FD280006; Thu, 25 Jan 2024 03:58:14 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id A278F280001; Thu, 25 Jan 2024 03:58:14 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 854EE280006; Thu, 25 Jan 2024 03:58:14 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0013.hostedemail.com [216.40.44.13]) by kanga.kvack.org (Postfix) with ESMTP id 75FA0280001 for ; Thu, 25 Jan 2024 03:58:14 -0500 (EST) Received: from smtpin18.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay08.hostedemail.com (Postfix) with ESMTP id 3AEAB140C0A for ; Thu, 25 Jan 2024 08:58:14 +0000 (UTC) X-FDA: 81717231708.18.D1C19C4 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) by imf17.hostedemail.com (Postfix) with ESMTP id C4F7840009 for ; Thu, 25 Jan 2024 08:58:12 +0000 (UTC) Authentication-Results: imf17.hostedemail.com; dkim=pass header.d=infradead.org header.s=bombadil.20210309 header.b=Z3XEP95U; dmarc=none; spf=none (imf17.hostedemail.com: domain of BATV+b97a0fc658bf3e588113+7459+infradead.org+hch@bombadil.srs.infradead.org has no SPF policy when checking 198.137.202.133) smtp.mailfrom=BATV+b97a0fc658bf3e588113+7459+infradead.org+hch@bombadil.srs.infradead.org ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1706173092; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=xkTkipsZ3cJs79h1k4zQ5uPIipflfgz0lHVVoqCuaRQ=; b=pejHBEwpf7kHEB+1ihzCfOM/vEueuO5zNLZEGa+JCiFC9QC4js3aXFbxUGfckZffWNOPcl kXVPBLZoCNZqBLraAUJZJNM+ZBGkIL6TAfcy3G+OdOPGEuKKRctNfgUJuXuTi9/wmqt4Ea oSChchP069RmmOSyzU9E7leuajuS6Os= ARC-Authentication-Results: i=1; imf17.hostedemail.com; dkim=pass header.d=infradead.org header.s=bombadil.20210309 header.b=Z3XEP95U; dmarc=none; spf=none (imf17.hostedemail.com: domain of BATV+b97a0fc658bf3e588113+7459+infradead.org+hch@bombadil.srs.infradead.org has no SPF policy when checking 198.137.202.133) smtp.mailfrom=BATV+b97a0fc658bf3e588113+7459+infradead.org+hch@bombadil.srs.infradead.org ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1706173092; a=rsa-sha256; cv=none; b=aSy++EORGTXKUcTZz+OAEtd/uzYSrlwbD0ibD7Qyrzx0VNaGcvHguDxd4Oq5UeTaI2WAZE l4M/MuegB2D1tYFCCarOecqmiTCgBLv8bF3jF8/agnEONcPTBLCnPwDtvVhvKBGjdbdk6Y Mh+9JQxVSoqFcYXBpvbrTDbqVQxcm2w= 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=xkTkipsZ3cJs79h1k4zQ5uPIipflfgz0lHVVoqCuaRQ=; b=Z3XEP95URFlirst2CbG0dJA364 FulC5T4auE+QQ1CfqyRb85iyZUG/TPGIRz5b0wz7TFrveqq3IdNZPwXIgIRRbr6NEALfARgSwvWOx HOiTEaXMXH8giauijMsmkpjphfncVFr2i+CdcM5P7ORAiBPrAHW6mSqcp0Z2JJDn03qMkxRCKBWQJ xUEWnDSWmFx6KsdgTmvqXzgUN0lUKW5JTLdLZlskqxCVmdYNC5ifTJBLUAUxGEz2nth6T+1RqkdAT riWAqFdM5DI2XAHdnBtVnh1L8WuYkmz6y2FwTQvZ7A+7O3awT4+96hnCM0clkbgm4A6kPyaJn2y36 mUR50Qng==; 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 1rSvYp-007Q9V-1E; Thu, 25 Jan 2024 08:58:11 +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/19] writeback: also update wbc->nr_to_write on writeback failure Date: Thu, 25 Jan 2024 09:57:41 +0100 Message-Id: <20240125085758.2393327-3-hch@lst.de> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20240125085758.2393327-1-hch@lst.de> References: <20240125085758.2393327-1-hch@lst.de> MIME-Version: 1.0 X-SRS-Rewrite: SMTP reverse-path rewritten from by bombadil.infradead.org. See http://www.infradead.org/rpr.html X-Rspamd-Queue-Id: C4F7840009 X-Rspam-User: X-Rspamd-Server: rspam05 X-Stat-Signature: fwd444cqrodzr8d3e39kkmkopqnyj9ud X-HE-Tag: 1706173092-577269 X-HE-Meta: U2FsdGVkX1+gKexRBeXN1DS6hSZzkTq9vZY79rKQlpbW1PTPvW3SeH+OZsISLpzGjSpQPCLq/u40PfkSJ1T207crQZlaYOXmkKy1WRhX6f/a9lNqmq8FgggFYpXlyuOvSK9/98BaGa5uT4O47NDuuG4yb6ADMn9FJ4N5UuJq1Pjq4K2JV9i6yuUYrO27W5FFCIvye9OUjfulDyJEfBHUX8n3rzGSe0Rih+YxJNcBUhaPx49oLMP1UFv3p4MqbhuyGiFNKv/kEzz20qxOEybkksb4oudDxAwG+izto4+nk4XErH6PA5L2vNlx9wy9cDmFyNlNp52eB2gu7nKaAbwPoMojTZR4mgQTooyB+gSdCHTciXNH44HTS8N3KAH6DBM2+Qec01yVDJ4xb78WD20OodQGvNowmErygIH2XpEDAAMhop2iR1KPXefEmq/0DIEjkGVfznjoV47fa0M/BBwQ1Srzu7SDZE2e0zLk76FOBUNb3VfM+tsJjphIJxQ7vd3vC2XsFu9LCQeXF1c5OI+gTlR7hjyMphSeZ9AuuC8Xy+qn+7RNpLE05muk/+yC51+iyoXoD0Ux/Y/nDcikO5+5BMbWninuOrlaCO0y2fnT3JAUk6DqyR1uyjF2bMkoGvmqDIWOMKwOBxq2ZRFiyXQrgJPdUmxJEYgtPB3tgRLHlp6/l91ApBQBkr9D8RybSxP2ubNbXPbMfWZdQ9IbItGbJifcGFs3oD9YKn1Z85Qnxd94DngwuYFDWswERFvN1/kNZxsnRkeQ5crPQqWocwcteD0SSHYZT5DfVhY+mfF1FmVYnflSg+JZoWet/7m6bt00qfcpuO1I9SNEBn5fWH2XIvbUAGurhBNsEje8L9MpyR6BiNzBJuMcF3skHlppy1+0URcsEim8ZqG5np9zBUmj8v/B94srUB3UykK2Y3NYNxkEEz/Eui37FS5SReEHUL5D7BtuQjyil1a+mwVL1YY Kt59wG8p X5Q9TNc315MKt8XfJZiDrxWd8kllHsh5CP7GqmqKmpQhdvoz9KQstEmh42zMsnfNJttSjb/a2l6PoqQCvD3C+DZvxc/UUC9vX1bEV3T/VfClkP0ixhcM/81+Sk2HtUHCV2ahyFayvFvmIFYxG36511No24aGIf4Wg+YyBkG6IGx8SXOBc4z+rKLWPO3s0arrWRDRkpYpyBKotq4Z+ekcRt959Yg== X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: 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: 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 ef2334291a7270..0c1e9c016bc48f 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 Thu Jan 25 08:57:42 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christoph Hellwig X-Patchwork-Id: 13530236 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 7C248C47422 for ; Thu, 25 Jan 2024 08:58:18 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 1783E280007; Thu, 25 Jan 2024 03:58:18 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 12B86280001; Thu, 25 Jan 2024 03:58:18 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id EBBFD280007; Thu, 25 Jan 2024 03:58:17 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0014.hostedemail.com [216.40.44.14]) by kanga.kvack.org (Postfix) with ESMTP id DA5BF280001 for ; Thu, 25 Jan 2024 03:58:17 -0500 (EST) Received: from smtpin24.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay06.hostedemail.com (Postfix) with ESMTP id A7D6BA23A0 for ; Thu, 25 Jan 2024 08:58:17 +0000 (UTC) X-FDA: 81717231834.24.1FD8B13 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) by imf24.hostedemail.com (Postfix) with ESMTP id 353DD180009 for ; Thu, 25 Jan 2024 08:58:16 +0000 (UTC) Authentication-Results: imf24.hostedemail.com; dkim=pass header.d=infradead.org header.s=bombadil.20210309 header.b=eLUk9fi9; dmarc=none; spf=none (imf24.hostedemail.com: domain of BATV+b97a0fc658bf3e588113+7459+infradead.org+hch@bombadil.srs.infradead.org has no SPF policy when checking 198.137.202.133) smtp.mailfrom=BATV+b97a0fc658bf3e588113+7459+infradead.org+hch@bombadil.srs.infradead.org ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1706173096; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=/IByKLVlZu2F9wnx0I/UOWkm2jwSLHoNKmPo511TdLQ=; b=jp8+/BAQLADAxd4yxNnNRQ4zpS3ELPgKKp0xJpiA7Nv3ecRcMOqXo2TH6Q9d5MKfhKNaIH GbX41OdoDj+GgO3sbl6GpyG6+zX/SUPzThHcB+BW76pTonEi7Cye6OTNLYAz5zKf/ZjERR X0kjSnBSAA0AsQst+Q4KtMiTZM3A/eQ= ARC-Authentication-Results: i=1; imf24.hostedemail.com; dkim=pass header.d=infradead.org header.s=bombadil.20210309 header.b=eLUk9fi9; dmarc=none; spf=none (imf24.hostedemail.com: domain of BATV+b97a0fc658bf3e588113+7459+infradead.org+hch@bombadil.srs.infradead.org has no SPF policy when checking 198.137.202.133) smtp.mailfrom=BATV+b97a0fc658bf3e588113+7459+infradead.org+hch@bombadil.srs.infradead.org ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1706173096; a=rsa-sha256; cv=none; b=nOvFJ+OoHP5445gsCOue1rzXbU9M6vU6YB/tpX+AxhyvXK5P0mzxplGQs1F71CXmJblFnR n8enctbA+FKBb384ku+sYHCSM5hvKYLejfLrK2RvLTDbSWwXuVogLD/uWzUSz86ZmAACuI fakRXhKrCPS/WJWA6n0yTw4iJ0szHO8= 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=/IByKLVlZu2F9wnx0I/UOWkm2jwSLHoNKmPo511TdLQ=; b=eLUk9fi9CgDuij9FcAeuvwTARz 8KJIalgD3lOvEQm62ev1whPRxGCnYvwgCXnYzGxY1Z6XK6kDAd0yo6bkm/gDeVk4+WaNIWOruRjDR +PJz06AgPTbEXqLs6VfmjRGGKBwIEbksUcd/Ru6/Y/JbLCVPoWmLWB0G2xnFny5y3sNQS9CbxmziL vBeQXKMKuN80WJXNn3pF4wB7Sq7vQUp6A4jX8BqdR2HVFnfnseHhUI+shRy1FgbiGcOHEaPeKL7Ol 8NQzQW3x+PqYfF4RYL4DqXwQnSf3SROFvkZuWlvr4ns6fBtbtLuO793R5ioUD12tlhVWFya9qiyKG rFxgu+YQ==; 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 1rSvYs-007QBY-2m; Thu, 25 Jan 2024 08:58:15 +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/19] writeback: rework the loop termination condition in write_cache_pages Date: Thu, 25 Jan 2024 09:57:42 +0100 Message-Id: <20240125085758.2393327-4-hch@lst.de> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20240125085758.2393327-1-hch@lst.de> References: <20240125085758.2393327-1-hch@lst.de> MIME-Version: 1.0 X-SRS-Rewrite: SMTP reverse-path rewritten from by bombadil.infradead.org. See http://www.infradead.org/rpr.html X-Rspamd-Server: rspam09 X-Rspamd-Queue-Id: 353DD180009 X-Stat-Signature: ygqmq74ehd6wgyhp1mecasbuqtyjniw5 X-Rspam-User: X-HE-Tag: 1706173096-903277 X-HE-Meta: U2FsdGVkX1+6+MKBR+eEhJxNU4jY/1KDBm2VyHi1leL3d44pmDTyngKYuqFmBaXT5TCzV+P+HtgCB3NxVVogCBpCJ7qoLs9sHqh1POz9sCU2myf5lLcK1LxN/zCXiN0IOIG87KrejtYUq8vZrybuaSvdbDBBHsdsVWLQFnqrYr/9qAbMp3WBq0icdzFcw6RXN7fL4SBRwEd1TvsYXHuuZndG+5a5gj7NIIAgC2RN01ooAVNEHl/afmXCZwOuMMwYCS3HxI1FWYe1NWQKqf1rbOAbhmX88TuGZDJRqyVAvrJCbg7ydKsYLB/fXNAdF6Z+p3AGaNnQtywNXymfd5wP1MZ+MrThZ0k5wKgnh7UjKcGOWN1ns8Hnz3GgCzuPLGqTfw916Y0qcR2y65beWR4O8cmjCn3jBlMsGOPFH40DBMaB/dwLcY9uzJSHIwOH9wKnuld4tRf1Wgn9HV5P+Ojuz+o/NeRz4KD/+QgZnfGKfqOEb9iAejTY6OUx/wqoze0UCjvfUiD0Nc5dK1X84vup7tF71woy4ShxxOtSIj5XVGzBQCofQUxpJOBZpps9dDgSZK3ltyX/wkqjTDMMHoXRpQ8gQGWl7uGm/uxk/1L+vvaUVMip/7E1atKov8nK62ryeKvFNl/iwS1LrM9sqKkt8Dv7N/UCl9YfaXy8UZTipFbi0sr5BY76vH/OWGN/4lHTEVdyes6+1mC9QLAehxURjelTGDeTNdTwxtbkB/v0Zgdg9NpfC9sG1I4QEO4l0bI5UUJBeo51PiRlE+ayc3m4ML9pMNEvRKXTeA7bjghd0p9XrF8zstZpzxxjxcm33hmqHl9LxLXvTOo3CpUbBFUTwI1giqjAtA0O9VqUSsDdprEdJMBlhOB72B8h61UwqN6LwMc0cRJ3axyPOSJdi5/4ntEzONUrjy30o0IDruP5KHJ/1Ep8yQECrCxxbSwqOE2o3UsDhegtpmV2tK4sTyI ohPUvTwl gAagTe9P9OCMPEKb5+jrx5uENkQeES32EP3HskGkJ1nSJ8bqaSyn1YHgC+/gH0rXAy+tWamB9vAHuuP2272DThhDAbggkLA/SZhn0h5VfVu/RaA5AQwcpRn0W7Rqqc52I7GSpUMca+mag0gQmXSmc1kSbHvFusiup8HV4HjA/pwiQ8GQUEsNKdQ+YA0ekEkNRWgKt9/MnP68UMteiZ+H2e2TQ+g== X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: 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. Then merge the code to set ret for integrity vs non-integrity writeback. For non-integrity writeback the loop is terminated on the first error, so ret will never be non-zero. Then use a single block to check for non-integrity writewack to consolidate the cases where it returns for either an error or running off the end of nr_to_write. Signed-off-by: Christoph Hellwig Reviewed-by: Jan Kara Acked-by: Dave Chinner --- mm/page-writeback.c | 62 +++++++++++++++++++++------------------------ 1 file changed, 29 insertions(+), 33 deletions(-) diff --git a/mm/page-writeback.c b/mm/page-writeback.c index 0c1e9c016bc48f..259c37bc34d2a7 100644 --- a/mm/page-writeback.c +++ b/mm/page-writeback.c @@ -2474,43 +2474,39 @@ int write_cache_pages(struct address_space *mapping, 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; + + /* + * Handle the legacy AOP_WRITEPAGE_ACTIVATE magic return + * value. Eventually all instances should just unlock + * the folio themselves and return 0; + */ + 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 sync we have to keep going until we + * have written all the folios we tagged for writeback + * prior to entering this loop, even if we run past + * wbc->nr_to_write or encounter errors. This is + * because the file system may still have state to clear + * for each folio. We'll eventually return the first + * error encountered. + * + * For background writeback just push done_index past + * this folio so that we can just restart where we left + * off and media errors won't choke writeout for the + * entire file. */ - done_index = folio->index + nr; - if (wbc->nr_to_write <= 0 && - wbc->sync_mode == WB_SYNC_NONE) { - done = 1; - break; + if (error && !ret) + ret = error; + if (wbc->sync_mode == WB_SYNC_NONE) { + if (ret || wbc->nr_to_write <= 0) { + done_index = folio->index + nr; + done = 1; + break; + } } } folio_batch_release(&fbatch); From patchwork Thu Jan 25 08:57: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: 13530237 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id C3B5CC47258 for ; Thu, 25 Jan 2024 08:58:22 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 60B33280008; Thu, 25 Jan 2024 03:58:22 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 5BB48280001; Thu, 25 Jan 2024 03:58:22 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 48357280008; Thu, 25 Jan 2024 03:58:22 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0017.hostedemail.com [216.40.44.17]) by kanga.kvack.org (Postfix) with ESMTP id 362AD280001 for ; Thu, 25 Jan 2024 03:58:22 -0500 (EST) Received: from smtpin21.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay05.hostedemail.com (Postfix) with ESMTP id 1C9C840C9E for ; Thu, 25 Jan 2024 08:58:22 +0000 (UTC) X-FDA: 81717232044.21.C7EABFC Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) by imf12.hostedemail.com (Postfix) with ESMTP id 7EEE14000F for ; Thu, 25 Jan 2024 08:58:20 +0000 (UTC) Authentication-Results: imf12.hostedemail.com; dkim=pass header.d=infradead.org header.s=bombadil.20210309 header.b=Oy0oWNx0; spf=none (imf12.hostedemail.com: domain of BATV+b97a0fc658bf3e588113+7459+infradead.org+hch@bombadil.srs.infradead.org has no SPF policy when checking 198.137.202.133) smtp.mailfrom=BATV+b97a0fc658bf3e588113+7459+infradead.org+hch@bombadil.srs.infradead.org; dmarc=none ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1706173100; a=rsa-sha256; cv=none; b=STkP5Ycki6Hr2fLD/I8d1O268xKZ5BAdgB8sG+YZDlg4SnAWA7yXYRQcxjz6eLpyR76qiQ KfJmdVeWbkzg+ABng9GzJU4r3sHSo9IY9f5Z2BLhN6kMitehNztLlj+EE4NAXnUrrSJROd hp0nbtyzj5xhtfUu+gOW+lCpLAzm2kA= ARC-Authentication-Results: i=1; imf12.hostedemail.com; dkim=pass header.d=infradead.org header.s=bombadil.20210309 header.b=Oy0oWNx0; spf=none (imf12.hostedemail.com: domain of BATV+b97a0fc658bf3e588113+7459+infradead.org+hch@bombadil.srs.infradead.org has no SPF policy when checking 198.137.202.133) smtp.mailfrom=BATV+b97a0fc658bf3e588113+7459+infradead.org+hch@bombadil.srs.infradead.org; dmarc=none ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1706173100; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=mQziaJTCCDa3AbhWn4nD8iCuTBFEarj2zw47+pSlXVY=; b=e64L+zKjnVoob5HUnmYCbNK9fIoOGpAvsImuVXzbOb16Q3AuoOICGYCmNatCAaXQO4zo2s G8OJamR3SjHexiU2MaGfbgRiF82OfNxBDk2CHollPhNm8kdATYYxJxalU/KWtAggvRJTLE P8jQT/NCehabKEYP1/2vwIANYCj32SY= 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=mQziaJTCCDa3AbhWn4nD8iCuTBFEarj2zw47+pSlXVY=; b=Oy0oWNx0ILlrqoqY3sBlCvuvXZ S3ehmhURa6VLxlHpNUebI4N5SPtGJYyUtcnpTLpTGZPZ5DMzi4PFRHs17w//dZc0AWskfkia5AQE9 FHQ/03fDGUaRt+Lcj9ip6NCdsmj4KucTZgvLxgWd35fo0XiJNc2frkzg2KeftFKcQkkCyWn1RXmFY XCdgxGihsEj6mcfdRDaaBknMcF9xTHSRcH6C+Z3MaEs0W8F8Wqlg2nDqVca3VE6VqK+sV1FcFxTRJ E+n6eEw+y8DQiZJzll8t8zEmLixh3Aynt5BB1xnOlkvmqSXpG0qZU+h4b8skQ1f43JyvYWur4lVQ9 YWyQ2AnQ==; 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 1rSvYw-007QDX-17; Thu, 25 Jan 2024 08:58:18 +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/19] writeback: only update ->writeback_index for range_cyclic writeback Date: Thu, 25 Jan 2024 09:57:43 +0100 Message-Id: <20240125085758.2393327-5-hch@lst.de> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20240125085758.2393327-1-hch@lst.de> References: <20240125085758.2393327-1-hch@lst.de> MIME-Version: 1.0 X-SRS-Rewrite: SMTP reverse-path rewritten from by bombadil.infradead.org. See http://www.infradead.org/rpr.html X-Rspamd-Server: rspam08 X-Rspamd-Queue-Id: 7EEE14000F X-Stat-Signature: qcn1sydhh13m5pg979izspt6r3m4i95t X-Rspam-User: X-HE-Tag: 1706173100-376328 X-HE-Meta: U2FsdGVkX18UZ44Njn02jFhC5t1oV+ep07m6GIkIQQ8o+ojwq9SY5tfjyf5VLtURopRan9h6HKGKPNkvycQoWORdHhTwUP9g79ZmpF4F5MaX1vCtPPe0H8guxofNylhojMJQM7u5hZg1ZdsooWBtEQs4fqhy5YOBuSj8DdySLE4W8zOdoAMvpPpbWGxfSCPijv705FyfO1Ige+phNM33M4YBmAH9+lX2LieNSFwpD6PhDhXyFme7F4pDlZXGSwgsdCdeptl1K4Jrg5T3GEgvLYvK4ru476/zGkduOrtsLdJZ+FUVzihYOzTGfH/zsNnSlYQui/X2RD0sNyACzNTkaA3HiHcagi7yVYfTWRACuFUkT5ZP+gmm9ymUhZ8QoxkaGJYMqhl+445rr8PYJeezugJ+4dbrfUbqSQktkQRXy14TQo+WTHXw6nqPuk31/of5WUoRAalpJPAGYDY71JrnMV3lqZYKyVKo9pnshBnv9Y3w+wihXZlMnEYbiBz3dUhv2mona0muRa/RXRdKERMTxrNmVT9ydqCzAJIMcZ4uklUbowUYD0As5lxuzZHRfreZT1zebjTFm2pXWHQ36yW4SUuBOCSpu54EKOvAlY+1ZGBF84n7miXMzePxXVQ1fPY5MY9zPjtYRGUptVs6Vzslv1v/4NaL1L56lz1aJ8bOCeaCxblemyTOn54N5FnQtllVx2+0uGQ4WO0C3N015gqdFCz5Kc1GPHZ17h0I4v6HLcpKp4yMN+/wYBnr4fG+dfOPz/pfQ3gLAI9Rp4LY9sdhaJPj/BeRL4difSnKp45sDRzJ7akc1/jvhYHCvkOL+WW8dq1aQ4nzOWjBypRgh3r5X/Oj18MQGioOi+u6Arvq3x1RG3mlI+2WoIk5dFuhI9JiA8LMIKhlKkBGe92WSCvY72Uf6PvGxfjB2fTvpwwfzTOwS5pqPhP0PqprGq/c6H3OTBRzAXb5CXYXT/OXJKh S/QNGebs iy2ossG5lGEBWFCuhBl5Fm/2QdPyrlvbqklmNfFwmhDc51FAQU3k3t3zoHwtmWbYz//fVtaSQCeCZzTuD0yx81JzwDxjuNSZOFRfW8/HypwMQroMn9LP0UHuYzyFNAVE3SzSCD27ZjLDQCPJAfvtr2oQRzkYFUSOe0gQK+ikV6eLvCzR8HVJjuKCj5F5sbk+toI4F2FZ5AwkDZTKd191C1T59rQZfqNVbPRQLUTR/eJl5jlyNWnZatlCscTsbhsyFS+77KZdTei0moQbmtlHJPmsD7NY+FTt+urC4py5gImZ4ee+99kVoZTM8e5LRGurO2IhnKByZoeUCATXdSvVB/qYQtar35+G0Xy0IwIFuduj2MOFHLrFQ9JJHwNBxTOXmFDYZKjHnM9kAQVNRC7ZXmduoy97mdrUXOjqsvq1IIxlv734x0225fgz4Rtxp5OlVlxLv0XOA7e9YmwxNO17gZB4Z5xXeJrqGLdtQlsewiQCv7g8= X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: 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: 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 259c37bc34d2a7..437745a511c634 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); @@ -2514,14 +2511,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 Thu Jan 25 08:57:44 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christoph Hellwig X-Patchwork-Id: 13530238 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 7EF00C47258 for ; Thu, 25 Jan 2024 08:58:25 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 17A90280009; Thu, 25 Jan 2024 03:58:25 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 14FC0280001; Thu, 25 Jan 2024 03:58:25 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 047F1280009; Thu, 25 Jan 2024 03:58:24 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0014.hostedemail.com [216.40.44.14]) by kanga.kvack.org (Postfix) with ESMTP id E5FE7280001 for ; Thu, 25 Jan 2024 03:58:24 -0500 (EST) Received: from smtpin05.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay02.hostedemail.com (Postfix) with ESMTP id B9C7B120DBE for ; Thu, 25 Jan 2024 08:58:24 +0000 (UTC) X-FDA: 81717232128.05.C6FEFF4 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) by imf28.hostedemail.com (Postfix) with ESMTP id 33474C001E for ; Thu, 25 Jan 2024 08:58:22 +0000 (UTC) Authentication-Results: imf28.hostedemail.com; dkim=pass header.d=infradead.org header.s=bombadil.20210309 header.b=GXlszTq6; dmarc=none; spf=none (imf28.hostedemail.com: domain of BATV+b97a0fc658bf3e588113+7459+infradead.org+hch@bombadil.srs.infradead.org has no SPF policy when checking 198.137.202.133) smtp.mailfrom=BATV+b97a0fc658bf3e588113+7459+infradead.org+hch@bombadil.srs.infradead.org ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1706173103; a=rsa-sha256; cv=none; b=4QLmXKhxpQzeC2+RE8h5f2faLg56zeKtbFVawdv0P7Seed5lJGnLAuKkWyVxJdhAwbPHFD DayYKVwibtDAtW1Ku3+xsOQ35V7wVYda5yqXIg84J2pfAw4p+bRXjx3aZtHyWy4o3IZez6 j70zmrZTKo+DP0l+S66X75MUgL9pFww= ARC-Authentication-Results: i=1; imf28.hostedemail.com; dkim=pass header.d=infradead.org header.s=bombadil.20210309 header.b=GXlszTq6; dmarc=none; spf=none (imf28.hostedemail.com: domain of BATV+b97a0fc658bf3e588113+7459+infradead.org+hch@bombadil.srs.infradead.org has no SPF policy when checking 198.137.202.133) smtp.mailfrom=BATV+b97a0fc658bf3e588113+7459+infradead.org+hch@bombadil.srs.infradead.org ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1706173103; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=Taksxj6ldsIHACaAalkM9jooesWM/uwlc+qMiL84I/w=; b=qwumoFOsFYa4uFAsFiIRboMvupxnYEasOqPAo5N/cnN2lefuur5vpENtlh+8V/wQ36OCZ7 XgRBcVdD8HAVfA3Ff/52mNYVfaHscJQ06oKbtNqxWCQq3LkF6hFBCzJYgJ+zqI7pCqUGfg V8dJhN6DUmnC2knJANr9cWHkH0o6ZIQ= 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=Taksxj6ldsIHACaAalkM9jooesWM/uwlc+qMiL84I/w=; b=GXlszTq66WVW6aNXlFQph8c9ec +uEY+GZCHqemFTAAG1dRDeShUFrgHZ886JX0tfhFtxQJ5IaaQrNNp8D3bk+EMuwcl34AbvvJM9l3J XS8A/YQ6Qhg9fsY7psv1wnOTtNFxk8ynFXa3yEGAJXJxnoPzO6kanY4MSDyepXIOpP4ttSUCJvALG icbVpuyEDb3zJBoekF8IPH5fBVW72ixdQpehxaJidncDc5Wq6S8fbyPITeP/8AHBYR5elWPXyzZDw gM/aWzH37d2eyg75230hwI9gEMGsl6+E0D09XvH7NE94ULvS3qmeFzXhs0osVgYjcWuUIPElZkuYB AUcJQ2Dg==; 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 1rSvYz-007QFR-2f; Thu, 25 Jan 2024 08:58:22 +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 05/19] writeback: remove a duplicate prototype for tag_pages_for_writeback Date: Thu, 25 Jan 2024 09:57:44 +0100 Message-Id: <20240125085758.2393327-6-hch@lst.de> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20240125085758.2393327-1-hch@lst.de> References: <20240125085758.2393327-1-hch@lst.de> MIME-Version: 1.0 X-SRS-Rewrite: SMTP reverse-path rewritten from by bombadil.infradead.org. See http://www.infradead.org/rpr.html X-Rspam-User: X-Rspamd-Server: rspam06 X-Rspamd-Queue-Id: 33474C001E X-Stat-Signature: gaqaorakrstwhpzoiz6cqjjg6xbjjifc X-HE-Tag: 1706173102-387504 X-HE-Meta: U2FsdGVkX19SXYlxoHq+8J4V+I0F2bo1XKRaP7xGYJf5a9LBdQFZIOTlbaatXgqCbdviydwHShKl7F4/AOIWb9b9iGYl6GqXbZwONf3L54PrIWs43K6Ol62d1BYUjfl2x3z/8AQLfHH5EUKXOOgmEvkPsfoLTGvjhAz3sc6XDRtjZ57hwB9v+XSwS52gWNuG9Ze+lRHyptv/La5hgwKitm7xOHxnnlVKbsnYpDUmjJEVkt83EmQMtaGpp5DOukiFEuVyrOCchOB92Icyl3jopaxzhjQqFf6qxcEzFv3G1uphb6mbdYG8qyO8qjHeZW8L3E4R9h8C+ZpElubrGd2Wu2Lxvgqy5XFivrxqSYAaqBHRsnK4++bNRp4wltmdyWe0TSUMk63QNJjR2o3MN7bAdrEPt3aPt1FRuR7lLnKAr3NDDHX5oTyWkjO7KNixS8vR40v3dn9LIMlcn6weTogRxPAZzfnREYRJP6SNlj04oi08L8QTEzsL0U1s4myP31AX4qK4BajWrzh6qqx58pkfWsLGk/A5WKtnjc55zKrF1OlDEf3MY6dMDOz5bhV9U8Fgg1Ce0tw2nTkZjzl8x4Hxcsf453JNgdAWWuWwUT9herbS2Lknt10Nr/r2LVa5JEKaxMlp9fKBFncEGd0P7G7zpUCXAPP50eh3H4crzJdj+D3mgqCQVcq9XREZf73xDd7uzYcNVxH3uMMV/IzFpEYK48ObsShoeS5+g7dLlHebKDGF2ATXLtsFOJWVAymj2us+lvY04BsUle71dG55WBoWMB6iBFW62RhWr0i/7WjXsHrBjBF7dkK9N26Qg/O2qyCXhuUakfTKt1FtQ1FrBrWgGa7sPQeHFq8MIr9MhnTk1oU512q2aDaYyLZy7x1VGzF6ZWxn64lPbpDMLgPrPs95O7SJ41n8RNRSwb5z9Gr7Qrvb/oL5UXt58aYV2aOden7jQgCfomK54HFSTqgIKME 40RN8boc 9oCyh1JnTPqPTUL0R8rG0wl7DGC6XMnGJexG1xsYtanYVp31adyC3Ye722+1Zs1AaZTxHVEOVUoLDYmzRejVrPvqXVTan1HIk8sXRS7tclg4dahpQTYdOb2kjA6a2GEGNlL/ovH8waVRFlnSKlsjVwmS6W1N+/r7XVCq93B896Sx0HGsuxBrA65xHBRvq6ZoTuZnTLDQGlIrKpxS+A3I5uGRs/WRi/AOHmj6EWwZZy73dAH8S1vs0F0NAD8Ty/k3GWJ1WakfWOlJkzVY2GvPaSX5rp82hpxvTG7QH4ZPdUQFaor8fu409t+9/WpZK+voRYsNxOEv2MlPQL7CY6RkXjt+WA5+30ClKlGycH2RPm+gZ/WTGAh5KnXSPnHwooxDll8bePZGObmG05kHNuQpVW/7xywbWygJFsYaVr1EXU7VjDBmYw3JI0JTZIrb9WXOUAfd60PLIXlvmoRHbypiFPuCZcu7EE3MIo6z3WUxX4WRSzoH3Tc1Aju9YnjfAAUesmA2k+fZ8j5p5EX6Fk9nSBcBRstxVipi0XwMW X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: From: "Matthew Wilcox (Oracle)" Signed-off-by: Christoph Hellwig [hch: split from a larger patch] Signed-off-by: Matthew Wilcox (Oracle) Reviewed-by: Jan Kara Acked-by: Dave Chinner --- include/linux/writeback.h | 2 -- 1 file changed, 2 deletions(-) diff --git a/include/linux/writeback.h b/include/linux/writeback.h index 453736fd1d23ce..4b8cf9e4810bad 100644 --- a/include/linux/writeback.h +++ b/include/linux/writeback.h @@ -363,8 +363,6 @@ bool wb_over_bg_thresh(struct bdi_writeback *wb); typedef int (*writepage_t)(struct folio *folio, struct writeback_control *wbc, void *data); -void tag_pages_for_writeback(struct address_space *mapping, - pgoff_t start, pgoff_t end); int write_cache_pages(struct address_space *mapping, struct writeback_control *wbc, writepage_t writepage, void *data); From patchwork Thu Jan 25 08:57: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: 13530261 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 635C0C47422 for ; Thu, 25 Jan 2024 08:58:31 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id E97056B0072; Thu, 25 Jan 2024 03:58:30 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id E47D46B007B; Thu, 25 Jan 2024 03:58:30 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id CE6EE6B0083; Thu, 25 Jan 2024 03:58:30 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0015.hostedemail.com [216.40.44.15]) by kanga.kvack.org (Postfix) with ESMTP id B9CDB6B0072 for ; Thu, 25 Jan 2024 03:58:30 -0500 (EST) Received: from smtpin21.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay10.hostedemail.com (Postfix) with ESMTP id 95566C0C57 for ; Thu, 25 Jan 2024 08:58:30 +0000 (UTC) X-FDA: 81717232380.21.84D7D4B Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) by imf17.hostedemail.com (Postfix) with ESMTP id E26BE40013 for ; Thu, 25 Jan 2024 08:58:28 +0000 (UTC) Authentication-Results: imf17.hostedemail.com; dkim=pass header.d=infradead.org header.s=bombadil.20210309 header.b=M2BAjIGA; spf=none (imf17.hostedemail.com: domain of BATV+b97a0fc658bf3e588113+7459+infradead.org+hch@bombadil.srs.infradead.org has no SPF policy when checking 198.137.202.133) smtp.mailfrom=BATV+b97a0fc658bf3e588113+7459+infradead.org+hch@bombadil.srs.infradead.org; dmarc=none ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1706173109; a=rsa-sha256; cv=none; b=LJxrkPJvaT/5H4SG8uUuuzZ3zbwZMJ4EdDdtPqIljoBXh06yeRSrXLrlf9+jCTTaz87PHP 4+MJlZtQQb5F1j+eZtpPgwiUHg79yXvjDwmis8MTwwGxROud+epvss33QpEwFYe88KzQIM 22N6StIcD5pmurj+U3cqZjRtvNVZctw= ARC-Authentication-Results: i=1; imf17.hostedemail.com; dkim=pass header.d=infradead.org header.s=bombadil.20210309 header.b=M2BAjIGA; spf=none (imf17.hostedemail.com: domain of BATV+b97a0fc658bf3e588113+7459+infradead.org+hch@bombadil.srs.infradead.org has no SPF policy when checking 198.137.202.133) smtp.mailfrom=BATV+b97a0fc658bf3e588113+7459+infradead.org+hch@bombadil.srs.infradead.org; dmarc=none ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1706173109; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=Vkaa3agK4bmExpMMpwz6raRR84eX1JPD0T6pdU6vMG0=; b=7WWizbhLmxElZqfpqZvtLh19P52cSQ/gRWRYHN4a6PnjngIAWhtB2wpmEWpYd4mmvy2k0i DD22ELxvHBLJS7FfA7MyjOxYsJms8c0FgTZ3lEZhkQ1h3jb2c+jyGu3j6jb6pUPHdzZA+v S+37WVkfg6rzibK/JzfAcsf7FxTETiI= 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=Vkaa3agK4bmExpMMpwz6raRR84eX1JPD0T6pdU6vMG0=; b=M2BAjIGAHnJ1E+ndMgAiCOjjYp 1a+nS3OdgBz8+6pf3SQxZDnckkrJM9+/8/o7yfitpdM+slw3S/cxglf8duyGyWNHivAuCeIQ0hBka 5zjfblB5iys/OqtNw3HsMQFxI1q7UhTSjlehkJhmeryqswG1YOAGC0KJnH5LeDkL1RKTzqXvV+xI4 lGFpynQi3ruaXpEk9G6tEusnvGA4IkCRSO2MGmqi/vhP2a0hMR3Vs9ztPcuS13v3qC2y9e5faOubW RnDjBphg9mhBmn8msek0d6YR3AwsDL+dmrJtKFhBgM70Rw9kRaBaVThf1Ai1b/8smeMnJDxmKIfLz Nv/zZssQ==; 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 1rSvZ3-007QGN-10; Thu, 25 Jan 2024 08:58:25 +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 06/19] writeback: Factor out writeback_finish() Date: Thu, 25 Jan 2024 09:57:45 +0100 Message-Id: <20240125085758.2393327-7-hch@lst.de> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20240125085758.2393327-1-hch@lst.de> References: <20240125085758.2393327-1-hch@lst.de> MIME-Version: 1.0 X-SRS-Rewrite: SMTP reverse-path rewritten from by bombadil.infradead.org. See http://www.infradead.org/rpr.html X-Rspamd-Server: rspam08 X-Rspamd-Queue-Id: E26BE40013 X-Stat-Signature: oi3k4b14sqkiqno49xq5rk1h1aej5nis X-Rspam-User: X-HE-Tag: 1706173108-224072 X-HE-Meta: U2FsdGVkX1+5tjOdOrzNeteSUY1fbeRUQDZ206EpWCXfPFJev7BlXDOWulC+xqSca2Czpp4Dyc3jh+FhyBOwOeF5hfEUKFQYUtNyRnTXGhLwcJ+dw0zomNmf1vY59O58R+rYV+enF/COr2ITOwyIZi1iZ8erlzcuUJNtdAgHMKIT+JKKuBN1nOgP5/h9BJoQLalewnIhU4C7yF+RhZRIJ/8VaKEA9xPv1aZRa+57MkQdB3jD8TrZ9MUV11Puip3GcSqrcr858wkAFOABQTHZYtdOZqDj7ML5QJ+XzWM0snedwFNKBr2aMoXLGyLG3soq/e7YNV+ixsh/Q3ATzOu1iYHh+qV3ZsrMahwXEq3+kCZR9aH/Qq5KYJ1hmFHyNq66OaMPAlK1PU1neslie7XWXo1iZjkeYAZte2opBhA/u4B4kT4GqNGvZAZic3Pa3DrOJdJsKVWR/zp2cXNZ+4iuixlbrW76OE2LQ4niY2S7y3G9pRd9h61/HLQEMJ4VW4IOA9GBp7NnFW1FBWHyixv0wlbO/MG+p6eSreCBXRlz93pWMRXSV5YXahCl2SbV5l+R8Nxdq9yhaKagV0P5TNPy0HnYQUjS2FzGzi2d8Oqvuqv0LhrwJxixrRU6okEUuwKPr6Xjv/dWv0wApk2UyF/kdUPP/m9mbyiKPiiyK7tqj16PvJJDt+0WnVE8MxNjAYtVHRYaeebHyhjMQU7/wK2nv8dOxzAbUKurycLQuXJB2MGTHP6xdtn2OGFXbQKVHW/YV2DAF7lrNU1b0seV31yrla0Ev3cy/iyg0bdoCgLTtWRbKFZTb/MazU30iLnbst7qO1AFJrTvKrGh95jRdVVfTwa/SsCV2AFsz2+jdrNfb+WSEgzHpRHPS9SUu0Zb1jB/Q8Wy5jkHXKtfjFPT4XEWHexI43I9Z40+IrJoZy8lfGNVu4hXGuVYyEOBpX+RUNZy8+LjqY2eOItXs1KuKkd uEn64kFX ETxezZO+S1WuWgSQzPPpqDujT654lpXPNDO6x9XvOUsh1j1zYuhldof9+R/wOCFJ+FjCFMNl63OSmVYFAoHytNB/YTOt9usILXIx7BNUbn7mv+g3YgchZc178Sth9jcbs7A74Qga7GjaRCYW8vGI0K+CmDst/JdQB/vjcbwTOUWND97iddV0s3Xj0+Fbn6RM4CSwcAqHTOwLSJadh7yKxsA2a/uSFNqdxSNOTNoYoL0Sr/jrJnd/eDOXzNlaFxl5/TObtXG29GULJs2Z/37Mt/3RCQ6Df5vjURFw/+uy2ZzCuspbnZi29iusmrGvnn8t9S+pHNNs/TkaV3vpNJHKKr60k4wnTrKKYpN23Y7KV1RIW0RpbQ23EdRaqSZ1ny2yKubUqiUbDmYeVSgtqdcKY4upFX103x9Bcwr9xXp3H8kMcTU5mW6Zf5mDexU0aRtpPzITbww+2R6dxIs1iTG6CGhNJ0lWG463bfotPOr6gccLviv2MqF+yxH72dJkv2slsHyAvbEi4FyxiRG0xpjtUbg/cfRSg9em3CyQLbafn+R8E6Y4ve2bSAQW0VuqDrD8TatCP X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: From: "Matthew Wilcox (Oracle)" Instead of having a 'done' variable that controls the nested loops, have a writeback_finish() that can be returned directly. This involves keeping more things in writeback_control, but it's just moving stuff allocated on the stack to being allocated slightly earlier on the stack. Signed-off-by: Matthew Wilcox (Oracle) [hch: heavily rebased, reordered and commented struct writeback_control] Signed-off-by: Christoph Hellwig Reviewed-by: Jan Kara Acked-by: Dave Chinner Reviewed-by: Brian Foster --- include/linux/writeback.h | 6 +++ mm/page-writeback.c | 79 ++++++++++++++++++++------------------- 2 files changed, 47 insertions(+), 38 deletions(-) diff --git a/include/linux/writeback.h b/include/linux/writeback.h index 4b8cf9e4810bad..7d60a68fa4ea47 100644 --- a/include/linux/writeback.h +++ b/include/linux/writeback.h @@ -11,6 +11,7 @@ #include #include #include +#include struct bio; @@ -40,6 +41,7 @@ enum writeback_sync_modes { * in a manner such that unspecified fields are set to zero. */ struct writeback_control { + /* public fields that can be set and/or consumed by the caller: */ long nr_to_write; /* Write this many pages, and decrement this for each page written */ long pages_skipped; /* Pages which were not written */ @@ -77,6 +79,10 @@ struct writeback_control { */ struct swap_iocb **swap_plug; + /* internal fields used by the ->writepages implementation: */ + struct folio_batch fbatch; + int err; + #ifdef CONFIG_CGROUP_WRITEBACK struct bdi_writeback *wb; /* wb this writeback is issued under */ struct inode *inode; /* inode being written out */ diff --git a/mm/page-writeback.c b/mm/page-writeback.c index 437745a511c634..fcd90a176d806c 100644 --- a/mm/page-writeback.c +++ b/mm/page-writeback.c @@ -2360,6 +2360,29 @@ void tag_pages_for_writeback(struct address_space *mapping, } EXPORT_SYMBOL(tag_pages_for_writeback); +static void writeback_finish(struct address_space *mapping, + struct writeback_control *wbc, pgoff_t done_index) +{ + folio_batch_release(&wbc->fbatch); + + /* + * 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) { + if (wbc->err || wbc->nr_to_write <= 0) + mapping->writeback_index = done_index; + else + mapping->writeback_index = 0; + } +} + /** * 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 @@ -2395,17 +2418,12 @@ int write_cache_pages(struct address_space *mapping, struct writeback_control *wbc, writepage_t writepage, void *data) { - int ret = 0; - int done = 0; int error; - struct folio_batch fbatch; int nr_folios; pgoff_t index; pgoff_t end; /* Inclusive */ - pgoff_t done_index; xa_mark_t tag; - folio_batch_init(&fbatch); if (wbc->range_cyclic) { index = mapping->writeback_index; /* prev offset */ end = -1; @@ -2419,22 +2437,23 @@ int write_cache_pages(struct address_space *mapping, } else { tag = PAGECACHE_TAG_DIRTY; } - done_index = index; - while (!done && (index <= end)) { + + folio_batch_init(&wbc->fbatch); + wbc->err = 0; + + while (index <= end) { int i; nr_folios = filemap_get_folios_tag(mapping, &index, end, - tag, &fbatch); + tag, &wbc->fbatch); if (nr_folios == 0) break; for (i = 0; i < nr_folios; i++) { - struct folio *folio = fbatch.folios[i]; + struct folio *folio = wbc->fbatch.folios[i]; unsigned long nr; - done_index = folio->index; - folio_lock(folio); /* @@ -2481,6 +2500,9 @@ int write_cache_pages(struct address_space *mapping, folio_unlock(folio); error = 0; } + + if (error && !wbc->err) + wbc->err = error; /* * For integrity sync we have to keep going until we @@ -2496,38 +2518,19 @@ int write_cache_pages(struct address_space *mapping, * off and media errors won't choke writeout for the * entire file. */ - if (error && !ret) - ret = error; - if (wbc->sync_mode == WB_SYNC_NONE) { - if (ret || wbc->nr_to_write <= 0) { - done_index = folio->index + nr; - done = 1; - break; - } + if (wbc->sync_mode == WB_SYNC_NONE && + (wbc->err || wbc->nr_to_write <= 0)) { + writeback_finish(mapping, wbc, + folio->index + nr); + return error; } } - folio_batch_release(&fbatch); + folio_batch_release(&wbc->fbatch); cond_resched(); } - /* - * 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) { - if (done) - mapping->writeback_index = done_index; - else - mapping->writeback_index = 0; - } - - return ret; + writeback_finish(mapping, wbc, 0); + return 0; } EXPORT_SYMBOL(write_cache_pages); From patchwork Thu Jan 25 08:57: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: 13530262 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id F0476C47258 for ; Thu, 25 Jan 2024 08:58:32 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 855806B007B; Thu, 25 Jan 2024 03:58:32 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 8050D6B0083; Thu, 25 Jan 2024 03:58:32 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 6A6926B0087; Thu, 25 Jan 2024 03:58:32 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0016.hostedemail.com [216.40.44.16]) by kanga.kvack.org (Postfix) with ESMTP id 4655C6B007B for ; Thu, 25 Jan 2024 03:58:32 -0500 (EST) Received: from smtpin14.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay01.hostedemail.com (Postfix) with ESMTP id EA0C51C08E6 for ; Thu, 25 Jan 2024 08:58:31 +0000 (UTC) X-FDA: 81717232422.14.676D35A Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) by imf14.hostedemail.com (Postfix) with ESMTP id 2BA4A10000B for ; Thu, 25 Jan 2024 08:58:29 +0000 (UTC) Authentication-Results: imf14.hostedemail.com; dkim=pass header.d=infradead.org header.s=bombadil.20210309 header.b=NYMtHn25; dmarc=none; spf=none (imf14.hostedemail.com: domain of BATV+b97a0fc658bf3e588113+7459+infradead.org+hch@bombadil.srs.infradead.org has no SPF policy when checking 198.137.202.133) smtp.mailfrom=BATV+b97a0fc658bf3e588113+7459+infradead.org+hch@bombadil.srs.infradead.org ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1706173110; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=iMNdeEcqkHffoQV1X3XMHDmnGgKthKHMo1jJFViVMos=; b=5zV2+Ti7q2d/AnnHeZ2HuxTXh0o9YOBYZyWwYFpqwnEg5kGvl6jTpIiDeMiE0QBP9SY1oH uJzxWwE6wHGLYmaMqztusidwRNgffZT5YJowmpKITDH+SKddtMOfLicjWRfiC50JA+3Idm mw3NxClROQc6KbcBiTJKbKZ/ZW34UYE= ARC-Authentication-Results: i=1; imf14.hostedemail.com; dkim=pass header.d=infradead.org header.s=bombadil.20210309 header.b=NYMtHn25; dmarc=none; spf=none (imf14.hostedemail.com: domain of BATV+b97a0fc658bf3e588113+7459+infradead.org+hch@bombadil.srs.infradead.org has no SPF policy when checking 198.137.202.133) smtp.mailfrom=BATV+b97a0fc658bf3e588113+7459+infradead.org+hch@bombadil.srs.infradead.org ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1706173110; a=rsa-sha256; cv=none; b=GFc9OD5oXrGcZsjpcSSxUwTNdFxensikjZlecmLpJlraJRCSFVHKjD0LzCQ2X1bxpwN4AC uBkuko3ib7w5dRuZ1KXQlYrM98Lw4HJYJLFJ36Na1kS5b83EQ22uzktLZq5o4UJe1hIhnI VU/ulfxY5CaOEJVyjyIzrmYEMUFcVXQ= 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=iMNdeEcqkHffoQV1X3XMHDmnGgKthKHMo1jJFViVMos=; b=NYMtHn25QyrrlxJcgdmcd5wXPv Fs4iTu7Y92y79RyHoSjqnlwmQ9qOeHg2R71DOkpgcyJhscAmH6I4dNw4srUwkykfySn/hDJUXF9Mg xE1KHnNO/4TDKC1BnAC9r/zqcHfUmFdxMYmeWpb6mOQR7ikjQnudqE5vJzum+sNrz7WREHDLNDbt8 aOCRcmIL3e0neCp4yrhGF9cF/98FYoaUTHSoa9ags1lcADvlSMN2TLch/Y/7NVitDRie7WYJvj4ps 0BORVBVnBJbJe3aJ/25+/xzXccPHir5JNNB1eIiE4OgrV4nMlCA8nj6yVyW4d0PWkGM78le+KiEiS 8mHMHEEA==; 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 1rSvZ6-007QHR-2Y; Thu, 25 Jan 2024 08:58:29 +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 07/19] writeback: Factor writeback_get_batch() out of write_cache_pages() Date: Thu, 25 Jan 2024 09:57:46 +0100 Message-Id: <20240125085758.2393327-8-hch@lst.de> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20240125085758.2393327-1-hch@lst.de> References: <20240125085758.2393327-1-hch@lst.de> MIME-Version: 1.0 X-SRS-Rewrite: SMTP reverse-path rewritten from by bombadil.infradead.org. See http://www.infradead.org/rpr.html X-Rspamd-Queue-Id: 2BA4A10000B X-Rspam-User: X-Rspamd-Server: rspam02 X-Stat-Signature: c4oskpwhwnxj5oe19igz6okab464dwbk X-HE-Tag: 1706173109-237881 X-HE-Meta: U2FsdGVkX19qOXrXA576WisulazHeGuhoqF4QSH4vgWqD8hiC6LcyKMYPi9ShwulqijCvmn59h3dRryErm5pZ6xlnokHzu8crtP2z7RkfJeF/IY2OWL3b+/wFRc4HwwMkqEiYwpHELuLV+yxvNtNrCiuApTM0SN36xgd0OdjgLSY65eiroVMOqqDNt43VEWVuutNbt0wcufL3CQg+mREAYTv5J74TrSGeaXw1FhAEThAFewJVOfl6vRtRxYZKmNfdsd/1kXFeQpOV8WEH/gF/4NH8CsYsohz3947xL5qIaYRpyAh9sIA8hveRc8DgB1u8xo+0enk6pKriCUrdzROcHJ/rRLfu3m62p00Jf/m7O6jwB+t93/tFlAjLZsubaMDOHaQy8w43WLoKIG3QPUqL+DGmw/MuGTIP/Y1M4Gd84t/dEed2H3Vyzbu2yWJL6vHe1hi8zyL8S07cscJ3Sow3oRkB320xyl0Jox7OkpkkjI9O394OXXF76bZObQ5n6ipmV0D1Q2M1fpCDc7eGhBSMir/7TtwEGXhJ2iBOkTKEssrl/aVErLouQrp1ZEhXhdGOvSP7RsuFsizZwRzt8H2sQ0NbjIczmJ5MTXXY4hi5DAgI+S1oSRwQi6E5C4xRwwnZny2n+ekn0EMcLXLRFkCA186+BhIVkFpk/3nwEUy4wDojkvjpEWiH0W52QAcM87L4m5SMSUpxF9Q280rdTnoeL+lS2OQD4TiyrnHLMEs3wYpaG8MwFcjww3DC0ct2O/uxNbl9DG+eusnquMLVMBKX518K3Z7XVmYFraisPk0NJsXrkVB4/vSzz9ZrWQ+b+Do/Jr8Sm5b9WimT3rxPa1XFwQUWtewtOnJZ20Sn86MTtYQhTvSUvGPJS838pLKO0hQtnxP/NOd5+mZTPRkYbTTge/6NmVvzYrzjsFzijP5HH5peD4zLMgCfF1oqp9IEy+ztZRN/1ADnRxbzjjLSsH TPfFqgHv wiBKk1T846fVGxQTXU5lkS+RsAcMdrCgmwqCAYIfwT4dsLLvXSd/4GzCwfxMshTLpzIKJV9rjJ3meYMgo0HkQHwFDfFHaQTECC9BfJaRcoMhMSs8xsXcc026blR60RsjOz4QubsPPi8EbokPqmdW7Cqu/pe7xpyu2ovfs9dqjMOzSwdbHhgkuNz1PYbLA3UU1dsSsqWdK3ABDOGV7DqTTaJU+mrMz+vuYwfp49nJzTbbSJ7OGBW2NOB0uFBBftrYPsi6u+HHLUw8Nrljap1Gx0R/4Qp3F+jCY7TnXP9i0lwhVUnsKMPpY5mK/YfSEeontD5Rv82Zn8hsR2eRiApPzAINtSp3AeZ/TWbIGe8w5QJiSLu4ZkYSPNELSj1EqGpWvE1srsfAYBbNs2R2uim0tOieM6pFcUc3xXxH9Qf6urfePaUmeHbU09E9NO4WfuVEbMjTUEVBPfiB4tRlFl8wH0NcEZzY+gILXIsLvaWtr93w9SVh7IYTtY8EXaU2QLfYq3tyLbLuZ+b31pS3VOTy5dHP6xKMjzFq6babNin1zWGoIh4ItZQ9GVcn1f+/jbvmGlGJG X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: From: "Matthew Wilcox (Oracle)" This simple helper will be the basis of the writeback iterator. To make this work, we need to remember the current index and end positions in writeback_control. Signed-off-by: Matthew Wilcox (Oracle) [hch: heavily rebased, add helpers to get the tag and end index, don't keep the end index in struct writeback_control] Signed-off-by: Christoph Hellwig Reviewed-by: Jan Kara Acked-by: Dave Chinner --- include/linux/writeback.h | 1 + mm/page-writeback.c | 49 +++++++++++++++++++++++++-------------- 2 files changed, 32 insertions(+), 18 deletions(-) diff --git a/include/linux/writeback.h b/include/linux/writeback.h index 7d60a68fa4ea47..a091817a5dba55 100644 --- a/include/linux/writeback.h +++ b/include/linux/writeback.h @@ -81,6 +81,7 @@ struct writeback_control { /* internal fields used by the ->writepages implementation: */ struct folio_batch fbatch; + pgoff_t index; int err; #ifdef CONFIG_CGROUP_WRITEBACK diff --git a/mm/page-writeback.c b/mm/page-writeback.c index fcd90a176d806c..426d929741e46e 100644 --- a/mm/page-writeback.c +++ b/mm/page-writeback.c @@ -2383,6 +2383,29 @@ static void writeback_finish(struct address_space *mapping, } } +static xa_mark_t wbc_to_tag(struct writeback_control *wbc) +{ + if (wbc->sync_mode == WB_SYNC_ALL || wbc->tagged_writepages) + return PAGECACHE_TAG_TOWRITE; + return PAGECACHE_TAG_DIRTY; +} + +static pgoff_t wbc_end(struct writeback_control *wbc) +{ + if (wbc->range_cyclic) + return -1; + return wbc->range_end >> PAGE_SHIFT; +} + +static void writeback_get_batch(struct address_space *mapping, + struct writeback_control *wbc) +{ + folio_batch_release(&wbc->fbatch); + cond_resched(); + filemap_get_folios_tag(mapping, &wbc->index, wbc_end(wbc), + wbc_to_tag(wbc), &wbc->fbatch); +} + /** * 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 @@ -2419,38 +2442,30 @@ int write_cache_pages(struct address_space *mapping, void *data) { int error; - int nr_folios; - pgoff_t index; pgoff_t end; /* Inclusive */ - xa_mark_t tag; if (wbc->range_cyclic) { - index = mapping->writeback_index; /* prev offset */ + wbc->index = mapping->writeback_index; /* prev offset */ end = -1; } else { - index = wbc->range_start >> PAGE_SHIFT; + 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, index, end); - tag = PAGECACHE_TAG_TOWRITE; - } else { - tag = PAGECACHE_TAG_DIRTY; - } + if (wbc->sync_mode == WB_SYNC_ALL || wbc->tagged_writepages) + tag_pages_for_writeback(mapping, wbc->index, end); folio_batch_init(&wbc->fbatch); wbc->err = 0; - while (index <= end) { + while (wbc->index <= end) { int i; - nr_folios = filemap_get_folios_tag(mapping, &index, end, - tag, &wbc->fbatch); + writeback_get_batch(mapping, wbc); - if (nr_folios == 0) + if (wbc->fbatch.nr == 0) break; - for (i = 0; i < nr_folios; i++) { + for (i = 0; i < wbc->fbatch.nr; i++) { struct folio *folio = wbc->fbatch.folios[i]; unsigned long nr; @@ -2525,8 +2540,6 @@ int write_cache_pages(struct address_space *mapping, return error; } } - folio_batch_release(&wbc->fbatch); - cond_resched(); } writeback_finish(mapping, wbc, 0); From patchwork Thu Jan 25 08:57: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: 13530263 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 04AA4C47258 for ; Thu, 25 Jan 2024 08:58:36 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 91A116B0087; Thu, 25 Jan 2024 03:58:35 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 8CA6F6B0089; Thu, 25 Jan 2024 03:58:35 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 743566B0093; Thu, 25 Jan 2024 03:58:35 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0015.hostedemail.com [216.40.44.15]) by kanga.kvack.org (Postfix) with ESMTP id 5F21A6B0087 for ; Thu, 25 Jan 2024 03:58:35 -0500 (EST) Received: from smtpin17.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay05.hostedemail.com (Postfix) with ESMTP id 4128E407EF for ; Thu, 25 Jan 2024 08:58:35 +0000 (UTC) X-FDA: 81717232590.17.6F17406 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) by imf07.hostedemail.com (Postfix) with ESMTP id AAEFD40016 for ; Thu, 25 Jan 2024 08:58:33 +0000 (UTC) Authentication-Results: imf07.hostedemail.com; dkim=pass header.d=infradead.org header.s=bombadil.20210309 header.b=U9NfiMtZ; dmarc=none; spf=none (imf07.hostedemail.com: domain of BATV+b97a0fc658bf3e588113+7459+infradead.org+hch@bombadil.srs.infradead.org has no SPF policy when checking 198.137.202.133) smtp.mailfrom=BATV+b97a0fc658bf3e588113+7459+infradead.org+hch@bombadil.srs.infradead.org ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1706173113; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=MhbOOusfwIyRDrId1i1glf9YHzO3PaLh+M9tTsTFsQo=; b=kgNG76yBbEheAt/03qo7g6JTpi2O3/hD3DXHDkcAFQbloIKtwyFZ1RuCfi/Shlx/VlXJCm 3K8rQPxZuMnV0TGitEs8/pfWJ5XOVMmW6pXWjmkyfyvQOxIyEI0fpYrjEYNYtMetfm/L41 LRPeA0JW/sGHXHx/8PxQmXSWDzOqZ24= ARC-Authentication-Results: i=1; imf07.hostedemail.com; dkim=pass header.d=infradead.org header.s=bombadil.20210309 header.b=U9NfiMtZ; dmarc=none; spf=none (imf07.hostedemail.com: domain of BATV+b97a0fc658bf3e588113+7459+infradead.org+hch@bombadil.srs.infradead.org has no SPF policy when checking 198.137.202.133) smtp.mailfrom=BATV+b97a0fc658bf3e588113+7459+infradead.org+hch@bombadil.srs.infradead.org ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1706173113; a=rsa-sha256; cv=none; b=LFIYtJEuZu25EwCS4/oqRodFnfDpiH3uxCrAE+5L9CSUkDeuHifPoPgRQOQkjqPaINCEtV NXp20XtCuuDz8UmBeOCkpdX81GB9TVH1z8aPcYvi79Ionshx1YBHwwHgYl3vYznvr2eMFe ApgDLdF3lN4i/vrq0XlccqZHgaIwvUs= 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=MhbOOusfwIyRDrId1i1glf9YHzO3PaLh+M9tTsTFsQo=; b=U9NfiMtZibO0s0QeoA5Pg1gJ5C rwwipdwF3Yn3mroMwF8qnFXyn5wCHy3BqYKg+BCIcX6hOa1gQqLQnK17/j3HVJFACNTRbYVxreETo FoHGqXvJjMgcyt8QKXxryhIxQgTHmkmXz6pB2L0XcO+XaHUxXg2MAKxMQtr2HLZj86MKZqMfxBeYN veKzugZU0wuKWSfKTTlfHMFKuaujyn4wB47NCJc4dPXOGbPd5X5Ymzp8ioS9tD1mEIvXDZvHkdkks 8DEWuOOCs+emJnWaZ1PQRPsF5CGm3a8HBqC9G4V1PCe72r2mNpd4fxHNaD3GgVSOSBIgJM4qal1vG lCzYLbVw==; 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 1rSvZA-007QIu-0t; Thu, 25 Jan 2024 08:58:32 +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 08/19] writeback: Factor folio_prepare_writeback() out of write_cache_pages() Date: Thu, 25 Jan 2024 09:57:47 +0100 Message-Id: <20240125085758.2393327-9-hch@lst.de> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20240125085758.2393327-1-hch@lst.de> References: <20240125085758.2393327-1-hch@lst.de> MIME-Version: 1.0 X-SRS-Rewrite: SMTP reverse-path rewritten from by bombadil.infradead.org. See http://www.infradead.org/rpr.html X-Rspam-User: X-Stat-Signature: ywdfus4y4dpjgcmk4odzcg5n4cbhhroc X-Rspamd-Server: rspam07 X-Rspamd-Queue-Id: AAEFD40016 X-HE-Tag: 1706173113-162152 X-HE-Meta: U2FsdGVkX1/ylFTzrTHZ0jZ98aqeJVB7H4QgnMsOx8yPxSWBu2sxk0HQ2Bvty7Ez6/GvG3xR07UNndiQQTUNlFflvvIEIW+L7evPO6XW3ARHpqKzUGySxT2egyDqnG5gPgNXFUvS4owefL3Ur0m6ksGHsczZrBWImEwasD21CCaMM2fG50U54WcOi8ZkANrb4bkGqvUxec17Z8Ic2lt+Er9AW1lT9hEsiBOK2Xb7c1a/DywdISB20Y3Q88Xw0kl5fjgxBvuOJ9W2obiaah/9sWao8yP+5zQprABFFHmI/QjwFEdwUUqegSqJPTR8DI7pTtFUERtLc97XH3w57h2Js/riUQWmo1qUpeDbCYaR0ZnQWl7RLjuhjRpD1FLSnjyTf+flooxdPhC/bjS+STQ3ERsbuG/dxOYzQrlnhG3SF9WxWzIGVPnm5ELy50wxpPa5oscHXodtUgADDju0nJS7u8hj1jiUbh8UUkqe0FqY/vfsZMNHNY4YC/4dJgiUUOVTmkRzHuVf9E9Z2EsZ5eoQ3mJHXiyyeoshjBYxW2VHRsyg99rSh3X2FiO7wxDrPva+Q6s7eTZNTFwVXxEWmbr0dfdYKtgfm9OhQLROoCp3jtMdJ5tH6jDddNGO0di4IoMJUfJQX/Os+63QSA97wePb6z+obx/LOj3X8PJo0LonlmJIUbzxpl1irwmRcPfPmzSGPzphxSIsI978CYDZOhoDMDnJhmZMaF8OftYqKc8I+SaI71+w9D6hBbqHDt9aJImJAuurYVad2/Wk2Q0AT78HG7EYxT4NI1taDKs2lckRJowx8I44VPHRtdSMS7KH7+jYAzaJYwngiL+5XQubo9P1Ue1XCf+XoAkzi5OiZov27tK3r85mTatQyJOdne4ZtHmcKZga39xZWVUOiEXovLiqFWoNA4I0QtNxKgLvpIF3RKs3e7+2oG/gu+kzkskpPS8rXClotzpapVieVBy7DmQ 5tbU9Tga /C3MG9AaaDn9xFoAlA2o+0/MPxUfkS9HWzkecRs5idqVItTcC0dkn6Ka9bZgHBHlN78P72YC8JYEn/pQQhnUizMp6rCGBR3r9RywY5/VXJsoCOkTAWOvJ4X1CfZn98PZCszR/lXTBBTN79zJOl6ASHg9VLVALSBXDFM4lEz+3LZoKlzD4e8elE8GJY5SDhdicXEvnXwzs2P4zOTSEpKgQOiWBCuwOlTq5yJiaFvVDGR/3CJPNmnvteYJILWvOeW2Vs8wXnSMpiWu9SBDleIv+4Omjx/Aoq1wi4XtwJRS23bqNjn+uPAFSW/ZiawZkTNsiwRYTxWKS4T5ypf/jo1gTS+GuxPlLIk+HQCmm81LUAqiUk7+ScQMDQlnhJP+3LY7n0S67B0w9IL7KvfE71ujdELVfw/evc/02KKnDhwbuTJLFV5a4i9/4kTFYUHVsgMNJt40yIP99rotN0HaeNAdnNoUVSVdAnGyd69QNR4LIVmAuAOnmzAYoyhpqoXolSH9PyQBmIC07LZUgkvnenHH+c31JBdZbN13ZtNic X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: From: "Matthew Wilcox (Oracle)" Reduce write_cache_pages() by about 30 lines; much of it is commentary, but it all bundles nicely into an obvious function. Signed-off-by: Matthew Wilcox (Oracle) [hch: rename should_writeback_folio to folio_prepare_writeback based on a comment from Jan Kara] Signed-off-by: Christoph Hellwig Reviewed-by: Jan Kara Acked-by: Dave Chinner --- mm/page-writeback.c | 61 +++++++++++++++++++++++++-------------------- 1 file changed, 34 insertions(+), 27 deletions(-) diff --git a/mm/page-writeback.c b/mm/page-writeback.c index 426d929741e46e..cec683c7217d2e 100644 --- a/mm/page-writeback.c +++ b/mm/page-writeback.c @@ -2397,6 +2397,38 @@ static pgoff_t wbc_end(struct writeback_control *wbc) return wbc->range_end >> PAGE_SHIFT; } +static bool folio_prepare_writeback(struct address_space *mapping, + struct writeback_control *wbc, struct folio *folio) +{ + /* + * Folio truncated or invalidated. We can freely skip it then, + * even for data integrity operations: the folio has disappeared + * concurrently, so there could be no real expectation of this + * data integrity operation even if there is now a new, dirty + * folio at the same pagecache index. + */ + if (unlikely(folio->mapping != mapping)) + return false; + + /* + * Did somebody else write it for us? + */ + if (!folio_test_dirty(folio)) + return false; + + if (folio_test_writeback(folio)) { + if (wbc->sync_mode == WB_SYNC_NONE) + return false; + folio_wait_writeback(folio); + } + BUG_ON(folio_test_writeback(folio)); + + if (!folio_clear_dirty_for_io(folio)) + return false; + + return true; +} + static void writeback_get_batch(struct address_space *mapping, struct writeback_control *wbc) { @@ -2470,38 +2502,13 @@ int write_cache_pages(struct address_space *mapping, unsigned long nr; folio_lock(folio); - - /* - * Page truncated or invalidated. We can freely skip it - * then, even for data integrity operations: the page - * has disappeared concurrently, so there could be no - * real expectation of this data integrity operation - * even if there is now a new, dirty page at the same - * pagecache address. - */ - if (unlikely(folio->mapping != mapping)) { -continue_unlock: + if (!folio_prepare_writeback(mapping, wbc, folio)) { folio_unlock(folio); continue; } - if (!folio_test_dirty(folio)) { - /* someone wrote it for us */ - goto continue_unlock; - } - - if (folio_test_writeback(folio)) { - if (wbc->sync_mode != WB_SYNC_NONE) - folio_wait_writeback(folio); - else - goto continue_unlock; - } - - BUG_ON(folio_test_writeback(folio)); - if (!folio_clear_dirty_for_io(folio)) - goto continue_unlock; - trace_wbc_writepage(wbc, inode_to_bdi(mapping->host)); + error = writepage(folio, wbc, data); nr = folio_nr_pages(folio); wbc->nr_to_write -= nr; From patchwork Thu Jan 25 08:57:48 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christoph Hellwig X-Patchwork-Id: 13530264 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 7744DC47258 for ; Thu, 25 Jan 2024 08:58:42 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 0DD4D6B0093; Thu, 25 Jan 2024 03:58:42 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 03D1E6B0096; Thu, 25 Jan 2024 03:58:41 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id E201A6B0099; Thu, 25 Jan 2024 03:58:41 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0016.hostedemail.com [216.40.44.16]) by kanga.kvack.org (Postfix) with ESMTP id CE0406B0093 for ; Thu, 25 Jan 2024 03:58:41 -0500 (EST) Received: from smtpin10.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay08.hostedemail.com (Postfix) with ESMTP id A6093140C2D for ; Thu, 25 Jan 2024 08:58:41 +0000 (UTC) X-FDA: 81717232842.10.336D1DC Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) by imf01.hostedemail.com (Postfix) with ESMTP id 0F1A340012 for ; Thu, 25 Jan 2024 08:58:39 +0000 (UTC) Authentication-Results: imf01.hostedemail.com; dkim=pass header.d=infradead.org header.s=bombadil.20210309 header.b="m/Q1LhPC"; dmarc=none; spf=none (imf01.hostedemail.com: domain of BATV+b97a0fc658bf3e588113+7459+infradead.org+hch@bombadil.srs.infradead.org has no SPF policy when checking 198.137.202.133) smtp.mailfrom=BATV+b97a0fc658bf3e588113+7459+infradead.org+hch@bombadil.srs.infradead.org ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1706173120; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=uF8JIxjy5aR+l38o23/kghoy+Tugnu4jphYuZf7Sd0E=; b=AeSq+a299m47Hpq6zlo0klYBMJX8EqsnYr54/rvCP8/JWiYyXVWJw7whiNt5p7q8A57Gv7 yUjkUfv+m/tYb12A9mbX2PxpgM2uA89VwUpWzW0gows0UAlPdKlfBNQjJ9faPfX30S82l0 QKmr79ynVBnUJy+YRCbWiGc9aeX+7dQ= ARC-Authentication-Results: i=1; imf01.hostedemail.com; dkim=pass header.d=infradead.org header.s=bombadil.20210309 header.b="m/Q1LhPC"; dmarc=none; spf=none (imf01.hostedemail.com: domain of BATV+b97a0fc658bf3e588113+7459+infradead.org+hch@bombadil.srs.infradead.org has no SPF policy when checking 198.137.202.133) smtp.mailfrom=BATV+b97a0fc658bf3e588113+7459+infradead.org+hch@bombadil.srs.infradead.org ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1706173120; a=rsa-sha256; cv=none; b=jlECT6IhGKHjeQoHmqmUR8poeFzf2DUV7Pj7I4rOB8u1P9zYEW1kUkcNtwot1sqfJa9mhH LjOxADMqkUEtEGsahSJzNxTwQi2Z3Mgzy2iVkiNTM7ACJ/qDIoFoj/iilLf5Zj7Jd1B/5w PgchH8OLDQG3JHZ17wUit8Rwl1LsXxE= 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=uF8JIxjy5aR+l38o23/kghoy+Tugnu4jphYuZf7Sd0E=; b=m/Q1LhPC2/vHTSRu90DWvDptL5 BKQMoE7BL5NkeXAax6P9Yv8CPEYpHoiimUbS48P6z7/UaStZmi3exEaCGCxntBxKnEwJjDTnI5VJP Hf/ZvL0N6tR+UAfkRsSsa0kOyxZryKyVHCuJ+SxCxuef8kZRlV6Ym+mhT7BEBLe/BosuzkrdLBmOZ nsnk9cVwIBEe3hI5Yr0oDGINfAcHWHBX17YJwjH2PzML7Wnv4py4ZII5IEDM6VZuzb+pM1vr/GPre prsVBlnIAvbyHoHFjjv3sboVrNToPf28igDzhaChDmBlBkJfOdLkdbj3l9AHoxNZ8CoaNeULCDXY4 vuN06pFA==; 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 1rSvZG-007QKS-21; Thu, 25 Jan 2024 08:58:39 +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/19] writeback: Simplify the loops in write_cache_pages() Date: Thu, 25 Jan 2024 09:57:48 +0100 Message-Id: <20240125085758.2393327-10-hch@lst.de> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20240125085758.2393327-1-hch@lst.de> References: <20240125085758.2393327-1-hch@lst.de> MIME-Version: 1.0 X-SRS-Rewrite: SMTP reverse-path rewritten from by bombadil.infradead.org. See http://www.infradead.org/rpr.html X-Rspam-User: X-Stat-Signature: nn8z3ft195s6gtn3tpzsx8ny6hfma75e X-Rspamd-Server: rspam07 X-Rspamd-Queue-Id: 0F1A340012 X-HE-Tag: 1706173119-579791 X-HE-Meta: U2FsdGVkX1/QNZRxCVbucFKbZ8a1Iu7YLIAjAiX7+Ma8Kh3mjqDOFS8cJ6I2l6bSnJhfSgftloUh8bqpJJz3t+N4B63o6IN5qNAunBOllN19kZ1s6BZyUpY+4FcBNXqJOqqXYePHLVd4u+udIfzfxS1TO6GtOfOd42Qmroj7Vwkh1gp+vY66nFNkD3xqNj8AQaf5HaK4uVpD0Xl4ZAfTuqijYHxM4VzD5/wq10109y3H7SucFnr1N2a+bKDoZW9om5tX+HXkQbtjL/vG0M1puYRWUxbAtw7VRhfymmJzJZR1184wlJAQuGowuNbVvmX64Idy9sWnCNRkXkYQGx/OAvxej+/U3OuXuPwLRacO54DszCWir1lgNcZG4AnJxhgZ/SUtucmFqXIXuSTAEQBsgvamd8pSIRRxNoSBYqeYK9fAu75HMEsSywJSceYSwucEhjfJvfNVVv5yhJnQ0/FqaRK5VJPPFgjwcv1I7k08bNFaz4w2auBARKSSFJoL0qYhWqZ+RK9cPpp1Gw/eZNokaLe22YXs7bgEK9sEoJHy5J4SqcpVbw7Nfa0SRocZuKPv2dTHVqsIRDzrjzCCSBWuydlxqBxINlXzynPTEAVi6fFu/fYc9OBEgo51hJR+GGLrzdvoLIVqKHtv2hhg01KKnE7Nfv0RInjnFCw0r6gDrVTi51BQT/WXqeh89btreuOvekOPY6vgeumyoXF3T6Wf7Hk7IAE3JiVcB0cZflk8ubQmxgN8nD8Yje3l/hPRzjg0pSTTthGd3vHlmuBtsb/0vD0wPyAFDzRyRDAPSCYfzK8CBnfheBiaMg+/NlTgMaPkgbouyi0KjCM4nUrj2rtME2+N+JW/WWlE4D9UgaEJJF0yFW/WJeZyYVkGqyHC3jvjx0M6rYiBuTEmIKip0Wom16q0w6v9INQbGjNb+GLpU/PzDOPl0Xvfx2+w39BQU4+qbqNJe78bPRGenXmb0jm 1UjuUC5k +0bBQTvebgTQTdjhyOwc9pqWf6+ViAh2w69r56pJ78NcYG/M6DOtqVAiok+fKvz4fXQJF/7Vwcwx8pam2iakx1NAf+9mLtomxPxh1cc1l9Vwgex0gX6ZTFBJYTgVDK+QjXiKCIlhUhFTLI1uAjVbHMjjiM2Ok7rdeVt6bZAD5ykaCU7ZCt9CZUbQ/hoVLQE2/xqXRk6iqchcEdYtqGMgZOUeRnreKFyq2vniCEqbfHz5NQ2lGpdNCGr+jGN6fk06MR3eMeV/RZNU6MugY4prTYGg088jZJtfg5mDC4KIchxgFC5H/79HlS/tG9GnK7XC+cgC/AEF1bv3zAzMsuPO3UXIYs6eRUFfD/kq7JbIm1KptRc9MEENfgCC/7coFvYJk1Gz3VSHlnOnz8SUrDr3z3OZc4q4LKFQ4Cw2A+fFxYGsj5ghE64qYjTzT4R7fqJTrcvwjgSyF4Kq6cUznHyNXAGrW9W6g+dAkcoOxkF5jrRCGzf1viwtx1e8kxBCcFFp3o1HpdJuL6ii2dE60EokwVIgbM7XSlOgxSdp4BhB90dgZDuo= X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: From: "Matthew Wilcox (Oracle)" Collapse the two nested loops into one. This is needed as a step towards turning this into an iterator. Note that this drops the "index <= end" check in the previous outer loop and just relies on filemap_get_folios_tag() to return 0 entries when index > end. This actually has a subtle implication when end == -1 because then the returned index will be -1 as well and thus if there is page present on index -1, we could be looping indefinitely. But as the comment in filemap_get_folios_tag documents this as already broken anyway we should not worry about it here either. The fix for that would probably a change to the filemap_get_folios_tag() calling convention. Signed-off-by: Matthew Wilcox (Oracle) [hch: updated the commit log based on feedback from Jan Kara] Signed-off-by: Christoph Hellwig Reviewed-by: Jan Kara Acked-by: Dave Chinner --- mm/page-writeback.c | 94 ++++++++++++++++++++++----------------------- 1 file changed, 46 insertions(+), 48 deletions(-) diff --git a/mm/page-writeback.c b/mm/page-writeback.c index cec683c7217d2e..d6ac414ddce9ca 100644 --- a/mm/page-writeback.c +++ b/mm/page-writeback.c @@ -2475,6 +2475,7 @@ int write_cache_pages(struct address_space *mapping, { int error; pgoff_t end; /* Inclusive */ + int i = 0; if (wbc->range_cyclic) { wbc->index = mapping->writeback_index; /* prev offset */ @@ -2489,63 +2490,60 @@ int write_cache_pages(struct address_space *mapping, folio_batch_init(&wbc->fbatch); wbc->err = 0; - while (wbc->index <= end) { - int i; - - writeback_get_batch(mapping, wbc); + for (;;) { + struct folio *folio; + unsigned long nr; + if (i == wbc->fbatch.nr) { + writeback_get_batch(mapping, wbc); + i = 0; + } if (wbc->fbatch.nr == 0) break; - for (i = 0; i < wbc->fbatch.nr; i++) { - struct folio *folio = wbc->fbatch.folios[i]; - unsigned long nr; + folio = wbc->fbatch.folios[i++]; - folio_lock(folio); - if (!folio_prepare_writeback(mapping, wbc, folio)) { - folio_unlock(folio); - continue; - } + folio_lock(folio); + if (!folio_prepare_writeback(mapping, wbc, folio)) { + folio_unlock(folio); + continue; + } - trace_wbc_writepage(wbc, inode_to_bdi(mapping->host)); + trace_wbc_writepage(wbc, inode_to_bdi(mapping->host)); - error = writepage(folio, wbc, data); - nr = folio_nr_pages(folio); - wbc->nr_to_write -= nr; + error = writepage(folio, wbc, data); + nr = folio_nr_pages(folio); + wbc->nr_to_write -= nr; - /* - * Handle the legacy AOP_WRITEPAGE_ACTIVATE magic return - * value. Eventually all instances should just unlock - * the folio themselves and return 0; - */ - if (error == AOP_WRITEPAGE_ACTIVATE) { - folio_unlock(folio); - error = 0; - } - - if (error && !wbc->err) - wbc->err = error; + /* + * Handle the legacy AOP_WRITEPAGE_ACTIVATE magic return value. + * Eventually all instances should just unlock the folio + * themselves and return 0; + */ + if (error == AOP_WRITEPAGE_ACTIVATE) { + folio_unlock(folio); + error = 0; + } - /* - * For integrity sync we have to keep going until we - * have written all the folios we tagged for writeback - * prior to entering this loop, even if we run past - * wbc->nr_to_write or encounter errors. This is - * because the file system may still have state to clear - * for each folio. We'll eventually return the first - * error encountered. - * - * For background writeback just push done_index past - * this folio so that we can just restart where we left - * off and media errors won't choke writeout for the - * entire file. - */ - if (wbc->sync_mode == WB_SYNC_NONE && - (wbc->err || wbc->nr_to_write <= 0)) { - writeback_finish(mapping, wbc, - folio->index + nr); - return error; - } + if (error && !wbc->err) + wbc->err = error; + + /* + * For integrity sync we have to keep going until we have + * written all the folios we tagged for writeback prior to + * entering this loop, even if we run past wbc->nr_to_write or + * encounter errors. This is because the file system may still + * have state to clear for each folio. We'll eventually return + * the first error encountered. + * + * For background writeback just push done_index past this folio + * so that we can just restart where we left off and media + * errors won't choke writeout for the entire file. + */ + if (wbc->sync_mode == WB_SYNC_NONE && + (wbc->err || wbc->nr_to_write <= 0)) { + writeback_finish(mapping, wbc, folio->index + nr); + return error; } } From patchwork Thu Jan 25 08:57:49 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christoph Hellwig X-Patchwork-Id: 13530265 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 61D1CC47258 for ; Thu, 25 Jan 2024 08:58:45 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id E4C066B0096; Thu, 25 Jan 2024 03:58:44 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id DD2BB6B0099; Thu, 25 Jan 2024 03:58:44 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id C72956B009B; Thu, 25 Jan 2024 03:58:44 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0014.hostedemail.com [216.40.44.14]) by kanga.kvack.org (Postfix) with ESMTP id B2E486B0096 for ; Thu, 25 Jan 2024 03:58:44 -0500 (EST) Received: from smtpin16.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay01.hostedemail.com (Postfix) with ESMTP id 9640D1C04ED for ; Thu, 25 Jan 2024 08:58:44 +0000 (UTC) X-FDA: 81717232968.16.6012589 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) by imf16.hostedemail.com (Postfix) with ESMTP id ECD3218000B for ; Thu, 25 Jan 2024 08:58:42 +0000 (UTC) Authentication-Results: imf16.hostedemail.com; dkim=pass header.d=infradead.org header.s=bombadil.20210309 header.b=fJTltGtB; spf=none (imf16.hostedemail.com: domain of BATV+b97a0fc658bf3e588113+7459+infradead.org+hch@bombadil.srs.infradead.org has no SPF policy when checking 198.137.202.133) smtp.mailfrom=BATV+b97a0fc658bf3e588113+7459+infradead.org+hch@bombadil.srs.infradead.org; dmarc=none ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1706173123; a=rsa-sha256; cv=none; b=hc4lpm+XruM7LrN7mL7aRNmu4BYLEIAG81qLRcN37JkEYbkMk4NYlfGX+NjT7neH9Dtn0t a7xoSg1/mQbdbcFI11v6YAk7Kat7zLHv/QD1djL+g3w07Svwjhk/k9OtdiVsnb406EwC+a bIWjE9Ij1GkFxrwAqoTWuPR4fxr4Mak= ARC-Authentication-Results: i=1; imf16.hostedemail.com; dkim=pass header.d=infradead.org header.s=bombadil.20210309 header.b=fJTltGtB; spf=none (imf16.hostedemail.com: domain of BATV+b97a0fc658bf3e588113+7459+infradead.org+hch@bombadil.srs.infradead.org has no SPF policy when checking 198.137.202.133) smtp.mailfrom=BATV+b97a0fc658bf3e588113+7459+infradead.org+hch@bombadil.srs.infradead.org; dmarc=none ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1706173123; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=dVreMySeIHkVOAtpz+bbvTB1WjeCUE+T6e0OUt9+4gE=; b=LuUAsrNUeRmykdOpyIWBdNeABu5a6nEEqj8xJk3D+xb05KAEdBULhXYdrUy0NqIAfEl7J6 M/65dOnKF1zNpuaNEHWsBgFGQPHqSzki8OUCgMPSCCiCGz4N3eAqOlFfzW74vtQhnJ8dAY WPG+I+oQsHEUVDHbvAzur7RWTY9ixPo= 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=dVreMySeIHkVOAtpz+bbvTB1WjeCUE+T6e0OUt9+4gE=; b=fJTltGtBkzo7VMXaXfEGU0S2qs Y3TXmX4Qw3Kb87AMBLFpKxAN9cRUSTRyhiiLisdvt3e15LemYDbHh8CX9oVaTrWkT5WcI5gqltSre gtXc3Rz3jEWxdX3UHPaeOS3Hb7hZHyiBx9CArSuas0VLj+Ee0BTXrEiRRZLHn1rJ0hvNfPCacQIwi 4w22mSTaXwIpKlSsPKZRSg8yGpeIFN3eeGaHzY2sIVQdKILOhUE8l7UQQW7gIheMp4DibuLjTg2lA lkMK3uinulqtVqUk1ihMf4BxEx5sAZjWCGzuhRZUixA07JrSrTkRKRTb4na0D7Pg3JVqopLmucgfQ J05KCISQ==; 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 1rSvZJ-007QNR-2E; Thu, 25 Jan 2024 08:58:42 +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 10/19] pagevec: Add ability to iterate a queue Date: Thu, 25 Jan 2024 09:57:49 +0100 Message-Id: <20240125085758.2393327-11-hch@lst.de> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20240125085758.2393327-1-hch@lst.de> References: <20240125085758.2393327-1-hch@lst.de> MIME-Version: 1.0 X-SRS-Rewrite: SMTP reverse-path rewritten from by bombadil.infradead.org. See http://www.infradead.org/rpr.html X-Rspamd-Server: rspam08 X-Rspamd-Queue-Id: ECD3218000B X-Stat-Signature: 8paadqnmckm8kqd63bii6rtixxw6xhqt X-Rspam-User: X-HE-Tag: 1706173122-404225 X-HE-Meta: U2FsdGVkX1/3eceohhCGzfRD7KkT/Ki6RNSEkpLJCUoVszvYNJn5iQ7dYprYk2pZ2BYfdQq4+bPiLiSVRZX+GgCpe8e7QPnO+n3JeGZRrBbG9qDZ007ZSJTA73ZtfbRoJKkeenQnjKs8kZkMFGlZwgQRhO6q93ESd5cpTqexfuBfe34YNLTpfjPDyC91ygGyfRJrzeWkGxI5eR3xbdK0TLF33TlLbxdkh8MS5Z7SL0djqRRP7gjoFYSHAM+Vhm2aribFLtngiOPeHe+4elfAkbeleZU4sBJkHOGdZcIwSzXe+IJWzwcTyZHstMOBXVXS0hH5Fl0r1XtZu3eXJmsp+mN1IVMLqMREmucg4hRQ9VgkPSxl2WZaIn5FDSWaA/sCkiB+3fnutJamw8SQ3FppQfBlRUYawi+xYcZryyW1BduMBGyJY72lNCBxHtIqrMz2/eWfN7BUGxY/ZXHBn5OA4d5YftoVHX4pwyP50s6CceLjhEMX2tVnp5f3DEVaLXgKBnfx1thi8asI4q44SHmkr3cyJJ/4SqWaxPF7W+IFbxiTo4u0Pt+1az9vp3HW3GrOiYhzRNzfZd4kY8bwZnGfRLocXMG7nBcdsb6W4SdbTzYUYRUTtpVAaGua0h92AOO/ZmMBfA7Q+GYA/FtabKBTlQ/m0DGfLlhe6wzMx2VvWrKJQXrjqVMnJHkw4AL1QqNjGqCvy0qI9vtbWyEVzaCZGdVUX/2cby48/Rj+kl7WF8LYWmeJwqVUE0UHGIPUMMYBG2drA6oxvf61AsREptiDatyWkOuQo19hLk2AycXSQcikOhK4zkXS9QiKF+nJgXnWCkdGJVhl1cs32rGo5DQwGLbU7NJSUK2cbS27wlqTwCaBsI76xy70k4YCHjbI9okO9oCIK0rBpcjvZETlXMeqrm3igv3zUt7VQ5Ls0LSZdeDaWwbau3g1pgH9aCWb7sBwNnjxP2Uwai6UTp13fG2 trkA+yA5 9KeR5u6B+0YGVrzLiq87RfA55lN7dsTfDdmnYsaG4Z6oquB0/zYXqCU7gnYhDImGbapr7imyvlJmVxJjfeaUT04/lRJ5dVeNUrNkDcQtpsQqDCuRjCgoYcgwrQ0sONVncaovewXgW5tOT/hG919UV2whmQdBI/BDPh1k3rSFCylsR/dz205k84cZmBLzoGAsejy4y7akkVtN8/JogZ9qbTAaUmQc11t1oqLfiELYfXW6vb7TSwT68Rwwqd2SguTLHfvhNLmz3WBM99YAkFh1cC76RLlN+DpdKcWndHbU6bG/Dz7n6TEP8e9PywzgObObWr7/3pPAuM+CNBaMb5JUYh/D4xu1HL9Y2ZW7MGbAfgC570condyYonHicZoY/98bTgbp+yyz69PKYPWPtuQjZ5K/fOcmyDcefTQx2g+kitQCkFvRdvFORIZxa9besmao5vIEttjtvT7P/6UtgfeCJJdoUoKatrd4D1FHWvf5ck6kanKqEY8TKo8sFIw== X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: From: "Matthew Wilcox (Oracle)" 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: 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 Thu Jan 25 08:57:50 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christoph Hellwig X-Patchwork-Id: 13530266 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id A5D0EC47258 for ; Thu, 25 Jan 2024 08:58:49 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 3E9808D000C; Thu, 25 Jan 2024 03:58:49 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 39ADB280001; Thu, 25 Jan 2024 03:58:49 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 212538D0020; Thu, 25 Jan 2024 03:58:49 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0011.hostedemail.com [216.40.44.11]) by kanga.kvack.org (Postfix) with ESMTP id 0D3B08D000C for ; Thu, 25 Jan 2024 03:58:49 -0500 (EST) Received: from smtpin17.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay08.hostedemail.com (Postfix) with ESMTP id D08A8140BBE for ; Thu, 25 Jan 2024 08:58:48 +0000 (UTC) X-FDA: 81717233136.17.454B1F5 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) by imf04.hostedemail.com (Postfix) with ESMTP id 434304000B for ; Thu, 25 Jan 2024 08:58:47 +0000 (UTC) Authentication-Results: imf04.hostedemail.com; dkim=pass header.d=infradead.org header.s=bombadil.20210309 header.b=YsqWm1Ve; dmarc=none; spf=none (imf04.hostedemail.com: domain of BATV+b97a0fc658bf3e588113+7459+infradead.org+hch@bombadil.srs.infradead.org has no SPF policy when checking 198.137.202.133) smtp.mailfrom=BATV+b97a0fc658bf3e588113+7459+infradead.org+hch@bombadil.srs.infradead.org ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1706173127; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=rQ/YR9r2MVXaLcMH7BH4MVX5/bfeEJP3+H7ANF9U6Gk=; b=nYD0lo9LWq+xILqgqqCAAIBGSz6tTbimeUBjr3hK0LGPp/GQFqi5Alo3LtqM1PuOvhFmfp pMzKD4/npFsFLKYVy5EQ0oCf5C59Ga882MRHCOXaAXZYe1co5hi3q9/N5xVK1hmfr0GVEF yhWm/r3czX1Anyc832Z2VP1ACECUEIQ= ARC-Authentication-Results: i=1; imf04.hostedemail.com; dkim=pass header.d=infradead.org header.s=bombadil.20210309 header.b=YsqWm1Ve; dmarc=none; spf=none (imf04.hostedemail.com: domain of BATV+b97a0fc658bf3e588113+7459+infradead.org+hch@bombadil.srs.infradead.org has no SPF policy when checking 198.137.202.133) smtp.mailfrom=BATV+b97a0fc658bf3e588113+7459+infradead.org+hch@bombadil.srs.infradead.org ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1706173127; a=rsa-sha256; cv=none; b=h/aAefhzoUozhx1qyL3moeDCRn+WfHo28XURP1D1pj61bI82RT+RBSaIoNKzP9P01371+e yVrzfImp0l308Gkp+tXE9T3Nq9kxwS8gcfqtaaSkWeee2DchL0OPNuB1YolyJeEn8GuOvw Y+eAHkCjFsYJe+THdvbzQ5a+DMYPeXQ= 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=rQ/YR9r2MVXaLcMH7BH4MVX5/bfeEJP3+H7ANF9U6Gk=; b=YsqWm1VeZ/5woXx1pI6UQ82TBP jEo9O0uC5yGJGqt3juo+7kF4mK/ojbfOCnOR2XsQzaQJLlCKWT7zXgQwChqWQVMoR+KVflOoSaRP7 WB1v6Ey5oqMI8hnNAL6t2AogyLtpByE7CzERscH+mKXtkULkp+e/lu+PFXcpjTSbEsSvoWB9NA27w DqyAEQS+XubKd67++tgTszn8Qzdx1vq/+tvzgi8MCg9x+i0doBASfAZ24YVnBQdvGOAqCRDiT5uDS LKjx14CAuf2dWanDl9/1HMpUHDgBzTBxeTmgpjLoQ1Ajc0T+IPmA78Cczi8TsIyZJAJNiJ9SkroZH vOyN5jMA==; 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 1rSvZM-007QOH-1U; Thu, 25 Jan 2024 08:58:46 +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/19] writeback: Use the folio_batch queue iterator Date: Thu, 25 Jan 2024 09:57:50 +0100 Message-Id: <20240125085758.2393327-12-hch@lst.de> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20240125085758.2393327-1-hch@lst.de> References: <20240125085758.2393327-1-hch@lst.de> MIME-Version: 1.0 X-SRS-Rewrite: SMTP reverse-path rewritten from by bombadil.infradead.org. See http://www.infradead.org/rpr.html X-Rspam-User: X-Rspamd-Server: rspam12 X-Rspamd-Queue-Id: 434304000B X-Stat-Signature: iazwpz8gootje4w5j6dywowzbstzk191 X-HE-Tag: 1706173127-710471 X-HE-Meta: U2FsdGVkX1/0X9CHfbHL3qUCBDG6UDl+tvaz/v5iIHTDWiluVzXYAqYdRZ0vmfYar3u/FKmPHKJRAPkySkMu5tU5ZKnjfH7V22Fbb/jWpReAnErjT6bvCg0rsHQrGHsHiVtOkYX+OtKfuPp/AglVp5PtknKaaJ4UrEXMLyhXEs+b7KEgX5unkeD3HjhRsqK0mDxjkzl3FNACeQR0zlAhigJa7BWPwcEpoDBL8w6H79zPM1QJZSqaXRv1IHVe3NkA7myrDz0oyyh9wfMH1tSTS9G42G8raEx0mVGYr9bdDOT7UdC1sVf6d2qhTBBpaRddebcieAaRx3p8F7CeHMf25eCbTbtU4gBlyc86iIgZevrUVtPmPqSYDKJn6QOU/RcBGnPd92f4enWe/+qYy03RH9q6HTUr4VpT5q2+1mWlmRkxToVDh4sRe3uLGJrE6szDS9qFtQQcR9QSbLJo5jrQVKDmEWus8y9+Hy/E8vN6+7bfyDfsHeR42EatWd3yqk0rdV8oFBh4NSDi8VEcMMq9X2xj/JOGo+y5ocnwTanUhVkNohjZcGcV3+ZexxB3o+EtTR7Hv3La1iNOd4Eh6Zxspme2+ZMCGs6d/DN1YvhrxHBnrRV6c8bgvXIJDV8VKHowOer89VLTkwXeHGx62lRg/2LJIvnK4xtjM/VKf7XZDjJcQoHoUxvcL4d3lC+Pg3zfr12zt0JlQ7ZwetpAeTg8/9CMVLkYum2gMBjpM9LzADQ8NeblzZ0TYwEvfiluJA+NPGXSyK49y+7wLfQJWGmf8Cp1cfusuiE/YumdZturgUPsiXdKykt/werFKOUei0y+D4Tx8GWfLhvzdzYocPNNKuank6T5Egcw0/anb53B4gf4im+GiTXtqxScPQpuvl+Ho+utvCloRnISQwo6oB57MawNFUHmTQqQEP8PXLMy8Rii05wGqu0MrzhaXbCSp+pvixJSew5kI+ieyzmJxGw gHQbs3Fe 5NtymcS3njgn2f1ydtOBrmNuzEscZK0cfb3mmuHMp1T4ldDzk7BF6Ets86N8MsnW+qCrxDiV90ylAY5yVLU0uPcT63v6YvuXOSLOghWQbVyVq4urFmSKb/tcTDDtaSrYfscWGkzq6/ZKfh7ulDR+4DpjWTPIZcABeJD6PqiLGX8eOJcPN2Koep2yJyJhpjTrpJ+ca5lzjVquWBJCoaE3Eh4BY68HYEcDLsASedtw37cUxRxVHd/P7ULXqx+EWZizK5J9dawdcg3DTNV/xvj8/ZtcgZbRCBAr9iOOb8kWC30JhmPZ6r0WigWrpjTxQiN53eBuWfO6lHGPbty1XpfaQjo8pocB/Qf4+n7QUww/Q6ZTGq/cTaq81J6e+SOaB2O9gOGZxALGmno8WPTWLq4TuF7dnnVv/eFuKuo3/aUhb1Rr0ySWQatpU/oKpSJLLrLbLW9mkNdMp/lfFmDsi6Ea6zRcpiqkSXEG5t75ZYNCARAglv5NkABVOHxz/aGyC8wIkof8UW9LFKkMkiEWxHu/A9U1KomVyXMjkgtli X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: From: "Matthew Wilcox (Oracle)" Instead of keeping our own local iterator variable, use the one just added to folio_batch. Signed-off-by: Matthew Wilcox (Oracle) Signed-off-by: Christoph Hellwig Reviewed-by: Jan Kara Acked-by: Dave Chinner --- mm/page-writeback.c | 29 +++++++++++++++-------------- 1 file changed, 15 insertions(+), 14 deletions(-) diff --git a/mm/page-writeback.c b/mm/page-writeback.c index d6ac414ddce9ca..432bb42d0829d1 100644 --- a/mm/page-writeback.c +++ b/mm/page-writeback.c @@ -2429,13 +2429,21 @@ static bool folio_prepare_writeback(struct address_space *mapping, return true; } -static void writeback_get_batch(struct address_space *mapping, +static struct folio *writeback_get_folio(struct address_space *mapping, struct writeback_control *wbc) { - folio_batch_release(&wbc->fbatch); - cond_resched(); - filemap_get_folios_tag(mapping, &wbc->index, wbc_end(wbc), - wbc_to_tag(wbc), &wbc->fbatch); + struct folio *folio; + + folio = folio_batch_next(&wbc->fbatch); + if (!folio) { + folio_batch_release(&wbc->fbatch); + cond_resched(); + filemap_get_folios_tag(mapping, &wbc->index, wbc_end(wbc), + wbc_to_tag(wbc), &wbc->fbatch); + folio = folio_batch_next(&wbc->fbatch); + } + + return folio; } /** @@ -2475,7 +2483,6 @@ int write_cache_pages(struct address_space *mapping, { int error; pgoff_t end; /* Inclusive */ - int i = 0; if (wbc->range_cyclic) { wbc->index = mapping->writeback_index; /* prev offset */ @@ -2491,18 +2498,12 @@ int write_cache_pages(struct address_space *mapping, wbc->err = 0; for (;;) { - struct folio *folio; + struct folio *folio = writeback_get_folio(mapping, wbc); unsigned long nr; - if (i == wbc->fbatch.nr) { - writeback_get_batch(mapping, wbc); - i = 0; - } - if (wbc->fbatch.nr == 0) + if (!folio) break; - folio = wbc->fbatch.folios[i++]; - folio_lock(folio); if (!folio_prepare_writeback(mapping, wbc, folio)) { folio_unlock(folio); From patchwork Thu Jan 25 08:57:51 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christoph Hellwig X-Patchwork-Id: 13530267 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id E7E2DC47258 for ; Thu, 25 Jan 2024 08:58:52 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 76CB5280006; Thu, 25 Jan 2024 03:58:52 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 6F6D1280001; Thu, 25 Jan 2024 03:58:52 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 546A5280006; Thu, 25 Jan 2024 03:58:52 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0011.hostedemail.com [216.40.44.11]) by kanga.kvack.org (Postfix) with ESMTP id 419C0280001 for ; Thu, 25 Jan 2024 03:58:52 -0500 (EST) Received: from smtpin25.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay05.hostedemail.com (Postfix) with ESMTP id 194FC40D68 for ; Thu, 25 Jan 2024 08:58:52 +0000 (UTC) X-FDA: 81717233304.25.C626AAD Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) by imf30.hostedemail.com (Postfix) with ESMTP id 76F1A8000D for ; Thu, 25 Jan 2024 08:58:50 +0000 (UTC) Authentication-Results: imf30.hostedemail.com; dkim=pass header.d=infradead.org header.s=bombadil.20210309 header.b=r5e1XEM8; spf=none (imf30.hostedemail.com: domain of BATV+b97a0fc658bf3e588113+7459+infradead.org+hch@bombadil.srs.infradead.org has no SPF policy when checking 198.137.202.133) smtp.mailfrom=BATV+b97a0fc658bf3e588113+7459+infradead.org+hch@bombadil.srs.infradead.org; dmarc=none ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1706173130; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=btL3AciRr+h+xXxfR+Yq/41M1ZAR/B4m6dVFwBdRQv0=; b=fc/PUp8Ns/nS+ox/Zf+2jCA3yUJISKFdS2qbrakARz+oLxod7JU+0h0lQttQscQfal0JML RjCV3jN6PmcclMcpQyG+8TXkkX0/Nedig1dSzikCgwcYcdIg1SbCjVFVi+7LIRkYPTYYJY k38tWcwa2GZy6R3J5j0oHpMGrhwBKVc= ARC-Authentication-Results: i=1; imf30.hostedemail.com; dkim=pass header.d=infradead.org header.s=bombadil.20210309 header.b=r5e1XEM8; spf=none (imf30.hostedemail.com: domain of BATV+b97a0fc658bf3e588113+7459+infradead.org+hch@bombadil.srs.infradead.org has no SPF policy when checking 198.137.202.133) smtp.mailfrom=BATV+b97a0fc658bf3e588113+7459+infradead.org+hch@bombadil.srs.infradead.org; dmarc=none ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1706173130; a=rsa-sha256; cv=none; b=3ETf3xiLeA8g6zR4EfEdo19ogfkwm8MYbMTXz8WJYqOq6UWL9A7sML8/z05b2F5IuTv6zf foVIWrh30D08fwNKD9dD94MEjCNO6RRvWrhHub/RirRTEChq9GzJQIWZU38a5wWrmTJqnz 1zRMUZkpCIX5QEpMU+2F0Be1xoh6XrM= 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=btL3AciRr+h+xXxfR+Yq/41M1ZAR/B4m6dVFwBdRQv0=; b=r5e1XEM8S9gQh8rBNXuD00dQSt nekiXLsV/Vk7BZw/6syGHv6F3sB9VECwP2G0QgBhGJeOnzfwy/mI92WsKGhst2tCM+Wi3az+xbmxJ gZldsll43mBMkAMXLPMaby4NPM0MwucidYZvYToaJikMi+1+p5W8ln2WpHXKffi82sEhTQL+PyRIO pO9/dx0INBNTIOEi5ebmi9UV+Yt1GOMFQJnURTXviErty+7hbRM4BtU+fUFe1923PB5lYFBpAy0j8 iwtnO4feBgof8IrJ8Sy8flg8sIbHfcVGuX/zP/ZWCe8ajPAAkpzPcFr8i2L62RcfwSsy1r6CWYetm NBUCsxaw==; 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 1rSvZR-007QQO-0Q; Thu, 25 Jan 2024 08:58:49 +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 12/19] writeback: Factor writeback_iter_init() out of write_cache_pages() Date: Thu, 25 Jan 2024 09:57:51 +0100 Message-Id: <20240125085758.2393327-13-hch@lst.de> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20240125085758.2393327-1-hch@lst.de> References: <20240125085758.2393327-1-hch@lst.de> MIME-Version: 1.0 X-SRS-Rewrite: SMTP reverse-path rewritten from by bombadil.infradead.org. See http://www.infradead.org/rpr.html X-Rspamd-Queue-Id: 76F1A8000D X-Rspam-User: X-Stat-Signature: 6ngg8wbzyqnzxx1e375jji77zc6t1i4d X-Rspamd-Server: rspam01 X-HE-Tag: 1706173130-761352 X-HE-Meta: U2FsdGVkX1+5+4CYVzzEnLbmPOscbPklR3OxtCz+KXAL1J4CHjeZddelMWACT3fW2UA/NAcrtGdUGE4jDSUKynoXc3UuE4bI+SzCiZ+aGNySVhi2jfQnSQXl828SRdidLS57zKd/Fq6agS2agmeCDezpDYEI6CFbP00xxSM9gACxVi1giBj0fweChl61Vudgal3KX4GXD1UzIEY7zaeAsYfRjxBV2cpWSF4sUPwSfIuOO+xSxeR8wiWl2l9RshBIfZ+WpDHNa88s6HweSfLKiMsYxrfU8/HUnUquM+SKSEJI0DbPcqabA/NH+Eq0YFloROP1pdvF13HEIZwekXyd99I8nd+QRS0xjMA/Kc+tk0vkWX6dutRro67HeXJW1Z56fV/6CNz4uv7dCc2WszG7vbfV5pDk70QptQfjJKlOROs5e302H6kU3avxcKs/dWvAk70It0TFiyoijQLT+zysW9ToxTNeEkCoVsZ5dl23QYLUjNnuGf4Zzx66Q/LaqPWVsZ6dNJ6XufO2001dxK6/wUyaWWf2I8h805CT4st8MG/WQLCxxt4O72SJIv2Pryv5UAUClwXFAtFtACiEQPGoo6asholscUB0Nf7XIlG+R0WcrIA6yQOtS4C0aDhxiK+kG/7J+8/S5zGmpwihgm+Zr0LvZPvm24TIu4E8mB/QOV8tMdEZpnGLQzN1QVFrI8fWS/mgVgtR28X2yYeHbaFD8l8IlpIbEyRbGqTdH4v0VjoaprovJVhI9Xpn5NyvK1C38ZL2YV76k3W5Y0PbVO6O97N2bGAehHvZCTXHeRpQN68Ymj0iJqzq7O8zMZ8sXdESLxCMqkcFTKqRX8T6a5kv4ihITR5vnTilELBxFIIGB/96s2OAziqV25f1IJ91tF0KL6o7oRJEKT6JfcxZpiFG1KEFqU/hYKTcfwSVQFnf6fSL9wE30ys4xjmfAj6IDkCOtySnmlRgdrKObR8F+Pu kRPDZXFe L7kI3/74pqeB1e7AxpGGbjtGzXvnURhrkwdh3w7f6RP2uFWjpdwIXJAHVRd+hL26N59eV5ZJ8OiX5ckvL2JXfhv/r7o/duUqdvN/HzYboFaC5vZt3G09+2uJriVir1L3aIi4I74PR1jqKydgF93rkER33K4RZMw2pFf6H1xJ33Pwt+I3iDDZQa2zPUO4mCesWEnouUJOaHJOSfx1t9tbcb8uwHZk8XJJkKzxI3ru+dxZ3r7j+/uPp/XRAT+8NpM3+/W8M0gQKgsj8LpovZok9kMEBc1Rk2tVwBtYNaZ3OOJEqHY2/q8EA/9c59Y/gjaW0obj077PEtcsz/5FcOsl0BuPgQq1FRLyQs0kFT5woHYQHPVn+IBWYIS8qO1obrgzdF+WJ3WPk/HflO/PUIcX19SGUOX22S+/fvRI3hQNb+D7Orao06e7rmfTYfJJNFI9JrVB9gjGYFJ4UpYk4AXQz43SZpSPQcW9AKPpajBGscgMAo6ZYAvNe9ndDdpzpps4m7kGbNt/21/aj8Qt/75+AWIzcONkw5gM7hPb7 X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: From: "Matthew Wilcox (Oracle)" Make it return the first folio in the batch so that we can use it in a typical for() pattern. Signed-off-by: Matthew Wilcox (Oracle) Signed-off-by: Christoph Hellwig Reviewed-by: Jan Kara Acked-by: Dave Chinner --- mm/page-writeback.c | 39 ++++++++++++++++++++------------------- 1 file changed, 20 insertions(+), 19 deletions(-) diff --git a/mm/page-writeback.c b/mm/page-writeback.c index 432bb42d0829d1..ae9f659e6796ac 100644 --- a/mm/page-writeback.c +++ b/mm/page-writeback.c @@ -2446,6 +2446,22 @@ static struct folio *writeback_get_folio(struct address_space *mapping, return folio; } +static struct folio *writeback_iter_init(struct address_space *mapping, + struct writeback_control *wbc) +{ + if (wbc->range_cyclic) + wbc->index = mapping->writeback_index; /* prev offset */ + else + wbc->index = wbc->range_start >> PAGE_SHIFT; + + if (wbc->sync_mode == WB_SYNC_ALL || wbc->tagged_writepages) + tag_pages_for_writeback(mapping, wbc->index, wbc_end(wbc)); + + wbc->err = 0; + folio_batch_init(&wbc->fbatch); + return writeback_get_folio(mapping, wbc); +} + /** * 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 @@ -2481,29 +2497,14 @@ int write_cache_pages(struct address_space *mapping, struct writeback_control *wbc, writepage_t writepage, void *data) { + struct folio *folio; int error; - 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); - wbc->err = 0; - - for (;;) { - struct folio *folio = writeback_get_folio(mapping, wbc); + for (folio = writeback_iter_init(mapping, wbc); + folio; + folio = writeback_get_folio(mapping, wbc)) { unsigned long nr; - if (!folio) - break; - folio_lock(folio); if (!folio_prepare_writeback(mapping, wbc, folio)) { folio_unlock(folio); From patchwork Thu Jan 25 08:57:52 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christoph Hellwig X-Patchwork-Id: 13530268 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 23587C47258 for ; Thu, 25 Jan 2024 08:58:56 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id AA0BF280007; Thu, 25 Jan 2024 03:58:55 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id A4FDB280001; Thu, 25 Jan 2024 03:58:55 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 8A248280007; Thu, 25 Jan 2024 03:58:55 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0012.hostedemail.com [216.40.44.12]) by kanga.kvack.org (Postfix) with ESMTP id 7AD01280001 for ; Thu, 25 Jan 2024 03:58:55 -0500 (EST) Received: from smtpin27.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay07.hostedemail.com (Postfix) with ESMTP id 589F6160D46 for ; Thu, 25 Jan 2024 08:58:55 +0000 (UTC) X-FDA: 81717233430.27.0B428FE Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) by imf26.hostedemail.com (Postfix) with ESMTP id DB086140008 for ; Thu, 25 Jan 2024 08:58:53 +0000 (UTC) Authentication-Results: imf26.hostedemail.com; dkim=pass header.d=infradead.org header.s=bombadil.20210309 header.b=ZQE+aY4V; spf=none (imf26.hostedemail.com: domain of BATV+b97a0fc658bf3e588113+7459+infradead.org+hch@bombadil.srs.infradead.org has no SPF policy when checking 198.137.202.133) smtp.mailfrom=BATV+b97a0fc658bf3e588113+7459+infradead.org+hch@bombadil.srs.infradead.org; dmarc=none ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1706173133; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=ukNtwPf12oSRUA3UJBplrrlZ3BMhuvUNPapQ7zi0Hu0=; b=zutLYZIIYZfCCmSsZMkPZ9g5udN+khX39ni1LNUg+5bTRBStKJrG3cMg5CMp0NmZQZ60Kk uhIFg1Pe48qruhw2p6FTWfB/uwwh2nxU2tE/PSeVIfwaL7nmYV2dwJcDxAfJAQgwhbpYe2 7Nyf5eHP72RPSj3WHBvj2LQbtoCdFq0= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1706173133; a=rsa-sha256; cv=none; b=Ci+1MXAkor3hCy/vIB2VUcaKyQfFtPfN9ulyBbu48prpDmVA5YseUH9965feECEs4I6mcV GjBzjn70T4bwE+KsWI1l7pkVefD0nLUcuF96/HPdGzqr6g/+lsjvLeSx/NqRoH7HaD5W2c WtZ5KshkW7b7OTvYfOBLD9uKVpHEmpM= ARC-Authentication-Results: i=1; imf26.hostedemail.com; dkim=pass header.d=infradead.org header.s=bombadil.20210309 header.b=ZQE+aY4V; spf=none (imf26.hostedemail.com: domain of BATV+b97a0fc658bf3e588113+7459+infradead.org+hch@bombadil.srs.infradead.org has no SPF policy when checking 198.137.202.133) smtp.mailfrom=BATV+b97a0fc658bf3e588113+7459+infradead.org+hch@bombadil.srs.infradead.org; dmarc=none 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=ukNtwPf12oSRUA3UJBplrrlZ3BMhuvUNPapQ7zi0Hu0=; b=ZQE+aY4VeQqULr6kd1ufkmZyCm g9XFXD48FdWm/3mGFDF270b4JWx4OZ1Vd/zauFYola5nkSWISmgToauOt+vPrpv0elJ11E7fycDW+ uOi2DFdCMSO/ZX0oeqLzF1JI8vL3pIexWD13RQ4jUekhoCKohpXznMGe5Uyou0O9KuF8gj5CUJEOF o7nEL9nQYx8FhnMMg3ZBtuM0yJyPDXOrqiutn+GUZRX+HAT/TooxYxn9uecwIuNBUADX/fGtI9kYl EMbhh8TGKk2tqfPi8Nb9f4CirptF/P969fIdg3CJ31Oh3webS++wJM9TVQQJOU/AFldl7RgCJIO+4 /gpbjwIA==; 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 1rSvZU-007QRY-1i; Thu, 25 Jan 2024 08:58:53 +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 13/19] writeback: Move the folio_prepare_writeback loop out of write_cache_pages() Date: Thu, 25 Jan 2024 09:57:52 +0100 Message-Id: <20240125085758.2393327-14-hch@lst.de> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20240125085758.2393327-1-hch@lst.de> References: <20240125085758.2393327-1-hch@lst.de> MIME-Version: 1.0 X-SRS-Rewrite: SMTP reverse-path rewritten from by bombadil.infradead.org. See http://www.infradead.org/rpr.html X-Stat-Signature: yjaqaoiypgjgsfe5houn4r4n8u3sqo4c X-Rspamd-Server: rspam10 X-Rspamd-Queue-Id: DB086140008 X-Rspam-User: X-HE-Tag: 1706173133-497357 X-HE-Meta: U2FsdGVkX1/wJxSrHAtiDJjVIW/6PRS0fSiSSCGIFJRDocThg3jXMRuup0UnkehZ+DZcMGvk3roLaWx9Y26VpwnH2CNv4OweyBGlLHToqu4RhFL1EJecwZUY8juJneSB1//7DLBPUsI2pzCHgI9x51JYbB1aUjQ5/GtYOGnedgBCQBQYELdEBCjt08pVh/Jk92NltqjIBAQRjhcn/yC0ef7vz3ZtAarUgkZ+ENvPUGo/be4Y6xA7hHcWCY8UrUXqLY/+mTL4bVILYT9zhjdh8uCw/pfIxPmrV8FLQfBRGZWO+kjwrJJh+ZcGS989emqwxOyRehDW1N5k07Gw65oOtLGvVo/910WACO4VP64Ci+DiqLMMoThDwhXzN0VOTbvgOx8HUneHleClow0IeOmhST3kNdFQI6P1PQZm39QOtBQLwldHOfLoPbnE/CHGl85iqruqoK5WptZgbT3SxrNnRt8oaOhO32iZE1UVq2Udk+4AYyXXQfklhB0D/4egPPCw3ISzWlVQaGqlH+92cZi0CRZNdhtKE0HHwd5rpqkgvs1ZINVv+R8+CZRJSdPXdY4Mudv8vHyaLU1e763mBF9JSaM2w8VsxJhRjk2iEbBwQSgqlPj046ha3KwOtPuNeHHFK9OfeBMPxBTPWF2r0XkalbUYaKd0IP379mX1d52wZObre3iAmR3qDs1mowoh2Danvf4nzIbVZOm7U7Khn8LxbRnWvppxSUcRcdv1eM8Jsxe7L3bpZzVh7d/B3XN83Aky6XJE50+9104ygyO+AOXNCAjF9hp2LD8k+wQ8PH7HG5yud9Pms9Agip3vmeByZkMGsGzuUkgy3qcyz2w3hhZXSE2JuugO/lwtP8dBoCS05UTF297OB5PA+7eREwb7Mi/2uccReChzgt3hXASnTYIAzWjr1cK0/pvcGRHEezNXcwGFFCFP3M8OqYh6X5WZ9kC0vQmzacRe67R0rxEQxDf B9Fsc51f 3ARjj6WBRg+Uq+w8dOiFJTYhjYpMHFgzxkE2HFnXwHPvHOK/L9qE8abp5t77FyjZUdXvnHTjyjfwaC4n+DON0T4p3KVrLs5J5WoPVFjLtJO6reDcYMW1yDvm/OU3E9wBo9eefeKwC2xK22qKVOzPUqpCQLx2Wmh4/PpoVhjuA8U5x+NL2Tw0stK+Ncc3Dl2XTS99tTUcahX4X2hcAhoy/V86gPw== X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: From: "Matthew Wilcox (Oracle)" Move the loop for should-we-write-this-folio to writeback_get_folio. Signed-off-by: Matthew Wilcox (Oracle) [hch: folded the loop into the existing helper instead of a separate one as suggested by Jan Kara] Signed-off-by: Christoph Hellwig Reviewed-by: 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 ae9f659e6796ac..d170dab07402ce 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; From patchwork Thu Jan 25 08:57:53 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christoph Hellwig X-Patchwork-Id: 13530269 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 2C200C47258 for ; Thu, 25 Jan 2024 08:58:59 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id BD830280008; Thu, 25 Jan 2024 03:58:58 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id B88A9280001; Thu, 25 Jan 2024 03:58:58 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id A01F0280008; Thu, 25 Jan 2024 03:58:58 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0015.hostedemail.com [216.40.44.15]) by kanga.kvack.org (Postfix) with ESMTP id 8B188280001 for ; Thu, 25 Jan 2024 03:58:58 -0500 (EST) Received: from smtpin06.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay04.hostedemail.com (Postfix) with ESMTP id 6652A1A07DE for ; Thu, 25 Jan 2024 08:58:58 +0000 (UTC) X-FDA: 81717233556.06.BCDB15B Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) by imf09.hostedemail.com (Postfix) with ESMTP id BA08B14000E for ; Thu, 25 Jan 2024 08:58:56 +0000 (UTC) Authentication-Results: imf09.hostedemail.com; dkim=pass header.d=infradead.org header.s=bombadil.20210309 header.b=d3rO9V9S; dmarc=none; spf=none (imf09.hostedemail.com: domain of BATV+b97a0fc658bf3e588113+7459+infradead.org+hch@bombadil.srs.infradead.org has no SPF policy when checking 198.137.202.133) smtp.mailfrom=BATV+b97a0fc658bf3e588113+7459+infradead.org+hch@bombadil.srs.infradead.org ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1706173136; a=rsa-sha256; cv=none; b=d8d2ZHGBrh7MitUeygsAXknaYjL3UL2Nl6CkSw/PmrsVg48wCfU7PDKq18pBTaDF3Wbq8J Vp2beG5623GoZa0u2x8MNHiAMZIQlda1lyVnIlUB8shmDCGaqt1HdC+FYyzj/lxHFp+LVP hlnMvFxgjAsZVRnVxercX4acQXRqc5k= ARC-Authentication-Results: i=1; imf09.hostedemail.com; dkim=pass header.d=infradead.org header.s=bombadil.20210309 header.b=d3rO9V9S; dmarc=none; spf=none (imf09.hostedemail.com: domain of BATV+b97a0fc658bf3e588113+7459+infradead.org+hch@bombadil.srs.infradead.org has no SPF policy when checking 198.137.202.133) smtp.mailfrom=BATV+b97a0fc658bf3e588113+7459+infradead.org+hch@bombadil.srs.infradead.org ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1706173136; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=6v9XAAhdpH6YgZ+Y+Fwce9RtWvlBgAi1bnWfafXvJ4k=; b=r3Ci2knbYfusubPeU3FDVAg4ouyCxSNOHkTbsCwWR51aN9Rixqf871O9peacJDeNkJQure hTrZkOnZD38WW0GEfTqEqhvcqpi8/UOCXD6wRnCfPDShhlUeaVdSTmJ7vFDLM32GSzIaZw KaJN1fpTZsmVJYl3cnno/PvkOKJWTLk= 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=6v9XAAhdpH6YgZ+Y+Fwce9RtWvlBgAi1bnWfafXvJ4k=; b=d3rO9V9SsGYi+hKqPmgZ4FhJpC YyFmQQC8kw3TEuvhCmh+RIj0Hrq9Ebm6JzPz1TPxhAQSlfikUlvmSe+xMs0a/XuOxlntOrUe/nN2t XfoAdRowfYiU1GLgD1pSW+VuuSUkCbuXk6xrF8BvY50J2REvBSgyKCTTmZISVw9vFlrPhyJ8iH7cf w6MnhBOjyEnC4JjDEJaTPzWJVOtoA0TtA5FIF1MwPuWIfzvXTFuN4E36VJbjulhSJgIE7ZH/rdZts 5H90iQduBnFLeqzLgKMDhukwZeWMBi4OvIVlOjKWyANJA6ueQT41NzyScrludnx4YKl6/kzTo8p2q YwJDKtiQ==; 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 1rSvZX-007QTL-1B; Thu, 25 Jan 2024 08:58:55 +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 14/19] writeback: Factor writeback_iter_next() out of write_cache_pages() Date: Thu, 25 Jan 2024 09:57:53 +0100 Message-Id: <20240125085758.2393327-15-hch@lst.de> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20240125085758.2393327-1-hch@lst.de> References: <20240125085758.2393327-1-hch@lst.de> MIME-Version: 1.0 X-SRS-Rewrite: SMTP reverse-path rewritten from by bombadil.infradead.org. See http://www.infradead.org/rpr.html X-Rspam-User: X-Rspamd-Server: rspam06 X-Rspamd-Queue-Id: BA08B14000E X-Stat-Signature: 8hbz3jpho3fpm93u4h195j9jchsxdrcu X-HE-Tag: 1706173136-193348 X-HE-Meta: U2FsdGVkX1+O5CoFFY4XDxselrZWl1wzYXxudOPDO04nG4TxrcuEJEf5bPw3npbxM3X8Bw1ITMWGiCd3JzcjxnauHGF6qldY/OSLKM1sQb56CK60DQ/3HBoctUOJX+ZI4XRdUXbuzrlVN0z8nynvB+ZKlOKNJN4hv6+IfukXWxArW7xgY/pX8u/Tp5rotPm1d3iZ/O/YsUCOkbcZumGMdCDyDqD+GE2ayY978Lz8s0+KOAr57WS4q6NHKj/A54ko1I6j4K3RGg+5NCl1hI1tDn/fdKmiZ2yN/AB9IWtBzF97DkoyRZrRLCk7FWcMhDRZXYPdoeU1jRq5uNOjGXSbWXqEjU9+bZ/4S5TqP4Oo9T8rTooHbRyq4zLGYdWoWyg+eYym7DsifTdoHkHQd/Fa8mX/pLUt/XNhfssy6unYlrRD8ZjQ1p0xya4KpeiKwH1cqVU86kWAAElKQwexRXhYUZt6l8APXOy/SNVxytMs77IXJqwyvhi964LdC3zrA1VRjMaOVsPxgvL/hmm2N8KdtWAgO3mXz2yw0naJVPID47ApDnk36ldfIlXJbguOycOFN1bdnHRvNGNXVAYF5M4ZOD6GUmpMCCbDjnozbG9PeKf/Kxb2snbKPFVItzgfcRDsL+gjnSqY3oKpCNO5k+VpuXsi/cT7GW+Hq90zFfs1rQBQKDBORkWorMD1O+VQVA8ZKMiAvZeHyObXjZhXkWazFp4DG5qCicMLM0bohsMUU6rlgkuuwusadQ9/huTExOHHk4nYLtcPpdx+LbpcUVjMvffXVaxkJe4POXi9rkoKd68NORu6mH6r5G+q8yVAO3diT09HqpMdRn8kd/WU7P6bNJVXLLkYScMLU+te2ieeqKuEYz71M3h50QejWEs37yVNSo+RXNKRNIk2L2KVM5SRNgY8zUIW9HJ1CvT3dD+ZFwNrCjEtvoH+I6rjdRS3nmB3mcV15pS2n1+i453aicT mYHAJHrf wKy/NOKdxgGOhHhzV1pAFITcGxX/iQoVNrx+QgQyKygPh9g0XTM+aScp0/lMBOYFDDTQm/StHTlFe+ApVaRrWqMmMbBzMFyalQ4yYZGn+LuLiYRhuBy3qyDegKjO9o1ei+WgxOIbmQo1AwmrrGEqanpnBioYiHKenV2bldP3zeuX+4fhIElbuET3Ia2oqCfvjY6QbkzGn8gLJVjL2O8splpHMlFi46YEQPltYVLBFJNcXNFF644+2J2OUaW3RL9KhZ4qfjjuojmF45D3AnV/8n2Ryb4bQmuhPdyCynoD4pKAtPdHG1eaL2I+dObH+RGsUXRXedzytFVZEbANoa195V/oINRsZc3Vm1SZJ08Z6kWxiZzsoAyiln+az3y8W1cPX9eaFrajO4MbplbCqog2h/1vO4g7iHtgxrYRyXvSBaWhe8P8VkcVnB52TvhEun/oN5Zmf+sVUo0nv/yjw/0RipR81URGc19kr4BX6cCg9kVOtueu05uB6POX0cQcUP+tie5tjOI4rmzL6AMUz4ab1YIRlwGl+q5whZAHqtZmgmerL5mI= X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: From: "Matthew Wilcox (Oracle)" Pull the post-processing of the writepage_t callback into a separate function. That means changing writeback_get_next() to call writeback_finish() when we naturally run out of folios. Signed-off-by: Matthew Wilcox (Oracle) Signed-off-by: Christoph Hellwig Reviewed-by: Jan Kara Acked-by: Dave Chinner --- mm/page-writeback.c | 85 ++++++++++++++++++++++++--------------------- 1 file changed, 45 insertions(+), 40 deletions(-) diff --git a/mm/page-writeback.c b/mm/page-writeback.c index d170dab07402ce..d5815237fbec29 100644 --- a/mm/page-writeback.c +++ b/mm/page-writeback.c @@ -2442,8 +2442,10 @@ 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) + if (!folio) { + writeback_finish(mapping, wbc, 0); return NULL; + } } folio_lock(folio); @@ -2472,6 +2474,46 @@ static struct folio *writeback_iter_init(struct address_space *mapping, return writeback_get_folio(mapping, wbc); } +static struct folio *writeback_iter_next(struct address_space *mapping, + struct writeback_control *wbc, struct folio *folio, int error) +{ + unsigned long nr = folio_nr_pages(folio); + + wbc->nr_to_write -= nr; + + /* + * Handle the legacy AOP_WRITEPAGE_ACTIVATE magic return value. + * Eventually all instances should just unlock the folio themselves and + * return 0; + */ + if (error == AOP_WRITEPAGE_ACTIVATE) { + folio_unlock(folio); + error = 0; + } + + if (error && !wbc->err) + wbc->err = error; + + /* + * For integrity sync we have to keep going until we have written all + * the folios we tagged for writeback prior to entering the writeback + * loop, even if we run past wbc->nr_to_write or encounter errors. + * This is because the file system may still have state to clear for + * each folio. We'll eventually return the first error encountered. + * + * For background writeback just push done_index past this folio so that + * we can just restart where we left off and media errors won't choke + * writeout for the entire file. + */ + if (wbc->sync_mode == WB_SYNC_NONE && + (wbc->err || wbc->nr_to_write <= 0)) { + writeback_finish(mapping, wbc, folio->index + nr); + return NULL; + } + + return writeback_get_folio(mapping, wbc); +} + /** * 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 @@ -2512,47 +2554,10 @@ int write_cache_pages(struct address_space *mapping, for (folio = writeback_iter_init(mapping, wbc); folio; - folio = writeback_get_folio(mapping, wbc)) { - unsigned long nr; - + folio = writeback_iter_next(mapping, wbc, folio, error)) error = writepage(folio, wbc, data); - nr = folio_nr_pages(folio); - wbc->nr_to_write -= nr; - - /* - * Handle the legacy AOP_WRITEPAGE_ACTIVATE magic return value. - * Eventually all instances should just unlock the folio - * themselves and return 0; - */ - if (error == AOP_WRITEPAGE_ACTIVATE) { - folio_unlock(folio); - error = 0; - } - - if (error && !wbc->err) - wbc->err = error; - /* - * For integrity sync we have to keep going until we have - * written all the folios we tagged for writeback prior to - * entering this loop, even if we run past wbc->nr_to_write or - * encounter errors. This is because the file system may still - * have state to clear for each folio. We'll eventually return - * the first error encountered. - * - * For background writeback just push done_index past this folio - * so that we can just restart where we left off and media - * errors won't choke writeout for the entire file. - */ - if (wbc->sync_mode == WB_SYNC_NONE && - (wbc->err || wbc->nr_to_write <= 0)) { - writeback_finish(mapping, wbc, folio->index + nr); - return error; - } - } - - writeback_finish(mapping, wbc, 0); - return 0; + return wbc->err; } EXPORT_SYMBOL(write_cache_pages); From patchwork Thu Jan 25 08:57:54 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christoph Hellwig X-Patchwork-Id: 13530270 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 96EC6C47258 for ; Thu, 25 Jan 2024 08:59:02 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 266C628000A; Thu, 25 Jan 2024 03:59:02 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 1EA80280001; Thu, 25 Jan 2024 03:59:02 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 0645228000A; Thu, 25 Jan 2024 03:59:01 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0012.hostedemail.com [216.40.44.12]) by kanga.kvack.org (Postfix) with ESMTP id E82A1280001 for ; Thu, 25 Jan 2024 03:59:01 -0500 (EST) Received: from smtpin14.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay05.hostedemail.com (Postfix) with ESMTP id C902940D68 for ; Thu, 25 Jan 2024 08:59:01 +0000 (UTC) X-FDA: 81717233682.14.0A98226 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) by imf28.hostedemail.com (Postfix) with ESMTP id 392B7C001C for ; Thu, 25 Jan 2024 08:59:00 +0000 (UTC) Authentication-Results: imf28.hostedemail.com; dkim=pass header.d=infradead.org header.s=bombadil.20210309 header.b=CWZJKe+f; spf=none (imf28.hostedemail.com: domain of BATV+b97a0fc658bf3e588113+7459+infradead.org+hch@bombadil.srs.infradead.org has no SPF policy when checking 198.137.202.133) smtp.mailfrom=BATV+b97a0fc658bf3e588113+7459+infradead.org+hch@bombadil.srs.infradead.org; dmarc=none ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1706173140; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=hycX01++9KfrQWd9zJFSZD7mlFdT083LhSglCnbjIfA=; b=sVV7bJVmWtO/or412IFQTEK5DUz7nPinCk76MWM7/DH9nbbmRe8NsFwfTR11ljicDvDnYf BtqF07GaTs9kzyqxuQHI3Qw1BZFt5/JDGVoXF84/anfraFLpumSVhYuK8j7pQ7xAoXLZuQ AHhSAmSfRL71ssceTrI+zUqJlej2OoM= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1706173140; a=rsa-sha256; cv=none; b=m9Fq8iKeY5djcOmRX5FLP5C8m8C83kd5r/rXYExGmnPDGSbc6duSG+FsV7lnhXll1jVpX5 qdKo4d8JPTOAXQvfFthrYCc2eYiN8Wmnl8TCzNJ4MkN1Rng5x91R2kXnQqPA58e+9qPDdy Z6qqKw+aE1R5ayxK+gU7SeUL4s5dOW8= ARC-Authentication-Results: i=1; imf28.hostedemail.com; dkim=pass header.d=infradead.org header.s=bombadil.20210309 header.b=CWZJKe+f; spf=none (imf28.hostedemail.com: domain of BATV+b97a0fc658bf3e588113+7459+infradead.org+hch@bombadil.srs.infradead.org has no SPF policy when checking 198.137.202.133) smtp.mailfrom=BATV+b97a0fc658bf3e588113+7459+infradead.org+hch@bombadil.srs.infradead.org; dmarc=none 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=hycX01++9KfrQWd9zJFSZD7mlFdT083LhSglCnbjIfA=; b=CWZJKe+fYMpoyNJTzLY6dZJyZA QYOX3JkYnjQSNZqRqWnV5LQJ5dcHTdNCtbSFBLQVS8uFpIHzJkuyQOnqlCRSH9/Eik0Bxh7kCd5tC Ophi8cnF1+hC+jcY4nHJOrBS7Qg+ajDD1z3M4DNxObV8/o2aB9ULuQQYqrNeBPF8ytfbSumetEYcw dhxh/yWN1eZFv6zTFaNHQ9tpiHLZN82AuIZh7cXSqcXBA3i6psFH+Rp7ifIufSFmF8k5C2ygBq3gs Na1eRG+Erd+ijYZb6gNByZXQaa+TTVlviqmjmiGIUDafwuHIG2zLEXmLPlciRMF1l1+yptTWAiy10 5WmAk/pw==; 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 1rSvZa-007QUh-2Y; Thu, 25 Jan 2024 08:58: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, Jan Kara , Dave Chinner Subject: [PATCH 15/19] writeback: Add for_each_writeback_folio() Date: Thu, 25 Jan 2024 09:57:54 +0100 Message-Id: <20240125085758.2393327-16-hch@lst.de> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20240125085758.2393327-1-hch@lst.de> References: <20240125085758.2393327-1-hch@lst.de> MIME-Version: 1.0 X-SRS-Rewrite: SMTP reverse-path rewritten from by bombadil.infradead.org. See http://www.infradead.org/rpr.html X-Rspamd-Queue-Id: 392B7C001C X-Rspam-User: X-Rspamd-Server: rspam11 X-Stat-Signature: e87ixdcaw6j7e45g5rn1f1fw5fqtuxpk X-HE-Tag: 1706173140-583018 X-HE-Meta: U2FsdGVkX18BzobK2zokV5ysSGi7kJ5ehDU5qHP65sWpoQ3nSf7pWI4Y50zcdwtsXEEOGhQdcFQTff3AGPjmWAhegIuzW6g0BFUEgxjbNR5ZWE3mIVlt9Tt8NHiPpxbweKcHm9odT2TzCVMQ8/ufhvosN/FeJHNok77/pfVPaj0GVmx5Rgc4ZENO7jqq8cEueHTKzjRiY0w+ZWPquhQDe9gfSKnqFwustWjeDhiP38VQKLkIuw9+vLiEWhUkQwy5ZKOLL03MgvMrGi0DXTctsxkCY9XxKkOOQARs9lVYdknk/KYOPdNaLstm0ZbCq/iPl8wOS/T0pQO8DxJEGYP7RctwC3V/3K6zbfzGwldW2nxuM3vN8frloIZTUjnRpXWIXTd6nuhWFxUzD3x7B503X0fRttVdeXW4FwMSF+LlG+nDZ+4RpQXOgRjM90XJy6o9ruZI4SLnPoOngcZBIaVx5H9a60VcvTbp1ZdJu1pOSejrELOonhLx7DFY22YARjNC2ZHNwz/QtQJVtlA1RCloIm77QBYN3HqDWbDGFvrIIKFC+Ip5lS0i8gTylgCR1Di2Suu60KTXBjPzX4HMKwo2pQlDyUnYCxChW+zqCh0Zje1yXYkWaYpn8A/Z36BsPQFjMIzh9SRMfPXwasskwE5JI1mYtwe8bfBIsDV4eTsL7DjRyOfGumX6aOodhlCpXAjl80Lokr1Zf9PBSCS0aq90Jt9cRkgqyqNumU7ufNb+QX4Rv9/dpG8vJOjsrfoG6iSTz8lln/SXjItLh1FCn94pPcrb54miL8kxfv2i41Yy2ln6v9ucNS+EIS2TE7nJOrl3wTgbwhbpQNZcB/96woWbvNVSYLTBKoRRtOvnwTScnAfUp+ns5LYqk+pIyNnQmn+Tr3THLwtCwZa3sG2iAR4KOFgBlgm2GQW4X8A0y/5cprY9UArJ375Sq4e/L46pnGMBBubiIA0jHpRqV0MwjGw i8gkzsTb dksc8JmdtID8rLKmako7rxBzd2dDUu31+LDAtw9zBo28MbK0DLQ7IB59GpWX/xsV6Wh2HFGF26ia8ClXA7+gdG3xzraMFSDh8umn5LGFWqx82VqDwTfqf3R61ojHJbeAMW/0dUofcfE5DwBoamXPwhuJAWZG6uhYwbWnfEEeKHNm+62HzWRr04ilJt38gOgPHiKQEffj8GLn7ttFYO8tKDzS5QGITKxT8iJkr1V5XvAkN8XNwTz5TdKuoe2ObBi1sO3KXeGcxn7wxE1ZUDwFT3vpsmd5+4BqGEdVTHtqEYjEtznxuebg0Bpv7kfRHzpUn8J6jyyWhi6Z9XirfWRD6F7Xcmta2hhN2SZmG9eNDB6djnUWkyMhWEIvmNWwGBLk4hpwbB1nn1hBFMNo0Oqa3uQxl7+UyzNgFxmmY1acWKKSKw+j9g8OX8O0fDiO1OvVVIR/0AMke9860+b5e9Q15dd7qwDv85zOfcBaPDWGu/BGVI+vX8lZkekH3fkmiGDaFiom3L2ladn50h7GkFXgdV7fj3y70JL52boi5 X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: From: "Matthew Wilcox (Oracle)" Wrap up the iterator with a nice bit of syntactic sugar. Now the caller doesn't need to know about wbc->err and can just return error, not knowing that the iterator took care of storing errors correctly. Signed-off-by: Matthew Wilcox (Oracle) Signed-off-by: Christoph Hellwig Reviewed-by: Jan Kara Acked-by: Dave Chinner --- include/linux/writeback.h | 10 ++++++++++ mm/page-writeback.c | 8 +++----- 2 files changed, 13 insertions(+), 5 deletions(-) diff --git a/include/linux/writeback.h b/include/linux/writeback.h index a091817a5dba55..2416da933440e2 100644 --- a/include/linux/writeback.h +++ b/include/linux/writeback.h @@ -367,6 +367,16 @@ int balance_dirty_pages_ratelimited_flags(struct address_space *mapping, bool wb_over_bg_thresh(struct bdi_writeback *wb); +struct folio *writeback_iter_init(struct address_space *mapping, + struct writeback_control *wbc); +struct folio *writeback_iter_next(struct address_space *mapping, + struct writeback_control *wbc, struct folio *folio, int error); + +#define for_each_writeback_folio(mapping, wbc, folio, error) \ + for (folio = writeback_iter_init(mapping, wbc); \ + folio || ((error = wbc->err), false); \ + folio = writeback_iter_next(mapping, wbc, folio, 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 d5815237fbec29..aca0f43021a20c 100644 --- a/mm/page-writeback.c +++ b/mm/page-writeback.c @@ -2458,7 +2458,7 @@ static struct folio *writeback_get_folio(struct address_space *mapping, return folio; } -static struct folio *writeback_iter_init(struct address_space *mapping, +struct folio *writeback_iter_init(struct address_space *mapping, struct writeback_control *wbc) { if (wbc->range_cyclic) @@ -2474,7 +2474,7 @@ static struct folio *writeback_iter_init(struct address_space *mapping, return writeback_get_folio(mapping, wbc); } -static struct folio *writeback_iter_next(struct address_space *mapping, +struct folio *writeback_iter_next(struct address_space *mapping, struct writeback_control *wbc, struct folio *folio, int error) { unsigned long nr = folio_nr_pages(folio); @@ -2552,9 +2552,7 @@ int write_cache_pages(struct address_space *mapping, struct folio *folio; int error; - for (folio = writeback_iter_init(mapping, wbc); - folio; - folio = writeback_iter_next(mapping, wbc, folio, error)) + for_each_writeback_folio(mapping, wbc, folio, error) error = writepage(folio, wbc, data); return wbc->err; From patchwork Thu Jan 25 08:57:55 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christoph Hellwig X-Patchwork-Id: 13530271 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 16A2CC47258 for ; Thu, 25 Jan 2024 08:59:07 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id A2A7328000B; Thu, 25 Jan 2024 03:59:06 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 9B358280001; Thu, 25 Jan 2024 03:59:06 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 87CFF28000B; Thu, 25 Jan 2024 03:59:06 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0012.hostedemail.com [216.40.44.12]) by kanga.kvack.org (Postfix) with ESMTP id 7263C280001 for ; Thu, 25 Jan 2024 03:59:06 -0500 (EST) Received: from smtpin30.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay02.hostedemail.com (Postfix) with ESMTP id 4BEA212050D for ; Thu, 25 Jan 2024 08:59:06 +0000 (UTC) X-FDA: 81717233892.30.1376DC6 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) by imf23.hostedemail.com (Postfix) with ESMTP id A54A814000D for ; Thu, 25 Jan 2024 08:59:04 +0000 (UTC) Authentication-Results: imf23.hostedemail.com; dkim=pass header.d=infradead.org header.s=bombadil.20210309 header.b=b9+nO3yw; spf=none (imf23.hostedemail.com: domain of BATV+b97a0fc658bf3e588113+7459+infradead.org+hch@bombadil.srs.infradead.org has no SPF policy when checking 198.137.202.133) smtp.mailfrom=BATV+b97a0fc658bf3e588113+7459+infradead.org+hch@bombadil.srs.infradead.org; dmarc=none ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1706173144; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=jmxBhEwvvP0SHYr6G/94FmB0blh/Svg4tA2Bb0QCX2c=; b=Rdh8C/UZYA0VDVSwW7jFOWTG2tme3282vd7lGFWInXpeFc8Um2e6Bt8/SA/E1jrgzmbPhz 6iAPq5FAJ8mKqAc026U+1ZTcA7vvTZRM7KhnUubN8S4RpaGoRGNTR2WWPmuA8CRVhmmn3V GvHRxK52rGl3cFXhx9apW+H2GKrDYpc= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1706173144; a=rsa-sha256; cv=none; b=aCWdKO/piC4UPbNUA+XJL7CKPaGzdsMQ2+aJdIkEtoz4CforO6hKiojTuh0vafu0GTarXb 4b5PH6UQMxq7RF4WmpXScea7LcqH/umni80QQ2eoSp4v2pc8Yv+M2+qm3RfPeS1OH6Cstb R1ozJzWD+MzTG6Y/yplGGcUw6/RADCw= ARC-Authentication-Results: i=1; imf23.hostedemail.com; dkim=pass header.d=infradead.org header.s=bombadil.20210309 header.b=b9+nO3yw; spf=none (imf23.hostedemail.com: domain of BATV+b97a0fc658bf3e588113+7459+infradead.org+hch@bombadil.srs.infradead.org has no SPF policy when checking 198.137.202.133) smtp.mailfrom=BATV+b97a0fc658bf3e588113+7459+infradead.org+hch@bombadil.srs.infradead.org; dmarc=none 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=jmxBhEwvvP0SHYr6G/94FmB0blh/Svg4tA2Bb0QCX2c=; b=b9+nO3ywJHkLbo7Hj/APqwblnx 0Jd3qWrW11823FTn4RkUzafKOu7wPN4qXVWb3Y3abZVmd6IeXCyA/8h25NwJ06dR7W4WRb0TiGxgS XRSu+AWHyptJe9dauajhaWAA7KsaMgHO5l9+fuWnqXd836VjWfYGn7T8rlHhDYiTUCCkjK7cBPpc1 YguvS1IP6xeXvIaJiu8J8kF5tdyVBGE4IcyAC3h8JRFPuKt3k5hsvByqL8Pqf64BAMQy8cd2Rfb0b wNkEzo0iawP2oJl4sK/Ea1XshNHk9nHAXQGTHXcSoqAs1Zmi24m5dyKVCgIG0/f8uPIA29xjnRI8R Fq8sz5/A==; 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 1rSvZe-007QWD-0t; Thu, 25 Jan 2024 08:59:03 +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 16/19] writeback: Remove a use of write_cache_pages() from do_writepages() Date: Thu, 25 Jan 2024 09:57:55 +0100 Message-Id: <20240125085758.2393327-17-hch@lst.de> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20240125085758.2393327-1-hch@lst.de> References: <20240125085758.2393327-1-hch@lst.de> MIME-Version: 1.0 X-SRS-Rewrite: SMTP reverse-path rewritten from by bombadil.infradead.org. See http://www.infradead.org/rpr.html X-Rspamd-Queue-Id: A54A814000D X-Rspam-User: X-Stat-Signature: g4h4b8uburpytza559xu1oq5xzkp1o17 X-Rspamd-Server: rspam03 X-HE-Tag: 1706173144-305132 X-HE-Meta: U2FsdGVkX1+IHA7a2ea+pChFtFqdTj9OV9Cx7TuFlv11Wew1ZqyXk/XkbHMZmPaPVPj4PKBOCTz0GfJZ+9/OBLN3tXtdOkeJHP59qU0UG9HBCqJwOE35n8tyYtjxfKQjONbRr8jgsppyvmvjEQjhtEB6HwARnHkjF9bHZCgvHe6NPLOJX593RGIEskE3ZzfTNqK4xdmY4zaK164mjtdD3ZkB+RvSXoqwYRvPJVFp+ghfWo31T0BzzXOkq6zQOqjftubCOS4R9mnMdXRAbw7LatpGTR7oijuXEs401Bcg5hR+hqybKU0AuHh6qvKSc8TSm2cUNn4C09cqS/a4oRuwKjSz49trssptWFkVZMF6E8y7VOVWwyjHecEuh5tTZfW34alossnbv01SGOfZESUXDdOY9MVyJEz8q8g7TTab/Zgy8+WtKKAga93IzLXXG1qWjRxEUhpLXy9sH+MlgZ7mmbpke5bb3tK5/qffBpXr/cbA6D6bhN8awZcUWi8Z799SceBKEsOEr8hhNnmsLTDS8yve1CdXtkG9T9djI/tCMua7XzEwJH4bV5xK91G4dc5Y142eP46BlVdZO15V/uRhyfZzc7U7/C2nKWGCAsMYnIjcpwDDxScp+La/f/px+cTZmevsUNYl0TUMDgxOplTEh1EiwAnnT6PdqpPwmdxJ7INdVM2M8yy77fbtTBHy9P3L3fdu3uRBNkulkNmjwKDmtkd2KWW3HoFhRoD88tZ2qDVbf/rz/XFijw2ggWkSPKl/hG9JzMjEtowzgUIg73Rp9tOCs1ydn5X/HY8UXm3rjVM9Y7Wx9VLV1mJrYOdNS4PPBOkcg8D7dXtzzOYx7nsCCIYiOseNbw5kXH3tLYGOjcbLIpz1peNU/K3Ndhw5ys9fQdy4qwGrpHoQIyWrg+6DnXO4YSOhBfv5pS/Gnlm1+byreizsS5qLn56IOlY0mNRLr1sPoB+zseUF1arjBAT mjS5kukM 5yxnJI6igrf+siDG0kNihcsstA75ZvBwEKol9Leszi/yCavHWGw+39XG2ZPgNsr+j+vLsIyeBFn+VpZFV515dXowVXqYXLt5+DQ9KaHY4WqSCjNbJ8EkdGc6o97WJJ8U4QlF8lVQ3E6JiTlaKxWvd7FVamAVMlcHuFXzLFduCv6rwKoT22h/vMONA/gaBk8N10wjKTj+OOGfdgUHZkPVlf7N6JE/6sjXrcoePgkcA2ojqwNrIUau/PosslZR6MPO3yGfNy+aiMFK1PMuwD8+HaaKMkrEch2wmPRbkLvpcBbHlwScKeuB9dFWdrP/J0TtBo5kvjMLJxGDkuaF4iXlF95JHH4soSTuhMvGnG3q8YLiryGCwApsFOyZOAn+t3Crg4fIn5LELxDivrwtS2qZx6ub81yMdcKyqaY0lfln6mebInSgOJ33/I6/3eu3hQBu58bWYfjy8MumLVlxbPuSEiowLiDiEWzUa5aAvLhzze6nLufZBZm34k8DHlmHNUm95VqXLBFe6RHuTMN1m1siZNWNhqxiKTC+KHiGf X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: From: "Matthew Wilcox (Oracle)" Use the new for_each_writeback_folio() directly instead of indirecting through a callback. Signed-off-by: Matthew Wilcox (Oracle) Signed-off-by: Christoph Hellwig Reviewed-by: Jan Kara Acked-by: Dave Chinner --- mm/page-writeback.c | 27 +++++++++++++++------------ 1 file changed, 15 insertions(+), 12 deletions(-) diff --git a/mm/page-writeback.c b/mm/page-writeback.c index aca0f43021a20c..81034d5d72e1f4 100644 --- a/mm/page-writeback.c +++ b/mm/page-writeback.c @@ -2559,13 +2559,21 @@ 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 blk_plug plug; + struct folio *folio; + int err; + + blk_start_plug(&plug); + for_each_writeback_folio(mapping, wbc, folio, err) { + err = mapping->a_ops->writepage(&folio->page, wbc); + mapping_set_error(mapping, err); + } + blk_finish_plug(&plug); + + return err; } int do_writepages(struct address_space *mapping, struct writeback_control *wbc) @@ -2581,12 +2589,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; From patchwork Thu Jan 25 08:57:56 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christoph Hellwig X-Patchwork-Id: 13530272 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id A6993C47422 for ; Thu, 25 Jan 2024 08:59:10 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 1C97A28000C; Thu, 25 Jan 2024 03:59:10 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 101FE280001; Thu, 25 Jan 2024 03:59:10 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id EE3AD28000C; Thu, 25 Jan 2024 03:59:09 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0013.hostedemail.com [216.40.44.13]) by kanga.kvack.org (Postfix) with ESMTP id D958A280001 for ; Thu, 25 Jan 2024 03:59:09 -0500 (EST) Received: from smtpin06.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay06.hostedemail.com (Postfix) with ESMTP id BE882A2396 for ; Thu, 25 Jan 2024 08:59:09 +0000 (UTC) X-FDA: 81717234018.06.F462777 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) by imf01.hostedemail.com (Postfix) with ESMTP id 2867940012 for ; Thu, 25 Jan 2024 08:59:07 +0000 (UTC) Authentication-Results: imf01.hostedemail.com; dkim=pass header.d=infradead.org header.s=bombadil.20210309 header.b=SvZnatM4; spf=none (imf01.hostedemail.com: domain of BATV+b97a0fc658bf3e588113+7459+infradead.org+hch@bombadil.srs.infradead.org has no SPF policy when checking 198.137.202.133) smtp.mailfrom=BATV+b97a0fc658bf3e588113+7459+infradead.org+hch@bombadil.srs.infradead.org; dmarc=none ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1706173148; a=rsa-sha256; cv=none; b=BH+DfPebA1GGjJDh3ZBaUyUJXQLvwseB0MByJS8RZJoXFYchYgPjxCTqNMqzrNkKDEUKJf Uy4FC0AXtC9of5Z76QBZkkafRCINfMzp0KmI6XM8b42l12wL3AE/IaA6CE8EzOCwM/vTJc abkblUW6q5hnC+T/noVF2q39WTR6p9M= ARC-Authentication-Results: i=1; imf01.hostedemail.com; dkim=pass header.d=infradead.org header.s=bombadil.20210309 header.b=SvZnatM4; spf=none (imf01.hostedemail.com: domain of BATV+b97a0fc658bf3e588113+7459+infradead.org+hch@bombadil.srs.infradead.org has no SPF policy when checking 198.137.202.133) smtp.mailfrom=BATV+b97a0fc658bf3e588113+7459+infradead.org+hch@bombadil.srs.infradead.org; dmarc=none ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1706173148; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=Nvs8NLSkqi3xoK+c7WXXiVGON/brvE1q1HDi04P3LYY=; b=T3cGfq1y5k78POJ1SbUDV/+TEhg1uTZA9ddyjRRIdDeytQGbFYOEPr4OFgisYfyg9Cp6WA V0VjNCLX2ypPcE/4pPQLprWR1ptgO842ybcBGbLUPVn7nPs8jRBtMRXU3OhojUJZHioJ63 3z38EHjT4+cn/V+1nMBhfuoZMFHSDqA= 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=Nvs8NLSkqi3xoK+c7WXXiVGON/brvE1q1HDi04P3LYY=; b=SvZnatM4pQklWGScC9mHPuWxUK zxfxMuZE0VccNfw9iFHQXq7CfxUxAP3ayswkwOH9oGRTaHShpXQo8x1SxDbYTd7mqbAwOA+TMKjKq hFqcp396BhSwypZVLIY+aIZk/MYyndo49M7J+2iJ990Bde2fVU10Tq4MAZMh6cNa0ObpmVQ59XT4c V5x6rM0QRwa7q5KZapCVtfd0UIznQdMlmIPdNRIoInoFYPxjpyeqvOX7Y2/WKzxzcvsnp40odmxRT HKO8V+ScM19lkFJ5wwS0ys900HDBiaI5ZkBZa9PvX4+ed9Zhci+vKj4wc+tB7mNLpanWNElWcVxVI gdKbdCKA==; 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 1rSvZi-007QYC-2B; Thu, 25 Jan 2024 08:59:07 +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, Dave Chinner , Jan Kara Subject: [PATCH 17/19] writeback: update the kerneldoc comment for tag_pages_for_writeback Date: Thu, 25 Jan 2024 09:57:56 +0100 Message-Id: <20240125085758.2393327-18-hch@lst.de> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20240125085758.2393327-1-hch@lst.de> References: <20240125085758.2393327-1-hch@lst.de> MIME-Version: 1.0 X-SRS-Rewrite: SMTP reverse-path rewritten from by bombadil.infradead.org. See http://www.infradead.org/rpr.html X-Rspamd-Server: rspam08 X-Rspamd-Queue-Id: 2867940012 X-Stat-Signature: 4n645nt7pfrny65q5uooz7eq5dksmja7 X-Rspam-User: X-HE-Tag: 1706173147-98162 X-HE-Meta: U2FsdGVkX1/i6tkZMSi+siaEDGDF64mhH8HrJ4UbMs6r5w3AWoH93wOs/soCZ+5vwqguhRLnJIfS8bGtrTu+tXYfxhH1xfklcFUbmh2jdOxH32oymbwOawzhMXa7mQdygm6XXl1Cm5WRhw8GvUYMyh4SEnlco930bhmvz15H45lZ+gkEhEemS99GHQen084+IZM6TTQHYzNgVyJiAQHLY6XH26SGDhiXvAouU6/r6au0MvqDpOaDtPulH8u2+0BoqaRRiPBdTsf1zVoVW6IG0Aqd2rs2isufb1QF1pWpGjNbImx4G0t37n5Kp5ZteuyhFbq+dm77WjySbqfYU8eREbbHwLuF6w+Sue8EI0WOAjKmRy0JHiqSEU81qSok2XSFzaeKo1YfJ1jen2E2injP8PJdx79WEPxsUgmozTO76Vv3HXilzRG9wriMsP9iDE9e9Z4amihAGE/wjD/1fLCkKsf/uRAzyQIOAgJjPs3vVJy//B3yV9haPlZM+H4i+mv/EYTRToJbXDVC2zrdLzp8pdDVPbErQohup1jBhKnY6nQUZcbZdpvZKPiD5blmhPeG9Jmo/Wa1t0Oot3dJgDiZhH4jWGNkvAfh5g8kTSDXxwkblhUSP8yRQTUIhPQ5fyazaQS3yAN0+Az/vpHjDvGxssDyFeeIEbkkC8NKu1jpvYvoUcPNLEoKcttFM6SkKZ02xec40EvepcEDtZ6kD6a51t0WbVyDcu+HUX5ZyvQJN0sEKKrKZ5ybCNvDFkB3iMk55502sGFp0kKoBxxokFTQD1ANyLRj2AUVnNl12n/ttWDorkRLF6qjrkcDBEL1BGP2peWNb/ZZDtVrVaHuJXKfpsuXR7o9W7byRMiJCTyvgtByX8GQ5YzYcEVi2fVaD0Tc9zDBltFEu0z5aDBylmbavqoCS/C9jENBNbW8PYNf44NGjiIIqLwcut4PGq70EbNVQlyZHL1PfgMftJ3OdZJ urDm274/ bJV9jYrcLl/v2gAIiUjYsMPfck2QNj8EpWgxsXMKod/fsCacatrtmitwlUVNr6iR+QgHD4iiSTQCBpuLDRgn4bsZwOEyzEi9EDzt7hDQo6FdD6uChSaWH8uEhm8zZeNmDgHZ5qXk2IcMcKwWoIF8i/xTrmuhhvUjv9afypgEyspvI3LzqcI5nRuCKlC/mds5+L1DoSTfOw8cDUjWzs3wScxXhUte9xZSYpWo0nhRNdLupTgEpjkS8OWbOGQK4GPEdoRhbel5hxUmqhnwd213lFzAHa1IT6kin46XGlNmJLRzR9rHrRWam9Jh9mQRWDzKSLLNpBVaXFvpxdHl6vpBq3pUkdfGBnWEAHUpkbw48OLHCsyO7TRB4l75TpWaBbJn7+fJMDw85u0u+Fis32u3nue0c+onvYGUH1C6qtZ8fV9wNtIWELh3BVMV4Kvk6ofkm/5N1sSjR/OPfcLx38PnXh1gD8M6drekybS8h2Jv8QtWbgNjLXPlNNclWZvmvPYiLS10L X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: Don't refer to write_cache_pages, which now is just a wrapper for the writeback iterator. Signed-off-by: Christoph Hellwig Acked-by: Dave Chinner Reviewed-by: Jan Kara --- mm/page-writeback.c | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/mm/page-writeback.c b/mm/page-writeback.c index 81034d5d72e1f4..2a4b5aee5decd9 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) From patchwork Thu Jan 25 08:57:57 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christoph Hellwig X-Patchwork-Id: 13530273 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id DADEBC47422 for ; Thu, 25 Jan 2024 08:59:14 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 74635280009; Thu, 25 Jan 2024 03:59:14 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 6F736280001; Thu, 25 Jan 2024 03:59:14 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 596A1280009; Thu, 25 Jan 2024 03:59:14 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0010.hostedemail.com [216.40.44.10]) by kanga.kvack.org (Postfix) with ESMTP id 45577280001 for ; Thu, 25 Jan 2024 03:59:14 -0500 (EST) Received: from smtpin04.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay01.hostedemail.com (Postfix) with ESMTP id 1756F1C132D for ; Thu, 25 Jan 2024 08:59:14 +0000 (UTC) X-FDA: 81717234228.04.7E02B3F Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) by imf23.hostedemail.com (Postfix) with ESMTP id 7C52F140012 for ; Thu, 25 Jan 2024 08:59:12 +0000 (UTC) Authentication-Results: imf23.hostedemail.com; dkim=pass header.d=infradead.org header.s=bombadil.20210309 header.b=MwDns8za; spf=none (imf23.hostedemail.com: domain of BATV+b97a0fc658bf3e588113+7459+infradead.org+hch@bombadil.srs.infradead.org has no SPF policy when checking 198.137.202.133) smtp.mailfrom=BATV+b97a0fc658bf3e588113+7459+infradead.org+hch@bombadil.srs.infradead.org; dmarc=none ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1706173152; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=VteIp731KUh3YSK1JiCDa6aylLsuTXuUpMz7VQeOhBM=; b=kgFUkNBuzxW/xRyXeHuFIJu/r3kAIpOyoGwXpQXgfQ0cpA47U7+6k9yhA54PmNhFZliyHA 2ck2E/GnQTgkO7pms87cV+8ezXssfZKT71+fwv5RfYfTWfiIRkGd2YhKXsZJkqwzLcOUl2 1wGFH0BJVgeP0a7lXGAwIlC1CokJV2Q= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1706173152; a=rsa-sha256; cv=none; b=nixUlQ74NKV3HUzU2ryuMUvKdYt5hZwH+MfwX0UvPgC7A0d1x9G4vqK8vaAUHqZd3CTpnK WW4naG0+jVIdTI0QFLuX1laxvfrGn6wEdtW0LaZjpVLvg9AYcVRKHA1QpgB7T79Y4AqCdj vtQOjQme2gLDm7F5IoShftKiyr327IY= ARC-Authentication-Results: i=1; imf23.hostedemail.com; dkim=pass header.d=infradead.org header.s=bombadil.20210309 header.b=MwDns8za; spf=none (imf23.hostedemail.com: domain of BATV+b97a0fc658bf3e588113+7459+infradead.org+hch@bombadil.srs.infradead.org has no SPF policy when checking 198.137.202.133) smtp.mailfrom=BATV+b97a0fc658bf3e588113+7459+infradead.org+hch@bombadil.srs.infradead.org; dmarc=none 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=VteIp731KUh3YSK1JiCDa6aylLsuTXuUpMz7VQeOhBM=; b=MwDns8za7rOoyeeWAlr3o2HuQV 6MsdXZx1OlD4vY4TVWPSxa5TjcHnxy09D2/JDj47wRd2wEL80LFuC5im3yK7CJXPj2jlucMoHhjYY 5ZfQoIWEjbS3nQGUD167nRpjZ9IYSoNIanwVbuJcTe8tTJhTKK4ufectQpX4R6xdrpv7nl7S3sak0 v3d1Nqpjk+YxJc8FB0tBthiV35NdcgzGgWajgKmp1mRJWvAQd5eTU+gEFmq7Eu6UAAF1itV8yLtxl 6KqrehrsyNRLzDHyou0HEwBNknKvykRNrwdjpWOZZrcDO7qYmxX27CByg2snYSfEFCFJfxeKf9Tkb Pf5DB47w==; 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 1rSvZm-007Qa9-3D; Thu, 25 Jan 2024 08:59:11 +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 18/19] iomap: Convert iomap_writepages() to use for_each_writeback_folio() Date: Thu, 25 Jan 2024 09:57:57 +0100 Message-Id: <20240125085758.2393327-19-hch@lst.de> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20240125085758.2393327-1-hch@lst.de> References: <20240125085758.2393327-1-hch@lst.de> MIME-Version: 1.0 X-SRS-Rewrite: SMTP reverse-path rewritten from by bombadil.infradead.org. See http://www.infradead.org/rpr.html X-Rspamd-Queue-Id: 7C52F140012 X-Rspam-User: X-Stat-Signature: 6bisqpn9chq9i4t466qzxmo19s6bg94a X-Rspamd-Server: rspam03 X-HE-Tag: 1706173152-209709 X-HE-Meta: U2FsdGVkX1+6qp3J1PF3raweAYstugve6zffIkHvNimmEpJIj/ShX27nN//UmPAx0pxGWBQOXgVpU6fGr7gz415RPCLjcDJqcc3i3VNaXksU3cQpm3efBxjvGacUGlxF1FbT84zyDu46IvP5AD+ObwOXATQvJqDvDVqP7JMhuorAJdIa1Y7HgnanSoRFkLWZcaN//Q9Gw2XggCH5tjMu8QmAE7/olFkW1MmeyhRcCcGGAr0Fp2PDCPwOO1JNSoUqTjlY/E98tPZff3DNq089uVbBA2zRHKwyONhpNxTzDLYH8nVlPatc4RtratWnVDu+H97j6ad85z/cP5wSw7UzhoObA9e4Kp/CoglgypI//HJrIvYqp5gTqpw1BdRRA3IcZJmIQc5MTvAkB5RSLqScSLhzz0/SDax4Ig1DHfhuo5n7ckiZfZ5tOHweb23kZar4qiXKJOfyIKkdddxnyVOFNl6C1/6uKWx0inxmtGLMkyxFihA8xSNAvc4csR5hijhdKybLR47WQsXKCuQnPAPlJ5AJ82yxJPxJ4NBVKGiOwYlqEUL36Iz5ufSBjAkaZi6QjfxzdtLKO4O9tkqdzPO2G+7zw67MryqeNJoUs42h0GtKvBDes1CPhMuCOdUVDEpEh8Hj4tudgkLrfpInfS+vh0KZ2X5FfVgv+CU1+v/pCT4JHRBfqHIPT15/PVlHppkJyotm3DTWTRdhmrv5BpiPkiUF2AP0OjYS4HmdZf6zNBY6RtCuOj7OwPbyHZV5nlZKzkb83dWqPm8sxcPgYeZtm6+jMvCRmVu4uekvjF7O0NrBv73w/g8VXe4PCW+NqdBFPjJdQTguwWeAmLHZptueWvHxoQORApjuXo+Sm+iJ77c2CvxK9qDCgVNGyQ8WxegmmBY1oCOkKBC6TIgJeOVpv68Icwq1zA/KKSCEYiMxnTMViMPHaE6IIpqkW1oVVuEQztlr2KdZvbEgCUKaUsK pmIyD/v4 ABheOXV9Q/jmQOLPjrzPmC2qsCxArYwlQ4V9yZ/M2oAtC76rHpO60EKjbqcUNz+NcUGMGBm5j2e5c8irL8sgxS9q8/gG+isG8aU/9vJN4jc5hMUTT9XgrxRz9u6CQN0rDcssGSBW5gkWpmide2YnNOV2XFr7v8dvxlVVeNSONhbSiJFDRrKWaTPMdnVDLVe/o44VML8JZubqlMQYxPfnh8xYPq/svT7+QmhSxDwrSNdfZXzcsNoMsILlDJ9SRnqgaQvniYe0gpATZ95q8uHLvxdej+q5KOvgwWd0Nl/h6J431MSqWZVI+YB6bO08N4IUt5VACNT4x6RBAAXdnWMpqXU3UIJ0dfzRux6O+OybEmA9sa7eE87GUjpVPrk7cnFQxrrJ8612eQwfcz3LB5b31NOovZ23IkBnYGt3rCTS94nPl9rfRKCj2J/dv+jvsUDTGXzf0bpgzcJ3SvdDYNjOoJAvABnaMApVr1f5807UBgj4c+sT05IS7crrlgAO7uM17VuSdCUYtrtUNTDU= X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: From: Matthew Wilcox This removes one indirect function call per folio, and adds typesafety by not casting through a void pointer. Signed-off-by: Matthew Wilcox (Oracle) Signed-off-by: Christoph Hellwig Reviewed-by: Jan Kara --- fs/iomap/buffered-io.c | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/fs/iomap/buffered-io.c b/fs/iomap/buffered-io.c index 093c4515b22a53..58b3661f5eac9e 100644 --- a/fs/iomap/buffered-io.c +++ b/fs/iomap/buffered-io.c @@ -1887,9 +1887,8 @@ iomap_writepage_map(struct iomap_writepage_ctx *wpc, * regular allocated space. */ static int iomap_do_writepage(struct folio *folio, - struct writeback_control *wbc, void *data) + struct writeback_control *wbc, struct iomap_writepage_ctx *wpc) { - struct iomap_writepage_ctx *wpc = data; struct inode *inode = folio->mapping->host; u64 end_pos, isize; @@ -1986,10 +1985,12 @@ iomap_writepages(struct address_space *mapping, struct writeback_control *wbc, struct iomap_writepage_ctx *wpc, const struct iomap_writeback_ops *ops) { - int ret; + struct folio *folio; + int ret; wpc->ops = ops; - ret = write_cache_pages(mapping, wbc, iomap_do_writepage, wpc); + for_each_writeback_folio(mapping, wbc, folio, ret) + ret = iomap_do_writepage(folio, wbc, wpc); if (!wpc->ioend) return ret; return iomap_submit_ioend(wpc, wpc->ioend, ret); From patchwork Thu Jan 25 08:57:58 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christoph Hellwig X-Patchwork-Id: 13530274 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 44402C47422 for ; Thu, 25 Jan 2024 08:59:18 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id CC3F628000D; Thu, 25 Jan 2024 03:59:17 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id C753E280001; Thu, 25 Jan 2024 03:59:17 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id AECB528000D; Thu, 25 Jan 2024 03:59:17 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0017.hostedemail.com [216.40.44.17]) by kanga.kvack.org (Postfix) with ESMTP id 9C5B7280001 for ; Thu, 25 Jan 2024 03:59:17 -0500 (EST) Received: from smtpin07.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay01.hostedemail.com (Postfix) with ESMTP id 69A6F1C1660 for ; Thu, 25 Jan 2024 08:59:17 +0000 (UTC) X-FDA: 81717234354.07.CB71E86 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) by imf06.hostedemail.com (Postfix) with ESMTP id B9CB7180002 for ; Thu, 25 Jan 2024 08:59:15 +0000 (UTC) Authentication-Results: imf06.hostedemail.com; dkim=pass header.d=infradead.org header.s=bombadil.20210309 header.b=yI1+JGkK; dmarc=none; spf=none (imf06.hostedemail.com: domain of BATV+b97a0fc658bf3e588113+7459+infradead.org+hch@bombadil.srs.infradead.org has no SPF policy when checking 198.137.202.133) smtp.mailfrom=BATV+b97a0fc658bf3e588113+7459+infradead.org+hch@bombadil.srs.infradead.org ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1706173155; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=W1Pg45e3YPveg08TzLy7LzAEvB67BYDtIDXVWrYOF4k=; b=UqUJXwgk0bnuR6A57varXnwKgpeGe/CKG6e7c3oR729NegzqXhGgL07zms/xRhPvmBQNZq vL5tZraD4z0gX+d0uvGz0KrucD7nfOZRWTc8BTnyLxANwGH53MPr0UyfVIMHbEKIDXXsHi P5lSndMVlY8G1nOXVOIVS1v/T98DlBg= ARC-Authentication-Results: i=1; imf06.hostedemail.com; dkim=pass header.d=infradead.org header.s=bombadil.20210309 header.b=yI1+JGkK; dmarc=none; spf=none (imf06.hostedemail.com: domain of BATV+b97a0fc658bf3e588113+7459+infradead.org+hch@bombadil.srs.infradead.org has no SPF policy when checking 198.137.202.133) smtp.mailfrom=BATV+b97a0fc658bf3e588113+7459+infradead.org+hch@bombadil.srs.infradead.org ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1706173155; a=rsa-sha256; cv=none; b=uDdIFFDozpGplfu99nFtWVqBvTj/d/e+kaWNYnZg9LVtgCNn0iJPFKwhiN+Sy3jQI37VkQ QMjtDgxLMifN/QkRttDM23TM7/SZrpO+xHb7oWChNe0fNjjB8ndCXUoKobdQ8WOVrzCjJD X75rCHtnocrlji6lfi4z8uD+6IvhtVU= 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=W1Pg45e3YPveg08TzLy7LzAEvB67BYDtIDXVWrYOF4k=; b=yI1+JGkKxGm9WfeiG/b4Yka18x c1mXHaGCYgK6mkxGcVo5gAHbOKDx9+0SYzjipTUFCR7tVQHmx8jfKBwoUQSpzV0Hl0HSi6ZIxbk4X o+ZvB7bpE8nEto805bTnTxGxRhJsSbfgcVGM8+wIdOoEikiUBttNbyBcb1DNZ8s75wbzeVEW07tpZ qSvj6gzosLUHO646NIP3w95G/xf5aiufxBVQU+oWuTXercuNL6hOZVTSXRRdpOz7d754pCeI68r0r Fhvwk5s7Jrh9Acbu4JXBI1UWYk3FH9vxl0k/up76e5MCS4mN1NhPBCzaj0pMgfN7TGLtGYAFIzxdR l/0mO7bw==; 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 1rSvZq-007Qbq-19; Thu, 25 Jan 2024 08:59: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 Subject: [PATCH 19/19] writeback: simplify writeback iteration Date: Thu, 25 Jan 2024 09:57:58 +0100 Message-Id: <20240125085758.2393327-20-hch@lst.de> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20240125085758.2393327-1-hch@lst.de> References: <20240125085758.2393327-1-hch@lst.de> MIME-Version: 1.0 X-SRS-Rewrite: SMTP reverse-path rewritten from by bombadil.infradead.org. See http://www.infradead.org/rpr.html X-Rspamd-Queue-Id: B9CB7180002 X-Rspam-User: X-Rspamd-Server: rspam02 X-Stat-Signature: t1mp7d53bpzmnurr53mtf5k6hsndrpuf X-HE-Tag: 1706173155-290500 X-HE-Meta: U2FsdGVkX18thyNNuJwyojngFdGblC2t6+0emYWiRd+DiUWU/aAn0ObJDFOHo6nNkyaAZU0v7IC+p7hsdxs0HpepMtqi4RxD56UHUMgVdJQYUYWdqfuZBRxCtkvl8lfZPaKLCaySR9+yhGSQ3p1Eo4bQ+rykIrY2necKvAPyMAdjJtOi78Gzj/uVyTm5CW7z04uaCETD3QeiUS1Ihkc+dFKsZvWTQQydw+0pinj/sfTPit7iBfEwavsdH/kM8JSP0ojKN8kRYa0yXJrZfwJLK6J4vF6GMB49a7KdASmTau1KMDCelJ1aDDclZnfzE+FY8qjm4HtKB8cHloViSV//JIXBkPQtNjUIZj0/Td4n5ueDyZG5BiO9iJSyzY9ln1Oq7XAxUz6pChTRYp8FKRm+bJDfv3SIPnlD+RP0a8N8rLRoDtrKRCnZY9Ol7L9PkmF15QuzO6jIGQMHQoDC2JHxVkV3C/AZ/2/bSAP1QSn81FWbU/CKtF7wX6BPL05RzZhyeem26bfjBg+stlcHEX7ys9ZjyY2WlfYu6Z9A0oAuAb3dps0Oh3WOYb3yqtipR9JD9fhhY1eCf2GOWdKRaWld7ujeRFEY8Dr/9EvpoKlqJkDv0UMf+NC/+nua7DOcR/QdqGz3bHjqIRDgcmMa0DrKduuY8N6MfRnbau4hrv6poj5wZ8J3oPD/uPTpZosMxC4pWor1UOShaCzXoa1vOR/KAEGi7fFcRtu+jBjA0rsYDyZwBrA7TzESh4xWmfxrIUTdi/IuB+6VuryPZGSeJQq52aSVwBcEuLtppGHKK8Uv1JQX71rhNclT6nWZRj1isWIP8VoNkV8KSzGm+9RQJs7/hXkWWX9sWISsWbY+Bc57+Jqn9oQLJ8p/hp1TlIB3bNlpXjLA/Jmowj2NVa8SilbvjPhOwp6nxPofzsPzM+BrGcy/lzbr3Aa1XuIm8+v7ze3hv3xarJ+9lM485EG0cla skIPT8dH GpvqWyYJJMTeem9Qxwzu1zH9NpxeOZbeqoD+LGXwtBDj6TOj55fVIOa1iw4ZktVCZa3O0SeIdsPnielPKOrCNSoru+UbySJxxv8FV5Z8zGubPuc9Lu67WGSzQMspg5AvFTzodG/P00IbGFUHBi10lP5ZrocN6LiFvKB5k/3/4QPByYGDHAXGSdnyCmzGmUBeBG6GatgBCnldSlZI3ANuJsMEs8l6p0deBsGjB67fm2cOI/SQ0VSIjx5dVfJPCggXOMiYfEq8Hb5/ASiMp9rVruw+LG7BiTVZKcCFMdXJT8XFA7YM7IimYJxAfq8NQKEI6/Lv7y5S0H/ny+fFGxjxU85EcU9PJq5sfTMlF+nXrUN/PmBBu5rH5+szp6rWP2yUPcbMQu8w3cJQSNnWY5QnOC7rMFOF4Wg+SR99DC3KLpbm89z7DUgbJ/sRSXUO29AL7Lg3I X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: Based on the feedback from Jan I've tried to figure out how to avoid the error magic in the for_each_writeback_folio. This patch tries to implement this by switching to an open while loop over a single writeback_iter() function: while ((folio = writeback_iter(mapping, wbc, folio, &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. Additionally it moves the AOP_WRITEPAGE_ACTIVATE out of the iterator and into the callers, in preparation for eventually killing it off with the phase out of write_cache_pages(). To me this form of the loop feels easier to follow, and it has the added advantage that writeback_iter() can actually be nicely used in nested loops, which should help with further iterizing the iomap writeback code. Signed-off-by: Christoph Hellwig Reviewed-by: Jan Kara --- fs/iomap/buffered-io.c | 7 +- include/linux/writeback.h | 11 +-- mm/page-writeback.c | 174 +++++++++++++++++++++----------------- 3 files changed, 102 insertions(+), 90 deletions(-) diff --git a/fs/iomap/buffered-io.c b/fs/iomap/buffered-io.c index 58b3661f5eac9e..1593a783176ca2 100644 --- a/fs/iomap/buffered-io.c +++ b/fs/iomap/buffered-io.c @@ -1985,12 +1985,13 @@ iomap_writepages(struct address_space *mapping, struct writeback_control *wbc, struct iomap_writepage_ctx *wpc, const struct iomap_writeback_ops *ops) { - struct folio *folio; - int ret; + struct folio *folio = NULL; + int ret = 0; wpc->ops = ops; - for_each_writeback_folio(mapping, wbc, folio, ret) + while ((folio = writeback_iter(mapping, wbc, folio, &ret))) ret = iomap_do_writepage(folio, wbc, wpc); + if (!wpc->ioend) return ret; return iomap_submit_ioend(wpc, wpc->ioend, ret); diff --git a/include/linux/writeback.h b/include/linux/writeback.h index 2416da933440e2..fc4605627496fc 100644 --- a/include/linux/writeback.h +++ b/include/linux/writeback.h @@ -367,15 +367,8 @@ int balance_dirty_pages_ratelimited_flags(struct address_space *mapping, bool wb_over_bg_thresh(struct bdi_writeback *wb); -struct folio *writeback_iter_init(struct address_space *mapping, - struct writeback_control *wbc); -struct folio *writeback_iter_next(struct address_space *mapping, - struct writeback_control *wbc, struct folio *folio, int error); - -#define for_each_writeback_folio(mapping, wbc, folio, error) \ - for (folio = writeback_iter_init(mapping, wbc); \ - folio || ((error = wbc->err), false); \ - folio = writeback_iter_next(mapping, wbc, folio, error)) +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 2a4b5aee5decd9..9e1cce9be63524 100644 --- a/mm/page-writeback.c +++ b/mm/page-writeback.c @@ -2360,29 +2360,6 @@ void tag_pages_for_writeback(struct address_space *mapping, } EXPORT_SYMBOL(tag_pages_for_writeback); -static void writeback_finish(struct address_space *mapping, - struct writeback_control *wbc, pgoff_t done_index) -{ - folio_batch_release(&wbc->fbatch); - - /* - * 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) { - if (wbc->err || wbc->nr_to_write <= 0) - mapping->writeback_index = done_index; - else - mapping->writeback_index = 0; - } -} - static xa_mark_t wbc_to_tag(struct writeback_control *wbc) { if (wbc->sync_mode == WB_SYNC_ALL || wbc->tagged_writepages) @@ -2442,10 +2419,8 @@ 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) { - writeback_finish(mapping, wbc, 0); + if (!folio) return NULL; - } } folio_lock(folio); @@ -2458,60 +2433,92 @@ static struct folio *writeback_get_folio(struct address_space *mapping, return folio; } -struct folio *writeback_iter_init(struct address_space *mapping, - struct writeback_control *wbc) -{ - if (wbc->range_cyclic) - wbc->index = mapping->writeback_index; /* prev offset */ - else - wbc->index = wbc->range_start >> PAGE_SHIFT; - - if (wbc->sync_mode == WB_SYNC_ALL || wbc->tagged_writepages) - tag_pages_for_writeback(mapping, wbc->index, wbc_end(wbc)); - - wbc->err = 0; - folio_batch_init(&wbc->fbatch); - return writeback_get_folio(mapping, wbc); -} - -struct folio *writeback_iter_next(struct address_space *mapping, - struct writeback_control *wbc, struct folio *folio, int error) +/** + * writepage_iter - iterate folio of a mapping for writeback + * @mapping: address space structure to write + * @wbc: writeback context + * @folio: previously iterated folio (%NULL to start) + * @error: in-out pointer for writeback errors (see below) + * + * This function should be called in a while loop in the ->writepages + * implementation and returns the next folio for the writeback operation + * described by @wbc on @mapping. + * + * To start writeback @folio should be passed as NULL, for every following + * iteration the folio returned by this function previously should be passed. + * @error should contain the error from the previous writeback iteration when + * calling writeback_iter. + * + * 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. + */ +struct folio *writeback_iter(struct address_space *mapping, + struct writeback_control *wbc, struct folio *folio, int *error) { - unsigned long nr = folio_nr_pages(folio); + if (folio) { + wbc->nr_to_write -= folio_nr_pages(folio); + if (*error && !wbc->err) + wbc->err = *error; - wbc->nr_to_write -= nr; - - /* - * Handle the legacy AOP_WRITEPAGE_ACTIVATE magic return value. - * Eventually all instances should just unlock the folio themselves and - * return 0; - */ - if (error == AOP_WRITEPAGE_ACTIVATE) { - folio_unlock(folio); - error = 0; + /* + * For integrity sync we have to keep going until we have + * written all the folios we tagged for writeback prior to + * entering the writeback loop, even if we run past + * wbc->nr_to_write or encounter errors. + * + * This is because the file system may still have state to clear + * for each folio. We'll eventually return the first error + * encountered. + * + * For background writeback just push done_index past this folio + * so that we can just restart where we left off and media + * errors won't choke writeout for the entire file. + */ + if (wbc->sync_mode == WB_SYNC_NONE && + (wbc->err || wbc->nr_to_write <= 0)) + goto finish; + } else { + if (wbc->range_cyclic) + wbc->index = mapping->writeback_index; /* prev offset */ + else + wbc->index = wbc->range_start >> PAGE_SHIFT; + if (wbc->sync_mode == WB_SYNC_ALL || wbc->tagged_writepages) + tag_pages_for_writeback(mapping, wbc->index, + wbc_end(wbc)); + folio_batch_init(&wbc->fbatch); + wbc->err = 0; } - if (error && !wbc->err) - wbc->err = error; + folio = writeback_get_folio(mapping, wbc); + if (!folio) + goto finish; + return folio; + +finish: + folio_batch_release(&wbc->fbatch); /* - * For integrity sync we have to keep going until we have written all - * the folios we tagged for writeback prior to entering the writeback - * loop, even if we run past wbc->nr_to_write or encounter errors. - * This is because the file system may still have state to clear for - * each folio. We'll eventually return the first error encountered. + * 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 background writeback just push done_index past this folio so that - * we can just restart where we left off and media errors won't choke - * writeout for the entire 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->sync_mode == WB_SYNC_NONE && - (wbc->err || wbc->nr_to_write <= 0)) { - writeback_finish(mapping, wbc, folio->index + nr); - return NULL; + if (wbc->range_cyclic) { + WARN_ON_ONCE(wbc->sync_mode != WB_SYNC_NONE); + if (wbc->err || wbc->nr_to_write <= 0) + mapping->writeback_index = + folio->index + folio_nr_pages(folio); + else + mapping->writeback_index = 0; } - - return writeback_get_folio(mapping, wbc); + *error = wbc->err; + return NULL; } /** @@ -2549,13 +2556,18 @@ int write_cache_pages(struct address_space *mapping, struct writeback_control *wbc, writepage_t writepage, void *data) { - struct folio *folio; - int error; + struct folio *folio = NULL; + int error = 0; - for_each_writeback_folio(mapping, wbc, folio, 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 wbc->err; + return error; } EXPORT_SYMBOL(write_cache_pages); @@ -2563,13 +2575,17 @@ static int writeback_use_writepage(struct address_space *mapping, struct writeback_control *wbc) { struct blk_plug plug; - struct folio *folio; - int err; + struct folio *folio = 0; + int err = 0; blk_start_plug(&plug); - for_each_writeback_folio(mapping, wbc, folio, err) { + 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); @@ -2590,6 +2606,8 @@ int do_writepages(struct address_space *mapping, struct writeback_control *wbc) ret = mapping->a_ops->writepages(mapping, wbc); } else if (mapping->a_ops->writepage) { ret = writeback_use_writepage(mapping, wbc); + if (!ret) + ret = wbc->err; } else { /* deal with chardevs and other special files */ ret = 0;