From patchwork Fri Dec 22 15:08:11 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christoph Hellwig X-Patchwork-Id: 182686 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7300:2483:b0:fb:cd0c:d3e with SMTP id q3csp1125720dyi; Fri, 22 Dec 2023 07:10:20 -0800 (PST) X-Google-Smtp-Source: AGHT+IG36PJHYM/9qA1krzn3aOZQ245PW38aCYyzGYABDnn8/fkCgZFM2Xy54dd10HErTiKn1xeX X-Received: by 2002:a05:6a20:325b:b0:191:520b:6d91 with SMTP id hm27-20020a056a20325b00b00191520b6d91mr1597549pzc.40.1703257820099; Fri, 22 Dec 2023 07:10:20 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1703257820; cv=none; d=google.com; s=arc-20160816; b=g5SPr4mPpEKFckEkk9XWgZe5Ai8wF8e9T8+z7zVEREOD9a6OMN56eELGn7y4iA3zfp Vna7ZoOK1wUPG6GJIHvYt+/tCh5ec2ZSRnREAAOr1Um+t82MSQ4XBXdPaXIt0vAGTiAf r4IVh9tfeeZoqgy3fm+fD11KDcvLTU6VQWlRT1tKI1g0lm9Z8QIw7b/DgxaCwwp5uQ4n O4dYG+0F6bB3Pdz3mUxusjeypU2VSIAsY32d8Ff5j8UWzCn40kx425XczBfX7JvGHZTD Qm5Ot105rIXsW2Z+r2KpP0zezujInuhDuobcXa+IWN2cQZJ/tQUb1zoZBojDbOEIvwAa eyBg== 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=UHLYB53YtGsTugfyc+sHmLVVrbGg0LS55c68Xz8vbHU=; fh=hzpEVxJ05G9gyZL9WVyKgOEGxITvmFSuTcKyr2ByStg=; b=SHHpaWSG5ZSLzy1Mlk/HwlZONECEi6arxmatZUdgTsfcXE3yinaFAk2eSY5wHrWm1y /l/xQLV0I5ZvXn9pWD4OnRaGr519LAAqjNGDPiUWqO7cYINpcpUVYWQdl0SPKgbIOfEs gmTZce5apWsSiCopVXdFQDHrK9SGxF775QG8hPL+z8Hhy+ExTYwKdBrmXmMJXB9x8DlF sPivXsHdd1PJLyqwftB/jf/ddlFJgfhWJ3UTXDJgXFaCossy4xi8RQ4Ur1u8FF7LJoQ6 LduRPscd9cvkyg408RZlKefiQLIW6oFXhsxwzwR9vSizeg3S8N7Cy5EsK+JpSEu6n7pl zoGg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@infradead.org header.s=bombadil.20210309 header.b=sS1lzdSK; spf=pass (google.com: domain of linux-kernel+bounces-9812-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) smtp.mailfrom="linux-kernel+bounces-9812-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 p29-20020aa79e9d000000b006d5aa09b7casi3290932pfq.396.2023.12.22.07.10.19 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 22 Dec 2023 07:10:20 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-9812-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=sS1lzdSK; spf=pass (google.com: domain of linux-kernel+bounces-9812-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) smtp.mailfrom="linux-kernel+bounces-9812-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 E8CFDB23551 for ; Fri, 22 Dec 2023 15:09:13 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 29926241FF; Fri, 22 Dec 2023 15:08:42 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=infradead.org header.i=@infradead.org header.b="sS1lzdSK" 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 0574A23741; Fri, 22 Dec 2023 15:08:34 +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=UHLYB53YtGsTugfyc+sHmLVVrbGg0LS55c68Xz8vbHU=; b=sS1lzdSKCtbDDt5pryAreVWTDH SjkKoxC7B15xtfkczw8hl1mfsQbLTllwOTvsAXunotk3Fp2hLQPGqlwbaVRFgsU0ZaAcyw6VQH9k1 kk2oEtaDSk0x88fUWX7NBy3ajJmxXiSLpCr+H/7QvpWjlhwAweh5KmPWDZEljN1iFlOqxQ2VknBah Wlr233mRp7xfWL07mAdOfNycfh9hy4Vmab1nwypZqdomhnN5QFuas6w8rM6D0zdOlQYfkuS1eN4g4 xf7tOIbwqPtd8oS5XwjiPBQoJYrMUK5MnXGVXxw9sfXfr8TzwUqZ5dVcUotykFxtw2mfLOg0vKZON E8ZhJhkw==; 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 1rGh8X-006BLb-2P; Fri, 22 Dec 2023 15:08: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, Jan Kara , Dave Chinner Subject: [PATCH 01/17] writeback: fix done_index when hitting the wbc->nr_to_write Date: Fri, 22 Dec 2023 16:08:11 +0100 Message-Id: <20231222150827.1329938-2-hch@lst.de> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20231222150827.1329938-1-hch@lst.de> References: <20231222150827.1329938-1-hch@lst.de> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 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: 1785995271537447305 X-GMAIL-MSGID: 1785995271537447305 When write_cache_pages finishes writing out a folio, it fails to update done_index to account for the number of pages in the folio just written. That means when range_cyclic writeback is restarted, it will be restarted at this folio instead of after it as it should. Fix that by updating done_index before breaking out of the loop. Signed-off-by: Christoph Hellwig Reviewed-by: Jan Kara Acked-by: Dave Chinner --- mm/page-writeback.c | 1 + 1 file changed, 1 insertion(+) diff --git a/mm/page-writeback.c b/mm/page-writeback.c index 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 Fri Dec 22 15:08:12 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christoph Hellwig X-Patchwork-Id: 182701 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7300:2483:b0:fb:cd0c:d3e with SMTP id q3csp1133961dyi; Fri, 22 Dec 2023 07:22:08 -0800 (PST) X-Google-Smtp-Source: AGHT+IGCFMzNvIYVkJI6dH6RdFaNEG4xQiihUIjAwQye3UIsXESKM/JyKhgvcII4f9F0kwQ8Nhpf X-Received: by 2002:a17:907:2cf4:b0:a1f:a0ac:ab3a with SMTP id hz20-20020a1709072cf400b00a1fa0acab3amr848927ejc.129.1703258528006; Fri, 22 Dec 2023 07:22:08 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1703258527; cv=none; d=google.com; s=arc-20160816; b=mIt9Q4B3P7Fe5/F0oGEMFr21DS3nXCn9Il9iLpCLH0PJt4gYa7e8qABum8gZTLNgc7 FRH1Upgy6JTpzlawlTLfcXkdBi3aLe8D8v3EoXVjYnUMro2LUZENju+GtNYA0yWoPLhk 4FinpYJVdNYbFkleGjY2zFee04xwH5qZoa0eDCmjo9FIQ7PgemlBLYP3yY4tuqAlqmGM isevl2GcRxkMEF2guxwbQe51hRFvceapJrdsD75kFAh39/1RYvoqCYmknZJ4L0g+PYhT KR2Mhs2hmparhyDa48vgURqOOwfOozrsUqOfSPt0fyMvq31j6/3F54hv8jKrm+FqNKFw Dc8g== 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=fN/ppIDjf8llE1R2IP9HkDxKkqwH+tE6Rl+QLZ2/TEU=; fh=hzpEVxJ05G9gyZL9WVyKgOEGxITvmFSuTcKyr2ByStg=; b=ALMpAgX81aAMmOGADkGrIdnQqQc7h/fsmXcLUlZZtRqtLGEB0VzoPYgyhARoS/24G/ epP4vUgJtK2KMSoqONfEo7EftJoiTSMw4bKy2KwO0t4LBLIDBdxxG5VVHWEH5vj799HT 9Vb8loOHp21vi4OEcRykkw7tRVuscYEzjPiHnLC3TsjeSCY5h4W9ldWByGfzA9ZgHeHk 5eJzDfqH2QLi6LepmcDdiy+6GGR1s5gC0WlW+cHtkcjfOR3N91+Jkhnvbp30N2JqD2Rw LKtW7NzWSKdrCnL1VjyOD4zYrOr9DPOLL2JecIArsvBRMCybx7DVWQIqbpEUlxO3zt3y hQTA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@infradead.org header.s=bombadil.20210309 header.b=eW2Uy2m7; spf=pass (google.com: domain of linux-kernel+bounces-9831-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-9831-ouuuleilei=gmail.com@vger.kernel.org" Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [2604:1380:4601:e00::3]) by mx.google.com with ESMTPS id e25-20020a170906249900b00a2349eee2b0si1928099ejb.636.2023.12.22.07.22.07 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 22 Dec 2023 07:22:07 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-9831-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) client-ip=2604:1380:4601:e00::3; Authentication-Results: mx.google.com; dkim=pass header.i=@infradead.org header.s=bombadil.20210309 header.b=eW2Uy2m7; spf=pass (google.com: domain of linux-kernel+bounces-9831-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-9831-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 12BD61F27968 for ; Fri, 22 Dec 2023 15:14:50 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id CC4F1241F7; Fri, 22 Dec 2023 15:09:28 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=infradead.org header.i=@infradead.org header.b="eW2Uy2m7" 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 26F5723741; Fri, 22 Dec 2023 15:09:23 +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=fN/ppIDjf8llE1R2IP9HkDxKkqwH+tE6Rl+QLZ2/TEU=; b=eW2Uy2m7FBO5xaNthhnztdQcks hrr4l0624Om9pIxbz9CvVT6F8/8GtvMNoXbmwGlCDFF8nGnq5VDQOhY68QwmxCcNbw02AiezjLC+h LciBMuT9iTN3DQKZJHLpSWtmgUBo1N6gBdfQ80vxoMRYMIFbnLv7rZkdvcE13PbK+RLrfJxZ6V/Wm NaEoaC6tJ3nXJN0Gfu7VKwYethnw5imyEeNqEF8c7//UPkIYO6NwJMsmMjN2v5/e76lJMEddiOmLy RQMKELa4SOwk1keLw5zIhtdwJ6WKunryCLuXgV9j0hnVCbu+3sDisXU0HwhYEHJuIKUDxvODk0o+Z CSzgEfwA==; 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 1rGh8a-006BM3-0e; Fri, 22 Dec 2023 15:08:32 +0000 From: Christoph Hellwig To: linux-mm@kvack.org Cc: "Matthew Wilcox (Oracle)" , Jan Kara , David Howells , Brian Foster , linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org, Jan Kara , Dave Chinner Subject: [PATCH 02/17] writeback: also update wbc->nr_to_write on writeback failure Date: Fri, 22 Dec 2023 16:08:12 +0100 Message-Id: <20231222150827.1329938-3-hch@lst.de> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20231222150827.1329938-1-hch@lst.de> References: <20231222150827.1329938-1-hch@lst.de> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 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: 1785996014006955175 X-GMAIL-MSGID: 1785996014006955175 When exiting write_cache_pages early due to a non-integrity write failure, wbc->nr_to_write currently doesn't account for the folio we just failed to write. This doesn't matter because the callers always ingore the value on a failure, but moving the update to common code will allow to simplify the code, so do it. Signed-off-by: Christoph Hellwig Reviewed-by: Jan Kara Acked-by: Dave Chinner --- mm/page-writeback.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mm/page-writeback.c b/mm/page-writeback.c index 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 Fri Dec 22 15:08:13 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christoph Hellwig X-Patchwork-Id: 182687 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7300:2483:b0:fb:cd0c:d3e with SMTP id q3csp1125750dyi; Fri, 22 Dec 2023 07:10:22 -0800 (PST) X-Google-Smtp-Source: AGHT+IFj8rpdrnL7yXAZ0aMNmlko6eMG7uG6RqUGF0oYY8VCIcGMR0favWZOdlY3dLYeA68Y2dMs X-Received: by 2002:a05:6870:1713:b0:204:4149:976b with SMTP id h19-20020a056870171300b002044149976bmr1760843oae.0.1703257822031; Fri, 22 Dec 2023 07:10:22 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1703257821; cv=none; d=google.com; s=arc-20160816; b=dXJNBgUewxiGHJmH2DW1jg1aDvcwhSei9alTWgrkMZr7oOOvUGRwraShHqxAjH30k4 nq6o6CVW28xYyI63gfvFM0svulL1twPMg6NkY6l6ekWmKQmffdK+afNv8Vgvp0uGD0x2 fyvbdx6Flp9jh3VWB0GWlcUOmX/kwqTthzyEwF/c7g5scKmr4uUF0Cr940gb2n4mS82U KmYzV5gfooTjQWjccWv/z4jER1dwNQIr1lg05f0kdErS7lNNurz88++TAxuumqOW+XtS 1Cdu1RGDaUlP6529u3aP3Yo2egsJGjEg+HlWarccdBLHZzHptnwhJTwygInh7HRUS+aL PhEQ== 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=aiTqCmsyGk4E7LEDYa2Lc4VptDi32CoIamzlkv7IN4k=; fh=hzpEVxJ05G9gyZL9WVyKgOEGxITvmFSuTcKyr2ByStg=; b=mK/lt2IXuLj1Rn7ZHOhLoB5enjV0o2CJXceGf0Grcduv9Y2Ew8A9uS2RAaahtXsDyf MJwuB7/aCoV78bxvVcdJXDFGiwfkUKFOlB2d2vxmtNwVku7GklY9I2AtaY5oBxJYvDi4 TfG4rk8pB849MykDUOnCiz07G5LsLD1HgunpkfyhB7XyplKcTc5qUv4RNbY3Yg394rTH SzusaMWwPIjFOOnAiIRzhfs2Hfdsyu2PBtpGLjMbPHeQh/tJOjq7BgdoD43Or7RYX7jJ EeIFU77rqhVLcf9K+b8YwM2Lhal7JfNLY28KjhC3lE/+jEJN4YfEKvssrU2wj6J0eiNl Cvuw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@infradead.org header.s=bombadil.20210309 header.b=Z6VUXUaO; spf=pass (google.com: domain of linux-kernel+bounces-9815-ouuuleilei=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-9815-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 i64-20020a639d43000000b005c65ee2abaesi492539pgd.219.2023.12.22.07.10.21 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 22 Dec 2023 07:10:21 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-9815-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=Z6VUXUaO; spf=pass (google.com: domain of linux-kernel+bounces-9815-ouuuleilei=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-9815-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 C71D5283890 for ; Fri, 22 Dec 2023 15:10:09 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id B090728DCC; Fri, 22 Dec 2023 15:08:46 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=infradead.org header.i=@infradead.org header.b="Z6VUXUaO" 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 DE95B24215; Fri, 22 Dec 2023 15:08:42 +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=aiTqCmsyGk4E7LEDYa2Lc4VptDi32CoIamzlkv7IN4k=; b=Z6VUXUaOnTXFhPPhvYLJ/CI7r+ 598L/x1qssfMn/59wmI2TR1LAjz4u+kDW5Nm60tNob0N/ESCYSA2gORLrF8dLjo+CB2AUmg9iWjiU vg3Yj1XFCntRF8l5h7YKvZVe5SEmrCIeF9qXoxetiOCRs4Q1Aitg6PbJi19nea7MVIO19Kp5CYZF+ 3Nnj3WXzTHCmBacJmCICSBDReSKIntJmPrV+8G22uCHaMisfcnpBn+5MVwkkeYU9SHRM8Yq+5wxK8 RQjG0VQl7bkgPwdxOLdyOnWEQzTsJ/bRLdG9XcL5S0sXkeQNYuqZwZ3EdiMtKs0PavEur4+WPuOJm HpUGJILg==; 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 1rGh8c-006BMq-2T; Fri, 22 Dec 2023 15:08:35 +0000 From: Christoph Hellwig To: linux-mm@kvack.org Cc: "Matthew Wilcox (Oracle)" , Jan Kara , David Howells , Brian Foster , linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org, Jan Kara , Dave Chinner Subject: [PATCH 03/17] writeback: rework the loop termination condition in write_cache_pages Date: Fri, 22 Dec 2023 16:08:13 +0100 Message-Id: <20231222150827.1329938-4-hch@lst.de> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20231222150827.1329938-1-hch@lst.de> References: <20231222150827.1329938-1-hch@lst.de> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 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: 1785995273964193466 X-GMAIL-MSGID: 1785995273964193466 Rework the way we deal with the cleanup after the writepage call. First handle the magic AOP_WRITEPAGE_ACTIVATE separately from real error returns to get it out of the way of the actual error handling path. Then merge the code to set ret for integrity vs non-integrity writeback. For non-integrity writeback the loop is terminated on the first error, so ret will never be non-zero. Then use a single block to check for non-integrity writewack to consolidate the cases where it returns for either an error or running off the end of nr_to_write. Signed-off-by: Christoph Hellwig Reviewed-by: Jan Kara Acked-by: Dave Chinner --- mm/page-writeback.c | 62 +++++++++++++++++++++------------------------ 1 file changed, 29 insertions(+), 33 deletions(-) diff --git a/mm/page-writeback.c b/mm/page-writeback.c index 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 Fri Dec 22 15:08:14 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christoph Hellwig X-Patchwork-Id: 182685 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7300:2483:b0:fb:cd0c:d3e with SMTP id q3csp1125555dyi; Fri, 22 Dec 2023 07:10:07 -0800 (PST) X-Google-Smtp-Source: AGHT+IFtyhAOml0BpSblLkcIMkJdZpjjv4Qj2as4+8+atu5vNA7HREBDGDMuXPFMiaqBU9rnxCb/ X-Received: by 2002:a19:2d12:0:b0:50e:5082:a868 with SMTP id k18-20020a192d12000000b0050e5082a868mr722622lfj.104.1703257807493; Fri, 22 Dec 2023 07:10:07 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1703257807; cv=none; d=google.com; s=arc-20160816; b=vqBeOBazw3vIswJRhynu+nkj3rMqrE6GceZAxCQmfjeCeEAo7DcYCw4touVdg/JIBm rLu9MoU4kUUk3yi/8eQHgliX0wY+VSr8zpFQ5c1f8E/Qbwf9bqbT/l4asBMXUJxQwE0j 30caKZw7dpy96a6dgQjCYTerCh0a66ly9qi2I2ltMk7Cz0LMXVmHpDqkCpi8b8+GoIEw W8X4/e/SmvKy/WEyoacwpi9G91mCH66yQng+vITmMMrAQZi6IDSrVoNu9xYqm8dMs45t BBoA5tboOpEOeHtX3WZkWKAt+Z4Sk1nH5NcHlpQO/O3J1I5Z6xVOhQf67WbdSmENt+nw g7xQ== 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=0tDqvYwFSGZxiPUTzlW4HNez1MU15vMHRFJdEDf7Dd0=; fh=hzpEVxJ05G9gyZL9WVyKgOEGxITvmFSuTcKyr2ByStg=; b=ojHPiQUbxPlr0beO1A9EjxcuNtH7MpgdIKgA4ECvS0m+bRkX3PTbqMBBxlNDgRZE2B ulv2gDrqRJZ4sb+glA3Hgafr7zx9lqapilcEizzWqxwScRKinC7l8jg4wELZmfkk0JHW dDhUUv4lBVxAwC8LLWDIJ2iT2jJms7DlvdcRQaqsO+mPnMmFUVJ6mPla+Zla34nFDbwC 8O/jvq7doKhlQybc3v7nwdFE0OyurO+lAXudKdLnAc0YEpFwld4gGiLhPi9CTutoivVO 04bgfPFF8CpCryVCrc0RwewlbXWcLh278qRBmgCvkUpdQqXVLx6G0hyA8HJI2o+GePFe dzqA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@infradead.org header.s=bombadil.20210309 header.b=lyhf1Gv6; spf=pass (google.com: domain of linux-kernel+bounces-9814-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-9814-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 a19-20020a170906685300b00a1ca020ce03si1767906ejs.787.2023.12.22.07.10.07 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 22 Dec 2023 07:10:07 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-9814-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=lyhf1Gv6; spf=pass (google.com: domain of linux-kernel+bounces-9814-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-9814-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 1D6521F2833B for ; Fri, 22 Dec 2023 15:10:07 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 683C928DC3; Fri, 22 Dec 2023 15:08:46 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=infradead.org header.i=@infradead.org header.b="lyhf1Gv6" 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 1FA382377F; Fri, 22 Dec 2023 15:08: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=0tDqvYwFSGZxiPUTzlW4HNez1MU15vMHRFJdEDf7Dd0=; b=lyhf1Gv62XTy6SIBb8FrvCwqeh 1RaBZI0ukFpiajsVrAsJrsZE92GjbqPfI6XSdb1FjhFStqbhHLQjcmygA2wH2wRH8g3+05NMl9J+N 42ri8YHKlGerT9Tdd/88EoNNxcMX1xuIID+mZi3Rh1dTDwGk4ls0ipAks+FX5tabN81pWf0lIHPRj NReb01NKF+7sAICLZpkCUU6tt3stIcOSMyEuON9OYEzR6kMjSiPZ2RCiEQU7gotUP29X6VXo8q5pY aZiHY97ygOa2Pd81Mq1Vmwb+9UWfc+APNvoMxS87cC91low9T6nGXFJCO4S6AiYx5ltUy6dTrm+i8 ULWolkew==; 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 1rGh8f-006BNf-1U; Fri, 22 Dec 2023 15:08: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, Jan Kara , Dave Chinner Subject: [PATCH 04/17] writeback: only update ->writeback_index for range_cyclic writeback Date: Fri, 22 Dec 2023 16:08:14 +0100 Message-Id: <20231222150827.1329938-5-hch@lst.de> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20231222150827.1329938-1-hch@lst.de> References: <20231222150827.1329938-1-hch@lst.de> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 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: 1785995259054927424 X-GMAIL-MSGID: 1785995259054927424 mapping->writeback_index is only [1] used as the starting point for range_cyclic writeback, so there is no point in updating it for other types of writeback. [1] except for btrfs_defrag_file which does really odd things with mapping->writeback_index. But btrfs doesn't use write_cache_pages at all, so this isn't relevant here. Signed-off-by: Christoph Hellwig Reviewed-by: Jan Kara Acked-by: Dave Chinner --- mm/page-writeback.c | 24 ++++++++++++++---------- 1 file changed, 14 insertions(+), 10 deletions(-) diff --git a/mm/page-writeback.c b/mm/page-writeback.c index 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 Fri Dec 22 15:08:15 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christoph Hellwig X-Patchwork-Id: 182692 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7300:2483:b0:fb:cd0c:d3e with SMTP id q3csp1127492dyi; Fri, 22 Dec 2023 07:12:42 -0800 (PST) X-Google-Smtp-Source: AGHT+IGnTq0koJrZ3xnWQ2I+dEfB7IS2gbf4MuOvdtNc5/wt8pW90EMXEvfOBarbG+bDwJ2TsM46 X-Received: by 2002:a2e:9b4c:0:b0:2cb:2b6a:e168 with SMTP id o12-20020a2e9b4c000000b002cb2b6ae168mr711709ljj.9.1703257962545; Fri, 22 Dec 2023 07:12:42 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1703257962; cv=none; d=google.com; s=arc-20160816; b=VmpXhugcNib2iBRaio8+AnXYupZxKvBK7ikSPoVyPjjnb+oSV5vyZFKyxKlaYPdTUo cx6wj+fHWIlOxrT3ldu68hD6W/nBjHhMZTXJ8cPIdVCcFgVZ7EDcZCBAiBoIhVSxmNT7 TQpQ+bUgRvNO8Lar9Nk7VxHfv9zpuUvUdVMpgP6/9cZPd1bnbOk6mgei0UyBSiWTq7QD J8+IkZ/3jU5DroBL6wQcFWX4Zymh23SecWNvsbrun4uq+HEJxgS0BIYg2MHEDlSuO/Py 3/M7rsYnCRU72cf+uM4Gn9j1KdTK8r02b5w5teiFJtloGRC3QFchmuHCUsnh19cSfbIP tj6w== 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=C2vff2ZtkO5ymT4AwpEFr32HKz+HzpqwK8XI6XGgOh0=; fh=hzpEVxJ05G9gyZL9WVyKgOEGxITvmFSuTcKyr2ByStg=; b=WF7pHB7Sgx6jjDC1dp6yUr1h+uC81sPWgRniHx0un6bPhZZhEqm6Bj+QQfcbu2DAZ+ yKQ0F+eRrLLtAtBQwzmatpe3CWrFceCcNvFC32Fb7IpGhAlJ29VE0rLwjWdH5BsWIuAV ba9ppq4jHkaPNVMIILW3qfx2TeyW+u5lgiN/uWcawvne8xwbUK3P9HcHV+D5rGD2hni4 mjJi3iM0JYeB50BFWFEvHLFZshp0VGerLfu3W/n3KNZdczOCP3xJxUd9hOro23hBOGMA NBVFCKEvj61M8vAutP5ZCdrrxEw39asPdDW4jH+WvuO4ZhD6X/qNLqKc6rfynDtVPmrV 5N3Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@infradead.org header.s=bombadil.20210309 header.b=e+k8f0nj; spf=pass (google.com: domain of linux-kernel+bounces-9818-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-9818-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 w4-20020a056402268400b00554778c8c2esi72399edd.144.2023.12.22.07.12.42 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 22 Dec 2023 07:12:42 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-9818-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=e+k8f0nj; spf=pass (google.com: domain of linux-kernel+bounces-9818-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-9818-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 1F0571F21D50 for ; Fri, 22 Dec 2023 15:10:55 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 9FE102C1A8; Fri, 22 Dec 2023 15:08:51 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=infradead.org header.i=@infradead.org header.b="e+k8f0nj" 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 CC23E28E08; Fri, 22 Dec 2023 15:08: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=C2vff2ZtkO5ymT4AwpEFr32HKz+HzpqwK8XI6XGgOh0=; b=e+k8f0njZ2ngt8JINzl1za1aVf AqLBYMRDqugK9fjHpoPbpRPF1/TsbUAE7Kfy64CrD2SeSgreU2Iyn580faBV0rYL0PUTKXxMeVfpo HUqRylBgNWtva7q42aOWQT6LUP6a/x9WqISQQrm1NVkRn5poiWf60Mf5wyANQ+squIwufjg/xdk+C TlDPW4CYPw3BK9kXfWumCK++9FtBRxmq2COpbt11zNiEl7ddJCP31czZVJ03312y/1xVlyxQTudaz xntQ4O6Y6XmU1m7AvmTu3f/OaPn8gbwT5rhHxelHYJBethKxbJ/bOJsh2ogp6H8Et73MtdKR6nRK/ Tuqyq/lw==; 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 1rGh8h-006BOe-2U; Fri, 22 Dec 2023 15:08: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, Jan Kara , Dave Chinner Subject: [PATCH 05/17] writeback: remove a duplicate prototype for tag_pages_for_writeback Date: Fri, 22 Dec 2023 16:08:15 +0100 Message-Id: <20231222150827.1329938-6-hch@lst.de> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20231222150827.1329938-1-hch@lst.de> References: <20231222150827.1329938-1-hch@lst.de> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 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: 1785995421760744527 X-GMAIL-MSGID: 1785995421760744527 From: "Matthew Wilcox (Oracle)" Signed-off-by: Christoph Hellwig [hch: split from a larger patch] Signed-off-by: Matthew Wilcox (Oracle) Reviewed-by: Jan Kara Acked-by: Dave Chinner --- include/linux/writeback.h | 2 -- 1 file changed, 2 deletions(-) diff --git a/include/linux/writeback.h b/include/linux/writeback.h index 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 Fri Dec 22 15:08:16 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christoph Hellwig X-Patchwork-Id: 182688 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7300:2483:b0:fb:cd0c:d3e with SMTP id q3csp1126100dyi; Fri, 22 Dec 2023 07:10:47 -0800 (PST) X-Google-Smtp-Source: AGHT+IHrzfOGhrzgk6CXgVAXJ1ebp30nBDgtwEel++UozcZJOHaZ6nk8Aaxw6K9/xtz4/wBI9DSW X-Received: by 2002:a05:600c:a388:b0:40c:a11:19df with SMTP id hn8-20020a05600ca38800b0040c0a1119dfmr552440wmb.180.1703257847680; Fri, 22 Dec 2023 07:10:47 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1703257847; cv=none; d=google.com; s=arc-20160816; b=Du8dTmmJp9ad3OTs6VmwZjHIoLfddSE2oxJuIo0jfN0o/2UBzf9bhBFUA2tZBog7Ee 8RUNi5/OLkYC+DHw8O/zReModp0b9FPGF7UOajZvQxiGPjtDlaJKxbyjYVyX8fecvKpb YgKupIiWacl3pSPLXtuM9bbS1BiA7h7d5cMtKdQk3ftL5DKU2lJ437eD5pgA4T17tD7l ETTLa20W4drLRn/J0R3vXgA8PDQvbrsQaDXqJLhMLe0wJ3UvUp4e90iDi2sob1inijp9 qX0KifrOpUXnptDYcqZojQElLRkymPgarCj2viQAdHI5Gx1U9VEa0wrx/i/gbjWolbs7 5wPA== 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=/YruVy693sIGMqSVhVr/4+JF9RoXWgnIrtLSdSPK4mw=; fh=hzpEVxJ05G9gyZL9WVyKgOEGxITvmFSuTcKyr2ByStg=; b=i6N/ITpa2UnpK0/EQtCPKj2MQLY/R25ZPN9GLRIXRO782kd2KMznQuXZRYOl4pnxD3 u8r7B5FgN+F28Lf5txNTmdOX0Ps3vd2b7j1exdFumVahaJzLNNYC00mo2sLOC2RPiddQ pdRFm5HywbKfvAvce2JnBGya0eaFBW8r0/RaFMDx1lTPKxGELdfFnG9dZMI+n8kOUaBX x5l47mCqmhmXjCPLT9Fp05y4zqVK/RvV4K0jHzuzi5NnROveWDI4cN+jx/ehir6/H6D2 sGxCL5e6A2PW2CVsACCUFmjkaRTQyRGBK0VQe0k7VTuwEzoD4N4APiKt+N2CIw0WdQGH BMwA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@infradead.org header.s=bombadil.20210309 header.b=IUhhnEiE; spf=pass (google.com: domain of linux-kernel+bounces-9817-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-9817-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 d19-20020a170906305300b00a26ac57b921si1131879ejd.63.2023.12.22.07.10.47 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 22 Dec 2023 07:10:47 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-9817-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=IUhhnEiE; spf=pass (google.com: domain of linux-kernel+bounces-9817-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-9817-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 22BA91F283B7 for ; Fri, 22 Dec 2023 15:10:47 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 923D82C196; Fri, 22 Dec 2023 15:08:50 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=infradead.org header.i=@infradead.org header.b="IUhhnEiE" 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 A895A28DCB; Fri, 22 Dec 2023 15:08:45 +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=/YruVy693sIGMqSVhVr/4+JF9RoXWgnIrtLSdSPK4mw=; b=IUhhnEiESKEpLJdHRKcnKDOIrR X/YC3xSsenqLCvV2hqbEjMjE89Dggeuq/l0/DFlCqq2/Dv9lihc3A4g65Is18xfqqudV8B8C6VTg8 98zB4odPXmtfjhGlT9Qr5bZE5v6hPJC3SONm67/k3Xp57dGsKfSil1ishKDCXwqnoavb2P7c8sUfr xpVag96xhLM5Gv7QXvrXSKHI2r/WRkoMO8M3woP4O5IILeOj3HNKE56jPhc81gRlYy/HbeVTNijyj iI71h+qfhB9lepfDz1Iwo3wR6OeeSGbmlaG8fi6gRgnQVU6rZW669WmymrBZG0afHVD/S/0WwrTLO MR/NZ56Q==; 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 1rGh8k-006BPW-0l; Fri, 22 Dec 2023 15:08:42 +0000 From: Christoph Hellwig To: linux-mm@kvack.org Cc: "Matthew Wilcox (Oracle)" , Jan Kara , David Howells , Brian Foster , linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org, Jan Kara , Dave Chinner Subject: [PATCH 06/17] writeback: Factor out writeback_finish() Date: Fri, 22 Dec 2023 16:08:16 +0100 Message-Id: <20231222150827.1329938-7-hch@lst.de> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20231222150827.1329938-1-hch@lst.de> References: <20231222150827.1329938-1-hch@lst.de> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 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: 1785995300579220537 X-GMAIL-MSGID: 1785995300579220537 From: "Matthew Wilcox (Oracle)" Instead of having a 'done' variable that controls the nested loops, have a writeback_finish() that can be returned directly. This involves keeping more things in writeback_control, but it's just moving stuff allocated on the stack to being allocated slightly earlier on the stack. Signed-off-by: Matthew Wilcox (Oracle) [hch: heavily rebased, reordered and commented struct writeback_control] Signed-off-by: Christoph Hellwig Reviewed-by: Jan Kara Acked-by: Dave Chinner --- 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 Fri Dec 22 15:08:17 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christoph Hellwig X-Patchwork-Id: 182696 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7300:2483:b0:fb:cd0c:d3e with SMTP id q3csp1127928dyi; Fri, 22 Dec 2023 07:13:20 -0800 (PST) X-Google-Smtp-Source: AGHT+IE3fJ3TNqoG9Joa0m4jqbtkupJ7jmHs6l0S+PHrz489BBN+gwfzoYc5k+tBRSFka4D3jxRB X-Received: by 2002:a50:9558:0:b0:553:55e8:98eb with SMTP id v24-20020a509558000000b0055355e898ebmr765126eda.34.1703258000334; Fri, 22 Dec 2023 07:13:20 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1703258000; cv=none; d=google.com; s=arc-20160816; b=eD1yJ+DnXT5eD3L/hvOHumAQbvm20PfYsV/tOHPaOe+yMfD3VFyGfCiB1bIRScEJ7g zTDTgWamrxEQazS3cBd+b7pSDBFL9l2SE4UiPOWI3Pb9kvyadJIRBsCu9l8iTUxW+bik tvaYYfKBn8ycppcpKZSdSvS8252o5ROwPeB6rufw87l/GrjDTzDdFpF0xOmEOB1gSPxd 2ifallmcd3OxIvS7qZDbvTxQdNwS5LdgqXiJyD3FhZwO/H3jMOPVfKB5gJXb9l10QdS0 h96sM5uvaMnOTb+bFymakbUIgYrPO6+OiqrqFFjC0i8b4cqrG0dUWh7JPiNZxVKhPilE +KQg== 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=dcSwdTVvCQUQwEHV9ZU6DKJi2JGMjLPwvaIvkNqY5Tg=; fh=hzpEVxJ05G9gyZL9WVyKgOEGxITvmFSuTcKyr2ByStg=; b=F1PtAwOaGLyXrD/nNrXMoH+SlheVbAww6nljujRQPDydTHDAdir+iuzlUCdPVjMF9u JfKN87Lv8IMy4OEE1tYdUvm3X8GafrvnObnzXEwzuf8z/5jWq+o5z5F1CNZD4Y0jGHML YeTm+fAsIYQU+Tne6yrrgiWeM3AMcMN2xZiFykEmfs/6W6fLjXnAGn7LVYOfPDimXnok N3s/W7AqFx1RDoFj+jJz1MRuz/z3HuPqU0UzRFGNfbXX01BHpwGs4gODLnsx6AqG9ibr O41vf5flEkz/7NWMXOghs3YZJgKq4yWoY0+kw2pzUWlfiMN0B9EXJU3FU2hXSEyUHOMc j1BA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@infradead.org header.s=bombadil.20210309 header.b=A1L3KGi7; spf=pass (google.com: domain of linux-kernel+bounces-9822-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-9822-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 t4-20020a056402524400b005547482a0efsi148626edd.158.2023.12.22.07.13.20 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 22 Dec 2023 07:13:20 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-9822-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=A1L3KGi7; spf=pass (google.com: domain of linux-kernel+bounces-9822-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-9822-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 D63381F26F13 for ; Fri, 22 Dec 2023 15:12:04 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 29E172E3FF; Fri, 22 Dec 2023 15:08:59 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=infradead.org header.i=@infradead.org header.b="A1L3KGi7" 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 104E92C855; Fri, 22 Dec 2023 15:08:53 +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=dcSwdTVvCQUQwEHV9ZU6DKJi2JGMjLPwvaIvkNqY5Tg=; b=A1L3KGi7p22WmVHYwn8JAqK2do OXUFMCP8LJGy0Us0BB+qtD7uRWeU14L7juYdVzyoo741jIvkCVavCFPr7vn49oJnwBeb31GwyhyCL XMkYwmZAir6Q8gmHFK6Gky8PEmPyGgyC/KQTwjJI/mv6W+LjQtY/VI5pXzlj9BZdnNVpCESlp38Vu jDKhsTX0+/J0c5ijdwDmuwZyFecpwZm4RDeHS0BP2noVcUDK4cFWRWT1GMfPdyriBSS6BSTLFTFv6 PXWgGoOYcEAcl640qINBEZZbXhmFnZy7yHZ5tKGTOCGoGVoGeI9mHWUXUgs3+Q2npwJgqbpQmtJd7 K5IukuVA==; 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 1rGh8m-006BQI-21; Fri, 22 Dec 2023 15:08:44 +0000 From: Christoph Hellwig To: linux-mm@kvack.org Cc: "Matthew Wilcox (Oracle)" , Jan Kara , David Howells , Brian Foster , linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org, Jan Kara , Dave Chinner Subject: [PATCH 07/17] writeback: Factor writeback_get_batch() out of write_cache_pages() Date: Fri, 22 Dec 2023 16:08:17 +0100 Message-Id: <20231222150827.1329938-8-hch@lst.de> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20231222150827.1329938-1-hch@lst.de> References: <20231222150827.1329938-1-hch@lst.de> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 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: 1785995460775316427 X-GMAIL-MSGID: 1785995460775316427 From: "Matthew Wilcox (Oracle)" This simple helper will be the basis of the writeback iterator. To make this work, we need to remember the current index and end positions in writeback_control. Signed-off-by: Matthew Wilcox (Oracle) [hch: heavily rebased, add helpers to get the tag and end index, don't keep the end index in struct writeback_control] Signed-off-by: Christoph Hellwig Reviewed-by: Jan Kara Acked-by: Dave Chinner --- include/linux/writeback.h | 1 + mm/page-writeback.c | 49 +++++++++++++++++++++++++-------------- 2 files changed, 32 insertions(+), 18 deletions(-) diff --git a/include/linux/writeback.h b/include/linux/writeback.h index 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 Fri Dec 22 15:08:19 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christoph Hellwig X-Patchwork-Id: 182695 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7300:2483:b0:fb:cd0c:d3e with SMTP id q3csp1127740dyi; Fri, 22 Dec 2023 07:13:03 -0800 (PST) X-Google-Smtp-Source: AGHT+IEtxFbOVUAHlq30gkcsP6PfkDKc82oXtrHDBFz9KQ6gCog9stuke17kdjT6FUwav+DKi/Fl X-Received: by 2002:a17:906:7481:b0:a1c:837c:e4a0 with SMTP id e1-20020a170906748100b00a1c837ce4a0mr539122ejl.29.1703257983334; Fri, 22 Dec 2023 07:13:03 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1703257983; cv=none; d=google.com; s=arc-20160816; b=luiLAHCqtyVj8ci1TETx1mEvcQxDgjktVDvtUuY+yU/trCxG8t1vcHIggs2xAFOD1B 0BEoR/SSWudgRLtiRJa8ZlrJlhD66Os425/ZDPuUjQIo80fKUMSnA+zBay43mVIJUl6X fMApeXBU2J1CSEF0PbMIEq8ZZ09Ntw0gbzk4Mbx3/VEO9Nz6JIhvDnp8D2huy8GLKvDT n8d9XMDZTfmvzWTuXIiExVP6Vd59qn5Tb4rKGfVeXDHu+PZCLfBsHL/vk1503xk5Dyci IqV57C+hHt/7vPDer5u5TFfhOOvee4BWnU8T6kfTliIf3a8dHR5e0WGVoPmmwn8Fpt6W ic0A== 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=3uxekAKYtWjU4xunWw9AHOgXL8ikM7hINi+MFUVXD1Q=; fh=hzpEVxJ05G9gyZL9WVyKgOEGxITvmFSuTcKyr2ByStg=; b=zjU2lueRCwQH8O7FsIdcv3rQXriGrcwn0mnTqBEXQ6U7/kwobGulMQo7zHBvxqx6VW miGmsWfS7nj1E+ehLQmW1cvEAXveIy6Vjk50RW3iI4jjdhFLZDJYdDBBHQ3q5crmiUD9 ThLRWzTJA+XugAKVJPntkWagaolXXlg6eWN3XTT6gW5xtIQNd2vzVt+G2xa4iJwmFFR6 WGK2EfbOUsEOyNM8qrOfCQapjM5mV6Mgyr4xGzNbgbhJFW2CLUyf9Z+oHwkLPWqlcsKJ Wvcs7zj5J4VT7ggnQjP4WHyQ0etbmbfQ/HNxR9rLgQp8HmOR1th0blggT3iE9jnMltYy 0w1Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@infradead.org header.s=bombadil.20210309 header.b=yIAvYy07; spf=pass (google.com: domain of linux-kernel+bounces-9820-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-9820-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 gi19-20020a1709070c9300b00a232e088c69si1746859ejc.290.2023.12.22.07.13.03 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 22 Dec 2023 07:13:03 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-9820-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=yIAvYy07; spf=pass (google.com: domain of linux-kernel+bounces-9820-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-9820-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 63BFF1F26BBA for ; Fri, 22 Dec 2023 15:11:31 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 7D7DD2D039; Fri, 22 Dec 2023 15:08:56 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=infradead.org header.i=@infradead.org header.b="yIAvYy07" 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 9D7212C1B5; Fri, 22 Dec 2023 15:08: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=3uxekAKYtWjU4xunWw9AHOgXL8ikM7hINi+MFUVXD1Q=; b=yIAvYy07YYVywxCYNd4RPpUC2z hov+bjdw7XI7TCb4f222lmJzvS4zTCCXlwyPjJvhMKKBCYuLTj719RJP03bEqb7Ny/AEXGYoBrHcJ bQlB9PsdksaKg3Kudutgim4vY/WWFKu+9i5EiMoYzhnkQ2fMUEncbFuxCNqzsW6Qo2DuXMnVs1neU 4eh+YkvnDEvwvL3fOe1ac3QeobScCtYlB/jENSX9n2lKGLzBwJBD4XxjurornDUhLw7t0P15+/sNC Hl3HtLu61rDDl8jjubtzUWofoOftxS277w6sKdRzINQQXfSfWcYjG92SuUr1GMB27Gab9/JW6O5bL q6JhGxDQ==; 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 1rGh8r-006BSh-23; Fri, 22 Dec 2023 15:08:50 +0000 From: Christoph Hellwig To: linux-mm@kvack.org Cc: "Matthew Wilcox (Oracle)" , Jan Kara , David Howells , Brian Foster , linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org, Jan Kara , Dave Chinner Subject: [PATCH 09/17] writeback: Simplify the loops in write_cache_pages() Date: Fri, 22 Dec 2023 16:08:19 +0100 Message-Id: <20231222150827.1329938-10-hch@lst.de> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20231222150827.1329938-1-hch@lst.de> References: <20231222150827.1329938-1-hch@lst.de> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 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: 1785995442968207052 X-GMAIL-MSGID: 1785995442968207052 From: "Matthew Wilcox (Oracle)" Collapse the two nested loops into one. This is needed as a step towards turning this into an iterator. Note that this drops the "index <= end" check in the previous outer loop and just relies on filemap_get_folios_tag() to return 0 entries when index > end. This actually has a subtle implication when end == -1 because then the returned index will be -1 as well and thus if there is page present on index -1, we could be looping indefinitely. But as the comment in filemap_get_folios_tag documents this as already broken anyway we should not worry about it here either. The fix for that would probably a change to the filemap_get_folios_tag() calling convention. Signed-off-by: Matthew Wilcox (Oracle) [hch: updated the commit log based on feedback from Jan Kara] Signed-off-by: Christoph Hellwig Reviewed-by: Jan Kara Acked-by: Dave Chinner --- mm/page-writeback.c | 94 ++++++++++++++++++++++----------------------- 1 file changed, 46 insertions(+), 48 deletions(-) diff --git a/mm/page-writeback.c b/mm/page-writeback.c index fe508548482217..d62bc3498ed975 100644 --- a/mm/page-writeback.c +++ b/mm/page-writeback.c @@ -2475,6 +2475,7 @@ int write_cache_pages(struct address_space *mapping, { int error; pgoff_t end; /* Inclusive */ + int i = 0; if (wbc->range_cyclic) { wbc->index = mapping->writeback_index; /* prev offset */ @@ -2489,63 +2490,60 @@ int write_cache_pages(struct address_space *mapping, folio_batch_init(&wbc->fbatch); wbc->err = 0; - while (wbc->index <= end) { - int i; - - writeback_get_batch(mapping, wbc); + for (;;) { + struct folio *folio; + unsigned long nr; + if (i == wbc->fbatch.nr) { + writeback_get_batch(mapping, wbc); + i = 0; + } if (wbc->fbatch.nr == 0) break; - for (i = 0; i < wbc->fbatch.nr; i++) { - struct folio *folio = wbc->fbatch.folios[i]; - unsigned long nr; + folio = wbc->fbatch.folios[i++]; - folio_lock(folio); - if (!folio_prepare_writeback(mapping, wbc, folio)) { - folio_unlock(folio); - continue; - } + folio_lock(folio); + if (!folio_prepare_writeback(mapping, wbc, folio)) { + folio_unlock(folio); + continue; + } - trace_wbc_writepage(wbc, inode_to_bdi(mapping->host)); + trace_wbc_writepage(wbc, inode_to_bdi(mapping->host)); - error = writepage(folio, wbc, data); - nr = folio_nr_pages(folio); - wbc->nr_to_write -= nr; + error = writepage(folio, wbc, data); + nr = folio_nr_pages(folio); + wbc->nr_to_write -= nr; - /* - * Handle the legacy AOP_WRITEPAGE_ACTIVATE magic return - * value. Eventually all instances should just unlock - * the folio themselves and return 0; - */ - if (error == AOP_WRITEPAGE_ACTIVATE) { - folio_unlock(folio); - error = 0; - } - - if (error && !wbc->err) - wbc->err = error; + /* + * Handle the legacy AOP_WRITEPAGE_ACTIVATE magic return value. + * Eventually all instances should just unlock the folio + * themselves and return 0; + */ + if (error == AOP_WRITEPAGE_ACTIVATE) { + folio_unlock(folio); + error = 0; + } - /* - * For integrity sync we have to keep going until we - * have written all the folios we tagged for writeback - * prior to entering this loop, even if we run past - * wbc->nr_to_write or encounter errors. This is - * because the file system may still have state to clear - * for each folio. We'll eventually return the first - * error encountered. - * - * For background writeback just push done_index past - * this folio so that we can just restart where we left - * off and media errors won't choke writeout for the - * entire file. - */ - if (wbc->sync_mode == WB_SYNC_NONE && - (wbc->err || wbc->nr_to_write <= 0)) { - writeback_finish(mapping, wbc, - folio->index + nr); - return error; - } + if (error && !wbc->err) + wbc->err = error; + + /* + * For integrity sync we have to keep going until we have + * written all the folios we tagged for writeback prior to + * entering this loop, even if we run past wbc->nr_to_write or + * encounter errors. This is because the file system may still + * have state to clear for each folio. We'll eventually return + * the first error encountered. + * + * For background writeback just push done_index past this folio + * so that we can just restart where we left off and media + * errors won't choke writeout for the entire file. + */ + if (wbc->sync_mode == WB_SYNC_NONE && + (wbc->err || wbc->nr_to_write <= 0)) { + writeback_finish(mapping, wbc, folio->index + nr); + return error; } } From patchwork Fri Dec 22 15:08:20 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christoph Hellwig X-Patchwork-Id: 182690 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7300:2483:b0:fb:cd0c:d3e with SMTP id q3csp1127056dyi; Fri, 22 Dec 2023 07:12:05 -0800 (PST) X-Google-Smtp-Source: AGHT+IFFGB9ZC2QUF1VQ2T7EXdSSqF2HSSYoVSujsapW8MmSKePquQ1cP/16lHx6RkxqHCKB2bXT X-Received: by 2002:a05:6870:1693:b0:204:182:7f0 with SMTP id j19-20020a056870169300b00204018207f0mr1637585oae.98.1703257924763; Fri, 22 Dec 2023 07:12:04 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1703257924; cv=none; d=google.com; s=arc-20160816; b=udmbo2PB6aa5PPoCemlPdFWjkeaTUy4koVDEcYRW8zOc+MkklGhroIaImSzkzuKEw+ 73UrdlIeNYTAdKkvHuTvmBi8wPfIxq27rn1dfd9KMttbAvHP+5NSo/DV8sqjw3TkQ0wX n3QULcjRMq1YcCAczTQNNzyNC/v8tnRDPVJpQL7/XMTQCxQknZ7xngc1eKOo7guJTg8z sMZzm0blGc1bvDRf5SrTdZ88PWX23sW7lSr35pEirrW/o21PL3MB+xgo8Q7C+ebPv4mz 7F2ow6byOZycav4+uzNzxRXy738/WJmBU3XJxPx5aXS0PgrHgZLE7auo5ghP+SJsN2L/ IUpg== 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=dVreMySeIHkVOAtpz+bbvTB1WjeCUE+T6e0OUt9+4gE=; fh=hzpEVxJ05G9gyZL9WVyKgOEGxITvmFSuTcKyr2ByStg=; b=TjHrm7uJqLWU/j/qvIhJ+DGOTF6/6L3lyMRN7l/Sz+hwTEappW4ENP8GH6NL7vfXrE 9WL3R1dIML0Nlez7Tv6Y8mIBtBFrPIQ+6uYEHMCU1Z0bw/dASHA5WEaNx/VhTavIpn7T 7OeEVrx2R5iop9wge9er1go7mVICPGXYhd3UC9Eavc2C9pdkuxrlqPDUndaZ0bEI0uB7 uJFJlWh4vMfMzlZ1M5PPpZGLiNC9fJtBbIv5hknYqYR2P2LIgMJIvJ9XrR/HkUSPYJYp 3app/5peUtIG88SJbS/wHpytgRwk5cL78WyTtnoIqYFae8kOtGKUMZFDAUPpSwKC9iTd +6xg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@infradead.org header.s=bombadil.20210309 header.b=JaAkdqZm; spf=pass (google.com: domain of linux-kernel+bounces-9821-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-9821-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 b1-20020a67f841000000b00466e4f34687si143003vsp.472.2023.12.22.07.12.04 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 22 Dec 2023 07:12:04 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-9821-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=JaAkdqZm; spf=pass (google.com: domain of linux-kernel+bounces-9821-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-9821-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 7FDAE1C21848 for ; Fri, 22 Dec 2023 15:12:04 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 29F972E400; Fri, 22 Dec 2023 15:08:59 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=infradead.org header.i=@infradead.org header.b="JaAkdqZm" 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 6B8B12CCD9; Fri, 22 Dec 2023 15:08:55 +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=dVreMySeIHkVOAtpz+bbvTB1WjeCUE+T6e0OUt9+4gE=; b=JaAkdqZmOduEeNKqFX4Ku2J7NE ZUlndRMyXJVHVpS3YBp+6lZQe4Hb/Oea/LNWPgl4QZ3Yd8ECfM3p5l6Uct6A8zEfAoOe+Z0jwyHJ7 0fm91BwTHShgOIQMcILm75blc7XQRH49G/JVXgOxWXo0dVFsqXpRBaEdyrPs0quk5x729W9gXmb98 e255UWRmLzkFgEPdttgBQuUTeEySgAg3MR6Ea+qCXmLfCd4NzBC6vD2F7y56dqROKEg04RYOnnN0N lEHwOMZeqBxD5fPkSLKirvNRdxdMaUp/A77YEni/edJFRZ5TA6D0gHH4uUlkwB64Jons6MuMIPqUz RJn1Yl1w==; 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 1rGh8u-006BUd-1I; Fri, 22 Dec 2023 15:08:52 +0000 From: Christoph Hellwig To: linux-mm@kvack.org Cc: "Matthew Wilcox (Oracle)" , Jan Kara , David Howells , Brian Foster , linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org, Jan Kara , Dave Chinner Subject: [PATCH 10/17] pagevec: Add ability to iterate a queue Date: Fri, 22 Dec 2023 16:08:20 +0100 Message-Id: <20231222150827.1329938-11-hch@lst.de> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20231222150827.1329938-1-hch@lst.de> References: <20231222150827.1329938-1-hch@lst.de> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 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: 1785995381686979505 X-GMAIL-MSGID: 1785995381686979505 From: "Matthew Wilcox (Oracle)" Add a loop counter inside the folio_batch to let us iterate from 0-nr instead of decrementing nr and treating the batch as a stack. It would generate some very weird and suboptimal I/O patterns for page writeback to iterate over the batch as a stack. Signed-off-by: Matthew Wilcox (Oracle) Signed-off-by: Christoph Hellwig Reviewed-by: Jan Kara Acked-by: Dave Chinner --- include/linux/pagevec.h | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/include/linux/pagevec.h b/include/linux/pagevec.h index 87cc678adc850b..fcc06c300a72c3 100644 --- a/include/linux/pagevec.h +++ b/include/linux/pagevec.h @@ -27,6 +27,7 @@ struct folio; */ struct folio_batch { unsigned char nr; + unsigned char i; bool percpu_pvec_drained; struct folio *folios[PAGEVEC_SIZE]; }; @@ -40,12 +41,14 @@ struct folio_batch { static inline void folio_batch_init(struct folio_batch *fbatch) { fbatch->nr = 0; + fbatch->i = 0; fbatch->percpu_pvec_drained = false; } static inline void folio_batch_reinit(struct folio_batch *fbatch) { fbatch->nr = 0; + fbatch->i = 0; } static inline unsigned int folio_batch_count(struct folio_batch *fbatch) @@ -75,6 +78,21 @@ static inline unsigned folio_batch_add(struct folio_batch *fbatch, return folio_batch_space(fbatch); } +/** + * folio_batch_next - Return the next folio to process. + * @fbatch: The folio batch being processed. + * + * Use this function to implement a queue of folios. + * + * Return: The next folio in the queue, or NULL if the queue is empty. + */ +static inline struct folio *folio_batch_next(struct folio_batch *fbatch) +{ + if (fbatch->i == fbatch->nr) + return NULL; + return fbatch->folios[fbatch->i++]; +} + void __folio_batch_release(struct folio_batch *pvec); static inline void folio_batch_release(struct folio_batch *fbatch) From patchwork Fri Dec 22 15:08:21 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christoph Hellwig X-Patchwork-Id: 182691 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7300:2483:b0:fb:cd0c:d3e with SMTP id q3csp1127295dyi; Fri, 22 Dec 2023 07:12:25 -0800 (PST) X-Google-Smtp-Source: AGHT+IFpyjNSjcVVepxnAlvRay9UBs0fAx0wRlv9+RpmvAD4cO/RaZghE4w60ydzHggxrfoOvn9t X-Received: by 2002:a17:90a:8d11:b0:28c:1161:5202 with SMTP id c17-20020a17090a8d1100b0028c11615202mr425696pjo.71.1703257944935; Fri, 22 Dec 2023 07:12:24 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1703257944; cv=none; d=google.com; s=arc-20160816; b=dcwkeO2+EZO3A3Qr7IXDV+2l/CerG+WVdi8iVUcG3UCIfdwFeMiSb58h9Urt3CxqYC OQG8GSIFNQbfJojog5u/Z2e3U51TIPTLNuZaJm+A9Lz1xcNQGGMYdNsOtQpHqiaRfY3O byB8UtQXu8ugVqvlz0GufWJnazdFavQ+gjwvI96eDt+EWld7k1c7OCLGxP+16imrfVkG UizXC9j5FDP3G3G4ukRcAoVfIABAbWSoC7KReN0L84FTbUZ9X354WrHS7BBQu9U0S3lH vLyuJVEHjdzv81MyY5dkhCnBsba/S7El26oLhtU987c8XLixr+Lh++4/sZCoVywN/O8y B69g== 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=o5H/XSwme7xEQtHV3m+ZJ3LCmsROSQ4hprrOJy3ayZQ=; fh=hzpEVxJ05G9gyZL9WVyKgOEGxITvmFSuTcKyr2ByStg=; b=ciTWQf8dow/cPZbk7LC0WspMdQTch22Ql5eU4KPUbtChbCTIqTjM67EbTQgAYOddOv 1B3Yj2E4TSyyVPYeFhaKVvXWTzUame+LUWSPpsuo04Jk5P+jEP0u11qqmlZs8TPgnHw3 UmUqzuDIoJl7+gJ7aNP19jownTWNJOjPkLLdt/2j3U/9rLl7HrcZaJEjIVACWgeDIBLM ligLmzk6M4hp/yvv9RYvD2ntETt3Pd62RbZVMlvK2CJ0OoLpeh0B+reaXgNw2JNDBtwR n1zkJn5L6yrYQotmduVeEDfbxZvxfblZTRM+jGZyTzDJtzKFO7t2Rm52EEZwYZHXUAqR jUWA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@infradead.org header.s=bombadil.20210309 header.b=1fWeY1tU; spf=pass (google.com: domain of linux-kernel+bounces-9823-ouuuleilei=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-9823-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 c12-20020a17090a8d0c00b0028c01af5d75si1854641pjo.113.2023.12.22.07.12.24 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 22 Dec 2023 07:12:24 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-9823-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=1fWeY1tU; spf=pass (google.com: domain of linux-kernel+bounces-9823-ouuuleilei=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-9823-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 B4A81282D4C for ; Fri, 22 Dec 2023 15:12:24 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id BD69F2E651; Fri, 22 Dec 2023 15:09:01 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=infradead.org header.i=@infradead.org header.b="1fWeY1tU" 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 164942D794; Fri, 22 Dec 2023 15:08:57 +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=o5H/XSwme7xEQtHV3m+ZJ3LCmsROSQ4hprrOJy3ayZQ=; b=1fWeY1tUuYOLXS4fYxt9eNpkZL uPDqWxlQRvE8go0ce8UcYudxrGF1l7Hsi2GJtUTlfsjpr+mucLE+tfcAIVoKgfxQNTLFBiMF7r/DY p038ichTWr69GTwEoBsSaNQuiXLmrhkToyxTmt+UC6O7wN0TyO8qBzkZeaUvRE0kPxYvKDXxGxOYW qHtxgdaRB9TK1g1hTe9EdhIoxKGVVqmmdo87DBp/9uLtiOOZj6aPO9zZLjWLCNCMR4p2Qcq3bJU/Y QrtkzDepUlCDu+3TMC/L214GlcREtVp+DAjwQOMC012XRtoSbmzTX27ToGjrv8hTtpiMxBwlg65sf 8wjZTjvw==; 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 1rGh8w-006BVk-2h; Fri, 22 Dec 2023 15:08:55 +0000 From: Christoph Hellwig To: linux-mm@kvack.org Cc: "Matthew Wilcox (Oracle)" , Jan Kara , David Howells , Brian Foster , linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org, Jan Kara , Dave Chinner Subject: [PATCH 11/17] writeback: Use the folio_batch queue iterator Date: Fri, 22 Dec 2023 16:08:21 +0100 Message-Id: <20231222150827.1329938-12-hch@lst.de> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20231222150827.1329938-1-hch@lst.de> References: <20231222150827.1329938-1-hch@lst.de> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 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: 1785995402793149310 X-GMAIL-MSGID: 1785995402793149310 From: "Matthew Wilcox (Oracle)" Instead of keeping our own local iterator variable, use the one just added to folio_batch. Signed-off-by: Matthew Wilcox (Oracle) Signed-off-by: Christoph Hellwig Reviewed-by: Jan Kara Acked-by: Dave Chinner --- mm/page-writeback.c | 29 +++++++++++++++-------------- 1 file changed, 15 insertions(+), 14 deletions(-) diff --git a/mm/page-writeback.c b/mm/page-writeback.c index d62bc3498ed975..47457895891221 100644 --- a/mm/page-writeback.c +++ b/mm/page-writeback.c @@ -2429,13 +2429,21 @@ static bool folio_prepare_writeback(struct address_space *mapping, return true; } -static void writeback_get_batch(struct address_space *mapping, +static struct folio *writeback_get_folio(struct address_space *mapping, struct writeback_control *wbc) { - folio_batch_release(&wbc->fbatch); - cond_resched(); - filemap_get_folios_tag(mapping, &wbc->index, wbc_end(wbc), - wbc_to_tag(wbc), &wbc->fbatch); + struct folio *folio; + + folio = folio_batch_next(&wbc->fbatch); + if (!folio) { + folio_batch_release(&wbc->fbatch); + cond_resched(); + filemap_get_folios_tag(mapping, &wbc->index, wbc_end(wbc), + wbc_to_tag(wbc), &wbc->fbatch); + folio = folio_batch_next(&wbc->fbatch); + } + + return folio; } /** @@ -2475,7 +2483,6 @@ int write_cache_pages(struct address_space *mapping, { int error; pgoff_t end; /* Inclusive */ - int i = 0; if (wbc->range_cyclic) { wbc->index = mapping->writeback_index; /* prev offset */ @@ -2491,18 +2498,12 @@ int write_cache_pages(struct address_space *mapping, wbc->err = 0; for (;;) { - struct folio *folio; + struct folio *folio = writeback_get_folio(mapping, wbc); unsigned long nr; - if (i == wbc->fbatch.nr) { - writeback_get_batch(mapping, wbc); - i = 0; - } - if (wbc->fbatch.nr == 0) + if (!folio) break; - folio = wbc->fbatch.folios[i++]; - folio_lock(folio); if (!folio_prepare_writeback(mapping, wbc, folio)) { folio_unlock(folio); From patchwork Fri Dec 22 15:08:22 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christoph Hellwig X-Patchwork-Id: 182693 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7300:2483:b0:fb:cd0c:d3e with SMTP id q3csp1127498dyi; Fri, 22 Dec 2023 07:12:43 -0800 (PST) X-Google-Smtp-Source: AGHT+IEly8Qy0P49coRVrTvi2WM6Q0dgaqksT4oF7qIPi8HeYqJOsdNNiFO0mdtAhiuw2vaUCsEt X-Received: by 2002:a05:6a20:144a:b0:195:3ba0:bc0c with SMTP id a10-20020a056a20144a00b001953ba0bc0cmr647681pzi.117.1703257963046; Fri, 22 Dec 2023 07:12:43 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1703257963; cv=none; d=google.com; s=arc-20160816; b=MsswGyyoGbJ2XAbedmMdq/bgLvcam1O0+oUyvSw/x8ta33vryiGkVAQAZtALItmlII fINomK5C9OwjNKPp6zYjpFqelqR8XII9uA9GGXiOa+oRAxRuz6Zlliv3VNgHSWtv2Bk6 VvKyCkQOIBsYQFlh48kr+I2gRKmRKN/QXQxtwTQaZ4RbaBXpdR9HCKJdgrn8KuCTLtiz FS3udO69ajGp3CM+mXNc8IbyCvZ2MwpsYEJNNV1TiWHjGe1BNsSGOFTErreEElahs63/ 5fBNV0lbsAsM+sf+DrWqPtNdQXJTia9LFw9Fm2LGCwi9uySmr6he4FbAQL9c17zMw3k6 xe6w== 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=uhQwu0XzlF9g6tYMy5v46u1+umuzBvOukQsb3rulW5U=; fh=hzpEVxJ05G9gyZL9WVyKgOEGxITvmFSuTcKyr2ByStg=; b=eny0KFMD3L1HWwjRDrgkH3bt6vqVl0WrZ+qNdwpCcdZ1dTtsGSR/2Saz9QnJpg53sJ 7MhjXQJDx+buGmzo0PyucxlTPPz+qSfjLZrTDjIzCMf/uzAMi7QMwwB5+bFOrlH7EIv2 kfAyGtV258DPfpiSw4m9XcjfZZUTlCHc6eOxH4fQAVN4tx/G7mtX2uJmE7qt3MSsMEbx edsgLhTIa+uMaCMQGxL+q3KtA3UcV5+Q78FlD/L9EzTOdr1X/aqaWNSh8+AvkJcIwjS+ Id9xRxkSF250husv/XLv1KG3mB58z2GXkCKHDhG26ouBTby6e6y6OHb31XaPPbcsQCkT 5xGA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@infradead.org header.s=bombadil.20210309 header.b=yfQSDflm; spf=pass (google.com: domain of linux-kernel+bounces-9824-ouuuleilei=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-9824-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 e14-20020a656bce000000b005be0ca9ca31si3476680pgw.294.2023.12.22.07.12.42 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 22 Dec 2023 07:12:43 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-9824-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=yfQSDflm; spf=pass (google.com: domain of linux-kernel+bounces-9824-ouuuleilei=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-9824-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 BF6D7281977 for ; Fri, 22 Dec 2023 15:12:42 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 444F62E845; Fri, 22 Dec 2023 15:09:04 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=infradead.org header.i=@infradead.org header.b="yfQSDflm" 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 8DAF02E643; Fri, 22 Dec 2023 15:09: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=uhQwu0XzlF9g6tYMy5v46u1+umuzBvOukQsb3rulW5U=; b=yfQSDflmOsFoQUBv7S0oxf31Lt bA8UjbacePhce939zrO4Ir44tqLbrgyX1i5WWUPFn1Dh+11PMGev7lVY8wnZureYjbZsYuESrU/5W 7r7TRMZJi1BVUw35tzYKJsGhRRphnMJlwuQRlfFG7hoKMPvs2RHHddSnKmZ5Zo6xy79keEUFELCWb di7aVlxzJVcxNMi/KVCgAn/kv4q2J3SRszZOCJqDD9t8X6NkbjyqzvwY30OmTwG+hrdVwHprkayFJ byFe+UZ+5u414GPfeJPQCofOizDxVA0C4ZgEqEEGUVbFOp5tujEidQTo2hVAYbvVDVsV6qignOnCn L7ZBVhGw==; 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 1rGh8z-006BXA-0y; Fri, 22 Dec 2023 15:08: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, Jan Kara , Dave Chinner Subject: [PATCH 12/17] writeback: Factor writeback_iter_init() out of write_cache_pages() Date: Fri, 22 Dec 2023 16:08:22 +0100 Message-Id: <20231222150827.1329938-13-hch@lst.de> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20231222150827.1329938-1-hch@lst.de> References: <20231222150827.1329938-1-hch@lst.de> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 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: 1785995421859468434 X-GMAIL-MSGID: 1785995421859468434 From: "Matthew Wilcox (Oracle)" Make it return the first folio in the batch so that we can use it in a typical for() pattern. Signed-off-by: Matthew Wilcox (Oracle) Signed-off-by: Christoph Hellwig Reviewed-by: Jan Kara Acked-by: Dave Chinner --- mm/page-writeback.c | 39 ++++++++++++++++++++------------------- 1 file changed, 20 insertions(+), 19 deletions(-) diff --git a/mm/page-writeback.c b/mm/page-writeback.c index 47457895891221..f85145f330bb36 100644 --- a/mm/page-writeback.c +++ b/mm/page-writeback.c @@ -2446,6 +2446,22 @@ static struct folio *writeback_get_folio(struct address_space *mapping, return folio; } +static struct folio *writeback_iter_init(struct address_space *mapping, + struct writeback_control *wbc) +{ + if (wbc->range_cyclic) + wbc->index = mapping->writeback_index; /* prev offset */ + else + wbc->index = wbc->range_start >> PAGE_SHIFT; + + if (wbc->sync_mode == WB_SYNC_ALL || wbc->tagged_writepages) + tag_pages_for_writeback(mapping, wbc->index, wbc_end(wbc)); + + wbc->err = 0; + folio_batch_init(&wbc->fbatch); + return writeback_get_folio(mapping, wbc); +} + /** * write_cache_pages - walk the list of dirty pages of the given address space and write all of them. * @mapping: address space structure to write @@ -2481,29 +2497,14 @@ int write_cache_pages(struct address_space *mapping, struct writeback_control *wbc, writepage_t writepage, void *data) { + struct folio *folio; int error; - pgoff_t end; /* Inclusive */ - if (wbc->range_cyclic) { - wbc->index = mapping->writeback_index; /* prev offset */ - end = -1; - } else { - wbc->index = wbc->range_start >> PAGE_SHIFT; - end = wbc->range_end >> PAGE_SHIFT; - } - if (wbc->sync_mode == WB_SYNC_ALL || wbc->tagged_writepages) - tag_pages_for_writeback(mapping, wbc->index, end); - - folio_batch_init(&wbc->fbatch); - wbc->err = 0; - - for (;;) { - struct folio *folio = writeback_get_folio(mapping, wbc); + for (folio = writeback_iter_init(mapping, wbc); + folio; + folio = writeback_get_folio(mapping, wbc)) { unsigned long nr; - if (!folio) - break; - folio_lock(folio); if (!folio_prepare_writeback(mapping, wbc, folio)) { folio_unlock(folio); From patchwork Fri Dec 22 15:08:23 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christoph Hellwig X-Patchwork-Id: 182694 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7300:2483:b0:fb:cd0c:d3e with SMTP id q3csp1127702dyi; Fri, 22 Dec 2023 07:13:00 -0800 (PST) X-Google-Smtp-Source: AGHT+IF0f0amW2ZfrA5mxTFqZ/7+WUYQUZxq3KqPJ1rohTLN0/8zcGm/QnGZcH5QvebjXg9xHrba X-Received: by 2002:a17:90a:49c1:b0:28b:d06d:9994 with SMTP id l1-20020a17090a49c100b0028bd06d9994mr891320pjm.30.1703257980744; Fri, 22 Dec 2023 07:13:00 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1703257980; cv=none; d=google.com; s=arc-20160816; b=qCZas+LG6Gc2UZG8vHhVQkuoOYMO/dqqQD059kdnK+gvIjbidagDjBSZTY3D/yJ7Uj UyAxR1NpevuuQlBOyFWTUmM7N4/HlN/vwfoWD2Q374nr4HdjhfPth/TJXCHJtUhGJQb4 Qn6DNsk3BmP2P4foI93hPs6DXkZ9CsbTg3TzNeTIMQTxPY5igIngvoy2/L1oqxhyUu0b HT1OhBSUa19hjgLRAu6M2dNNPTNDCjqs58wBUIHZJEFxWXINPPzAx8wmqqoKifu8S6FT duAk0mnwE15XF7A1s9VIEsSpdqvFmiCBfoEP/C79ZsXBDt4dO/LPMjyFGaQZ9PC7smD4 JyYQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :date:subject:cc:to:from:dkim-signature; bh=nwSb0aQ6WVWAqtAF+HdyJ3HlPU1688MOnHDS98Pt7+A=; fh=hzpEVxJ05G9gyZL9WVyKgOEGxITvmFSuTcKyr2ByStg=; b=gm+xch9t4yWKbnAFICZl5agQaojl1uE8OtP2MoMuBB1OQs1khV//26qM/nUfpJKTMp o7e1QBNaMXxR39txeoIzW+RWLxmaZz3E5XrZIYE5wGhRn2Fp8d0h2ZbLMldrooBk2x8C nq60+I6AiTGV/15Ph8LJwPEnifGT/CLgeDFOuqLZhv/29yN7pnWk/6gV0uw3zTbBNdbt jRy5JE+SJyHS5WnkEBmHUgdnoAUUjdm6mJkF1owL53j0M7xmmbJjUSwSniM/Pb3cDn28 7fgleN7ZgCVcdy649NLByE1s4Q7t9l/vvmwfl0koI0B+zN/X6/hqhaH1XbgB/69Za1BQ 0njg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@infradead.org header.s=bombadil.20210309 header.b=fsTEpZhG; spf=pass (google.com: domain of linux-kernel+bounces-9825-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-9825-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 z6-20020a17090a398600b0028bbd5f05ebsi6340879pjb.16.2023.12.22.07.13.00 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 22 Dec 2023 07:13:00 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-9825-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=fsTEpZhG; spf=pass (google.com: domain of linux-kernel+bounces-9825-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-9825-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 8462D282ECB for ; Fri, 22 Dec 2023 15:13:00 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id E00F52EAFB; Fri, 22 Dec 2023 15:09:06 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=infradead.org header.i=@infradead.org header.b="fsTEpZhG" X-Original-To: linux-kernel@vger.kernel.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 3582E2E837; Fri, 22 Dec 2023 15:09:02 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=lst.de Authentication-Results: smtp.subspace.kernel.org; spf=none smtp.mailfrom=bombadil.srs.infradead.org DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=bombadil.20210309; h=Content-Transfer-Encoding: MIME-Version:References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From:Sender :Reply-To:Content-Type:Content-ID:Content-Description; bh=nwSb0aQ6WVWAqtAF+HdyJ3HlPU1688MOnHDS98Pt7+A=; b=fsTEpZhGkE4khH8MXT4PtBYhdo ZQgp/dXeIGwyn7s3VuOqu6GmTRUxeSslau35ljaEbUfRgqA0ZEAH8JVNUJqryffLuZ1tiX++MxAHy Nq+T9gs+7AeBOpWiNijbKLhyOEzHiXCvYJyQBKAzyR6Jx96R9RLRtpKuVe/PAuijSu2MSVEHhsx60 po2QLtX1ruHagJovmBJr49HjCGb76ply2cGzBN7tNen/Y7LvzOWkGILqJzTcP2VcgfasfyxRa/YLB CMyztaZTGjFje4ZGqnH7q15JeaxPgTH5DZcug+qDAWvVZPH+wM4/3FoVMrbM3vDe1Jt7WqAsXg8ta 7O6j3/7A==; Received: from 2a02-8389-2341-5b80-39d3-4735-9a3c-88d8.cable.dynamic.v6.surfer.at ([2a02:8389:2341:5b80:39d3:4735:9a3c:88d8] helo=localhost) by bombadil.infradead.org with esmtpsa (Exim 4.96 #2 (Red Hat Linux)) id 1rGh91-006BYP-2j; Fri, 22 Dec 2023 15:09:00 +0000 From: Christoph Hellwig To: linux-mm@kvack.org Cc: "Matthew Wilcox (Oracle)" , Jan Kara , David Howells , Brian Foster , linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org, Jan Kara , Dave Chinner Subject: [PATCH 13/17] writeback: Move the folio_prepare_writeback loop out of write_cache_pages() Date: Fri, 22 Dec 2023 16:08:23 +0100 Message-Id: <20231222150827.1329938-14-hch@lst.de> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20231222150827.1329938-1-hch@lst.de> References: <20231222150827.1329938-1-hch@lst.de> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 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: 1785995440198728197 X-GMAIL-MSGID: 1785995440198728197 From: "Matthew Wilcox (Oracle)" Move the loop for should-we-write-this-folio to writeback_get_folio. Signed-off-by: Matthew Wilcox (Oracle) [hch: folded the loop into the existing helper instead of a separate one as suggested by Jan Kara] Signed-off-by: Christoph Hellwig Reviewed-by: Jan Kara Acked-by: Dave Chinner --- mm/page-writeback.c | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/mm/page-writeback.c b/mm/page-writeback.c index f85145f330bb36..b6048c14748fdb 100644 --- a/mm/page-writeback.c +++ b/mm/page-writeback.c @@ -2434,6 +2434,7 @@ static struct folio *writeback_get_folio(struct address_space *mapping, { struct folio *folio; +retry: folio = folio_batch_next(&wbc->fbatch); if (!folio) { folio_batch_release(&wbc->fbatch); @@ -2441,8 +2442,17 @@ static struct folio *writeback_get_folio(struct address_space *mapping, filemap_get_folios_tag(mapping, &wbc->index, wbc_end(wbc), wbc_to_tag(wbc), &wbc->fbatch); folio = folio_batch_next(&wbc->fbatch); + if (!folio) + return NULL; } + folio_lock(folio); + if (unlikely(!folio_prepare_writeback(mapping, wbc, folio))) { + folio_unlock(folio); + goto retry; + } + + trace_wbc_writepage(wbc, inode_to_bdi(mapping->host)); return folio; } @@ -2505,14 +2515,6 @@ int write_cache_pages(struct address_space *mapping, folio = writeback_get_folio(mapping, wbc)) { unsigned long nr; - folio_lock(folio); - if (!folio_prepare_writeback(mapping, wbc, folio)) { - folio_unlock(folio); - continue; - } - - trace_wbc_writepage(wbc, inode_to_bdi(mapping->host)); - error = writepage(folio, wbc, data); nr = folio_nr_pages(folio); wbc->nr_to_write -= nr; From patchwork Fri Dec 22 15:08:24 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christoph Hellwig X-Patchwork-Id: 182698 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7300:2483:b0:fb:cd0c:d3e with SMTP id q3csp1128266dyi; Fri, 22 Dec 2023 07:13:52 -0800 (PST) X-Google-Smtp-Source: AGHT+IGmgiCQCtUKUzdLYXIyr02tcnx/AVwL0nlHS0GLbRSmqLlN6AhSvWmqqldgPqoEGNOyYQ/S X-Received: by 2002:a05:6e02:1be5:b0:35d:59a2:1281 with SMTP id y5-20020a056e021be500b0035d59a21281mr1761386ilv.45.1703258032017; Fri, 22 Dec 2023 07:13:52 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1703258031; cv=none; d=google.com; s=arc-20160816; b=p0750kah1KklbILR9cqpkPqntO2JO+wTzRt4S0fEP5GV955JAmoyXaX6g8+cV0N80/ ujo+kfjNhEJZdyU0lxn33BKPfS6FwhRz86kAAR6pV6tp1kQU5S9wqsH2RZLb2sABf+cN LV2Dbb++Mca/GY+Rf2fWuZHq7ng9ocGjvRFFktfi7RhqglOjRdbZsJnIotLzH7d2hsAO OiX4VFJ6gThgTKuPwbPrCYiN7NiCAgL+rT48SX2xGReMSA5qA/wX9LO7/tydXn+NpYc0 EGLk8v2JkAIMK3pr+bFP05d55s+S4/7+GPMRh92W7yk+Czpc0J0iTcsZ5f9WNRPOfypn 8x0g== 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=Tv6lrDU8r6rlJypjv3siMvmCkcJEVy83R0f8GQdaFQU=; fh=hzpEVxJ05G9gyZL9WVyKgOEGxITvmFSuTcKyr2ByStg=; b=kfurM56N5Ny1QaqyUKEr2pf4Ie33npuYKKUvaxw9nOTSQ/FPU8Mi0eKAXse7e0mJ/F h7uXQT+RtoxLWqRWrfCk3AaEMS73KzM65AVQcmb2+L2DDSwpFzLO4k5fiB3eqxS+cB7W m87VA/CmH2w1Fzr1r7E7mDP2/DDggggPBZV7d/cdXW5K6scQGhbr8mf/zUNS8Uh97UkI 118BWsSC9mbZGknS7eCKb3fEKSvWz0ADhtiVXBgB5YmpnIxX1LmkehOYxczMDpquh9MJ +Tchytu3+Ue6EMlm+mhhE7Jz+Ad23zFUiHkVrFVoe/dLCBzC83n2zTCkRovOi4wXotXQ UGVg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@infradead.org header.s=bombadil.20210309 header.b=AWYiSCNJ; spf=pass (google.com: domain of linux-kernel+bounces-9827-ouuuleilei=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-9827-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 e2-20020a656782000000b005cdff2eb998si150172pgr.744.2023.12.22.07.13.51 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 22 Dec 2023 07:13:51 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-9827-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=AWYiSCNJ; spf=pass (google.com: domain of linux-kernel+bounces-9827-ouuuleilei=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-9827-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 BDA332818CB for ; Fri, 22 Dec 2023 15:13:51 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 8EB6731594; Fri, 22 Dec 2023 15:09:13 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=infradead.org header.i=@infradead.org header.b="AWYiSCNJ" 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 817E22F507; Fri, 22 Dec 2023 15:09:09 +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=Tv6lrDU8r6rlJypjv3siMvmCkcJEVy83R0f8GQdaFQU=; b=AWYiSCNJg8Yta3tpcjdQxGvw8L EvtMV1WeGwuWEB3TDrAffKN606PP/uIZLFU9/YNjCbAsUCYX8zUs8FeKkHub/niKeumC6GIoUiMHL V5wS03sfVZpFQd3R6vLLzbnYXMdQ5flWog5xsVIBG7V1iQqbWzO6skZlSrvW99SHHaEq1syx4w6Zp pOE4tEWlS0mGLIzJM2aqnc2cQvrATlEUfezMuN3fXjE7sR4E1+AxcuS8zLKxfCDXjzD+2Va6AJVN2 M/Tr2UDGLXa9y5PiBU3MybJUd+9vUnG/JxzdSmwqBzjTnEyr7h1SKZh6iYs8RGLha4KiO2za/uX8E 6DqydyuQ==; 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 1rGh94-006BZF-0b; Fri, 22 Dec 2023 15:09:02 +0000 From: Christoph Hellwig To: linux-mm@kvack.org Cc: "Matthew Wilcox (Oracle)" , Jan Kara , David Howells , Brian Foster , linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org, Jan Kara , Dave Chinner Subject: [PATCH 14/17] writeback: Factor writeback_iter_next() out of write_cache_pages() Date: Fri, 22 Dec 2023 16:08:24 +0100 Message-Id: <20231222150827.1329938-15-hch@lst.de> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20231222150827.1329938-1-hch@lst.de> References: <20231222150827.1329938-1-hch@lst.de> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 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: 1785995493898261563 X-GMAIL-MSGID: 1785995493898261563 From: "Matthew Wilcox (Oracle)" Pull the post-processing of the writepage_t callback into a separate function. That means changing writeback_get_next() to call writeback_finish() when we naturally run out of folios. Signed-off-by: Matthew Wilcox (Oracle) Signed-off-by: Christoph Hellwig Reviewed-by: Jan Kara Acked-by: Dave Chinner --- mm/page-writeback.c | 85 ++++++++++++++++++++++++--------------------- 1 file changed, 45 insertions(+), 40 deletions(-) diff --git a/mm/page-writeback.c b/mm/page-writeback.c index b6048c14748fdb..a041cc563762ae 100644 --- a/mm/page-writeback.c +++ b/mm/page-writeback.c @@ -2442,8 +2442,10 @@ static struct folio *writeback_get_folio(struct address_space *mapping, filemap_get_folios_tag(mapping, &wbc->index, wbc_end(wbc), wbc_to_tag(wbc), &wbc->fbatch); folio = folio_batch_next(&wbc->fbatch); - if (!folio) + if (!folio) { + writeback_finish(mapping, wbc, 0); return NULL; + } } folio_lock(folio); @@ -2472,6 +2474,46 @@ static struct folio *writeback_iter_init(struct address_space *mapping, return writeback_get_folio(mapping, wbc); } +static struct folio *writeback_iter_next(struct address_space *mapping, + struct writeback_control *wbc, struct folio *folio, int error) +{ + unsigned long nr = folio_nr_pages(folio); + + wbc->nr_to_write -= nr; + + /* + * Handle the legacy AOP_WRITEPAGE_ACTIVATE magic return value. + * Eventually all instances should just unlock the folio themselves and + * return 0; + */ + if (error == AOP_WRITEPAGE_ACTIVATE) { + folio_unlock(folio); + error = 0; + } + + if (error && !wbc->err) + wbc->err = error; + + /* + * For integrity sync we have to keep going until we have written all + * the folios we tagged for writeback prior to entering the writeback + * loop, even if we run past wbc->nr_to_write or encounter errors. + * This is because the file system may still have state to clear for + * each folio. We'll eventually return the first error encountered. + * + * For background writeback just push done_index past this folio so that + * we can just restart where we left off and media errors won't choke + * writeout for the entire file. + */ + if (wbc->sync_mode == WB_SYNC_NONE && + (wbc->err || wbc->nr_to_write <= 0)) { + writeback_finish(mapping, wbc, folio->index + nr); + return NULL; + } + + return writeback_get_folio(mapping, wbc); +} + /** * write_cache_pages - walk the list of dirty pages of the given address space and write all of them. * @mapping: address space structure to write @@ -2512,47 +2554,10 @@ int write_cache_pages(struct address_space *mapping, for (folio = writeback_iter_init(mapping, wbc); folio; - folio = writeback_get_folio(mapping, wbc)) { - unsigned long nr; - + folio = writeback_iter_next(mapping, wbc, folio, error)) error = writepage(folio, wbc, data); - nr = folio_nr_pages(folio); - wbc->nr_to_write -= nr; - - /* - * Handle the legacy AOP_WRITEPAGE_ACTIVATE magic return value. - * Eventually all instances should just unlock the folio - * themselves and return 0; - */ - if (error == AOP_WRITEPAGE_ACTIVATE) { - folio_unlock(folio); - error = 0; - } - - if (error && !wbc->err) - wbc->err = error; - /* - * For integrity sync we have to keep going until we have - * written all the folios we tagged for writeback prior to - * entering this loop, even if we run past wbc->nr_to_write or - * encounter errors. This is because the file system may still - * have state to clear for each folio. We'll eventually return - * the first error encountered. - * - * For background writeback just push done_index past this folio - * so that we can just restart where we left off and media - * errors won't choke writeout for the entire file. - */ - if (wbc->sync_mode == WB_SYNC_NONE && - (wbc->err || wbc->nr_to_write <= 0)) { - writeback_finish(mapping, wbc, folio->index + nr); - return error; - } - } - - writeback_finish(mapping, wbc, 0); - return 0; + return wbc->err; } EXPORT_SYMBOL(write_cache_pages); From patchwork Fri Dec 22 15:08:25 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christoph Hellwig X-Patchwork-Id: 182697 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7300:2483:b0:fb:cd0c:d3e with SMTP id q3csp1127984dyi; Fri, 22 Dec 2023 07:13:24 -0800 (PST) X-Google-Smtp-Source: AGHT+IEzYAIIBOUvFeZgNwHlBESb43totHDnLj24b6teJvZ5xv+vrUmyCgoJHVelLtAt7mksrQwN X-Received: by 2002:a17:90a:9bca:b0:28a:464d:5ec8 with SMTP id b10-20020a17090a9bca00b0028a464d5ec8mr1151942pjw.41.1703258004553; Fri, 22 Dec 2023 07:13:24 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1703258004; cv=none; d=google.com; s=arc-20160816; b=SJ9fcEGuBCAGzQ6A6e98+9I6GjaAqxvRWK4JJs1gvw56mzZjZmxJOyceC64cBs7VTe Negp5T3ctgcIZTfJ1rMsCPqtTZUD/siS5REl04iafINZ/P5XtmB0Ft0A53Wo2AUUiUNP LiFqw6siLkJoE9ASMeEQsu/qvsdFghyG8NIkCjg8LaytkZrPRxWIj1RAJ6z+jQnW8Nu1 dh4K+m3YrruxxOBD74FtPRKYVW7LvZbSQ2IvtOyjkZ+Yl7IWNshOXoDRU5KzuFfEGr0a rKAQhe26XgTP5I1SuZf2eOqHfIPzZ+SQJNj9AnFkFbgLkuGfkbgdSDVgV2W2djWMV516 E+iw== 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=Cpsd8l7OUn8C5bZQLGYGz9qCV/TqxduSbkyPfu2Mjvk=; fh=hzpEVxJ05G9gyZL9WVyKgOEGxITvmFSuTcKyr2ByStg=; b=abfX8FVNeo+k1oUZW0BnjzmUaVfm1ZgAodYkyIaLBw0N504EZRYJtT50lclo3ioTqz VXxS8gMMTC9CWF65tSRABKTvJ6gkph9VWPE1OpFMLnrcCFJzn+hwDT+eeA+dz199Gfby l/Hbj5WJLggDcfGY6FkikD6RhhXJyiuYV7cmETp/MKyFSFu3Zhu1UZ/DBhLVnMMXQ3Lp NPUVSNtGCB05GitEzf14AMK8fRbcFdHmzpbqv7Fq+/ZMpMWebiJnapFcq2jwYUHS/SwX y8KKne+4QrL08u00rzh6Rdkhl1mBjiuBNxLX80C+70CThIvR91pVAjLOhTqd2vtIIg3o U6Nw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@infradead.org header.s=bombadil.20210309 header.b=QcpTyTJu; spf=pass (google.com: domain of linux-kernel+bounces-9826-ouuuleilei=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-9826-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 c12-20020a17090a8d0c00b0028c01af5d75si1854641pjo.113.2023.12.22.07.13.24 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 22 Dec 2023 07:13:24 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-9826-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=QcpTyTJu; spf=pass (google.com: domain of linux-kernel+bounces-9826-ouuuleilei=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-9826-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 595C628035E for ; Fri, 22 Dec 2023 15:13:24 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 61D6C2FC2F; Fri, 22 Dec 2023 15:09:11 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=infradead.org header.i=@infradead.org header.b="QcpTyTJu" 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 96AB22EB07; Fri, 22 Dec 2023 15:09: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=Cpsd8l7OUn8C5bZQLGYGz9qCV/TqxduSbkyPfu2Mjvk=; b=QcpTyTJuJ95zy8zQxfBVMOoGDn sw2GJk7mt4gkoe22EcMVpN5zoyxcTZ73p+PdkX60CZgHZeUAuIUr2oVe8FRVmI8/vAcpKnpluXuEu TUUZxssJV21oSRM3MQ9FjEgkhDo2BKBvRLib0rucgP+qyhWCD0t6FBI8QvgXSiu3rZjMwYBrflf0M uoIruyUMiuNMWZXyPdg5PqtA3L2CzyA4EIAD0M+B5pGflz0iEsiuxw8YZ2tO6wp2UnPyPwLrtqOIi L2C1oIjxnOjwUKsQO/pO4H+bWqA1WGkCM7vItyfaVkeb+MtDYyqFpiRj3tcKyxP2vT3yQKv8ByTNA uje57PSw==; 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 1rGh96-006Bb2-1Z; Fri, 22 Dec 2023 15:09:04 +0000 From: Christoph Hellwig To: linux-mm@kvack.org Cc: "Matthew Wilcox (Oracle)" , Jan Kara , David Howells , Brian Foster , linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org, Jan Kara , Dave Chinner Subject: [PATCH 15/17] writeback: Add for_each_writeback_folio() Date: Fri, 22 Dec 2023 16:08:25 +0100 Message-Id: <20231222150827.1329938-16-hch@lst.de> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20231222150827.1329938-1-hch@lst.de> References: <20231222150827.1329938-1-hch@lst.de> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 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: 1785995465647166252 X-GMAIL-MSGID: 1785995465647166252 From: "Matthew Wilcox (Oracle)" Wrap up the iterator with a nice bit of syntactic sugar. Now the caller doesn't need to know about wbc->err and can just return error, not knowing that the iterator took care of storing errors correctly. Signed-off-by: Matthew Wilcox (Oracle) Signed-off-by: Christoph Hellwig Reviewed-by: Jan Kara Acked-by: Dave Chinner --- include/linux/writeback.h | 10 ++++++++++ mm/page-writeback.c | 8 +++----- 2 files changed, 13 insertions(+), 5 deletions(-) diff --git a/include/linux/writeback.h b/include/linux/writeback.h index 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 a041cc563762ae..5c33a4a527b3fa 100644 --- a/mm/page-writeback.c +++ b/mm/page-writeback.c @@ -2458,7 +2458,7 @@ static struct folio *writeback_get_folio(struct address_space *mapping, return folio; } -static struct folio *writeback_iter_init(struct address_space *mapping, +struct folio *writeback_iter_init(struct address_space *mapping, struct writeback_control *wbc) { if (wbc->range_cyclic) @@ -2474,7 +2474,7 @@ static struct folio *writeback_iter_init(struct address_space *mapping, return writeback_get_folio(mapping, wbc); } -static struct folio *writeback_iter_next(struct address_space *mapping, +struct folio *writeback_iter_next(struct address_space *mapping, struct writeback_control *wbc, struct folio *folio, int error) { unsigned long nr = folio_nr_pages(folio); @@ -2552,9 +2552,7 @@ int write_cache_pages(struct address_space *mapping, struct folio *folio; int error; - for (folio = writeback_iter_init(mapping, wbc); - folio; - folio = writeback_iter_next(mapping, wbc, folio, error)) + for_each_writeback_folio(mapping, wbc, folio, error) error = writepage(folio, wbc, data); return wbc->err; From patchwork Fri Dec 22 15:08:26 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christoph Hellwig X-Patchwork-Id: 182699 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7300:2483:b0:fb:cd0c:d3e with SMTP id q3csp1128315dyi; Fri, 22 Dec 2023 07:13:56 -0800 (PST) X-Google-Smtp-Source: AGHT+IE8lFjzCdi+Tz4Znuq4gOWAfpaJ07Ys1cGyYR+mnduPYli9jwWG56S5XAjfWPGN5TvoK/Md X-Received: by 2002:a05:6808:164b:b0:3b9:ea0c:609a with SMTP id az11-20020a056808164b00b003b9ea0c609amr1609021oib.104.1703258035918; Fri, 22 Dec 2023 07:13:55 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1703258035; cv=none; d=google.com; s=arc-20160816; b=0TQY9e4ELnusZ64bwCQGqMi62Vmm0qwf6uqEXw87FIhqQ6ok9c7epVWgAaNQapAqgi mQ+X94dH+2t/1O916Ls4WgRpJhnp3Idt5eD1a3pEjXPc/6AYcFTP4wvC4L4I4Guufntn oR0HkS/HvXNWoXe1t+FNsLnbTEELzntCcxdxPeXr3LkJ02odkrmsPYVPVC3gFXtL8lCT /fZv8U4jdmb/MFZ6O+TsBsSMmRK1w8TymLFoUjAMmhfBkq20SG2IKDJnMfmaBPW5YoPS YNLwaTl2PlYdVoeiU8mDIzSM64Q8kn0TeNi+pDjw7KeZumcpnCyj+hygi3K9fkdcsemP /dfQ== 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=lixDX8ZESJjee4RWhykT/1y+dKD2DSRjw7efEsZauMY=; fh=hzpEVxJ05G9gyZL9WVyKgOEGxITvmFSuTcKyr2ByStg=; b=pLs+MV4hScSbQaVeR6thQoJIq1N782AFATAromMq/8T1oJJNzHp8P4ClwM05TRdntC GCNG2uBVQSLB66Dc3uaYXJIVHsVNUSovrMnC/yIcd556UP6YmcqhxCpKt6Hiqf8bzEuB 4pVs1rqJ1Th5PR6JR2PdhzQMhEblpOW7PwH6HJpB665zvNgjG7zah6J9j1ztmYvEhwbC UjGRVGL4c6XTVqJQ8dzU7bfS5cgxqKNyc79dIL58Jyp9EODAc//zd09mbbu7DDOQdnIa 0npkXJLvxGB+/fgb1rK8k+oUyPJ1kEWxFn3nnlqajBbykbjfwLBQUw2cEi8Hyda7Qr4+ p57Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@infradead.org header.s=bombadil.20210309 header.b=fr1wzmpg; spf=pass (google.com: domain of linux-kernel+bounces-9828-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-9828-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 h21-20020a67ec95000000b00466dddbe229si233839vsp.356.2023.12.22.07.13.55 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 22 Dec 2023 07:13:55 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-9828-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=fr1wzmpg; spf=pass (google.com: domain of linux-kernel+bounces-9828-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-9828-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 AA1971C20E31 for ; Fri, 22 Dec 2023 15:13:55 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id C6F1C315A5; Fri, 22 Dec 2023 15:09:13 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=infradead.org header.i=@infradead.org header.b="fr1wzmpg" 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 F21A82F848; Fri, 22 Dec 2023 15:09:09 +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=lixDX8ZESJjee4RWhykT/1y+dKD2DSRjw7efEsZauMY=; b=fr1wzmpg3g1yRFa0Y9DqGv06Wk cfDoK78nyVATk2W00QiKsY/vi82udAF0M2pyy+Ay93XVwZPJE4qz+MVWOhvOnuXDUpB2cDR0YviWU pEa0p7C4tjXfPes+OGICWcueTOsQ06AIm0+bbjDoBE1CB0mmoXrZbVxR+vklmsbA8hsDQKSvi1pEy 26uOQbqYl11Ollia+yPhtCKAS7dsKtR+F/IMr9+yAhj597hdQxeg68obkW8aguZaJl/ZMU2OFxJjc N10rjpNyBKRSURZsWSof2IhpBNqPx+qHoW6tbAa3Vig8tLlTZDipLRaHFw1jenO2m6NAKArNjk9Ba 8eg37u/A==; Received: from 2a02-8389-2341-5b80-39d3-4735-9a3c-88d8.cable.dynamic.v6.surfer.at ([2a02:8389:2341:5b80:39d3:4735:9a3c:88d8] helo=localhost) by bombadil.infradead.org with esmtpsa (Exim 4.96 #2 (Red Hat Linux)) id 1rGh98-006Bcf-2W; Fri, 22 Dec 2023 15:09:07 +0000 From: Christoph Hellwig To: linux-mm@kvack.org Cc: "Matthew Wilcox (Oracle)" , Jan Kara , David Howells , Brian Foster , linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org, Jan Kara , Dave Chinner Subject: [PATCH 16/17] writeback: Remove a use of write_cache_pages() from do_writepages() Date: Fri, 22 Dec 2023 16:08:26 +0100 Message-Id: <20231222150827.1329938-17-hch@lst.de> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20231222150827.1329938-1-hch@lst.de> References: <20231222150827.1329938-1-hch@lst.de> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 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: 1785995498350439620 X-GMAIL-MSGID: 1785995498350439620 From: "Matthew Wilcox (Oracle)" Use the new for_each_writeback_folio() directly instead of indirecting through a callback. Signed-off-by: Matthew Wilcox (Oracle) Signed-off-by: Christoph Hellwig Reviewed-by: Jan Kara Acked-by: Dave Chinner --- mm/page-writeback.c | 27 +++++++++++++++------------ 1 file changed, 15 insertions(+), 12 deletions(-) diff --git a/mm/page-writeback.c b/mm/page-writeback.c index 5c33a4a527b3fa..1ff444d5e4317a 100644 --- a/mm/page-writeback.c +++ b/mm/page-writeback.c @@ -2559,13 +2559,21 @@ int write_cache_pages(struct address_space *mapping, } EXPORT_SYMBOL(write_cache_pages); -static int writepage_cb(struct folio *folio, struct writeback_control *wbc, - void *data) +static int writeback_use_writepage(struct address_space *mapping, + struct writeback_control *wbc) { - struct address_space *mapping = data; - int ret = mapping->a_ops->writepage(&folio->page, wbc); - mapping_set_error(mapping, ret); - return ret; + struct blk_plug plug; + struct folio *folio; + int err; + + blk_start_plug(&plug); + for_each_writeback_folio(mapping, wbc, folio, err) { + err = mapping->a_ops->writepage(&folio->page, wbc); + mapping_set_error(mapping, err); + } + blk_finish_plug(&plug); + + return err; } int do_writepages(struct address_space *mapping, struct writeback_control *wbc) @@ -2581,12 +2589,7 @@ int do_writepages(struct address_space *mapping, struct writeback_control *wbc) if (mapping->a_ops->writepages) { ret = mapping->a_ops->writepages(mapping, wbc); } else if (mapping->a_ops->writepage) { - struct blk_plug plug; - - blk_start_plug(&plug); - ret = write_cache_pages(mapping, wbc, writepage_cb, - mapping); - blk_finish_plug(&plug); + ret = writeback_use_writepage(mapping, wbc); } else { /* deal with chardevs and other special files */ ret = 0; From patchwork Fri Dec 22 15:08:27 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christoph Hellwig X-Patchwork-Id: 182700 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7300:2483:b0:fb:cd0c:d3e with SMTP id q3csp1131075dyi; Fri, 22 Dec 2023 07:17:31 -0800 (PST) X-Google-Smtp-Source: AGHT+IEBR1HOew8Or8AXCpunYFSm48m5+OcBWqrCrh7Uyeib5YP7z0rkpo3mfR2w3EyL0Enx32Gq X-Received: by 2002:a05:6a20:2584:b0:18f:97c:9269 with SMTP id k4-20020a056a20258400b0018f097c9269mr1211196pzd.78.1703258250784; Fri, 22 Dec 2023 07:17:30 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1703258250; cv=none; d=google.com; s=arc-20160816; b=ZxygWjS2Ysfv/oGXxw6sW2YLtue8tMiRu+kuC54jXe+YVfqjRQj0PYN9eibpKhVzKK VqU2QwF45gQBOU3184g/d20SdsRdP6k7aw5D0qvH0QZkv5lX8448nDpbs1NYIcfFJ5l/ IRaoHLQEwb/GgcoMOJJBxC85MgDlyIJB4M+X7ypXRznNuxHYPrhmdmV9Ltr8v3UF55Ji pPGgRTer9x3E/NI7z+mPf/JhQCX056nKOgOametwcj5WIkHKY8jq9rkzvNwNVw491gln JkOXcM+Uu0PGOoA5ZDbXO7kZuSPHoC7ES+BP446jXJORVYa6EDqVareOSLUhp01by9SX G90w== 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=vSRtoBhWiymkrUriREDGEOquZtVYvqi7wp6gqOzPpq0=; fh=fUFzgJc1/kgUfq6BPN/bCy6q7r4YjH7SPfVUiUwIe+0=; b=MZFS+k+jtyASQoSs5IFf/MGV9s5nKzczF+HcHBC6Q8y/5SKf+K9mb3rTc7KbRD2X1L SythMNo4BKPB4RbfOgwcLQlpVdSCPvN7jIXazvqIOhN7UqcCZtE1Oi1u6rVqw1nd8T9P Y0RiyZuTVSV4Dn4NzTKPAvpWvB5desyx5tIqaAOrPeqoUrIo63JrXu4TWaDrqg92tXVU FigPZzFEMsFGY5JJQW5KPJ3MSFIcfKNvx/hccRhIfwxx+/zsjqUQMlUUaV80v90Q+8ye 5qiLA3Dn8Au2iS8OjTldw4Bfqlx0IRkE6TUGdIJ+GgNGsjXCBZVOUf9mW7pSZYEY5jFd odIA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@infradead.org header.s=bombadil.20210309 header.b=EwhMMlXL; spf=pass (google.com: domain of linux-kernel+bounces-9829-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-9829-ouuuleilei=gmail.com@vger.kernel.org" Received: from sy.mirrors.kernel.org (sy.mirrors.kernel.org. [2604:1380:40f1:3f00::1]) by mx.google.com with ESMTPS id me1-20020a17090b17c100b0028a84e29ca4si6918789pjb.159.2023.12.22.07.17.30 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 22 Dec 2023 07:17:30 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-9829-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) client-ip=2604:1380:40f1:3f00::1; Authentication-Results: mx.google.com; dkim=pass header.i=@infradead.org header.s=bombadil.20210309 header.b=EwhMMlXL; spf=pass (google.com: domain of linux-kernel+bounces-9829-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-9829-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 4A01CB2572D for ; Fri, 22 Dec 2023 15:14:14 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 1E0E43218D; Fri, 22 Dec 2023 15:09:16 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=infradead.org header.i=@infradead.org header.b="EwhMMlXL" 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 6202630CFB; Fri, 22 Dec 2023 15:09:12 +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=vSRtoBhWiymkrUriREDGEOquZtVYvqi7wp6gqOzPpq0=; b=EwhMMlXLFZbb/tlh1Ap0vPdrcR QeXKb5dVMvla5R8BdZFAmfwJTIijr0Gqh4grvfBE2kVQ74iY2pchwGk1U6PBfvQLlseP3Joxij14M f6DDtw8jvufT1eQ0dD6EnwdEEfmngoOSFwXb3tcNOHge1rxqDek23e1IBIgaxlzAOjCOrrDyZ1Pm9 6bpZHxF0yNGAKL1BWEHRC7Ee16sHdUCn73JAe5XO5P7gvg/24bmDnR1HUJ/8m8hxdxp+ALaoGDdjh CrJ0gy89UfK4aZ28Lih1VvI2b3nUn8Yje//rK3yG35lU++vIYwhUFSmTiW8uFt5D70kn6sI9l1clv MGfNkVlA==; 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 1rGh9B-006Bdj-10; Fri, 22 Dec 2023 15:09: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, Dave Chinner , Jan Kara Subject: [PATCH 17/17] writeback: update the kerneldoc comment for tag_pages_for_writeback Date: Fri, 22 Dec 2023 16:08:27 +0100 Message-Id: <20231222150827.1329938-18-hch@lst.de> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20231222150827.1329938-1-hch@lst.de> References: <20231222150827.1329938-1-hch@lst.de> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 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: 1785995723593547552 X-GMAIL-MSGID: 1785995723593547552 Don't refer to write_cache_pages, which now is just a wrapper for the writeback iterator. Signed-off-by: Christoph Hellwig Acked-by: Dave Chinner Reviewed-by: Jan Kara --- mm/page-writeback.c | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/mm/page-writeback.c b/mm/page-writeback.c index 1ff444d5e4317a..0546741856d70d 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)