From patchwork Mon Dec 18 15:35:37 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christoph Hellwig X-Patchwork-Id: 180491 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7300:24d3:b0:fb:cd0c:d3e with SMTP id r19csp1326777dyi; Mon, 18 Dec 2023 07:37:05 -0800 (PST) X-Google-Smtp-Source: AGHT+IETofxz9983aPYI0Z3GEh6m2niTSugq8Fo7lu0Si43vsQ3xNknXB2haplFNxU+dK81iNA5d X-Received: by 2002:a05:620a:640e:b0:77e:fba3:a7bb with SMTP id pz14-20020a05620a640e00b0077efba3a7bbmr14908561qkn.153.1702913825656; Mon, 18 Dec 2023 07:37:05 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1702913825; cv=none; d=google.com; s=arc-20160816; b=gg3KXx5RxN5zbphiDfm30sxB8Z0Zlv68d6abRrMN6kebv9bXXtvt/yr+ErBzbNSr8v OpFNLCqNGccOvcnEcAXykTX2N4iIs6r+UTCTh2r7ZcEeRNJWjy8JRYLKaFjQ1gapVald 4uIMYE0zYCaAlMc45ma39QxDD/XOADEWhaXBjjjBZnB2zZSGNbnwXVla7J5Iukm12RMP I8f0WBph2EP5ewq2B8Or8Blgr+iRp8R0YU2PYX5hfLlY1XO12GNli3vOUryWBBH1tgmv leDXSYwqQ/GT23J3R6z5RE73gKW/hlue/plBxZGwmXan4pt1paZRW9rs+EZlIGe5rifK w7Bg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :date:subject:cc:to:from:dkim-signature; bh=fOpePqIlVODGcmo3HFeeBH3g3RORLTSl2mjzxWXksuo=; fh=m0HBXuwgOCKat7wyuY7vstPypqMqxNmINnjBv5+EUjU=; b=X3gIasRtaZJIodckJ6NQ+8DJ0ZV/R7u6uOfelTinyeOdPfyy3Ueqn5seFREj+th56X 2nFHjmg0RMVwv2ao2P9/uonCD1Ms+4cAYQarq/J4pgwzAleCuRukHW4qrL/Wpxi3Tvtc oeEy6OJ1ev8iQBP3/A9N8DTMYvb0M3p+gdqTPCNlKxR+KeeQRqYsMIf5VtrekGr4xrix xXws7LDFHqJEz2aZPF1jRPCHwISCCPZwhM0PRr8tO+ZOw7c0hPeZC3FHGFJ+2yP+46Zy u221wzprl3d46xXYPypwqX96Q0rpm7No6TJm5HkFV+wpIRad7gfwmLnr2dNE/yjZh0Jv Q4bA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@infradead.org header.s=bombadil.20210309 header.b="ef/z6OGi"; spf=pass (google.com: domain of linux-kernel+bounces-3944-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-3944-ouuuleilei=gmail.com@vger.kernel.org" Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [147.75.199.223]) by mx.google.com with ESMTPS id v3-20020a05620a440300b0077fb410f618si7737603qkp.661.2023.12.18.07.37.05 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 18 Dec 2023 07:37:05 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-3944-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) client-ip=147.75.199.223; Authentication-Results: mx.google.com; dkim=pass header.i=@infradead.org header.s=bombadil.20210309 header.b="ef/z6OGi"; spf=pass (google.com: domain of linux-kernel+bounces-3944-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-3944-ouuuleilei=gmail.com@vger.kernel.org" Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ny.mirrors.kernel.org (Postfix) with ESMTPS id 70BD81C24811 for ; Mon, 18 Dec 2023 15:37:05 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id E2A493A1D4; Mon, 18 Dec 2023 15:36:06 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=infradead.org header.i=@infradead.org header.b="ef/z6OGi" X-Original-To: linux-kernel@vger.kernel.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id D8C9A4236F; Mon, 18 Dec 2023 15:36:00 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=lst.de Authentication-Results: smtp.subspace.kernel.org; spf=none smtp.mailfrom=bombadil.srs.infradead.org DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=bombadil.20210309; h=Content-Transfer-Encoding: MIME-Version:References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From:Sender :Reply-To:Content-Type:Content-ID:Content-Description; bh=fOpePqIlVODGcmo3HFeeBH3g3RORLTSl2mjzxWXksuo=; b=ef/z6OGiym6VMWNndQHzrgSssf EBETFKYXoYJJtNq1C9mH3HuQTgUYIICMzdd+RJk8f+bqPeZKgzvB9r5denj/kjl/6Rx1laQB+QPKl DO3ufG2jER5Chm9x/qyjOt395t6P9gk68QkXovUQH5R59J5O3aMBsHkdqZnw8EXlo+8WSOXh2CyCo mGbZti/G13+GR2IhJD4QsOC5HvnTbrBUPuDxuY/KTbu8mGypWYmtg04XB2h+fqEHuLSDGv7gKBIqB miSSHI1Dm4Q6uZ/1EpT8SkEKNlarqS5kEziIicr0rCyU/RxykqvJqeHnylZgKnTxUOQqQ9FAasDJQ 4J/FaIDg==; 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 1rFFev-00BEH0-0h; Mon, 18 Dec 2023 15:35:57 +0000 From: Christoph Hellwig To: linux-mm@kvack.org Cc: "Matthew Wilcox (Oracle)" , Jan Kara , David Howells , Brian Foster , linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH 01/17] writeback: fix done_index when hitting the wbc->nr_to_write Date: Mon, 18 Dec 2023 16:35:37 +0100 Message-Id: <20231218153553.807799-2-hch@lst.de> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20231218153553.807799-1-hch@lst.de> References: <20231218153553.807799-1-hch@lst.de> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-SRS-Rewrite: SMTP reverse-path rewritten from by bombadil.infradead.org. See http://www.infradead.org/rpr.html X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1785634567596398194 X-GMAIL-MSGID: 1785634567596398194 When write_cache_pages finishes writing out a folio, it fails to update done_inde 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 --- mm/page-writeback.c | 1 + 1 file changed, 1 insertion(+) diff --git a/mm/page-writeback.c b/mm/page-writeback.c index ee2fd6a6af4072..b13ea243edb6b2 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 Mon Dec 18 15:35:38 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christoph Hellwig X-Patchwork-Id: 180500 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7300:24d3:b0:fb:cd0c:d3e with SMTP id r19csp1328539dyi; Mon, 18 Dec 2023 07:40:06 -0800 (PST) X-Google-Smtp-Source: AGHT+IFiV/iy8EllSEqJpIw/7VwM198iBoYxLDAbnVsDgwGHLfA/3Je8Xd3WrGo6AdfsBmNROi/l X-Received: by 2002:a05:6a20:a125:b0:190:490b:39da with SMTP id q37-20020a056a20a12500b00190490b39damr22815329pzk.59.1702914005626; Mon, 18 Dec 2023 07:40:05 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1702914005; cv=none; d=google.com; s=arc-20160816; b=UTE00ZK0ZuV3LFaOOF9hIFXvbSF5C0k/CFy7piqkOl5fXgwK+DSsAZIWkP+uS6nE3a vdOJ0otTIZAKvh4oB7cQ3ICwBCaJ5nm4oyXzBaQzMcN+AYcx28jAdskt9IwNYN4FlAP8 JrQFlBgbyoNdcqDDDleeai3FtljDcFae6lXIW8jLnxamvV3vZU3O67UVtmLdrpe0vTgd lYy6Sz5ep3hkhXZHLhEp8cFbRCScHVi8YdDvQ17+3EHJ2bnqcI4w7LIbym2D6x4OehFV 2C5DtyJGHo1hswxQ5T8GiDI7dO9KhK7XLptmcaPv/6+A4qsOzS052TtWmDRiwGmOGU0B JaAQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :date:subject:cc:to:from:dkim-signature; bh=7163FLdiULRyCtlx5MbrRVNBpAWhlO7V2EZv7W3gfys=; fh=m0HBXuwgOCKat7wyuY7vstPypqMqxNmINnjBv5+EUjU=; b=xKAJX3ZpHD0/8tUQCDTZ1KMaO8D7sj0PB4qFS6EYrZajz4A2T3ucG+syONs7i6Hvy1 HEkjp6gC+lfJgGBC6gO6XKZLoPRasv+L1YGpkgl0Wj7marmbJ171K39HGS2TwvRRx4Fb +1YbYGD3YBTosiuHWXTdZA3jscbNjRVLsfJ3BYZOsLMhI/p6bfkqPNISOsWoCMv8Kxeo 6lWfv63Tgwyva6yOzY+fYUBcZAyhW7sEMqFfykoubNlVhQ2jwjwFLRmlC6byqP/8K/KS b8B7hRAhDXwfSn5bOK7N171FOKTuFVTmYQSLIVxTGjxM7HoYS3wottp967KETKlicer1 AWZQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@infradead.org header.s=bombadil.20210309 header.b=3ZpRbR4d; spf=pass (google.com: domain of linux-kernel+bounces-3946-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) smtp.mailfrom="linux-kernel+bounces-3946-ouuuleilei=gmail.com@vger.kernel.org" Received: from sy.mirrors.kernel.org (sy.mirrors.kernel.org. [147.75.48.161]) by mx.google.com with ESMTPS id c4-20020a63ef44000000b005b834096959si17973762pgk.851.2023.12.18.07.40.05 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 18 Dec 2023 07:40:05 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-3946-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) client-ip=147.75.48.161; Authentication-Results: mx.google.com; dkim=pass header.i=@infradead.org header.s=bombadil.20210309 header.b=3ZpRbR4d; spf=pass (google.com: domain of linux-kernel+bounces-3946-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) smtp.mailfrom="linux-kernel+bounces-3946-ouuuleilei=gmail.com@vger.kernel.org" Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sy.mirrors.kernel.org (Postfix) with ESMTPS id 4FEE8B23406 for ; Mon, 18 Dec 2023 15:37:48 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 840C63D57B; Mon, 18 Dec 2023 15:36:12 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=infradead.org header.i=@infradead.org header.b="3ZpRbR4d" X-Original-To: linux-kernel@vger.kernel.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 99AC34FF7C; Mon, 18 Dec 2023 15:36:07 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=lst.de Authentication-Results: smtp.subspace.kernel.org; spf=none smtp.mailfrom=bombadil.srs.infradead.org DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=bombadil.20210309; h=Content-Transfer-Encoding: MIME-Version:References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From:Sender :Reply-To:Content-Type:Content-ID:Content-Description; bh=7163FLdiULRyCtlx5MbrRVNBpAWhlO7V2EZv7W3gfys=; b=3ZpRbR4dzIQW6XHwppDqZ0VacY /+zRsMPUMvnF7Sy5qNbH115aR7DDOQvaHRu710B91NeXzplfp3qTlgw7xfv0KrcyWORdshwnkkTmA wBgJWLmbwKN5wKEgBZ0dNa1dWgFi/CFzWBohlP/g028rqSTZvYH+R18Xwim7yG1K7ATbdoWKJVTTk eYplI3MAGnKoB0nLg8K150hBAhpd9H2ehkExYxakdZNWBLN5nTWldq39fKlzTGSPHfUsFl47/nG4W Kb5D26H9trc75XVfWUbmdH/gddMp2u//JG6HZRNz6kFm7Mt3YMVvl1fA/LFDPemXhHP/apthEfVde SioTXypQ==; 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 1rFFex-00BEI3-2w; Mon, 18 Dec 2023 15:36:00 +0000 From: Christoph Hellwig To: linux-mm@kvack.org Cc: "Matthew Wilcox (Oracle)" , Jan Kara , David Howells , Brian Foster , linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH 02/17] writeback: also update wbc->nr_to_write on writeback failure Date: Mon, 18 Dec 2023 16:35:38 +0100 Message-Id: <20231218153553.807799-3-hch@lst.de> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20231218153553.807799-1-hch@lst.de> References: <20231218153553.807799-1-hch@lst.de> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-SRS-Rewrite: SMTP reverse-path rewritten from by bombadil.infradead.org. See http://www.infradead.org/rpr.html X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1785634756445416949 X-GMAIL-MSGID: 1785634756445416949 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 simply the code, so do it. Signed-off-by: Christoph Hellwig Reviewed-by: Jan Kara --- 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 b13ea243edb6b2..8e312d73475646 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 Mon Dec 18 15:35:39 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christoph Hellwig X-Patchwork-Id: 180493 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7300:24d3:b0:fb:cd0c:d3e with SMTP id r19csp1327084dyi; Mon, 18 Dec 2023 07:37:36 -0800 (PST) X-Google-Smtp-Source: AGHT+IFX8DysRHA2kBToMX+WzytCw6zp85dO9ZTM4VXcFIVDarJzjcKLGuI1boPJ7bAS/YYUqqBU X-Received: by 2002:a05:620a:2489:b0:77f:34bf:5593 with SMTP id i9-20020a05620a248900b0077f34bf5593mr26802215qkn.17.1702913856037; Mon, 18 Dec 2023 07:37:36 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1702913856; cv=none; d=google.com; s=arc-20160816; b=lTPwUq1N+mImvO/JlQ4wr4bF1GDxGYHm3jxWVQwQ2khc/zcw1RdiV77anCG1KfgLSd MlpCwgWKCagGXvLtEV7u391nlEgVEE3SR1Ok7C4tQ2+0YgUXjo9lw60PT+Epm/ZvzvJE 0oOGGLGF8kH06LLC44+Wdr0n8pt1v79KdKPsp8Is/+UCct+gt055XHVcd0FawTRYsOPP M+2lyu5TioKj0iwSdYc3+snNqsBVjTKOfsuWjX7C9mTWn9LhJV/CFCE3RrA3deQATAfv VkaTS5zDKjdFTnOzZNtwLjUZCq/0lTDBS3ZO5A4e/1UPL/Gcw13KAcDOH5mZuT85EsFv Azyg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :date:subject:cc:to:from:dkim-signature; bh=SkcRys0g0eAUf8/FxArC7DdEKspx8sFQujh+FCrTtN4=; fh=m0HBXuwgOCKat7wyuY7vstPypqMqxNmINnjBv5+EUjU=; b=sk59IaP+/Ekr4WaFnviEEaqqm/82VANJswl6xMLlzbIi+PqyR2rX0uYxNls7UZbpQh ByGinx9q087jxR9wZ086mOH7K3NzK55SfSSdPQQ5JY646rxGyoZG90BnE+Ztbp2ddoFC o/E81lLwUR6uTfCNLQzyont90ADX40OSUldcFniugbvc8/PYl3ZgbnrFC8RzUIfZ8dAH +q25iaWIsKL3jyi6/dFEDNK8U3otobiaCbdHJzjFhdBEr6KwJTaGiY/Hi/WT9fehFro2 ZarLEbqeBkApMq9kP4GD3T6Yr/lSTQayJk3vOyqVJHOWVNcAwe580vYhXXa6/fZvx5AL s+8Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@infradead.org header.s=bombadil.20210309 header.b=wv7lyBIR; spf=pass (google.com: domain of linux-kernel+bounces-3945-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-3945-ouuuleilei=gmail.com@vger.kernel.org" Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [147.75.199.223]) by mx.google.com with ESMTPS id pe34-20020a05620a852200b0077d7c33e00bsi13965869qkn.369.2023.12.18.07.37.35 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 18 Dec 2023 07:37:36 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-3945-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) client-ip=147.75.199.223; Authentication-Results: mx.google.com; dkim=pass header.i=@infradead.org header.s=bombadil.20210309 header.b=wv7lyBIR; spf=pass (google.com: domain of linux-kernel+bounces-3945-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-3945-ouuuleilei=gmail.com@vger.kernel.org" Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ny.mirrors.kernel.org (Postfix) with ESMTPS id C91081C249F9 for ; Mon, 18 Dec 2023 15:37:35 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id D5B3E5A84E; Mon, 18 Dec 2023 15:36:10 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=infradead.org header.i=@infradead.org header.b="wv7lyBIR" X-Original-To: linux-kernel@vger.kernel.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 966BF4FF74; Mon, 18 Dec 2023 15:36:06 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=lst.de Authentication-Results: smtp.subspace.kernel.org; spf=none smtp.mailfrom=bombadil.srs.infradead.org DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=bombadil.20210309; h=Content-Transfer-Encoding: MIME-Version:References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From:Sender :Reply-To:Content-Type:Content-ID:Content-Description; bh=SkcRys0g0eAUf8/FxArC7DdEKspx8sFQujh+FCrTtN4=; b=wv7lyBIRNIQLwC91K/1xIPUpmW 14UXm/U10zKWL8yi3CuNad4Wvj16dy3mlQm0OVgg9NbwoDwc9qHaPbHXu2UjDhtjk2lWCXoBQfv5y YEpJvvDmZco1oWzVjD3D1Bgi4x8XaNM+D43GKOOpJzTHkDmAlPg/KuQswq8wrsi4bfjwuTjO/hdvm dUdZUwx4kWJO8dxO3K/HNOHsO1nztgCOjXKRGJ3UzIgnl6x1j4KIzYPFncrhFFqH64N2gYSfK/F7I wirO6bPgiOsKjEkwmyDnPYkuODr8U12dz5uP43SplWoRAOxukXhfL16C6CpPgTpzEr6QuMYcez9D6 2LhabeBQ==; 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 1rFFf1-00BEIj-0m; Mon, 18 Dec 2023 15:36:03 +0000 From: Christoph Hellwig To: linux-mm@kvack.org Cc: "Matthew Wilcox (Oracle)" , Jan Kara , David Howells , Brian Foster , linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH 03/17] writeback: rework the loop termination condition in write_cache_pages Date: Mon, 18 Dec 2023 16:35:39 +0100 Message-Id: <20231218153553.807799-4-hch@lst.de> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20231218153553.807799-1-hch@lst.de> References: <20231218153553.807799-1-hch@lst.de> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-SRS-Rewrite: SMTP reverse-path rewritten from by bombadil.infradead.org. See http://www.infradead.org/rpr.html X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1785634599757554495 X-GMAIL-MSGID: 1785634599757554495 Rework 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. 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 --- 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 8e312d73475646..7ed6c2bc8dd51c 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 Mon Dec 18 15:35:40 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christoph Hellwig X-Patchwork-Id: 180496 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7300:24d3:b0:fb:cd0c:d3e with SMTP id r19csp1327725dyi; Mon, 18 Dec 2023 07:38:36 -0800 (PST) X-Google-Smtp-Source: AGHT+IHs4n5z+dBA1yhWO7rfbrwsR9+K9gd1LYvT2mW1nqvUnFf7Vcd8GyD83t7M1poFcGpYybZw X-Received: by 2002:a05:6a20:8e04:b0:18c:ba47:74ea with SMTP id y4-20020a056a208e0400b0018cba4774eamr19901627pzj.31.1702913915881; Mon, 18 Dec 2023 07:38:35 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1702913915; cv=none; d=google.com; s=arc-20160816; b=kc3sMyyyN4p8iOsfB2HE4E09JQAhaDXrX50PDBMMoJjoVbtvXN5E5ajTWBmPsFaHoM khRUtDKhDftfOt2hrVtt+1FnnUKxAqq2aKL9N854e5K7Y3TNTh4BNGDADfG32Lr1399+ 97aMRzwFI+fF35GWFzGprBJQbs+koIWshaA6u1qjtbq/N9ezn3rmiRSsGKV7OpKdqyVU XrqUReD4ebs93KVtljbGyVy5bU9kHFDq1jCllUdXP+Y08M3ufF9jyB5aBoFTyUVkuo8J lSJICuCW7g81WaaUcxKFxiTjtZ4ANUzqh4d4WomjJ1jsBNBXmoYsGKJM9gstXOOBjJ/7 LRTg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :date:subject:cc:to:from:dkim-signature; bh=fDBIexIwQQEq1Dyw3cSe2v/4ysO2ouYCXslUPJX9cLQ=; fh=m0HBXuwgOCKat7wyuY7vstPypqMqxNmINnjBv5+EUjU=; b=a28h4B6hSvVF2Ahynu+KYvd65i5kFnIZ1NNvndp9jdVS7vA8rQX6QA/vEtfV1phEQr 2wrHcuRJM6moP9lTZx3mo4YSkfttbFf30wvj+huAG6wQIJXdL+l20wGLCET57iOhoumD ULRsRgM/6FA8YKRiCPuDSsYYd6+prshyfTSiPQJt5jG4OutQ17/fshiRiHnj4ecn3XdJ TxwZdEJkBY6Lwva5ORpoxIZbGduk4Kxn4gLSpKCWEORMiC4kFHMZVdK+yyrnnZlgfdt4 8Y08rr9A9xHhzz+XMmdrbeOqy15LExtkqEGZ2pIJJEFAH9BDgNjaNCctUVxJ9egvpcXg DGZA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@infradead.org header.s=bombadil.20210309 header.b=VdO2027f; spf=pass (google.com: domain of linux-kernel+bounces-3948-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-3948-ouuuleilei=gmail.com@vger.kernel.org" Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [2604:1380:45e3:2400::1]) by mx.google.com with ESMTPS id bt21-20020a056a00439500b006d511505de0si3284519pfb.166.2023.12.18.07.38.35 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 18 Dec 2023 07:38:35 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-3948-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) client-ip=2604:1380:45e3:2400::1; Authentication-Results: mx.google.com; dkim=pass header.i=@infradead.org header.s=bombadil.20210309 header.b=VdO2027f; spf=pass (google.com: domain of linux-kernel+bounces-3948-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-3948-ouuuleilei=gmail.com@vger.kernel.org" Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sv.mirrors.kernel.org (Postfix) with ESMTPS id A6125283B54 for ; Mon, 18 Dec 2023 15:38:35 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 2E2D75D721; Mon, 18 Dec 2023 15:36:17 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=infradead.org header.i=@infradead.org header.b="VdO2027f" X-Original-To: linux-kernel@vger.kernel.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 2DF1C5A865; Mon, 18 Dec 2023 15:36:13 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=lst.de Authentication-Results: smtp.subspace.kernel.org; spf=none smtp.mailfrom=bombadil.srs.infradead.org DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=bombadil.20210309; h=Content-Transfer-Encoding: MIME-Version:References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From:Sender :Reply-To:Content-Type:Content-ID:Content-Description; bh=fDBIexIwQQEq1Dyw3cSe2v/4ysO2ouYCXslUPJX9cLQ=; b=VdO2027fZSQ6+ARV1T/HY1vjUJ qO+GRQF4owYZjioIiUVuSwZTEQ/cN/nrg5ibAjNHnyq/cr4zSGzlcM3y2Q1UMgHoJjGN5t8V1EETI Dpwa6PCMko3S+HiZS52aj4OQNyFjw58ZygjiHjXBfLsvnE/Xaz+CYmUQUEyXNr1g8ps8aTfa+ueqv L5OSfZ0qwYzFm6wuHHBT8kMKqm3isVDi4DjtWHI7vcv8A1rqKaok+5uIIQfDRfIgfvKrprHGmV/PM XheCITb/c+GkDmqgc2t1vJgBr7RoVG3iJpGyIdSONPMKpgv5v6LKHArfqGzB8I/iBFTcGlAch4WA7 2FJMcPyw==; 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 1rFFf3-00BEKx-2M; Mon, 18 Dec 2023 15:36:06 +0000 From: Christoph Hellwig To: linux-mm@kvack.org Cc: "Matthew Wilcox (Oracle)" , Jan Kara , David Howells , Brian Foster , linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH 04/17] writeback: only update ->writeback_index for range_cyclic writeback Date: Mon, 18 Dec 2023 16:35:40 +0100 Message-Id: <20231218153553.807799-5-hch@lst.de> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20231218153553.807799-1-hch@lst.de> References: <20231218153553.807799-1-hch@lst.de> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-SRS-Rewrite: SMTP reverse-path rewritten from by bombadil.infradead.org. See http://www.infradead.org/rpr.html X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1785634662105589684 X-GMAIL-MSGID: 1785634662105589684 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 --- 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 7ed6c2bc8dd51c..c798c0d6d0abb4 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 Mon Dec 18 15:35:41 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christoph Hellwig X-Patchwork-Id: 180495 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7300:24d3:b0:fb:cd0c:d3e with SMTP id r19csp1327693dyi; Mon, 18 Dec 2023 07:38:32 -0800 (PST) X-Google-Smtp-Source: AGHT+IEhV2O/pdw3FzDGub/9p5rTZQZt/ysMY5I32Kmag/g+puQYrMGJ0LF+WRecXJaQSbB+eG8S X-Received: by 2002:a05:622a:1646:b0:423:6eb5:c18b with SMTP id y6-20020a05622a164600b004236eb5c18bmr23191223qtj.50.1702913912554; Mon, 18 Dec 2023 07:38:32 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1702913912; cv=none; d=google.com; s=arc-20160816; b=P1ela9wplq45xGj4D2TYktWvWcbMDAozBVMV8lpH/10GHXL9vM3Au1memv7+n4S+lf r5dKvRr3pf+ehP62F8M0vQRy4CvEEpspspH/7C2hwaCmKI5DnHgmfO69mqM45aItWLjo hyEnS7+9hXqQOJwQVvF1Lf5Uyr7xV0uocwJCAISAcxoqjOo3dbwFtubWfj2yzEEnE8MU 4YFt3vHE4h8K46bThDuJL6rvQVPp5bMpCMwjdYqxLwv1G5yoDJbq/mT/u7iRH1eCFoM3 /r/Q4V+Rk1vkvGnfVn5NPaSsnP0vevN4iTck3kWkfP9FDwHSG7DBOlinkvWiae4qHSkA zK3g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :date:subject:cc:to:from:dkim-signature; bh=36T96oIsRQC1BPzxAOWfEESJ9XwkyWKz6mizx5levB4=; fh=m0HBXuwgOCKat7wyuY7vstPypqMqxNmINnjBv5+EUjU=; b=Zlm7sy4fXVOQwwuP+8ArILVCqX0XuAP+5Bgil8V+I44C9SpJjWDaVE2Yvb88Dl9iCu V5XH7pvJG2al3H2vNIv+RzaieSaMabgx8njbkd7488SpyKp4ffm0wG5eqvd2ZanvFNll qfmcr/okxw1o0rKgzeszztevGvhAZ55Q4bt8I1098NfsvKO2VGWQ5V4n6Vg8R+l6znLz DImez8YgFjyfVcEdBDL8buHiX4pAUykMeBdKuCWBc5zzIUwZct5W+pCyrYabrbNPNq9h GwHiae3LigkKkg9vl+Vywl/WVGI+hLfC7k/Vf/asQNxJhOiYd+8FZ1pgE7uJkUwaSnE6 vA/A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@infradead.org header.s=bombadil.20210309 header.b=42baJCQw; spf=pass (google.com: domain of linux-kernel+bounces-3947-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-3947-ouuuleilei=gmail.com@vger.kernel.org" Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [147.75.199.223]) by mx.google.com with ESMTPS id fd12-20020a05622a4d0c00b0042588bbca5csi24776068qtb.716.2023.12.18.07.38.32 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 18 Dec 2023 07:38:32 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-3947-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) client-ip=147.75.199.223; Authentication-Results: mx.google.com; dkim=pass header.i=@infradead.org header.s=bombadil.20210309 header.b=42baJCQw; spf=pass (google.com: domain of linux-kernel+bounces-3947-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-3947-ouuuleilei=gmail.com@vger.kernel.org" Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ny.mirrors.kernel.org (Postfix) with ESMTPS id 587041C241F7 for ; Mon, 18 Dec 2023 15:38:32 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 00FBB5BFB9; Mon, 18 Dec 2023 15:36:17 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=infradead.org header.i=@infradead.org header.b="42baJCQw" X-Original-To: linux-kernel@vger.kernel.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 2289F5A86A; Mon, 18 Dec 2023 15:36:13 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=lst.de Authentication-Results: smtp.subspace.kernel.org; spf=none smtp.mailfrom=bombadil.srs.infradead.org DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=bombadil.20210309; h=Content-Transfer-Encoding: MIME-Version:References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From:Sender :Reply-To:Content-Type:Content-ID:Content-Description; bh=36T96oIsRQC1BPzxAOWfEESJ9XwkyWKz6mizx5levB4=; b=42baJCQw3pOImDKmFbkkzEpkVQ 5NCVTCjUI/QZvG9jAZnUK4eyKqg84LJYQzNjtFggZSHzUQbx3wv/0y5vf20tJEpkPcN4clo+C8Gah damfhaw5voBLIumLJ7gGslg3H01RWcXG2RyNByfC6JWSnPfezp2VXRvqa9TlemNsnsh6fx90vCdNE QCybiqW+qDXQzcNbVC29SchVdBVODfmFbi1d6AxVM31jdqZAPxo9rQ9vPyfHTafY12LbYBVYOTs+2 oPjMMUHHR1Xbnti7JO9/8/ZtRt3YHFmxVv/j0Ngpl7h4Q3yavIoFQtGXYJSeX3ABChPl9NCimD7kx jSDTxgNw==; 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 1rFFf6-00BELm-1G; Mon, 18 Dec 2023 15:36:09 +0000 From: Christoph Hellwig To: linux-mm@kvack.org Cc: "Matthew Wilcox (Oracle)" , Jan Kara , David Howells , Brian Foster , linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH 05/17] writeback: remove a duplicate prototype for tag_pages_for_writeback Date: Mon, 18 Dec 2023 16:35:41 +0100 Message-Id: <20231218153553.807799-6-hch@lst.de> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20231218153553.807799-1-hch@lst.de> References: <20231218153553.807799-1-hch@lst.de> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-SRS-Rewrite: SMTP reverse-path rewritten from by bombadil.infradead.org. See http://www.infradead.org/rpr.html X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1785634658640240187 X-GMAIL-MSGID: 1785634658640240187 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 --- include/linux/writeback.h | 2 -- 1 file changed, 2 deletions(-) diff --git a/include/linux/writeback.h b/include/linux/writeback.h index 083387c00f0c8b..833ec38fc3e0c9 100644 --- a/include/linux/writeback.h +++ b/include/linux/writeback.h @@ -364,8 +364,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 Mon Dec 18 15:35:42 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christoph Hellwig X-Patchwork-Id: 180497 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7300:24d3:b0:fb:cd0c:d3e with SMTP id r19csp1327853dyi; Mon, 18 Dec 2023 07:38:51 -0800 (PST) X-Google-Smtp-Source: AGHT+IEWl2rKqf/fyKZgmNRzvH6n5OEuw93C75IbuI/MnQ+qD8V1DKK6kgka85sf+AxCkoG6ME0A X-Received: by 2002:a05:6a00:9381:b0:6d5:8f70:f52d with SMTP id ka1-20020a056a00938100b006d58f70f52dmr3548278pfb.17.1702913931635; Mon, 18 Dec 2023 07:38:51 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1702913931; cv=none; d=google.com; s=arc-20160816; b=PFB5StnC6eR7ZJteWKanZjyvfLhtoyvS0CwJg7+6DV4XKow2Nx45sdpgc7OhOuQxfw /oztet0mNBXpXdkvSGCzG8GJ45w8OJ4j9vv1hMkDssl0PvvGvvw2pol5rSI7PFN8ad0K GzPSUkD4RX/mPI4ID8PJMdlytiRCujgrOnbEwBQwUiyE86pL92eyO57Cs0EWduhASn0R 945qXD8zC8qfNZjsfalyK3tMx/8LLHxhKUCf3MD/m1wTVHxmuIXH9RxJFTJr38S05xJJ wzxYdvuimjyvPBKspJlVyjzE1rSPRgf8WM2Bw3NtMC+dNZevQJudiEevqjT2iGxwLh80 I2EA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :date:subject:cc:to:from:dkim-signature; bh=vvqaN8/KIqeuNXG6MsZVXoxWgrAefdh1jtznLiH0jnU=; fh=m0HBXuwgOCKat7wyuY7vstPypqMqxNmINnjBv5+EUjU=; b=lD0ZjIqYKgOX/5XsgEFpKqH0cV0GLarVeRDsBTi0F066TX5Z89YrOE54hGnoFhw4iz rhbQk6Z9haY4jIxry3pE3JQCx3W3+Q2eih2HjELRYayBv4k9nKO+USwQUbjAmhm0QTZK Uqn2DyDGY+7J3aQfXlcCZjlhkoq9UeO69v3SzUd4RPCNn7eDXz0Nwpv/eNWS5sD7cpbQ y9MVbeeEjllUUidnfsJD741lF0oHAnkK6EtWiL+8yOfbPWZnpYLQQhXQsMgmQ4IIL5zj NyEyuAfpDCE6Y0ASvvdib9lsboSpc/o6TzaC5pAfHMTWbqrfezf61yzf06yPLKQ6RO9q COcw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@infradead.org header.s=bombadil.20210309 header.b=C5A4jUNK; spf=pass (google.com: domain of linux-kernel+bounces-3949-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-3949-ouuuleilei=gmail.com@vger.kernel.org" Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [2604:1380:45e3:2400::1]) by mx.google.com with ESMTPS id i127-20020a636d85000000b005c6254ecfadsi4628616pgc.95.2023.12.18.07.38.51 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 18 Dec 2023 07:38:51 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-3949-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) client-ip=2604:1380:45e3:2400::1; Authentication-Results: mx.google.com; dkim=pass header.i=@infradead.org header.s=bombadil.20210309 header.b=C5A4jUNK; spf=pass (google.com: domain of linux-kernel+bounces-3949-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-3949-ouuuleilei=gmail.com@vger.kernel.org" Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sv.mirrors.kernel.org (Postfix) with ESMTPS id 631C6283A8F for ; Mon, 18 Dec 2023 15:38:51 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 03E055BFAB; Mon, 18 Dec 2023 15:36:19 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=infradead.org header.i=@infradead.org header.b="C5A4jUNK" X-Original-To: linux-kernel@vger.kernel.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id EB53A5A87E; Mon, 18 Dec 2023 15:36:14 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=lst.de Authentication-Results: smtp.subspace.kernel.org; spf=none smtp.mailfrom=bombadil.srs.infradead.org DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=bombadil.20210309; h=Content-Transfer-Encoding: MIME-Version:References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From:Sender :Reply-To:Content-Type:Content-ID:Content-Description; bh=vvqaN8/KIqeuNXG6MsZVXoxWgrAefdh1jtznLiH0jnU=; b=C5A4jUNKNWWGNM0AFYi1+TbZqg OyJLFLMAYeRWAkGFHpJj2/i2TpKNAExClZQ0eq/kfZp9NcqLA2do4BbRXo2Q4W+iK4j5Vs5EGWTtw cidcKA8PuBHBAzMjolCFFwvjF1I65aziLi6OSncFKhd+PQGJunCSWzOvrXiVNjvRdL+5XxP+vGK8s 5lB8Xhy8YqBjIl7CVAQyC5btI+HQsTN1MM7VZBSIoR4vpfh7l2M+kWRPnHGFvl25PWqUT6OFS6ICi R5oHvPfCAlXyzNuVQr2cvIxcGzsS5vrPEMkOuUUNuuUzCVzHfnUMHd5Uzh71D7Wv6+5fte9QYjw/K yYSn0SnQ==; 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 1rFFf9-00BEMU-2Y; Mon, 18 Dec 2023 15:36:12 +0000 From: Christoph Hellwig To: linux-mm@kvack.org Cc: "Matthew Wilcox (Oracle)" , Jan Kara , David Howells , Brian Foster , linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH 06/17] writeback: Factor out writeback_finish() Date: Mon, 18 Dec 2023 16:35:42 +0100 Message-Id: <20231218153553.807799-7-hch@lst.de> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20231218153553.807799-1-hch@lst.de> References: <20231218153553.807799-1-hch@lst.de> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-SRS-Rewrite: SMTP reverse-path rewritten from by bombadil.infradead.org. See http://www.infradead.org/rpr.html X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1785634678843147657 X-GMAIL-MSGID: 1785634678843147657 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 --- 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 833ec38fc3e0c9..390f2dd03cf27e 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 c798c0d6d0abb4..564d5faf562ba7 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 Mon Dec 18 15:35:43 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christoph Hellwig X-Patchwork-Id: 180498 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7300:24d3:b0:fb:cd0c:d3e with SMTP id r19csp1328030dyi; Mon, 18 Dec 2023 07:39:12 -0800 (PST) X-Google-Smtp-Source: AGHT+IF+0lWDycitlsbaPxFHW+wAUFGfIUx25dyR+lHqF5AH0zfrS4w3/iSKqjLfN++J1izbpSRV X-Received: by 2002:a05:6870:b8b:b0:1fa:e115:ef6c with SMTP id lg11-20020a0568700b8b00b001fae115ef6cmr25468707oab.38.1702913952430; Mon, 18 Dec 2023 07:39:12 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1702913952; cv=none; d=google.com; s=arc-20160816; b=HiLCJqSZ7vJgkJH8pL07U+2vhphJ8yzACa6v0s6kP7frRRMgZhh6tfv7WbFeMUGIGD Iru9jAcEYewyhx2O0gKUdwD1J5ywmA904tHoVnQTMnyjO1rUV4NoiXhpDKahJAF3cLFK nxqzhkEst9Y2lhV0Ggilz05ZDYvKI88xWM6N5/LEmKC04DM1LwX/CbPa7b6BsiLqizBS NahxPanbOZOmxVR1wK7MKjEhsOoOrMIA+FSFCZ8dYBe+Q59JTdj8NAVBGixhgKgFinmX Hc/9ficCDy3QcuR9n1L6DPourY34Mmbf8zqsTrUSMZn49iewBWnZfPlAGCTNxRmPJcw8 dKgA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :date:subject:cc:to:from:dkim-signature; bh=aHXKO1UbJHXuqoP1fMOkKbpvbuANBll89l/hQyqHhR4=; fh=m0HBXuwgOCKat7wyuY7vstPypqMqxNmINnjBv5+EUjU=; b=ZChlaZ7djhe+yMMu77DtbHLPh32vIwMizARsBpguDbuakwZ928DL8Wr+sIf+VPwOe8 fTt1WliZHfeAt1l/LnfuQcycgWxPccHtZPKhOgqpu3ku/opYz719M292eGme1M3kB0bn yppqcx9MiK6f2tR7h+R3VnGHnhhPwimo1KFdnVHf6IGyncSzNiwkaysSExewSWz2OXX7 BwF5CuegEo9RoOIzxY7mi+Y15YFSZexBtxF+1nGWlmP9M6T7hjHvSKb5fuTHxrTj4AdO SXnJvLQyHVmaAJ3uv4lkP4UlBZ08u0vCQL+YrialKqSGFYE5U9U73Rpl4nVrcMGz5zsI TL2A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@infradead.org header.s=bombadil.20210309 header.b="Fx9/cCVV"; spf=pass (google.com: domain of linux-kernel+bounces-3950-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-3950-ouuuleilei=gmail.com@vger.kernel.org" Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [147.75.199.223]) by mx.google.com with ESMTPS id cn10-20020a05622a248a00b0042372cecceasi26116283qtb.656.2023.12.18.07.39.12 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 18 Dec 2023 07:39:12 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-3950-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) client-ip=147.75.199.223; Authentication-Results: mx.google.com; dkim=pass header.i=@infradead.org header.s=bombadil.20210309 header.b="Fx9/cCVV"; spf=pass (google.com: domain of linux-kernel+bounces-3950-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-3950-ouuuleilei=gmail.com@vger.kernel.org" Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ny.mirrors.kernel.org (Postfix) with ESMTPS id 29C281C232FF for ; Mon, 18 Dec 2023 15:39:12 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 87BC171440; Mon, 18 Dec 2023 15:36:21 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=infradead.org header.i=@infradead.org header.b="Fx9/cCVV" X-Original-To: linux-kernel@vger.kernel.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 8F77D5D72F; Mon, 18 Dec 2023 15:36:17 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=lst.de Authentication-Results: smtp.subspace.kernel.org; spf=none smtp.mailfrom=bombadil.srs.infradead.org DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=bombadil.20210309; h=Content-Transfer-Encoding: MIME-Version:References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From:Sender :Reply-To:Content-Type:Content-ID:Content-Description; bh=aHXKO1UbJHXuqoP1fMOkKbpvbuANBll89l/hQyqHhR4=; b=Fx9/cCVVlwYOnhe/PSU89cDqVD NI/Css67r/FlsYc8NmCfniGg54QHQxgHsspAS57gDul5cTzL0hn1ZYeRU9gC8qFIq//ZJLH1vTyTT NkYZETzb+w26apnFjyIKLapIGMmBHyHAabMX4hk9cvfq0clnn+uyJpYeekVoYtCuTYVUNQFlPatrZ SSsp/9CpzQ3RKUCNPWaBU4OgSu7Wl1+hiqb+XWiQ2Uv+YBGT9sPgftDPPkSwJXycLm4D/AKXvHjus 0HFC0kopXSnEv2BVLjCG4hwfCCGuT9gt5VWusTok0xcANlH5KBh8QDWOzHVEd1W+MU2o0JryEnPBY gQ5ZhBvA==; 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 1rFFfC-00BENM-0x; Mon, 18 Dec 2023 15:36:14 +0000 From: Christoph Hellwig To: linux-mm@kvack.org Cc: "Matthew Wilcox (Oracle)" , Jan Kara , David Howells , Brian Foster , linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH 07/17] writeback: Factor writeback_get_batch() out of write_cache_pages() Date: Mon, 18 Dec 2023 16:35:43 +0100 Message-Id: <20231218153553.807799-8-hch@lst.de> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20231218153553.807799-1-hch@lst.de> References: <20231218153553.807799-1-hch@lst.de> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-SRS-Rewrite: SMTP reverse-path rewritten from by bombadil.infradead.org. See http://www.infradead.org/rpr.html X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1785634700811270034 X-GMAIL-MSGID: 1785634700811270034 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 --- 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 390f2dd03cf27e..195393981ccb5c 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 564d5faf562ba7..798e5264dc0353 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 Mon Dec 18 15:35:45 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christoph Hellwig X-Patchwork-Id: 180499 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7300:24d3:b0:fb:cd0c:d3e with SMTP id r19csp1328496dyi; Mon, 18 Dec 2023 07:40:01 -0800 (PST) X-Google-Smtp-Source: AGHT+IFVkAQO73vCnVLkLkXnJjG5+4ZxGpNnZScBCMHLhJX1OLOWv8WSEmCd1hXr8bss/1N7ZHdt X-Received: by 2002:a17:90a:460d:b0:28b:2a84:a91d with SMTP id w13-20020a17090a460d00b0028b2a84a91dmr1905214pjg.43.1702914001409; Mon, 18 Dec 2023 07:40:01 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1702914001; cv=none; d=google.com; s=arc-20160816; b=XGqibgr9iwOQryO6cQFMsyzVH/TWKiqNkGMazwQvidwtYLdZZ/+ZhK/HTMtiMKRzuR SvINuPaP40YJyTN5qgglX0wx57Y71mSLTJr7V9l9gAbnpTKQq2F8sPsxt6ksV52ZZ4Gs S4Rz8qEVY9oHU1xomJAdV7uORYgNtC1gqhcXrr97MjwpGkXHxrB6edAhmMn8NUBqBIZu deokg2pR3OGd5Ki0Gj8T3pI+M324DMAwXY4NPXU3FvOXWxpfDqNm0vAor9TQC3SrH26N eV6UsOyUohLthZoMp7zLwvfd+dqaOdR3IU8geLB0tC1v5A07UXxT6RoSA1Tp9ia0ZUkT j0Sw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :date:subject:cc:to:from:dkim-signature; bh=9E46P8RBBTh6OS7XsshX1gEfzWzF0rjfwCHf/2TCoS8=; fh=m0HBXuwgOCKat7wyuY7vstPypqMqxNmINnjBv5+EUjU=; b=MmxFMMgbPf2T3JUWzw7Ke3N0v0hk+SJ5xsbHZ9LMaPO/wx3bnU8QpjNaLSwSfiqH/8 nKtcafD2BPCiGy3NuTdzznqErJ2+xmfRchYaBxbC6+yE8w6ZPxvm8zqH78udbiYz2kkq wLiUbk/LvQ1i+Ua/Kfcf0SCiFae9j2ZoMV85WbguIodsRusj+KOsHaDsK0h2PQq0/kTD MWRI5xrJGHHfkULV9M7iiICUuXKQ4Uz5fdsw/0wmAjP7o9Zzr4EtpFlZK5c2WYEsT+Y3 n7I2IrzJTRInIknyB8+wOBs36waSxaKB5USzyMoHkfyFnpSaVCzwpnYNcZecUWBNBkIA c2MA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@infradead.org header.s=bombadil.20210309 header.b=DfogWbTo; spf=pass (google.com: domain of linux-kernel+bounces-3952-ouuuleilei=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-3952-ouuuleilei=gmail.com@vger.kernel.org" Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [139.178.88.99]) by mx.google.com with ESMTPS id y17-20020a17090aa41100b0028875adc38asi18174453pjp.171.2023.12.18.07.40.01 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 18 Dec 2023 07:40:01 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-3952-ouuuleilei=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) client-ip=139.178.88.99; Authentication-Results: mx.google.com; dkim=pass header.i=@infradead.org header.s=bombadil.20210309 header.b=DfogWbTo; spf=pass (google.com: domain of linux-kernel+bounces-3952-ouuuleilei=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-3952-ouuuleilei=gmail.com@vger.kernel.org" Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sv.mirrors.kernel.org (Postfix) with ESMTPS id 320EA280F13 for ; Mon, 18 Dec 2023 15:40:01 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 24B1D72048; Mon, 18 Dec 2023 15:36:33 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=infradead.org header.i=@infradead.org header.b="DfogWbTo" X-Original-To: linux-kernel@vger.kernel.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 82BB642378; Mon, 18 Dec 2023 15:36:28 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=lst.de Authentication-Results: smtp.subspace.kernel.org; spf=none smtp.mailfrom=bombadil.srs.infradead.org DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=bombadil.20210309; h=Content-Transfer-Encoding: MIME-Version:References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From:Sender :Reply-To:Content-Type:Content-ID:Content-Description; bh=9E46P8RBBTh6OS7XsshX1gEfzWzF0rjfwCHf/2TCoS8=; b=DfogWbTovC+MaOjnIwtN1k+ufe 43Ts4mac1JK2rDHqW2s9mobtENbKUfR9BFoKwLFg1BcjgMQ/GLdPgjocsslPLAvmryBkB+L6aBzFd 4f2bI16jaiAJ26Qxe8VT2ft+yHYcDpYUO4wZZ0CHOua1wdkZm/mH7Yml1PKCixNZ4/egD9MPx9yG5 v8SBQAHvbwgiAd3NzfUQUr96kLLHmE17pRAuOmQu3Y0G9xI54rO+mUK3+sHk+j57wTC5j5rMCEMXx +wxkIw4M6tuiC9vd/QjEMHqBqbxQtz1uRFx2lutS1EQnjOZt5+jkyHdqmKI58AU1hOHa774zf+XRm vMF4vlvQ==; 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 1rFFfH-00BEQj-3D; Mon, 18 Dec 2023 15:36:20 +0000 From: Christoph Hellwig To: linux-mm@kvack.org Cc: "Matthew Wilcox (Oracle)" , Jan Kara , David Howells , Brian Foster , linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH 09/17] writeback: Simplify the loops in write_cache_pages() Date: Mon, 18 Dec 2023 16:35:45 +0100 Message-Id: <20231218153553.807799-10-hch@lst.de> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20231218153553.807799-1-hch@lst.de> References: <20231218153553.807799-1-hch@lst.de> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-SRS-Rewrite: SMTP reverse-path rewritten from by bombadil.infradead.org. See http://www.infradead.org/rpr.html X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1785634751762222811 X-GMAIL-MSGID: 1785634751762222811 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 --- 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 2a004c0b9bdfbf..c7983ea3040be4 100644 --- a/mm/page-writeback.c +++ b/mm/page-writeback.c @@ -2473,6 +2473,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 */ @@ -2487,63 +2488,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 (!should_writeback_folio(mapping, wbc, folio)) { - folio_unlock(folio); - continue; - } + folio_lock(folio); + if (!should_writeback_folio(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 Mon Dec 18 15:35:47 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christoph Hellwig X-Patchwork-Id: 180501 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7300:24d3:b0:fb:cd0c:d3e with SMTP id r19csp1329142dyi; Mon, 18 Dec 2023 07:41:01 -0800 (PST) X-Google-Smtp-Source: AGHT+IEIeyOmENyyyR4FnPc0vR8xComYXuXujMSenGAeFniconm+2zFiYhbKf/5QVDI1BaVhNVET X-Received: by 2002:a17:906:6c92:b0:a23:6eb6:6b35 with SMTP id s18-20020a1709066c9200b00a236eb66b35mr20677ejr.136.1702914060930; Mon, 18 Dec 2023 07:41:00 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1702914060; cv=none; d=google.com; s=arc-20160816; b=i5RhPAS9wFJHwnQzXmmzLQPN9tW799myGZHo/TI3yY/jGEy+X5rkVImEDqc7T9HctP XYDRURQeDlPyqnU2vgEHL9fNCtxln8Itb+J5xbDlXTRWVTJOKx9lxv1QBLnU7/tUMdFF 3Kbbdu14EoW71S8qM84HgDv/UNB2XISW89OTIqB/HdPxXl2x21qpGoRAFA2gsIRSWedP 4BOaqyeFa/Q//EXsWbA3Vc3CYmxITg8wBWHq5HII1X4rAwiPqeRupV9CMGY1BdEwqZOK lK1gvyfarPb7osOpZuy7UfBgaIBJjMIPUNCGb17pTApjU/1M/NaFfruB02i83QPzv3jZ 7dww== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :date:subject:cc:to:from:dkim-signature; bh=3B9Hp+QAdQFWcqrQUPpFbTk6qvR0M5sjBup3lTEiqhs=; fh=m0HBXuwgOCKat7wyuY7vstPypqMqxNmINnjBv5+EUjU=; b=GX/wtOGSgdQFZ+mOVcRWK0WQ1tkiP98j20c8KXsZiPpTkwiboBPGXlVl/tTQRIqvgx apPRaYtYFD3ZfiCAccMu8rNZ1/K+SQ2RTu0OmwO9AYZKnpia5P0fkeeG0SROHekJ9urF UAUVRpkauwc1fK3NI9NoHCoTUNaB8EWfD5ipmbCWpONODLQK2/oL1mK+9NKfVX/8Amiu 6ui/ByAMHZNEi4CuWJ0hcrFHS2pBxhJb+1FmLL4pcmiXBrmpUIxArUTj+uSdszqQFZ7n M6/n2wrK5ngkAmdSwtwvNHrj7eP38QhAqX6Isc/rEzjQvQUJtCbqbrXmdL3AbhkwK9eV mEeg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@infradead.org header.s=bombadil.20210309 header.b=THuXRAhN; spf=pass (google.com: domain of linux-kernel+bounces-3953-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-3953-ouuuleilei=gmail.com@vger.kernel.org" Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [147.75.80.249]) by mx.google.com with ESMTPS id j25-20020a170906051900b00a2352a12fb4si1153328eja.1017.2023.12.18.07.41.00 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 18 Dec 2023 07:41:00 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-3953-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) client-ip=147.75.80.249; Authentication-Results: mx.google.com; dkim=pass header.i=@infradead.org header.s=bombadil.20210309 header.b=THuXRAhN; spf=pass (google.com: domain of linux-kernel+bounces-3953-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-3953-ouuuleilei=gmail.com@vger.kernel.org" Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by am.mirrors.kernel.org (Postfix) with ESMTPS id 02DD81F24816 for ; Mon, 18 Dec 2023 15:40:38 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 9043273473; Mon, 18 Dec 2023 15:36:35 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=infradead.org header.i=@infradead.org header.b="THuXRAhN" X-Original-To: linux-kernel@vger.kernel.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 536C34239E; Mon, 18 Dec 2023 15:36:30 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=lst.de Authentication-Results: smtp.subspace.kernel.org; spf=none smtp.mailfrom=bombadil.srs.infradead.org DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=bombadil.20210309; h=Content-Transfer-Encoding: MIME-Version:References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From:Sender :Reply-To:Content-Type:Content-ID:Content-Description; bh=3B9Hp+QAdQFWcqrQUPpFbTk6qvR0M5sjBup3lTEiqhs=; b=THuXRAhNeLCiO2K1fm6woSSF0o FKejSp1UwrESZMKns9PM7cdQ7F8P7vGO1leM/ItulT1ZAASbVhH3soffvn0yy2cYNQ7Db4BAOr9ku m7Aeco/LSG1tytEmmHRNB8t01Capsk3p3022lowatIGQS/92K5TIZZ50ORvE1uUbfbl5qTGihahCG t7RR7qRTsnt6rYpRX6/KmySAwqvvivwVdHHPiSnYv+ICCPdXwP4idam3OfER0xCEM1QDucjIIGYwL z3kxcpHeMwiL3Gk+EC3dtqn2BU8RvjxXmiBBSf79ujCTwihDzG75A4W/ShiFDKWGhEztFg+1o/gtd WL+ry0qg==; 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 1rFFfO-00BEUC-1y; Mon, 18 Dec 2023 15:36:27 +0000 From: Christoph Hellwig To: linux-mm@kvack.org Cc: "Matthew Wilcox (Oracle)" , Jan Kara , David Howells , Brian Foster , linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH 11/17] writeback: Use the folio_batch queue iterator Date: Mon, 18 Dec 2023 16:35:47 +0100 Message-Id: <20231218153553.807799-12-hch@lst.de> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20231218153553.807799-1-hch@lst.de> References: <20231218153553.807799-1-hch@lst.de> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-SRS-Rewrite: SMTP reverse-path rewritten from by bombadil.infradead.org. See http://www.infradead.org/rpr.html X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1785634814315315578 X-GMAIL-MSGID: 1785634814315315578 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 --- mm/page-writeback.c | 19 +++++++++---------- 1 file changed, 9 insertions(+), 10 deletions(-) diff --git a/mm/page-writeback.c b/mm/page-writeback.c index c7983ea3040be4..70f42fd9a95b5d 100644 --- a/mm/page-writeback.c +++ b/mm/page-writeback.c @@ -2397,13 +2397,19 @@ static pgoff_t wbc_end(struct writeback_control *wbc) return wbc->range_end >> PAGE_SHIFT; } -static void writeback_get_batch(struct address_space *mapping, +static struct folio *writeback_get_next(struct address_space *mapping, struct writeback_control *wbc) { + struct folio *folio = folio_batch_next(&wbc->fbatch); + + if (folio) + return folio; + folio_batch_release(&wbc->fbatch); cond_resched(); filemap_get_folios_tag(mapping, &wbc->index, wbc_end(wbc), wbc_to_tag(wbc), &wbc->fbatch); + return folio_batch_next(&wbc->fbatch); } static bool should_writeback_folio(struct address_space *mapping, @@ -2473,7 +2479,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 */ @@ -2489,18 +2494,12 @@ int write_cache_pages(struct address_space *mapping, wbc->err = 0; for (;;) { - struct folio *folio; + struct folio *folio = writeback_get_next(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 (!should_writeback_folio(mapping, wbc, folio)) { folio_unlock(folio); From patchwork Mon Dec 18 15:35:48 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christoph Hellwig X-Patchwork-Id: 180502 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7300:24d3:b0:fb:cd0c:d3e with SMTP id r19csp1329186dyi; Mon, 18 Dec 2023 07:41:06 -0800 (PST) X-Google-Smtp-Source: AGHT+IE0P+E4gNsWNZQwgl07bAJuxk8RO7qMMpxpLl10V4+ibMz/0oWR7dR3JECqzuDUZpl/nbWq X-Received: by 2002:ac8:59d3:0:b0:425:8882:32f9 with SMTP id f19-20020ac859d3000000b00425888232f9mr22122063qtf.22.1702914066264; Mon, 18 Dec 2023 07:41:06 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1702914066; cv=none; d=google.com; s=arc-20160816; b=OPyzchsHyzDNkVPMdN3mn9C5z7B67o86eNFSo1bXWSim1MFcaP4kEDaj/nKFDCCjJ4 sHADapYBoFB/F3O/Ev405ezg2EDWfo4yD+Kuf4sKMrj5PZwcxFQ53I5+TRTIwq/D/21b UB1CF+xU7dGrqT2icLbm3c5cTXO83mhx36ssC6luGDvpkBmn7peXeJadEHdrVYMWf/h1 zJxLWc+n+TsKvjPeG5JX8wy3+PAKvudrgniUUrSFSb1HmEER6YBgyCtqNFfSTm/lKBTo w+yLw6OF3RfvpnVRhFnxc3NrWWGEdW2KVWWQsT+KNytLb0+4jspegpqTZ8g/QYC3JVaA TFuw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :date:subject:cc:to:from:dkim-signature; bh=11fJOeLJtEu+HLcWStjNzVEg8D8E0pgLFFPvW65M4Co=; fh=m0HBXuwgOCKat7wyuY7vstPypqMqxNmINnjBv5+EUjU=; b=R2UluY8fpXzONLnicTOd4t9luUvu2Zz/jrw/EKK13b6ilkYqcWz02xhWplTjuqapG1 gPUzyoZ9L/7N1rDGHcCIE1PHi/HFq+vUwOd81b44d8Qqk7oiGwVKARKdvMntAjGZKIzu gCd2G88z1aJLh4M7eJYquT/EhiETCW0gXdKp8AvyMMRbMDmoca15MxgtPJk9QJBSfkQe +jbRlg6yuT7aO4nsPwW27BndaO86CkFE5My0k1DDR0e57cn5yq2GAnNPwf4C3IaJXiqn n6VFqfr9jzWj88ARAU8ABTM2aXTAeeWbMYSX1ay4jUoXBDjIiyS3Y2Ngih6+KN+Mq7zi YscA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@infradead.org header.s=bombadil.20210309 header.b=MXOOyyiG; spf=pass (google.com: domain of linux-kernel+bounces-3955-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-3955-ouuuleilei=gmail.com@vger.kernel.org" Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [2604:1380:45d1:ec00::1]) by mx.google.com with ESMTPS id fa15-20020a05622a4ccf00b004257ad3977dsi26367953qtb.521.2023.12.18.07.41.06 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 18 Dec 2023 07:41:06 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-3955-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) client-ip=2604:1380:45d1:ec00::1; Authentication-Results: mx.google.com; dkim=pass header.i=@infradead.org header.s=bombadil.20210309 header.b=MXOOyyiG; spf=pass (google.com: domain of linux-kernel+bounces-3955-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-3955-ouuuleilei=gmail.com@vger.kernel.org" Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ny.mirrors.kernel.org (Postfix) with ESMTPS id A88111C25007 for ; Mon, 18 Dec 2023 15:40:53 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 6593C7347A; Mon, 18 Dec 2023 15:36:37 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=infradead.org header.i=@infradead.org header.b="MXOOyyiG" X-Original-To: linux-kernel@vger.kernel.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 5D4917204D; Mon, 18 Dec 2023 15:36:33 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=lst.de Authentication-Results: smtp.subspace.kernel.org; spf=none smtp.mailfrom=bombadil.srs.infradead.org DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=bombadil.20210309; h=Content-Transfer-Encoding: MIME-Version:References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From:Sender :Reply-To:Content-Type:Content-ID:Content-Description; bh=11fJOeLJtEu+HLcWStjNzVEg8D8E0pgLFFPvW65M4Co=; b=MXOOyyiG08iR+isoX6KD7RrhRt 0QmbZm+seKCas0S98o9hhqfjQr+vlWEOPT/rhVKpCa/ug/D/NkXWj7C1tgZXQeIQVkVhCIs//zQHy t3gNoGV16ux4RaT1JuRzdxFP47V9wmEuzUaBUuWpBMIWmvjTHcVrRKP+iRpnx2k+O0LglLWfTgCiC p3ZhIyUOhbchYAy4iRYYUIw38YozNgK4QODvPde8KbAfKrK0yLwBCx3tJ63AZ+x815DPNLbVSczvb H5oQ+NezuCm0IvG56bFh5739uRp0nWlfpeCgsFIiZRsfEL8M9gbUEyjA6HfZ7Y7yfgWBJfb13/aN4 WwKzKFCg==; 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 1rFFfS-00BEVg-0O; Mon, 18 Dec 2023 15:36:30 +0000 From: Christoph Hellwig To: linux-mm@kvack.org Cc: "Matthew Wilcox (Oracle)" , Jan Kara , David Howells , Brian Foster , linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH 12/17] writeback: Factor writeback_iter_init() out of write_cache_pages() Date: Mon, 18 Dec 2023 16:35:48 +0100 Message-Id: <20231218153553.807799-13-hch@lst.de> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20231218153553.807799-1-hch@lst.de> References: <20231218153553.807799-1-hch@lst.de> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-SRS-Rewrite: SMTP reverse-path rewritten from by bombadil.infradead.org. See http://www.infradead.org/rpr.html X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1785634819690134427 X-GMAIL-MSGID: 1785634819690134427 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 --- 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 70f42fd9a95b5d..efcfffa800884d 100644 --- a/mm/page-writeback.c +++ b/mm/page-writeback.c @@ -2442,6 +2442,22 @@ static bool should_writeback_folio(struct address_space *mapping, return true; } +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_next(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 @@ -2477,29 +2493,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_next(mapping, wbc); + for (folio = writeback_iter_init(mapping, wbc); + folio; + folio = writeback_get_next(mapping, wbc)) { unsigned long nr; - if (!folio) - break; - folio_lock(folio); if (!should_writeback_folio(mapping, wbc, folio)) { folio_unlock(folio); From patchwork Mon Dec 18 15:35:50 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christoph Hellwig X-Patchwork-Id: 180503 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7300:24d3:b0:fb:cd0c:d3e with SMTP id r19csp1329442dyi; Mon, 18 Dec 2023 07:41:32 -0800 (PST) X-Google-Smtp-Source: AGHT+IFjH0TkcSZQw8vHSkOYfkt+N9XbdsXWcWeUursCS9pa9piyozKzOUWsmn/IXBIP+y5QFhzC X-Received: by 2002:a05:6102:292b:b0:464:9277:1f23 with SMTP id cz43-20020a056102292b00b0046492771f23mr13293767vsb.31.1702914091746; Mon, 18 Dec 2023 07:41:31 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1702914091; cv=none; d=google.com; s=arc-20160816; b=Syt8bMScr0QBvjAbIhWjIklyVPwdWU49idOWWfUoIdgw7AoWnqATu2/cX00R+oQoos RIjluz7Tzo78viWuYJwW3mYfXxfofHbghlS+6uJulMuWfEiad/LI5EQZ/bJR0AKG4JQb ODsspLdm1E1nTzUlK6oeNOoK7ep5+zRMEw+ezsCt6M77l6JrmC9alelybK+kDrvGw6Ao Y7QhgNyDAWSmIMi/jgpYXacceMfr/QkB4TBzOmV3ZXVHTBAN6fkm991d+n4m6i557b+H EwQT5Z0wtkewEQ1kN8HWA7PQGY0v2u75SDJWltf/gxwtWmEhIUENvgtq7DQgsNOjONhL qPNQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :date:subject:cc:to:from:dkim-signature; bh=lOde0PGi4Z6M7IdLHCKfLkz19eMYDieJg9XbB+ncAEo=; fh=m0HBXuwgOCKat7wyuY7vstPypqMqxNmINnjBv5+EUjU=; b=s080qk8I/pQotVul1rq4JdXN1oaxxxTgP28xPQ+nGIP6O607pgmPewv0xlgfK/EB1S zCDmHWXsPigrVVE+4VEP+eEAayu3oHl2+ednXdfd4lv2XX0YOPsDIn1mYQ6cRUrVWbAw ljqwv4fhvi27s4OSwnobq2rMRybgyx9dG2L7bthhkqGJo/vOOc5E70lSZWVyZyyOUx3M YUjglHR/as18mNuU0MAxhInfeGQPZNvhDPIbgCCyByYl1XRRSHgTPcp1ZJ0qq3LtIQRQ pdh1yC+ldyisKtFnmU77CLJoyAM/lq4HpXXz7OR8lTbdxzdV6N1vb80pQv9lsS2DH7iQ NhLA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@infradead.org header.s=bombadil.20210309 header.b="n/KNWRHz"; spf=pass (google.com: domain of linux-kernel+bounces-3957-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-3957-ouuuleilei=gmail.com@vger.kernel.org" Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [147.75.199.223]) by mx.google.com with ESMTPS id q9-20020a67b909000000b004669dfe345csi204233vsn.340.2023.12.18.07.41.31 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 18 Dec 2023 07:41:31 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-3957-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) client-ip=147.75.199.223; Authentication-Results: mx.google.com; dkim=pass header.i=@infradead.org header.s=bombadil.20210309 header.b="n/KNWRHz"; spf=pass (google.com: domain of linux-kernel+bounces-3957-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-3957-ouuuleilei=gmail.com@vger.kernel.org" Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ny.mirrors.kernel.org (Postfix) with ESMTPS id 73F4F1C208BB for ; Mon, 18 Dec 2023 15:41:31 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id E0EF9498A3; Mon, 18 Dec 2023 15:36:44 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=infradead.org header.i=@infradead.org header.b="n/KNWRHz" X-Original-To: linux-kernel@vger.kernel.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 03CA174097; Mon, 18 Dec 2023 15:36:40 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=lst.de Authentication-Results: smtp.subspace.kernel.org; spf=none smtp.mailfrom=bombadil.srs.infradead.org DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=bombadil.20210309; h=Content-Transfer-Encoding: MIME-Version:References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From:Sender :Reply-To:Content-Type:Content-ID:Content-Description; bh=lOde0PGi4Z6M7IdLHCKfLkz19eMYDieJg9XbB+ncAEo=; b=n/KNWRHzl0Vuw7qwMs1UYzUUD+ itAzOZiMXFPZCbTYFwBvFV2uQpY3ZdylXEIWixZXWjNKLUCXFSQ57YVIbXC8wJScFm28gORoCP+Yi hZWQK8/6AkPBsNn7WjAHENXCNj+5xS1xxxEnfprZO2gzyaxOtGqdUqb9VYPWGt+1/ebCeTj52bMkV eEWxwgWKuQvWNHrgQpzFNaQqNPqCqaSsXje3yLomMY4ATq2rL67xi0bZijgTq8eTBV2zniKCTgGjs 6yp0+AJIT0zWHgTOFWE15g4u0wKKgOI7K7XRNoilnqCmsKHJwS2V/24atVv67qSQSUEtUNZH/UU0Z vEC8Dhsg==; 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 1rFFfZ-00BEZB-0p; Mon, 18 Dec 2023 15:36:37 +0000 From: Christoph Hellwig To: linux-mm@kvack.org Cc: "Matthew Wilcox (Oracle)" , Jan Kara , David Howells , Brian Foster , linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH 14/17] writeback: Factor writeback_iter_next() out of write_cache_pages() Date: Mon, 18 Dec 2023 16:35:50 +0100 Message-Id: <20231218153553.807799-15-hch@lst.de> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20231218153553.807799-1-hch@lst.de> References: <20231218153553.807799-1-hch@lst.de> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-SRS-Rewrite: SMTP reverse-path rewritten from by bombadil.infradead.org. See http://www.infradead.org/rpr.html X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1785634846803243821 X-GMAIL-MSGID: 1785634846803243821 From: "Matthew Wilcox (Oracle)" Pull the post-processing of the writepage_t callback into a separate function. That means changing writeback_finish() to return NULL, and 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 --- 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 9d37dd5e58ffb6..0771f19950081f 100644 --- a/mm/page-writeback.c +++ b/mm/page-writeback.c @@ -2449,8 +2449,10 @@ static struct folio *writeback_get_folio(struct address_space *mapping, for (;;) { folio = writeback_get_next(mapping, wbc); - if (!folio) + if (!folio) { + writeback_finish(mapping, wbc, 0); return NULL; + } folio_lock(folio); if (likely(should_writeback_folio(mapping, wbc, folio))) break; @@ -2477,6 +2479,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 @@ -2517,47 +2559,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 Mon Dec 18 15:35:51 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christoph Hellwig X-Patchwork-Id: 180504 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7300:24d3:b0:fb:cd0c:d3e with SMTP id r19csp1329798dyi; Mon, 18 Dec 2023 07:42:05 -0800 (PST) X-Google-Smtp-Source: AGHT+IG0vYyGfZ21FcpX2NeZnTcbePlOHmIf/z08Ww2CV8yqbidxiq9xT7FwPQmaABcqGCo11/Fc X-Received: by 2002:a05:6a21:1a2:b0:194:8117:b36b with SMTP id le34-20020a056a2101a200b001948117b36bmr644853pzb.44.1702914125492; Mon, 18 Dec 2023 07:42:05 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1702914125; cv=none; d=google.com; s=arc-20160816; b=nTiO6bfW9QvNn1c4Vzd8C8lnkMDI+FBxiu5S4azJrlhxlJluIA2TVZhRgsxw0W3Sbk JxKGnqT/WHTB6E6+zyuNVeIWAIdXtqlX2fVb32tIcoxXNVzr3imjFuE4gBT+Uhg9bifd FSVWLOJtAQPsp7sdkGu7i/wkxm15m0ZGRWBeXPpM8KCc327as4LTE52gin5X8encp6cd EquDaLn2XpUimPDTs4GC268PQ0zByL7WxqHT/x0YCCDsRvpiBGvWsp1/idf1FQzm3Gnj q2qRaN8Urd70v4roUiXvmsTXL2w++6OeUtaR27BDZlWVP3AT+pEFfxBImqWRoFj606nT +mFA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :date:subject:cc:to:from:dkim-signature; bh=b65KMtlYAzH3EUkpAxud2ReFVr8IHYHtgd3wSTH/RNI=; fh=m0HBXuwgOCKat7wyuY7vstPypqMqxNmINnjBv5+EUjU=; b=Rbvv2vT2Hb04egVPFLp88HQoXCrv1AgVypYxJQjdf9qLQgpicSbUxaVFtqGyhmD1pN JzaO6SJ3lT6WatNPxVuBoD/UZENda9/Kuq2dxRQgJGJH/SKGGnRs5X75bAbB9kJFe9Kn FV0Ymor3gMo7BQKEmNwjTxR6TrrtNrnytkWJZoQmu/Du+tdhfqtgj4wdX3oeUQoNGRDF jWHQ/67NYbkU5iQ/MD6mSBj7uDrKAF5krJps52xDu1sWl0xS0pR15ey/v6l3XCr0OoJh 8IY0FW5buocjRgqHwc55cpi/V8S6opkY+IPjHlNWQ/A6JleXFviOUG0o39EqmXidUVVG ZtSQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@infradead.org header.s=bombadil.20210309 header.b=wIxOQSPZ; spf=pass (google.com: domain of linux-kernel+bounces-3958-ouuuleilei=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-3958-ouuuleilei=gmail.com@vger.kernel.org" Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [139.178.88.99]) by mx.google.com with ESMTPS id z5-20020a656645000000b005bd3da15474si17441577pgv.839.2023.12.18.07.42.05 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 18 Dec 2023 07:42:05 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-3958-ouuuleilei=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) client-ip=139.178.88.99; Authentication-Results: mx.google.com; dkim=pass header.i=@infradead.org header.s=bombadil.20210309 header.b=wIxOQSPZ; spf=pass (google.com: domain of linux-kernel+bounces-3958-ouuuleilei=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-3958-ouuuleilei=gmail.com@vger.kernel.org" Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sv.mirrors.kernel.org (Postfix) with ESMTPS id 46428283A17 for ; Mon, 18 Dec 2023 15:42:05 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 7D36874E3C; Mon, 18 Dec 2023 15:36:51 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=infradead.org header.i=@infradead.org header.b="wIxOQSPZ" X-Original-To: linux-kernel@vger.kernel.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 82A7F74097; Mon, 18 Dec 2023 15:36:47 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=lst.de Authentication-Results: smtp.subspace.kernel.org; spf=none smtp.mailfrom=bombadil.srs.infradead.org DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=bombadil.20210309; h=Content-Transfer-Encoding: MIME-Version:References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From:Sender :Reply-To:Content-Type:Content-ID:Content-Description; bh=b65KMtlYAzH3EUkpAxud2ReFVr8IHYHtgd3wSTH/RNI=; b=wIxOQSPZ9QaTybwrOD9nlYUkRM y+8Zb6dvZntvYiEKJllN8zuuGypcmjeu7cPyJWRRE+Fi8fVWQFfIPzfFljzQWA/7m7EebXSjpuGby ZxBT7WwEcpjYBrspB6z1WTQYVpyBXVdki2ccUQzksG71f2mGj6xHmzzSn29+2TiUT07EYabtmsSEA yjpaneMn2i1b5z0M+EWN6cvSKICP2g8eokXeawjJmIBfdsCN2ms6qC+WjksIXZgx/AY0iZWo/q1dc q1nJKDQPAPGC8P8DMR1Hb0mCPDuXhcA8+sfDzv9zFVilbUWOxiWUrz7F6UwF/edDUhPjfpeF9mZJg gxKIqiRg==; 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 1rFFfc-00BEaV-0K; Mon, 18 Dec 2023 15:36:40 +0000 From: Christoph Hellwig To: linux-mm@kvack.org Cc: "Matthew Wilcox (Oracle)" , Jan Kara , David Howells , Brian Foster , linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH 15/17] writeback: Add for_each_writeback_folio() Date: Mon, 18 Dec 2023 16:35:51 +0100 Message-Id: <20231218153553.807799-16-hch@lst.de> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20231218153553.807799-1-hch@lst.de> References: <20231218153553.807799-1-hch@lst.de> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-SRS-Rewrite: SMTP reverse-path rewritten from by bombadil.infradead.org. See http://www.infradead.org/rpr.html X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1785634882097667921 X-GMAIL-MSGID: 1785634882097667921 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 --- 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 195393981ccb5c..1c1a543070c17b 100644 --- a/include/linux/writeback.h +++ b/include/linux/writeback.h @@ -368,6 +368,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 0771f19950081f..fbffd30a9cc93f 100644 --- a/mm/page-writeback.c +++ b/mm/page-writeback.c @@ -2463,7 +2463,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) @@ -2479,7 +2479,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); @@ -2557,9 +2557,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 Mon Dec 18 15:35:52 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christoph Hellwig X-Patchwork-Id: 180505 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7300:24d3:b0:fb:cd0c:d3e with SMTP id r19csp1329958dyi; Mon, 18 Dec 2023 07:42:21 -0800 (PST) X-Google-Smtp-Source: AGHT+IGtlfzyzhQRE2cvVspIflzh08bkw+QEHl4jEIK2XHv8Da9k17COHr72rAMK7gw59eFKUzsU X-Received: by 2002:a17:906:a003:b0:a23:682b:751a with SMTP id p3-20020a170906a00300b00a23682b751amr493107ejy.108.1702914141110; Mon, 18 Dec 2023 07:42:21 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1702914141; cv=none; d=google.com; s=arc-20160816; b=h0gwjaG/9EYvslHc51Dl0hPk2c/fvXDypWKX2rT7aPry7NL+Tn6uX2PHPPB369OxB0 F/ePCHw3kAa8JhX/bk6wBj9dA+QPW6pedPx3Fh5sIUV0Vh9rBeRXuMxCTyUvtPSgGIeh 8EQfgh/r1pDHu4HwgMYPYRdGbDkHj+gK6dMeMjRWvsZR9YSSeyhLUVEHQLg+DRzSJSWM Vs/tv4IXlP1NL5TqJZc4kQXCOb6na0BR3QrrBW4wdt8JHytHDgjzKD6Tqh5KH7f8sPnb VM4wYr6cKE2ZGeorTp7CjyzVY5VYQqQp4M6w6RpSyYCd9PWO1ePSVferyKNm5gkNKitg M4Mw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :date:subject:cc:to:from:dkim-signature; bh=KurkZBc/b3Q18ZfxQxDEcSa/TUrlUIiFySdkJrxwQjU=; fh=m0HBXuwgOCKat7wyuY7vstPypqMqxNmINnjBv5+EUjU=; b=Q6eTjgGwh0SaNc8nSsXaf9sqC5XKnFASaaRJKwei6w7JpEk6j4a2E9+AmDBnZeICyw 36TlRDFP2TwQoECIhwNyYeJv0cjxtaiL0HOmtEECjGnnNIaym23JMvKqm4rNAQAc8e1n t3Ozx4CA2KqfCxu0RrRkOGcFuV767kpyF0pVMlBrMgrrtbo3meuiNoPnY4M7DTydTI1Y UbW29XO0s6NRGR30HaLUWsA9y/K+jAyrl34RovjHw5jyEU/kFAf3MP7TCLG3jjUy8skf TOLbTjppSVlCgaDusVqGcUYoGZR1e8oPdZZOCGRYFavLE0Cc+NQaDgKb/ZFG5/5kaEXf WVVA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@infradead.org header.s=bombadil.20210309 header.b=LVqlIw7q; spf=pass (google.com: domain of linux-kernel+bounces-3959-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-3959-ouuuleilei=gmail.com@vger.kernel.org" Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [147.75.80.249]) by mx.google.com with ESMTPS id m6-20020a1709060d8600b00a235839bab9si924751eji.735.2023.12.18.07.42.20 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 18 Dec 2023 07:42:21 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-3959-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) client-ip=147.75.80.249; Authentication-Results: mx.google.com; dkim=pass header.i=@infradead.org header.s=bombadil.20210309 header.b=LVqlIw7q; spf=pass (google.com: domain of linux-kernel+bounces-3959-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-3959-ouuuleilei=gmail.com@vger.kernel.org" Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by am.mirrors.kernel.org (Postfix) with ESMTPS id 600391F22BC7 for ; Mon, 18 Dec 2023 15:42:12 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 4285C74097; Mon, 18 Dec 2023 15:36:52 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=infradead.org header.i=@infradead.org header.b="LVqlIw7q" X-Original-To: linux-kernel@vger.kernel.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 56A1D498A9; Mon, 18 Dec 2023 15:36:48 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=lst.de Authentication-Results: smtp.subspace.kernel.org; spf=none smtp.mailfrom=bombadil.srs.infradead.org DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=bombadil.20210309; h=Content-Transfer-Encoding: MIME-Version:References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From:Sender :Reply-To:Content-Type:Content-ID:Content-Description; bh=KurkZBc/b3Q18ZfxQxDEcSa/TUrlUIiFySdkJrxwQjU=; b=LVqlIw7qs07E3gyDPGZmtD0XyP 0J7DxBmpXttZFRG+IwdLRoQ210NJqeMDCPwvx8pcytOPK4WaPF5iALq+Gere9cAAFy5YHYuoayf7o WKwlr5cnMo6YK/xL/Cid/5e4NHsvCFFUVnAZk6rEgRm6ta5km+tzbpG8tZ3u4VQX7YjwvdIvd9La/ UUs/2czN4LRM0MbYNCm8auOK1c94pPR2Eurr2Se1DpfMw6swR2Hs3y1wij2cA5jK2l4wHgZychHBa Linj7FiVDQk01OoYZwI+pB0Q7q0czwR2HmdVCNnS2czPrextgY+XsAC2CLKMbkZM68/VA3sMoQD2r mAGHD9Yw==; 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 1rFFfe-00BEby-2D; Mon, 18 Dec 2023 15:36:43 +0000 From: Christoph Hellwig To: linux-mm@kvack.org Cc: "Matthew Wilcox (Oracle)" , Jan Kara , David Howells , Brian Foster , linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH 16/17] writeback: Remove a use of write_cache_pages() from do_writepages() Date: Mon, 18 Dec 2023 16:35:52 +0100 Message-Id: <20231218153553.807799-17-hch@lst.de> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20231218153553.807799-1-hch@lst.de> References: <20231218153553.807799-1-hch@lst.de> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-SRS-Rewrite: SMTP reverse-path rewritten from by bombadil.infradead.org. See http://www.infradead.org/rpr.html X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1785634898180874388 X-GMAIL-MSGID: 1785634898180874388 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 --- 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 fbffd30a9cc93f..d3c2c78e0c67ce 100644 --- a/mm/page-writeback.c +++ b/mm/page-writeback.c @@ -2564,13 +2564,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) @@ -2586,12 +2594,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 Mon Dec 18 15:35:53 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christoph Hellwig X-Patchwork-Id: 180506 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7300:24d3:b0:fb:cd0c:d3e with SMTP id r19csp1330048dyi; Mon, 18 Dec 2023 07:42:31 -0800 (PST) X-Google-Smtp-Source: AGHT+IG8VVqewx+JzOp3zbXJFnNBQaDuBtPo5VYoXfihTlrYhlFak9bM6p8/T9hYxojd35x5tSQg X-Received: by 2002:a17:902:f54a:b0:1d3:ad3b:466 with SMTP id h10-20020a170902f54a00b001d3ad3b0466mr1117822plf.13.1702914151402; Mon, 18 Dec 2023 07:42:31 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1702914151; cv=none; d=google.com; s=arc-20160816; b=XoKAUqXguLTNgswpfAZyKVsK+GD9QNAGGSzPZlUvQ9nMq2LJJg6rkmfM5HzOcSTdz5 k9nkQ+lK6TB9fub8xG9vr0TTwK6Qo1t16K2DRznf3H1tKfs9ujf0JOAGHKZPN2cLIa+M 2dvRDB7KMYnd58lfl68M0BJFO/1UyKJHXh64yQGPHNZzwXR5S8DKwjv6Xn1qNEkunqoL 1OuBHVclyHILICQml877+Fd3uIg8F21uf5d40l52DQsqYmNtrS3xAIAIh0SKb/ChySge IlYrZ0N/zvsr7YBw2wuA3Xrx/Uw+dcriceBwjW0+e1kXK9HJknoPIUxwFk12iYvzhEBS +JjQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :date:subject:cc:to:from:dkim-signature; bh=Yv9NEALRhhPVlldz2t/Fuz2oV/CBEjy/kwNcSSKy2c0=; fh=m0HBXuwgOCKat7wyuY7vstPypqMqxNmINnjBv5+EUjU=; b=Fp1dDzYX8dA4uKZ+gdW0RMdJbeW+9s1raltbpRvUD/Tfn3FVMUPrOWReGXoluMRyrV JbKJ7911CfXat5Qv59rV27QzDoHnji2D6ILlVTgT7avYLDQHPZoC82SlR9irio4QbezC Pa/9fsA5rJbz3BbNoJxvTK2f5pxctuS/wB7lRV55oZ7EnHw4aPQU6CY4k4EfIu8KTO3/ +HAnZJDVyPJGSEetIh/z3XFZICRaUJtNe9vEP2wknI0eJMzytYCPp0EhfpG0NrWS+pMy 4MuaNC+hC0q9bTSFOAhlr6DoeUu4ltkB2u7xficEIzVfJlhcWvILKxWYFaA/OvpjPHWQ g8Aw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@infradead.org header.s=bombadil.20210309 header.b="Ta/ZLMIs"; spf=pass (google.com: domain of linux-kernel+bounces-3960-ouuuleilei=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-3960-ouuuleilei=gmail.com@vger.kernel.org" Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [139.178.88.99]) by mx.google.com with ESMTPS id b6-20020a170902bd4600b001d055df4ce6si17889349plx.422.2023.12.18.07.42.31 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 18 Dec 2023 07:42:31 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-3960-ouuuleilei=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) client-ip=139.178.88.99; Authentication-Results: mx.google.com; dkim=pass header.i=@infradead.org header.s=bombadil.20210309 header.b="Ta/ZLMIs"; spf=pass (google.com: domain of linux-kernel+bounces-3960-ouuuleilei=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-3960-ouuuleilei=gmail.com@vger.kernel.org" Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sv.mirrors.kernel.org (Postfix) with ESMTPS id 2DFC1283CD7 for ; Mon, 18 Dec 2023 15:42:31 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id C186B760AF; Mon, 18 Dec 2023 15:36:56 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=infradead.org header.i=@infradead.org header.b="Ta/ZLMIs" X-Original-To: linux-kernel@vger.kernel.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id A7D347608C; Mon, 18 Dec 2023 15:36:52 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=lst.de Authentication-Results: smtp.subspace.kernel.org; spf=none smtp.mailfrom=bombadil.srs.infradead.org DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=bombadil.20210309; h=Content-Transfer-Encoding: MIME-Version:References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From:Sender :Reply-To:Content-Type:Content-ID:Content-Description; bh=Yv9NEALRhhPVlldz2t/Fuz2oV/CBEjy/kwNcSSKy2c0=; b=Ta/ZLMIsSHqIp2kIeOMq/K8hB2 zFZCr1dwmBjJEP7zd40V7gPNrS8Qq8UdpAP4HvpFibJa7PnELaGjiXIkJgs9LbZfhxzMLiZxR19/Z ++ITeDX1dp9VlPnF7QA5rPA1D7yzo/KssnWGNQfL8BiIiooj5jmwq4zPBo9jPWNrxYSz0+JvXqQzt PcEtGKUqDiewhkGM0ONfc2onosXMtAAhLVUhezlbdzmUWnT4EE50UjXRKfAWvUhEtjA4PLGZp0qYc a8UXrSBukXbauIaVN5VwADLcnX3Mq8vOHhtXGAGyXTGZLBBIcMALFeurlzETNild+N+rdYR7/ZYiq U19LWeWQ==; 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 1rFFfh-00BEdJ-09; Mon, 18 Dec 2023 15:36:45 +0000 From: Christoph Hellwig To: linux-mm@kvack.org Cc: "Matthew Wilcox (Oracle)" , Jan Kara , David Howells , Brian Foster , linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH 17/17] writeback: update the kerneldoc comment for tag_pages_for_writeback Date: Mon, 18 Dec 2023 16:35:53 +0100 Message-Id: <20231218153553.807799-18-hch@lst.de> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20231218153553.807799-1-hch@lst.de> References: <20231218153553.807799-1-hch@lst.de> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-SRS-Rewrite: SMTP reverse-path rewritten from by bombadil.infradead.org. See http://www.infradead.org/rpr.html X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1785634909078327854 X-GMAIL-MSGID: 1785634909078327854 Don't refer to write_cache_pages, which now is just a wrapper for the writeback iterator. Signed-off-by: Christoph Hellwig 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 d3c2c78e0c67ce..bc69044fd063e8 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)