From patchwork Thu Feb 15 06:36:36 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christoph Hellwig X-Patchwork-Id: 13557435 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id A40DCC4829E for ; Thu, 15 Feb 2024 06:37:09 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id B5C346B00AB; Thu, 15 Feb 2024 01:37:08 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id AE20B6B00AC; Thu, 15 Feb 2024 01:37:08 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 7D4FA6B00AC; Thu, 15 Feb 2024 01:37:08 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0011.hostedemail.com [216.40.44.11]) by kanga.kvack.org (Postfix) with ESMTP id 65AF56B00A9 for ; Thu, 15 Feb 2024 01:37:08 -0500 (EST) Received: from smtpin10.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay08.hostedemail.com (Postfix) with ESMTP id 0612C1402E5 for ; Thu, 15 Feb 2024 06:37:08 +0000 (UTC) X-FDA: 81793080936.10.926F1C7 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) by imf09.hostedemail.com (Postfix) with ESMTP id 30FB6140005 for ; Thu, 15 Feb 2024 06:37:02 +0000 (UTC) Authentication-Results: imf09.hostedemail.com; dkim=pass header.d=infradead.org header.s=bombadil.20210309 header.b=Rp1jtgBv; dmarc=none; spf=none (imf09.hostedemail.com: domain of BATV+a252b21bd4a653ddb6e6+7480+infradead.org+hch@bombadil.srs.infradead.org has no SPF policy when checking 198.137.202.133) smtp.mailfrom=BATV+a252b21bd4a653ddb6e6+7480+infradead.org+hch@bombadil.srs.infradead.org ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1707979024; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=5GhhuDyIOonlmDg/Vr+y+ffKK6l+9T3rNZ2pDiaN6Ho=; b=YEicOUuVZA1InwGTefRbpAqpeJ/HjN06uM+0U9tXGyK7YqkTiHvd0iIqPCbgWozOPdSR7c q6Mppvwd0DiNNrPYU8+5+gQLFAFChJIsBaSVhPyZSawvGGHWEUcmLfjN1wRmbrBY4g5gIY SNz75BDYqRj46q/1174ZAiPN9UqSmCc= ARC-Authentication-Results: i=1; imf09.hostedemail.com; dkim=pass header.d=infradead.org header.s=bombadil.20210309 header.b=Rp1jtgBv; dmarc=none; spf=none (imf09.hostedemail.com: domain of BATV+a252b21bd4a653ddb6e6+7480+infradead.org+hch@bombadil.srs.infradead.org has no SPF policy when checking 198.137.202.133) smtp.mailfrom=BATV+a252b21bd4a653ddb6e6+7480+infradead.org+hch@bombadil.srs.infradead.org ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1707979024; a=rsa-sha256; cv=none; b=QRNJItqllDVHEYeDRBgoFQchU7OykEtnI/Gdp+e1D/ySQln8bK5X0j4PWQr37VPyXeme4L nRLIThWLfOkBN4Z0leyfuwmxruFvsFKW+v8koBsBvWTk1HIH5wMMLjbh0iSyIVWwo9s0Ei c8NFkkU2YZ7X6XNFyZQb3bkrh96Fjhk= 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=5GhhuDyIOonlmDg/Vr+y+ffKK6l+9T3rNZ2pDiaN6Ho=; b=Rp1jtgBvUtxVvNXp1sP56Ko4Aa gktEnrNCtkAvu7DLUea8tY8oFyjpctbtKJQBqAp/Y3F+AZE9f2WmupbVNkGAO/jVSuRg5osa1TJDa 5HXAMzm+rMKBxQw9f7g4YK38K2o2ZFM+2H8bJ08bAzZkL1d+WINW1Y+Pyn5UTq5dBzEnZ+yjgvrFc sTCCoQbU4LXqQbKUy6a6VISm3ggtoKihCXjmjG39/Ss9iIJFzecFVDLrIGrRf0JkdJcMjIRDWvDvB W0RXMYe1UBA0Vz6LnvyBO7Kbu6iVlmtQLIc/rbe6hSdf+UvEL+qMgQSU3ERH/uI3ylw1dPHiRL5cL kWnYLxfQ==; 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.97.1 #2 (Red Hat Linux)) id 1raVMj-0000000F6rJ-3g8h; Thu, 15 Feb 2024 06:37:02 +0000 From: Christoph Hellwig To: linux-mm@kvack.org Cc: Matthew Wilcox , Jan Kara , David Howells , Brian Foster , Christian Brauner , linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH 01/14] writeback: don't call mapping_set_error on AOP_WRITEPAGE_ACTIVATE Date: Thu, 15 Feb 2024 07:36:36 +0100 Message-Id: <20240215063649.2164017-2-hch@lst.de> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20240215063649.2164017-1-hch@lst.de> References: <20240215063649.2164017-1-hch@lst.de> MIME-Version: 1.0 X-SRS-Rewrite: SMTP reverse-path rewritten from by bombadil.infradead.org. See http://www.infradead.org/rpr.html X-Rspam-User: X-Rspamd-Server: rspam12 X-Rspamd-Queue-Id: 30FB6140005 X-Stat-Signature: 84dqia3qhmbu3oqcimmr8uey4c7moyg9 X-HE-Tag: 1707979022-828261 X-HE-Meta: U2FsdGVkX19U+dH8ybn/TrgbCL/o/Qn2L6Yq5w0m9itHE3Qf15zHU4lH67JIARCkxWLN20VsB/Xvm5ICOgol2LNlou0feGmnJcWT0KUFozxdianAiiG5rnkM/uhZEakdSqSxEI5Iqji80YfMJc0545SgYrFD0EJEY60ksMbyRo5uFIDOmVoQ7mbCOpqOpjBkR2o7DMyk9qdZsCA7TsU4mlOfeTTWLDYn1C858L8IlobfG0Cz3G9ZznrmXrs4LHfzL3cF7O2b5SBMPM0VXnM4+XVPoUjvJu5elTzEYUuC31TELor+NkhFI7gpxlojn1nROGaea/6GImd4DK2GGdYzu4e0qnuZKMEk36+YqWRGF0mZL+CVjXYVDMrme1bgHQ6b7h8gNrTRb0B4EHeM/YEyFCn5BI2TdPnYiXNKDWJ1WnSZ+rXv3Gfi51y30rT7SE/7FiDac4Fp+8Ms9gvzojH/Abwz5QXsX53f1YPtOWRWuXlz7HJgywKnuGWF2uVNkkrX2/SwtS5PQ1RH9Arhi/qXLlxCa2mgzukG80SHxLsgdm9CbgD3pVy1BEyLEp91A3VCE1pbAIzwLWeRznQ15vfqEoYlJi4z86GC8yfFBfZ0geCoFqhaBMHIPQuYT7BMXl1n2MUoqRnATLaJc4c3ybyNMh1Zx4YYEAi3Koy240GNzdLY+boO0GTi0hojEES1M0IY9iUnm3TH1F3DYZK0ZA3CWMUTB+wyldDAEyNgE8g3OoCpv8+5GLp14MxKQfGpBNju3RBa4yrx49/gVffAlFvbwYUsT7JCt03gFTZxiPRI2ECO/+tUFUM1KXy5ZksMD9B4h+20IckhiHSpR1UTRWJCrlxirINZyqCGZhVeCkDZlX/hftJCGt6isn3CHUp69hwUzMhPUuU/CnDit7gOt2I65C34EUg+e7OFZpCnKR01QwueBkWtFntEFfFjbLK9GPLfLP13F7W8ZTTp/weyCqt aR+HOs1e eBAUM0/7penYdUduDixANBIxye6GRlPYwKL/xqlf0Z4iOG10iHEx/ioVZxcjNIDd9UFt6mzDmqxgKbX+d2RRZPFngg+l9vj3UTqukcPhnFhu7I6AbgR1TArhq2ZmGs+JRgHW/ODyNbs9OtOY+8pbk+fUGmQgMlAWPVq8pxnwel3A4PhHEfGK0/xICW1wYqL22AnDywbFU/iUo0pqt+TX8/98wcw== X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: mapping_set_error should only be called on 0 returns (which it ignores) or a negative error code. writepage_cb ends up being able to call writepage_cb on the magic AOP_WRITEPAGE_ACTIVATE return value from ->writepage which means success but the caller needs to unlock the page. Ignore that and just call mapping_set_error on negative errors. (no fixes tag as this goes back more than 20 years over various renames and refactors so I've given up chasing down the original introduction) Signed-off-by: Christoph Hellwig Reviewed-by: Jan Kara Reviewed-by: Brian Foster --- mm/page-writeback.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/mm/page-writeback.c b/mm/page-writeback.c index 3f255534986a2f..703e83c69ffe08 100644 --- a/mm/page-writeback.c +++ b/mm/page-writeback.c @@ -2535,7 +2535,9 @@ static int writepage_cb(struct folio *folio, struct writeback_control *wbc, { struct address_space *mapping = data; int ret = mapping->a_ops->writepage(&folio->page, wbc); - mapping_set_error(mapping, ret); + + if (ret < 0) + mapping_set_error(mapping, ret); return ret; } From patchwork Thu Feb 15 06:36:37 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christoph Hellwig X-Patchwork-Id: 13557436 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id D2E6FC4829E for ; Thu, 15 Feb 2024 06:37:14 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 125C86B00AA; Thu, 15 Feb 2024 01:37:09 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id D31616B00A7; Thu, 15 Feb 2024 01:37:08 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 9D1956B00A9; Thu, 15 Feb 2024 01:37:08 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0012.hostedemail.com [216.40.44.12]) by kanga.kvack.org (Postfix) with ESMTP id 650226B00A7 for ; Thu, 15 Feb 2024 01:37:08 -0500 (EST) Received: from smtpin07.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay05.hostedemail.com (Postfix) with ESMTP id 1BF9140873 for ; Thu, 15 Feb 2024 06:37:08 +0000 (UTC) X-FDA: 81793080936.07.BF2D3AC Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) by imf13.hostedemail.com (Postfix) with ESMTP id 70DAC20005 for ; Thu, 15 Feb 2024 06:37:06 +0000 (UTC) Authentication-Results: imf13.hostedemail.com; dkim=pass header.d=infradead.org header.s=bombadil.20210309 header.b=RQy5ZP4K; dmarc=none; spf=none (imf13.hostedemail.com: domain of BATV+a252b21bd4a653ddb6e6+7480+infradead.org+hch@bombadil.srs.infradead.org has no SPF policy when checking 198.137.202.133) smtp.mailfrom=BATV+a252b21bd4a653ddb6e6+7480+infradead.org+hch@bombadil.srs.infradead.org ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1707979026; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=+lqvdXiJyeUBbv4RbCH+VsOF1ziPvzDxge6GroiRQvo=; b=pTRXN7Gu2mKwsCY8vxVOpXNqT2c12oDeH3vJ4gayfkW/SgcPJjFNmdaz+U7RUgPc53K9RG EmTn8PeaiM7/SHfauO/+S2lTUUjiyR8bNk/9rubFM9WF8TNNTn88wVzVzWZC/NhUfWPRoy ah4ZbJ7puf2ewim5E8PokS2lOIP3ZmI= ARC-Authentication-Results: i=1; imf13.hostedemail.com; dkim=pass header.d=infradead.org header.s=bombadil.20210309 header.b=RQy5ZP4K; dmarc=none; spf=none (imf13.hostedemail.com: domain of BATV+a252b21bd4a653ddb6e6+7480+infradead.org+hch@bombadil.srs.infradead.org has no SPF policy when checking 198.137.202.133) smtp.mailfrom=BATV+a252b21bd4a653ddb6e6+7480+infradead.org+hch@bombadil.srs.infradead.org ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1707979026; a=rsa-sha256; cv=none; b=wvDZF/7Hyl/gZkI2kun5pLizhlJ6TfMevquu/Pm4CBz7c+cUisjVKPKqoe5IN7RMDt7+Uu 3T0KAMykPafVs0OiUUBRaURupWqq5X5IkQKq4Da9mhfFO3FRcu0KWmYI3uxkgqURuUhCpR X1GUzK58vJOU21VBJAVw25hst4TBCCY= 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=+lqvdXiJyeUBbv4RbCH+VsOF1ziPvzDxge6GroiRQvo=; b=RQy5ZP4K+MfZPbgvfHc/NQ8KKg /6kUwQ2DirErEZ02NYbD0SuZEXTN3xFdk4RRZgNfUoghQCegfesZxeVsgjgZuqljlaTeehhhryRws H8jn4iZs9OkXYFWnHUUKPoobWTwYzUUqEDUvFFwISJtD0CL3ljuJimr8QWkLNiJ3PZ+d9lzt00uqT CH+gSCJeBoj9W/Tu06EUGk+0rt5X8l+aleBGY15DXdZ1jKJjezRErCB5Yjwex3fP4Igr8mavIXIJ3 VQI5RStF7Dma1XC8/Lq4JqxK0xzV5sLj1ucujTbSmsrHvq80FRAY5npC3+SOcKP1qUJkQ7acIERdO u/QgPIkw==; 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.97.1 #2 (Red Hat Linux)) id 1raVMm-0000000F6rU-0x11; Thu, 15 Feb 2024 06:37:04 +0000 From: Christoph Hellwig To: linux-mm@kvack.org Cc: Matthew Wilcox , Jan Kara , David Howells , Brian Foster , Christian Brauner , linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org, Jan Kara , Dave Chinner Subject: [PATCH 02/14] writeback: remove a duplicate prototype for tag_pages_for_writeback Date: Thu, 15 Feb 2024 07:36:37 +0100 Message-Id: <20240215063649.2164017-3-hch@lst.de> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20240215063649.2164017-1-hch@lst.de> References: <20240215063649.2164017-1-hch@lst.de> MIME-Version: 1.0 X-SRS-Rewrite: SMTP reverse-path rewritten from by bombadil.infradead.org. See http://www.infradead.org/rpr.html X-Rspam-User: X-Stat-Signature: hbznyfe7h55bp5gajuqsmwfsubsjejcq X-Rspamd-Server: rspam07 X-Rspamd-Queue-Id: 70DAC20005 X-HE-Tag: 1707979026-155330 X-HE-Meta: U2FsdGVkX1++QTvG9Jttl+oW2dRgFxcmCuho1+HdSSKcqMmkpVnFly13WFxNTPXFlYOaRczMLCRZz5daN+w2y6iuiyLbuSYaIZCmD6yNF+/Udvay/mqew294RGK3jLPBGrnklCdyXF1hmKLeV/H5EdodLu8TmSlfh9igB/zMxlW2Vn7XWjhwKiS607LCvFpV32egxotMqfLKgy24ooNtLh/iGs3FIZLaS0MyQnMRYcnpG/Zx7IgJuIn1E4BYzcKQzo2qJDxYLjr11JKw325zgHFLViSj6EgxWrybgKuR0rcFneBOYTNTf2OvpGBiyNkYn8p8S7sATaBDXmheXhhur3Di9O59LUKZYHzHHyyH2JfboSWHPbY1FROe3Sxwr3Ra21ZjMV6jk+8b/h+gPSBJmqAbhtgLMT6jlHYnSNWiNCKlfiLFNt8YpqWDNRqskatLnNYw2LsqHGPHelLQ0zD8R7WwvTS9J03aPzviGgxMH+i5OVX6aLNvyDbiFnja83dL0zzyvPkzuTDApSSMbIK9c88jTrklmeLUmicM9LFpS//BnX9wT8zzTGFAGkI88WUoq/hnC4/2HeClW4dsynf0opXAY/Dycx/lWWieUbIbiwwNq9oL1xEvQw9q5bnQCuvkLeeIVARAykZOjgyh9UGqSzWdPO/MQy2Cxja5BIdMgqvyeUh3LTm3F+y56mH8MdsfaSeN4Sw7oEdbBPayAcje0hAjSQw2bO/X9KU3JcInY0A4/SmJn/vZfhn7MoRDX/nJMCtw9swhuy41nbOZjBkewKAkR3v2fHNVqIrUK7aezSeHXsSnnB31XKPp3UBu9puDhxY8bA2Y3HYZtlMM9K30gcEMg7GUJv1kPXZLteb+caq7h8KwHHeTVRmuN1XI1eTeJp9awcFXePO+jm+aOULg+mOorb4VueenV2JvCGEjlOVO9sL/nY56MQE7Bb/+Qjgj5E1vIKvbXZesC4afYh3 cbY39WlN jSk6lzXSLm38OZUU3Or5xKQfpodmtoduH7TLnSqvKO27ggFlTKAdVhdV9jZAAuWTVhj9YgPF3JpAu2kiZW3woZFvQeYUKPMTtUkKBt2nMgjcKeeBQrZu23In9shu86sU8rVmCXcI4EZL2pD+s7B5QYynNQKjUQnl9if+MlccipiJ4gl5d2l6XVB2tO+UUCz/5K3lrqvhr2jNInR4dn27I70pSNuJpLjxJzxHaHu+n7CPiVLyAuEgmzoe5DfzjMcA1tpyqlrkgiRzRnLcNC2SZi43VS6u431QSvL8eiXsKYO5Jh/e7J8JYNb4XzlbLwtVxaFX2Z7Rb8SDKn+/72EX72QffHd/F5F1R/FLOBMUyOHbZPntHycgySNiSYXYOecoZqsGndr9kMgAq1xXhbV+LWmULlNqNzKPkk+rvYT5uG/44ut8EQFQArrwXWm85TzVUPOiKGyfMakkKDEpKkt5ehMM2x7PkmreJ2GIRHfthssuJAuet9fLnDPvKhwQEtO5IzZ5Wg3tLZ9s1kmaJoNJd+gSq+jeemnKuxlkJ X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: From: "Matthew Wilcox (Oracle)" Signed-off-by: Christoph Hellwig [hch: split from a larger patch] Signed-off-by: Matthew Wilcox (Oracle) Reviewed-by: Brian Foster Reviewed-by: Jan Kara Acked-by: Dave Chinner --- include/linux/writeback.h | 2 -- 1 file changed, 2 deletions(-) diff --git a/include/linux/writeback.h b/include/linux/writeback.h index 453736fd1d23ce..4b8cf9e4810bad 100644 --- a/include/linux/writeback.h +++ b/include/linux/writeback.h @@ -363,8 +363,6 @@ bool wb_over_bg_thresh(struct bdi_writeback *wb); typedef int (*writepage_t)(struct folio *folio, struct writeback_control *wbc, void *data); -void tag_pages_for_writeback(struct address_space *mapping, - pgoff_t start, pgoff_t end); int write_cache_pages(struct address_space *mapping, struct writeback_control *wbc, writepage_t writepage, void *data); From patchwork Thu Feb 15 06:36:38 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christoph Hellwig X-Patchwork-Id: 13557437 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 107C7C48BEB for ; Thu, 15 Feb 2024 06:37:18 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 910126B00A7; Thu, 15 Feb 2024 01:37:09 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 898BF6B00AC; Thu, 15 Feb 2024 01:37:09 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 6EB616B00AD; Thu, 15 Feb 2024 01:37:09 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0011.hostedemail.com [216.40.44.11]) by kanga.kvack.org (Postfix) with ESMTP id 55BE56B00A7 for ; Thu, 15 Feb 2024 01:37:09 -0500 (EST) Received: from smtpin04.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay03.hostedemail.com (Postfix) with ESMTP id 360CAA0856 for ; Thu, 15 Feb 2024 06:37:09 +0000 (UTC) X-FDA: 81793080978.04.C1F7FB1 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) by imf16.hostedemail.com (Postfix) with ESMTP id B7AED18000A for ; Thu, 15 Feb 2024 06:37:07 +0000 (UTC) Authentication-Results: imf16.hostedemail.com; dkim=pass header.d=infradead.org header.s=bombadil.20210309 header.b=S4NXeWjC; spf=none (imf16.hostedemail.com: domain of BATV+a252b21bd4a653ddb6e6+7480+infradead.org+hch@bombadil.srs.infradead.org has no SPF policy when checking 198.137.202.133) smtp.mailfrom=BATV+a252b21bd4a653ddb6e6+7480+infradead.org+hch@bombadil.srs.infradead.org; dmarc=none ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1707979027; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=kSMXi3gz5VM6F2g1+TWrPGgNlolETTCiIJzlQ/AveA4=; b=fRz3SWZqlOwxL0yeaDBSsh+LHoVYdYtwH7rtrYJ3RIYYHZA3QSAHObePzU8e0mSNp4dyWM Zr/mrvpfpYVgDcaWQCRTiGo1lE5mwpulpM7VMOpJA8qE75KHtZO7c4Fjrcxzvo/+I4migN LPPWY6aCG2luKOH8sBfcPhDzfA9GLyQ= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1707979027; a=rsa-sha256; cv=none; b=EQs85hPVe8q9GMVTZmZJ7Koz5mfy8S9c7YDrHaSDXUbiWTvBi0eKrVh9XlC6vKHTmgD6j4 TLprVs+wLtKFeSRPgDQmuVVDe82pdbCt45VrqiIRIeHfBzYlSGw2QcO9b99VtvuHExGZ+P MV0zqXWyN4mR2LTulTpVxz1g6Ht3bTA= ARC-Authentication-Results: i=1; imf16.hostedemail.com; dkim=pass header.d=infradead.org header.s=bombadil.20210309 header.b=S4NXeWjC; spf=none (imf16.hostedemail.com: domain of BATV+a252b21bd4a653ddb6e6+7480+infradead.org+hch@bombadil.srs.infradead.org has no SPF policy when checking 198.137.202.133) smtp.mailfrom=BATV+a252b21bd4a653ddb6e6+7480+infradead.org+hch@bombadil.srs.infradead.org; dmarc=none DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=bombadil.20210309; h=Content-Transfer-Encoding: MIME-Version:References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From:Sender :Reply-To:Content-Type:Content-ID:Content-Description; bh=kSMXi3gz5VM6F2g1+TWrPGgNlolETTCiIJzlQ/AveA4=; b=S4NXeWjCQySPi/zq4OM137aJ+6 vVdn/P9suTKm0us/wsY/Fv8b/20hUhILA19+5Ue3hWr6rBBb3U7kL8pSAoAkwjXWcMicNhajbI6xX EbgO3XefR/t34tuSkYHtTd9Njp4hIN9viDPkgVx74GlSP8t3vk871RskDSii5HkIODE7I8U2HXivd o/kmDk4nmPf+yzU7vIYhIPxU9+NPRtsDIfpHNcjVE6BikfhfOu8KASo0OeOoQJP4XMhW44VXabbct 6X7hYud0O18iDSb5usFsuDLPYY3c3E3ig71IflA7KenkTFNVBQ5bRbt0FEFfg19bw7GFC3u334/MT eleLva4A==; 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.97.1 #2 (Red Hat Linux)) id 1raVMo-0000000F6rf-2Dq1; Thu, 15 Feb 2024 06:37:06 +0000 From: Christoph Hellwig To: linux-mm@kvack.org Cc: Matthew Wilcox , Jan Kara , David Howells , Brian Foster , Christian Brauner , linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org, Jan Kara , Dave Chinner Subject: [PATCH 03/14] writeback: fix done_index when hitting the wbc->nr_to_write Date: Thu, 15 Feb 2024 07:36:38 +0100 Message-Id: <20240215063649.2164017-4-hch@lst.de> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20240215063649.2164017-1-hch@lst.de> References: <20240215063649.2164017-1-hch@lst.de> MIME-Version: 1.0 X-SRS-Rewrite: SMTP reverse-path rewritten from by bombadil.infradead.org. See http://www.infradead.org/rpr.html X-Rspamd-Queue-Id: B7AED18000A X-Rspam-User: X-Rspamd-Server: rspam11 X-Stat-Signature: ksm1ccsekes9krhrpccegcq5xcehxkwj X-HE-Tag: 1707979027-380863 X-HE-Meta: U2FsdGVkX184qWHd1liWTOeQfFNWb+nr3g3gSOHBWYzEYRI7DN8OqBikFN14bktPmnuJZhveKJePmlFEWYhEMbTsq9ee23/6jc2DvTBdGWl2L0NdyKjDtGWJCcyDiqm+wO7wnjvpIaEFX238G02+GqyXU/LCuqqOXco9t5vYCRquF9oxehw1pPcGp2PHGmA/LdPx0PVEOXJYh9xfbYAwRWqrmR2VKReOXgNkyZKXXn+tnrIX89WJOfwv344n1QmEchAwKn+7lqyNwjPrLlj+Ghhg2XQ3Ej8FmY9INpNB7hzZB5K+Yp1tluSGzrs27GVjjH7mtRZnGZEoqSXpk4RuWf6+RSWiw0M6i0InBuBEEt2Eb06LROG2jqJpfBN+oz1lhiVLYNIEPqYblSj4qaOHIXtMe+QvGANLjORyMVaKxJ/26upM820JxEjHBEawXrflyZ8tjpLB2gwAyBDM9FQAx9+CvK+rUHoBcQ2SoiqqpaMMViork5q69H4De3PWd2Hf2SqtCTLdPb1JaaFZYWWcXWmCKIif1O/KMqnI+LAm5I6f3sNWp1KFvr9yv/KFdqKA9z9NwGUflqhUwml58TxmUbaDOINZ0Z91tBi4GnsDfHq3S+MYtkE8Km+k8WofeCaYY+ykdH7BYzu5jH8afRpy/pWThAoXFr8Fkwsjadj3+dgBA+bJAU+y3PbhE6Qq7OUTRQTEbpQF515t8q/+8XQmA3Zm4/H+fSBIfVuU6Cb2SEiPrkjZhmgz7S1OP5rmMpnZuBDZFUxi8NWczTY/7kal4q+yN9FlUnsvmFjXszERwY4EbHf5h+10wc5K/uIDX6gCPxF6lQ3AXRwxpUNLqYdp/pZw9baFx3/Ogc4+MHahlX5l9btnReXmkD7vt4DVAxnjCcqcOKlIB0Fub0xRUfAn1m8RMYiqTZ2jha52pCqKUzaGAlaXqx2uuqxrhxfUIqR0lwzR0+MDtfm5xMqPOjn k+IuHJWN u9lXuc4ccJoUmwhRm1eDiAwYfdLqtTpvpKAyXNlwrpT+kgrCtAhD6XvtGeCnf6apGAy00g12Dm0Z2SidJmeYj6k8ySryzbTcCALob2ZciYIn8eY/tvpVBCEkvRBwkgUdJJlyUdEPu8SxEIrwu6MXhabMjkPuP5JGRyKLVxH8LCK1LVI79DreQQ+zdaMmigHHO/cvH+L7QH9M6Rc1Wxdtceo5aoQ== X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: When write_cache_pages finishes writing out a folio, it fails to update done_index to account for the number of pages in the folio just written. That means when range_cyclic writeback is restarted, it will be restarted at this folio instead of after it as it should. Fix that by updating done_index before breaking out of the loop. Signed-off-by: Christoph Hellwig Reviewed-by: Brian Foster Reviewed-by: Jan Kara Acked-by: Dave Chinner --- mm/page-writeback.c | 1 + 1 file changed, 1 insertion(+) diff --git a/mm/page-writeback.c b/mm/page-writeback.c index 703e83c69ffe08..2679176da316b3 100644 --- a/mm/page-writeback.c +++ b/mm/page-writeback.c @@ -2505,6 +2505,7 @@ int write_cache_pages(struct address_space *mapping, * keep going until we have written all the pages * we tagged for writeback prior to entering this loop. */ + done_index = folio->index + nr; wbc->nr_to_write -= nr; if (wbc->nr_to_write <= 0 && wbc->sync_mode == WB_SYNC_NONE) { From patchwork Thu Feb 15 06:36:39 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christoph Hellwig X-Patchwork-Id: 13557438 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 5E0F6C4829E for ; Thu, 15 Feb 2024 06:37:21 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 69FFC6B00AE; Thu, 15 Feb 2024 01:37:12 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 604076B00AF; Thu, 15 Feb 2024 01:37:12 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 42F816B00B0; Thu, 15 Feb 2024 01:37:12 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0016.hostedemail.com [216.40.44.16]) by kanga.kvack.org (Postfix) with ESMTP id 1D6BB6B00AE for ; Thu, 15 Feb 2024 01:37:12 -0500 (EST) Received: from smtpin22.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay10.hostedemail.com (Postfix) with ESMTP id C3EA7C0296 for ; Thu, 15 Feb 2024 06:37:11 +0000 (UTC) X-FDA: 81793081062.22.E46D8B4 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) by imf21.hostedemail.com (Postfix) with ESMTP id 1C0A11C0019 for ; Thu, 15 Feb 2024 06:37:09 +0000 (UTC) Authentication-Results: imf21.hostedemail.com; dkim=pass header.d=infradead.org header.s=bombadil.20210309 header.b=uCBSVVuE; dmarc=none; spf=none (imf21.hostedemail.com: domain of BATV+a252b21bd4a653ddb6e6+7480+infradead.org+hch@bombadil.srs.infradead.org has no SPF policy when checking 198.137.202.133) smtp.mailfrom=BATV+a252b21bd4a653ddb6e6+7480+infradead.org+hch@bombadil.srs.infradead.org ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1707979030; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=VFSwwvxPq8YqSy1LhT+7I32BZPWfWyPm9+xgXvBp1QY=; b=MEQMLNvSy4M/mPL8LecY0VpkqbUH4o9AMYcjQ8fTv3rDSH7XeRqEZ4L0biSjo8e7wT8Qxx oTD2EdKWeqoEKJ7AaZnXZVe1v6g6jo4SbXgaclX+hZEKvzXrGKA2QqXPBSyMZnSKrNRCAC JvH8emVuFE0t6Mtxzc+2w+m3dAT5W6Y= ARC-Authentication-Results: i=1; imf21.hostedemail.com; dkim=pass header.d=infradead.org header.s=bombadil.20210309 header.b=uCBSVVuE; dmarc=none; spf=none (imf21.hostedemail.com: domain of BATV+a252b21bd4a653ddb6e6+7480+infradead.org+hch@bombadil.srs.infradead.org has no SPF policy when checking 198.137.202.133) smtp.mailfrom=BATV+a252b21bd4a653ddb6e6+7480+infradead.org+hch@bombadil.srs.infradead.org ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1707979030; a=rsa-sha256; cv=none; b=yxEdk57OC4iwyR87liz8R59+1m7zzGveMHBHC9XCKHqPEImQKrYHidVaxEcDr1ziVVeh/8 Cfpsk8p9+JRlpqjQCKQNWz+1ezdq+HoDajENUaGLvuh0mXJoXN7e2QQJES7ZGz6MONI9IU QpbECGpMYHwPm8XzFFGuY+QzAFd68hM= 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=VFSwwvxPq8YqSy1LhT+7I32BZPWfWyPm9+xgXvBp1QY=; b=uCBSVVuEZjdlJt7d69NrZVeolB /kjMsFwTJq60LblBUNHI8D9FKeIk7EaezCshL5MogOcilaVzUumWQGFyJrDArSTXi7Be+4pxG1SNU S4gmAl49iTyY6WOw8cOyjIXQ0HQRApALNkz2oNuat9VB/mKsPrv7sgmbsT8B+ncFcw0sKTS3fDhhE dIVKGU2jvuQRTYkueAMF6D4cvDfNdntGtGWQfI2Ks96cc93QJiyGud5hoxOyUcxhQT8n/0WhK+ijs 84Swzl2V1QHFqyP82EEgRAqxGEJybxmPbUJ4jjUtr9JCOKeok9U6pcX4oWzLWefbnx74h/KMQUTzE TZv+y9eg==; 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.97.1 #2 (Red Hat Linux)) id 1raVMq-0000000F6ro-3TeQ; Thu, 15 Feb 2024 06:37:09 +0000 From: Christoph Hellwig To: linux-mm@kvack.org Cc: Matthew Wilcox , Jan Kara , David Howells , Brian Foster , Christian Brauner , linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org, Jan Kara , Dave Chinner Subject: [PATCH 04/14] writeback: also update wbc->nr_to_write on writeback failure Date: Thu, 15 Feb 2024 07:36:39 +0100 Message-Id: <20240215063649.2164017-5-hch@lst.de> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20240215063649.2164017-1-hch@lst.de> References: <20240215063649.2164017-1-hch@lst.de> MIME-Version: 1.0 X-SRS-Rewrite: SMTP reverse-path rewritten from by bombadil.infradead.org. See http://www.infradead.org/rpr.html X-Rspamd-Queue-Id: 1C0A11C0019 X-Rspam-User: X-Rspamd-Server: rspam02 X-Stat-Signature: b89arjynh5daernmj5xpdpmpxr5ungez X-HE-Tag: 1707979029-218462 X-HE-Meta: U2FsdGVkX19BqH8yu300U3kNXaRxn4stCQJh8AhGHcSTjZKYHFooRyVSiKl+fJfW3B8yh3y+TqdGuLLCbtXqGSlcGOIw2rLrAshEcfb7hbUJ/K1LugBpWBcG9jcY1hB+fxpEXq5vohTILsDiasTSto9ciROqkcuVUy7SztPyIXKPYizL1d1TmEApHQaqoCMNUexk/1UlsPtBXCwGRniE6ii13+NCRjyHXvq8bLRIyR41dgQF1QxIqXD0kzaRpgrvBBvFn3LiGR+yyM47DjzOvl4YTeeH2TKEAfoZudaiY5+FtxWk/mGWq392u2fqK/Yuq2zGbCKpk4Zw/Cn1D2K86Z7+IiN3d5KVAc7EElkLWmE9jwDpWuUEoYkTy9VMmteVe/bShn+ypvDo7TpeLHBAB9HKxF6fyHWjemqQiXK20EJzq8JQOYC9cBBvliJK3X17MbVbku8kcBzETxX+EzB/eXSxfNkRq4SJqxVC1d3J5x0yLHPH/c5glYzGNrg/ZCmoXEPqWAQZQZG2Jo83c3XKU1EGq60OrN7AtYWIJqbtkgk4Gl88X5chVMQOcR8Q7TbeCLfqtO8xxU6lve/NqWkchMDCYu60zEXwyVOnZGqHnQ0PiRHfaUNLzVc1xEiFXreyad4N6rxqXcf6S/N+Qq1FBLyBm72Tr2YJkpdi3wXc8hQAucKEdio+3qXR14I1WegExHzkI1vUaDIDtpsyD7buTm86GwBxdoIQoOe2x5iHuhmsPyMBjP3H2rlxqREUA0JHEDuphPif8dvKV0iqyOhKClzN8c8YGsuwQmBD17Zz4OP1NHa512s8Y/cLHI5hnkqoOY1pDWctFeuE8959DGipOTrclE5lYcrjcmbixmEp8Jux5KT4rSQLok9O1Xjoat2Kqt1pxltwwnrvR5WB22IqioqEW80S7WeRTBy4DnP27GL4HQElnXfoNmARfRp+PWPQPkfMMIycxNlhHA3WLBF lw/KTDNN 9af0rslc8pglAVZVOsAooNGUJkT0Wfizt54itJsy1KZ8kkjI4PIv6d94aG4odzbCwgxiWYgNoqTcNk+RR6b0fUG6VOza3BlIk8Uul46h76ecmZhKWyW7VAIbxeUtXc8aRXWBLBwE7G5zyS6k2ihwBEls7/TASRmt4NX5RoPOP6rpr/GCDqlXCK/bW5Lx4/OI5cXm8LmD5eyT0SzR0zUX1/aLYwCq7AMqOEx+9/gNKba7DOz7BIlaqJJGbIhA4ZTE1+45Hs6MZ6hZwbfED9w4sIhNX8kn0v1pg/277jg6DsP3ls1mzB3lbVQHtD8EEeC4DBfjnD4nelzjHXTzI0qUvsQ5hY0Wj/TD+wUzP5GPHIiEVnHB+D/M8W+8NMDcKu+5JU+PBsJ2qjcMGTn0JBL2OE4fTomeTzPRB8A5+q6qJGfMgwMebQK+dcIaZtLqBQdLAT2+pVRn1V7oL3o0Wktge9W6ioEKxdhLhOrbnfuok/pPpi7A= X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: When exiting write_cache_pages early due to a non-integrity write failure, wbc->nr_to_write currently doesn't account for the folio we just failed to write. This doesn't matter because the callers always ingore the value on a failure, but moving the update to common code will allow to simplify the code, so do it. Signed-off-by: Christoph Hellwig Reviewed-by: Brian Foster Reviewed-by: Jan Kara Acked-by: Dave Chinner --- mm/page-writeback.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mm/page-writeback.c b/mm/page-writeback.c index 2679176da316b3..abbee369405a83 100644 --- a/mm/page-writeback.c +++ b/mm/page-writeback.c @@ -2473,6 +2473,7 @@ int write_cache_pages(struct address_space *mapping, trace_wbc_writepage(wbc, inode_to_bdi(mapping->host)); error = writepage(folio, wbc, data); nr = folio_nr_pages(folio); + wbc->nr_to_write -= nr; if (unlikely(error)) { /* * Handle errors according to the type of @@ -2506,7 +2507,6 @@ int write_cache_pages(struct address_space *mapping, * we tagged for writeback prior to entering this loop. */ done_index = folio->index + nr; - wbc->nr_to_write -= nr; if (wbc->nr_to_write <= 0 && wbc->sync_mode == WB_SYNC_NONE) { done = 1; From patchwork Thu Feb 15 06:36:40 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christoph Hellwig X-Patchwork-Id: 13557439 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id C4D67C48BEF for ; Thu, 15 Feb 2024 06:37:26 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 678496B00B0; Thu, 15 Feb 2024 01:37:14 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 5D9CC6B00B1; Thu, 15 Feb 2024 01:37:14 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 42E716B00B2; Thu, 15 Feb 2024 01:37:14 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0010.hostedemail.com [216.40.44.10]) by kanga.kvack.org (Postfix) with ESMTP id 28EE06B00B0 for ; Thu, 15 Feb 2024 01:37:14 -0500 (EST) Received: from smtpin10.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay10.hostedemail.com (Postfix) with ESMTP id 007C8C0511 for ; Thu, 15 Feb 2024 06:37:13 +0000 (UTC) X-FDA: 81793081146.10.ABF072F Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) by imf18.hostedemail.com (Postfix) with ESMTP id 589B01C0008 for ; Thu, 15 Feb 2024 06:37:12 +0000 (UTC) Authentication-Results: imf18.hostedemail.com; dkim=pass header.d=infradead.org header.s=bombadil.20210309 header.b=sXSaoAWJ; spf=none (imf18.hostedemail.com: domain of BATV+a252b21bd4a653ddb6e6+7480+infradead.org+hch@bombadil.srs.infradead.org has no SPF policy when checking 198.137.202.133) smtp.mailfrom=BATV+a252b21bd4a653ddb6e6+7480+infradead.org+hch@bombadil.srs.infradead.org; dmarc=none ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1707979032; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=xKyzTXAMH1rh/hkISGxP5mL+5GL5qSZuP787X1EFqpI=; b=Ee0uuLJC+Zhxupdzwl18P96tnfIxCCU8m/kcJtCcULOZ0CZ0K7lK3WjTRdEx7Vb3MWRxu7 wJAs2x1TfW8JcCfcZgP1aHJjAls1kwsgh7K4aanCGOQuTms077zlZWk1AYs4QIgsZ5sBVG 81qRUPxyyoM5YezS66Lg8ERBTxlyUHM= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1707979032; a=rsa-sha256; cv=none; b=hSEk6QOsJuWbq09uOYaMaPlDv5RZ+UcrqfN6iixu5F482E+u1iMjRZvg7qMLU4Q5lvneX9 eUtbpoenYAJp42zDRaJwhNKzRF/OygVzhWsD0qe9Ejv6NuXFjhUmcSITnryx04SzxyXHSp guy4SSFHBp7m970EsKGbe2a4I1AOluw= ARC-Authentication-Results: i=1; imf18.hostedemail.com; dkim=pass header.d=infradead.org header.s=bombadil.20210309 header.b=sXSaoAWJ; spf=none (imf18.hostedemail.com: domain of BATV+a252b21bd4a653ddb6e6+7480+infradead.org+hch@bombadil.srs.infradead.org has no SPF policy when checking 198.137.202.133) smtp.mailfrom=BATV+a252b21bd4a653ddb6e6+7480+infradead.org+hch@bombadil.srs.infradead.org; dmarc=none DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=bombadil.20210309; h=Content-Transfer-Encoding: MIME-Version:References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From:Sender :Reply-To:Content-Type:Content-ID:Content-Description; bh=xKyzTXAMH1rh/hkISGxP5mL+5GL5qSZuP787X1EFqpI=; b=sXSaoAWJwPtvCVhZUDGt68K5Xk wRIacKs9X39sZS58OFVm/UZYlROkXnmTbM1YNk8+SNUaK8La9ctbfp61ePeYGQ4xOywRTPhzEsn3E QOEogTeYSOLM2YlGSXafPgjRrqpYy1/vCrYCup3YcBSmzeXuanP8YMP6anKDq7NQYvmMhiCBYYSEW iElzGVrVXeGUPT9hSGDaqvyhUepWjdiOeTnsUIJKQbByIG104tuJblnE1kpbkn/xmZQfmtCnBH2is l5/ebDiH2HyDNeJE+MDVA/saWA/vYU1YE6Mrlthjh2h0sKnT5r93af1RB9mp34gRBHhpIREexyz0a r1K7JMIg==; 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.97.1 #2 (Red Hat Linux)) id 1raVMt-0000000F6s3-0QQO; Thu, 15 Feb 2024 06:37:11 +0000 From: Christoph Hellwig To: linux-mm@kvack.org Cc: Matthew Wilcox , Jan Kara , David Howells , Brian Foster , Christian Brauner , linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org, Jan Kara , Dave Chinner Subject: [PATCH 05/14] writeback: only update ->writeback_index for range_cyclic writeback Date: Thu, 15 Feb 2024 07:36:40 +0100 Message-Id: <20240215063649.2164017-6-hch@lst.de> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20240215063649.2164017-1-hch@lst.de> References: <20240215063649.2164017-1-hch@lst.de> MIME-Version: 1.0 X-SRS-Rewrite: SMTP reverse-path rewritten from by bombadil.infradead.org. See http://www.infradead.org/rpr.html X-Rspamd-Queue-Id: 589B01C0008 X-Rspam-User: X-Stat-Signature: mucohqdzhewamci7dp8mthths6kh44h4 X-Rspamd-Server: rspam03 X-HE-Tag: 1707979032-460855 X-HE-Meta: U2FsdGVkX19EArjc2zZ6k+zbwh7UCIGLevZ7IOaGals2cysoiCTwhXaywbQ2hwxqP7jm9q3UaPglRIESeq9SUsgBidiOFOmGJrP0/fzjHxcb5OwuINPW/lSCyI8PQGW5bR8WRt2prGn+tOFryTzRiR6JnpkjO/IKw6YXPXlfcgmPePiIweoJ5X84Wjdq+3U1KAemmM5No70IEAMJbbt1Na86v18lmrHvZCZObux84V2FuzD0RZ4CBVNKcNJyw3mmrv176R4d/U8kGaSxZCRb+8q24Cx3ll2yKbN7LVrlEEajtryN1hm5Dw6Gj6abdL+NaA2R9IF48f21+/4ycvaIXsO3rWM4JLG+VHRDdvDEFu7BJfv3RXzDERas0wKo4zVOMiK6hIbBzo3zEm7t/GYZNsfHOD41PadtpWiJKE/MhtsjHACSHPjvPAXWx5tuxytsc573Tekckyj/DeAy3QA3owO8JNM6yIvUbVLbJoKqTh7/sgyNg3mSZ/GGlEOQ8Q4wRbywuaQs8bs8IDLWZzkWdGwdI05PK1QkpUl0/oAMpPoQ2TwIFpKm9nIs1gPPtwJ2D/MhVMnQDzhWABamZ82qh5R/jhUs0LNwuQb8SdE1VPot6HZZUNG9MmAtbZuthChWnpnn7vMK3M0sn9PMnbR4Dr/Ex3QpJmuy0GOjykcCgUfWf25Gz4nSWHVDbZM3rVj7yXK9zk8EH8geJ0XajVSnxoIQ2CvyiNDFtJlTWtre9I6tnpAm+l/bEVJfo9+QNaw82LJZN4/r3JmK/bpEghcp0daSnWxoa0zzLcN2jvastBp/qiKsX5e665hxcUGMPCVutvLt6Lr9yVEjsE63uSSI7oE83893hoU5wb+7zRinfsLO+8i2ikXFHB9Rb+0Sc3rrV33RH+miKZdsmaAYzIXgW9/sr7uXcg60W0t8t0K6/Ox4RohVlYU6RS5CpyywsOLz0T2CfZRRfEqKgmA4vb5 4aJtrMiG dxYw6qbUjuba77B560YgMVKpB6M48whnP29g0xpC0BnqlVSo38+nysX3SHVx047eJJt2RGs0j3JuABirR5EV2qZbF8FqO/iMs5XjGatUgC6e+W57/++0eZ48/WwU5qZ2nWyYNvwFacrsBX+IBqlONzzPOnBsCB7/KuKGygk9qd8rD1iLHsFOGEW47gUzhA/6x/f2EmnfrYXHJCQrn375Raed/Xy1icLWp7aZBapUhfta+L8td9Gr7ciBEh+8IlkmLLMk7340XFr+t2Hc+Il8e0TbwbEUSY3O188V1AfOa8PgmweF99YDXYlo8WMYdAa7R6ULlbaDIHp/rD23QfHMMK22XQfYPH0o/NEOLxToAooYW9Sehq5jaFKtnZHiOIDR6FiytHIaSGes3QwyC0xiwHn0CepBYIYWtgr5xgR7a1fZQ27W4F9mSq0QurCrBX1SKhhcmU1ZghoBsCdCMpJN0NVS9e22Muk+dhvYNFrtjg5y93Uc= X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: mapping->writeback_index is only [1] used as the starting point for range_cyclic writeback, so there is no point in updating it for other types of writeback. [1] except for btrfs_defrag_file which does really odd things with mapping->writeback_index. But btrfs doesn't use write_cache_pages at all, so this isn't relevant here. Signed-off-by: Christoph Hellwig Reviewed-by: Brian Foster Reviewed-by: Jan Kara Acked-by: Dave Chinner --- mm/page-writeback.c | 24 ++++++++++++++---------- 1 file changed, 14 insertions(+), 10 deletions(-) diff --git a/mm/page-writeback.c b/mm/page-writeback.c index abbee369405a83..f02014007b57cc 100644 --- a/mm/page-writeback.c +++ b/mm/page-writeback.c @@ -2403,7 +2403,6 @@ int write_cache_pages(struct address_space *mapping, pgoff_t index; pgoff_t end; /* Inclusive */ pgoff_t done_index; - int range_whole = 0; xa_mark_t tag; folio_batch_init(&fbatch); @@ -2413,8 +2412,6 @@ int write_cache_pages(struct address_space *mapping, } else { index = wbc->range_start >> PAGE_SHIFT; end = wbc->range_end >> PAGE_SHIFT; - if (wbc->range_start == 0 && wbc->range_end == LLONG_MAX) - range_whole = 1; } if (wbc->sync_mode == WB_SYNC_ALL || wbc->tagged_writepages) { tag_pages_for_writeback(mapping, index, end); @@ -2518,14 +2515,21 @@ int write_cache_pages(struct address_space *mapping, } /* - * If we hit the last page and there is more work to be done: wrap - * back the index back to the start of the file for the next - * time we are called. + * For range cyclic writeback we need to remember where we stopped so + * that we can continue there next time we are called. If we hit the + * last page and there is more work to be done, wrap back to the start + * of the file. + * + * For non-cyclic writeback we always start looking up at the beginning + * of the file if we are called again, which can only happen due to + * -ENOMEM from the file system. */ - if (wbc->range_cyclic && !done) - done_index = 0; - if (wbc->range_cyclic || (range_whole && wbc->nr_to_write > 0)) - mapping->writeback_index = done_index; + if (wbc->range_cyclic) { + if (done) + mapping->writeback_index = done_index; + else + mapping->writeback_index = 0; + } return ret; } From patchwork Thu Feb 15 06:36:41 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christoph Hellwig X-Patchwork-Id: 13557440 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 7B258C4829E for ; Thu, 15 Feb 2024 06:37:29 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 9AB726B00B1; Thu, 15 Feb 2024 01:37:16 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 937956B00B2; Thu, 15 Feb 2024 01:37:16 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 761F76B00B3; Thu, 15 Feb 2024 01:37:16 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0010.hostedemail.com [216.40.44.10]) by kanga.kvack.org (Postfix) with ESMTP id 604496B00B1 for ; Thu, 15 Feb 2024 01:37:16 -0500 (EST) Received: from smtpin30.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay02.hostedemail.com (Postfix) with ESMTP id 378CA120482 for ; Thu, 15 Feb 2024 06:37:16 +0000 (UTC) X-FDA: 81793081272.30.15231BF Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) by imf05.hostedemail.com (Postfix) with ESMTP id B6C08100010 for ; Thu, 15 Feb 2024 06:37:14 +0000 (UTC) Authentication-Results: imf05.hostedemail.com; dkim=pass header.d=infradead.org header.s=bombadil.20210309 header.b=GGTJ9HLd; spf=none (imf05.hostedemail.com: domain of BATV+a252b21bd4a653ddb6e6+7480+infradead.org+hch@bombadil.srs.infradead.org has no SPF policy when checking 198.137.202.133) smtp.mailfrom=BATV+a252b21bd4a653ddb6e6+7480+infradead.org+hch@bombadil.srs.infradead.org; dmarc=none ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1707979034; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=rJ/bHu0SmYtGFgvaRb+fv4HTWCusH5CJuQRO0eXVfZ0=; b=S3Vk2syQjukWT70FY7nC9tXrj7VVB+/3htDaxSmEqwqxCTq/T6WSL+l9BB2mffbdCa0/wd eZkwnILVcp7Vqrg010Aq48yYekD7/zWxMUhVaIrAKMFbkhjVD4Y7PkbXWgKlUFIFX9lSIZ 40FguVu34XrYCzgjrVtfOx8bCshGlA0= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1707979034; a=rsa-sha256; cv=none; b=CSduNQjjocb6hHtYk71/DzhluiES9T3nMm0vn2iMEfsjseljXD1foNqgAfRlqmTVX37OCa GwJ2uNC5ESVb51LWc6pDmmu8T+KoP8iJAOWxz/FldYVdHq1tNkAIzXwBtvqqlxt9f+UPaK SMEtKFUcjYBkbgLab8tBJ9tEqSVG4MU= ARC-Authentication-Results: i=1; imf05.hostedemail.com; dkim=pass header.d=infradead.org header.s=bombadil.20210309 header.b=GGTJ9HLd; spf=none (imf05.hostedemail.com: domain of BATV+a252b21bd4a653ddb6e6+7480+infradead.org+hch@bombadil.srs.infradead.org has no SPF policy when checking 198.137.202.133) smtp.mailfrom=BATV+a252b21bd4a653ddb6e6+7480+infradead.org+hch@bombadil.srs.infradead.org; dmarc=none DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=bombadil.20210309; h=Content-Transfer-Encoding: MIME-Version:References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From:Sender :Reply-To:Content-Type:Content-ID:Content-Description; bh=rJ/bHu0SmYtGFgvaRb+fv4HTWCusH5CJuQRO0eXVfZ0=; b=GGTJ9HLdBqJtjEDdAZPFyCXJKz 5OpCGv6U6mxH7l0ON1NV9hf/LGAvWPmgLT5xEtpqFEdbTb3JgxbZtpqS6QErp9Yn7+xFzbLI5X8Gy Kf/P1l06aiZEP55CJiJ/1dn82k66gidI9kL49JKCNwGP0FmjQLuAYAaSB4pTo5WloYMO5+NumsjRB 0U6k9DH+J1Dg67Xev9cQ1i4nBYi7tNwUyF3AcqlRBNqUINiRl+AdCmdy0Gv9to8alx4PFHbzgtWqo 3gs1KYgVW425l2kLMfdn98G37mY25LpqEV+C07/CBp/lAPCNv7QImxzejpnNHH6nTNXu+iu9/sGGI xs1Epexg==; 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.97.1 #2 (Red Hat Linux)) id 1raVMv-0000000F6ss-1jAV; Thu, 15 Feb 2024 06:37:13 +0000 From: Christoph Hellwig To: linux-mm@kvack.org Cc: Matthew Wilcox , Jan Kara , David Howells , Brian Foster , Christian Brauner , linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org, Jan Kara Subject: [PATCH 06/14] writeback: rework the loop termination condition in write_cache_pages Date: Thu, 15 Feb 2024 07:36:41 +0100 Message-Id: <20240215063649.2164017-7-hch@lst.de> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20240215063649.2164017-1-hch@lst.de> References: <20240215063649.2164017-1-hch@lst.de> MIME-Version: 1.0 X-SRS-Rewrite: SMTP reverse-path rewritten from by bombadil.infradead.org. See http://www.infradead.org/rpr.html X-Rspamd-Queue-Id: B6C08100010 X-Rspam-User: X-Stat-Signature: qytwxfksbsdpoojhonjwi9rda9heapxd X-Rspamd-Server: rspam03 X-HE-Tag: 1707979034-954787 X-HE-Meta: U2FsdGVkX1/HB7w9p+oUkXXiPYpRMW3UUZGV+Qqn5z6rRkVsBeQeShpAYbZ27HYg63zZwYrbCpVOiiNeYlVnDZwsONTeXDlNLT2HxkJxuQmRPKWdgrY1mbHVUSOyCXOOE2lmrJxINrRosenOTFwYkAE59evaT+t1FCCiwYv10jakjlXPZXy4gqw5PbTuuLtc0dkHI8iNQMM5wB/LLI+87f1MoMGlUa1sx3yACsbvIGWYf5RQYIInyiJD0HApeCgKIVpoPfpEtTPYt6lMDaoMmj/dS/Cu8/SIYyYEsJuq40bUek0UamG9b8wc/LLVWotJHUm9By5v1ykjnCjmCGmr2gXqiG7mBuLko1PZwVrwQ9IL7L/dP+BM+5jYrtmxJKsGzFonrpSmGA+6ibrauMRX574QqVt8TDBywwBCraVVrM3VraO6xlLtuwnii37eznzAJWnK13V/JKo+RnS+ET83Wi5S4voUmAJnhOe14Oh4pRBPgux9jmaofQF90YgNCnkIZYd7i3LhRVTn+1v2ZfBT2BkKFoQuh8wQWTaPGo67iYtDMNEcRG7dnd5HzihFW4CvaMFkSPpxPNyXdepy1oZIs9480jcVCV7md1G+CPKoafnG7waIrnfD1JVwdIuDkp0EDcxSgV8v5LWxRUokNETEIkD9aXo35wlqwAnPRfIvKw4ktENuzK2Z8veBEdiQ3vpR5LNpTlOti0d1CjCTPTEXq7tQUihvSgbKYKIL2Flt1mppjCFejZ51hcreodvj2zjaUIb3zTuWc4f4of/LQROGJCvcxeIn5R6vImIVNroKYXQwPCECiOGRFaV/618j93Dfjx02JGAiAzYsYAm3hlJ/dnp3CfdYwIqFy8eUuP4MW+FrCKDlP2heV3I/xpAcCSrG/aefJQYEQ6tSLfIfMrlJDCtdHn219nS0Ffs9lFOccohxqMal8O6dFffPAXkIKUBly5A3w/s6szU14grqKLZ BdRL0P7R RYZowG3PtSrtj1w8YGe9dBoIu8rL5cD7qjPU5zLNdj2fjDUrNmcocSQIwyPPxxTjj8D8j2qE0wEnggmLRnEAW1U7sGRf5/P0V8OL52+6nlALvkpSRRquEw7aL+YvRsS+sFSxHp65nTSWCz8yLm2ABFzZ5cQFdnNyrAd9WapZ4W6ogiIbYip9zF37hkzeOH0Z1FaXWU2c2t+BYCLyqFeENxjzijw== X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: Rework the way we deal with the cleanup after the writepage call. First handle the magic AOP_WRITEPAGE_ACTIVATE separately from real error returns to get it out of the way of the actual error handling path. The split the handling on intgrity vs non-integrity branches first, and return early using a goto for the non-ingegrity early loop condition to remove the need for the done and done_index local variables, and for assigning the error to ret when we can just return error directly. Signed-off-by: Christoph Hellwig Reviewed-by: Brian Foster Reviewed-by: Jan Kara --- mm/page-writeback.c | 84 ++++++++++++++++++--------------------------- 1 file changed, 33 insertions(+), 51 deletions(-) diff --git a/mm/page-writeback.c b/mm/page-writeback.c index f02014007b57cc..3a1e23bed4052c 100644 --- a/mm/page-writeback.c +++ b/mm/page-writeback.c @@ -2396,13 +2396,12 @@ int write_cache_pages(struct address_space *mapping, void *data) { int ret = 0; - int done = 0; int error; struct folio_batch fbatch; + struct folio *folio; int nr_folios; pgoff_t index; pgoff_t end; /* Inclusive */ - pgoff_t done_index; xa_mark_t tag; folio_batch_init(&fbatch); @@ -2419,8 +2418,7 @@ int write_cache_pages(struct address_space *mapping, } else { tag = PAGECACHE_TAG_DIRTY; } - done_index = index; - while (!done && (index <= end)) { + while (index <= end) { int i; nr_folios = filemap_get_folios_tag(mapping, &index, end, @@ -2430,11 +2428,7 @@ int write_cache_pages(struct address_space *mapping, break; for (i = 0; i < nr_folios; i++) { - struct folio *folio = fbatch.folios[i]; - unsigned long nr; - - done_index = folio->index; - + folio = fbatch.folios[i]; folio_lock(folio); /* @@ -2469,45 +2463,32 @@ int write_cache_pages(struct address_space *mapping, trace_wbc_writepage(wbc, inode_to_bdi(mapping->host)); error = writepage(folio, wbc, data); - nr = folio_nr_pages(folio); - wbc->nr_to_write -= nr; - if (unlikely(error)) { - /* - * Handle errors according to the type of - * writeback. There's no need to continue for - * background writeback. Just push done_index - * past this page so media errors won't choke - * writeout for the entire file. For integrity - * writeback, we must process the entire dirty - * set regardless of errors because the fs may - * still have state to clear for each page. In - * that case we continue processing and return - * the first error. - */ - if (error == AOP_WRITEPAGE_ACTIVATE) { - folio_unlock(folio); - error = 0; - } else if (wbc->sync_mode != WB_SYNC_ALL) { - ret = error; - done_index = folio->index + nr; - done = 1; - break; - } - if (!ret) - ret = error; + wbc->nr_to_write -= folio_nr_pages(folio); + + if (error == AOP_WRITEPAGE_ACTIVATE) { + folio_unlock(folio); + error = 0; } /* - * We stop writing back only if we are not doing - * integrity sync. In case of integrity sync we have to - * keep going until we have written all the pages - * we tagged for writeback prior to entering this loop. + * For integrity writeback we have to keep going until + * we have written all the folios we tagged for + * writeback above, even if we run past wbc->nr_to_write + * or encounter errors. + * We stash away the first error we encounter in + * wbc->saved_err so that it can be retrieved when we're + * done. This is because the file system may still have + * state to clear for each folio. + * + * For background writeback we exit as soon as we run + * past wbc->nr_to_write or encounter the first error. */ - done_index = folio->index + nr; - if (wbc->nr_to_write <= 0 && - wbc->sync_mode == WB_SYNC_NONE) { - done = 1; - break; + if (wbc->sync_mode == WB_SYNC_ALL) { + if (error && !ret) + ret = error; + } else { + if (error || wbc->nr_to_write <= 0) + goto done; } } folio_batch_release(&fbatch); @@ -2524,14 +2505,15 @@ int write_cache_pages(struct address_space *mapping, * of the file if we are called again, which can only happen due to * -ENOMEM from the file system. */ - if (wbc->range_cyclic) { - if (done) - mapping->writeback_index = done_index; - else - mapping->writeback_index = 0; - } - + if (wbc->range_cyclic) + mapping->writeback_index = 0; return ret; + +done: + if (wbc->range_cyclic) + mapping->writeback_index = folio->index + folio_nr_pages(folio); + folio_batch_release(&fbatch); + return error; } EXPORT_SYMBOL(write_cache_pages); From patchwork Thu Feb 15 06:36:42 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christoph Hellwig X-Patchwork-Id: 13557441 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 2B388C4829E for ; Thu, 15 Feb 2024 06:37:32 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 0F9DD6B00B2; Thu, 15 Feb 2024 01:37:19 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 05CC36B00B3; Thu, 15 Feb 2024 01:37:18 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id DC9896B00B4; Thu, 15 Feb 2024 01:37:18 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0016.hostedemail.com [216.40.44.16]) by kanga.kvack.org (Postfix) with ESMTP id C67E56B00B2 for ; Thu, 15 Feb 2024 01:37:18 -0500 (EST) Received: from smtpin19.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay10.hostedemail.com (Postfix) with ESMTP id A835BC01B6 for ; Thu, 15 Feb 2024 06:37:18 +0000 (UTC) X-FDA: 81793081356.19.6E7FFE2 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) by imf10.hostedemail.com (Postfix) with ESMTP id 02B9FC0006 for ; Thu, 15 Feb 2024 06:37:16 +0000 (UTC) Authentication-Results: imf10.hostedemail.com; dkim=pass header.d=infradead.org header.s=bombadil.20210309 header.b=Sq+z8AZs; spf=none (imf10.hostedemail.com: domain of BATV+a252b21bd4a653ddb6e6+7480+infradead.org+hch@bombadil.srs.infradead.org has no SPF policy when checking 198.137.202.133) smtp.mailfrom=BATV+a252b21bd4a653ddb6e6+7480+infradead.org+hch@bombadil.srs.infradead.org; dmarc=none ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1707979037; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=j7oK7/19ACOHFK7IfrqUkUYg5wgn+UHWF7oPozt79Xs=; b=vc3xyx7raRLnHuw/hwtUWfPYNWcTVwNAf7nZ8QVWQlAPLlGiAMHxP+gYL3xWhEUr7f1/OB O6DdEmQqNrhmqFNaR/OQjE564QF95DVzAPNEmYdJ3t9lmFf1k3Pp0Q14frqwDgs/YhxySJ nzWuAcrpub1fUHFtU/XT60uzuvsWZQ0= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1707979037; a=rsa-sha256; cv=none; b=TZ9RCbcCjpPWyCjugaZtAvmLm+MxZ+m9B9WvJ6+Cx7S5R2eLOTm4brJ5Rk7j80Q6H7LX7v VMBipCxuuDsH/F2JgsbprscRnRTSRTOQSwRP1gkrw/GtPVA+O1n86ejMTSoEQ8vOKIWTly elJQhiqU4UZdeY7LpMeatsILAaHkDy8= ARC-Authentication-Results: i=1; imf10.hostedemail.com; dkim=pass header.d=infradead.org header.s=bombadil.20210309 header.b=Sq+z8AZs; spf=none (imf10.hostedemail.com: domain of BATV+a252b21bd4a653ddb6e6+7480+infradead.org+hch@bombadil.srs.infradead.org has no SPF policy when checking 198.137.202.133) smtp.mailfrom=BATV+a252b21bd4a653ddb6e6+7480+infradead.org+hch@bombadil.srs.infradead.org; dmarc=none DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=bombadil.20210309; h=Content-Transfer-Encoding: MIME-Version:References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From:Sender :Reply-To:Content-Type:Content-ID:Content-Description; bh=j7oK7/19ACOHFK7IfrqUkUYg5wgn+UHWF7oPozt79Xs=; b=Sq+z8AZsN0OQbwPCVzc+xwQZGf fm7ViVlN00hHrVnU8bKUDWgWsINORFCOeB+0xJoU8o4n9XW0DUTNhYVyHCWo2D9EAbYlSs+mH2Zi3 cpFB3g/my0T6zfQauarrKIvaavz8csDa0WZzcqjrtb46C+vOL7IhnqPIra1qjqOttDVVXV53wU0kx dOUAlCiVv+TEA9PIDtoJZSnY8o+DS3Fln0eJY88JIE/JF/a8psprUrXFNayGPEzIQfuLeMwDKSV7y ukZ6Q+vsJSn6lKCKVRjJtjtBjaraFHqZiwoUa3zHZQcOnCDCId4RHZYS8dh0gHaO5Do9icAR8Jgfd DIfn1KdA==; 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.97.1 #2 (Red Hat Linux)) id 1raVMx-0000000F6uZ-36cp; Thu, 15 Feb 2024 06:37:16 +0000 From: Christoph Hellwig To: linux-mm@kvack.org Cc: Matthew Wilcox , Jan Kara , David Howells , Brian Foster , Christian Brauner , linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org, Jan Kara , Dave Chinner Subject: [PATCH 07/14] writeback: Factor folio_prepare_writeback() out of write_cache_pages() Date: Thu, 15 Feb 2024 07:36:42 +0100 Message-Id: <20240215063649.2164017-8-hch@lst.de> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20240215063649.2164017-1-hch@lst.de> References: <20240215063649.2164017-1-hch@lst.de> MIME-Version: 1.0 X-SRS-Rewrite: SMTP reverse-path rewritten from by bombadil.infradead.org. See http://www.infradead.org/rpr.html X-Stat-Signature: 8deb8ucpsjxn7okzwbhsx9656743oh7x X-Rspamd-Server: rspam10 X-Rspamd-Queue-Id: 02B9FC0006 X-Rspam-User: X-HE-Tag: 1707979036-522891 X-HE-Meta: U2FsdGVkX1+AmyvSUVs+Jf3DKh7hDZQl50Vxff1a6cM8cPYGN8MGnJsJiN/kOT97+DFqcMRzhSQKMjTbo8da/mWjek8xmd9FUH5CcJzuf/lI/uA+AlIBiV9zEMkIHCfP3e20g8YACK7Sm1tJ2ugltHuydBtGyHOL96d/gIPvYX9oCxyvPZYOAWcITjik07PskaMXB+HNBBdWoCYgeOwfYplKkEMcky2GTHADVEEhaf4zLO4KSDtrzV71ROb4OU4cMtUxnCCEqUpObUemLC7fX7fDGtUfqqLCj+pYySlLKxpJMNMb/ak7zOkeKETNeLaNm4PENi+rlcq3kvW93uXeffk+jERwJRLbAwSewqpuPe4XfNWsATrds1yuF0eaDqHg3ba14d9BZXK6SCkFCumv7WjiGyCifa9xB5oJWVLGfYHY4TkS9FfuBvN9QKAqWd416gil7jSZsPapxhGRqy5+fHnVoOMoz9mTedAWTdy/zjGczCXBOoQpDhSAn3AYBfqUE/71/44EgedJDt9BH3x3HDJd0lfJu5/9YCyXPAh4V4IRDXsB6RGhW6JmzVVKSoxnNZoMHwboU84WVwBFDMShL6kh8xJofTxHiMBGpJe+t0dguQfG1i6bTB2SDslEdJUrLMnkcPb083vsXybVWiBJ2atyA+WzocJFuC2AIdHRnfFslRAzPLSl8gRj3tW1NcYC5EhPAJ55v0fTxXrhzgVip2DD7weuS1zaE6gsQkFuBn1neOBao26wWUnJjP166jXuHI/RHeh7OCx7PGlQCYE+kWM7FrbFxQ1wqe9h2YvgiYitVgN8cBMiz3MLzJz4+kxzRHvGGvFiC2zpAXwGH5LUusA2mIcZaLneEU41YfVh30uDICGiMB4O5At4IrTiRraCYJuIxVqTkoIjRSy+2Nw2hXUpuEst8kpgKdt2dw334cfrut5zXqYh7HRSbjcGzp2r6XKnQdSwSSc7hJae4R/ JpQLKK3R 5gQeKMWyi7RtKO4IEBLovFjYl+hffhFh59AYjr6JRpMHyRYsCzPmftpdAWfKzc89gTmo4Q4+9Ga3QxGRzrvNuQGUp5AsONtzo+4jXu27QyPMvPraWKo3H+6g3jU4sVJQQ/nXwNXZS5+3JjTX25ub9UlopVmr0S2MUQB4nKsJcUT78HUrjoLxcdufwOXDGFR8fnjO8xEY3mdS0fZLWrovnAaFMUxmTyHXz5AsURfHRxa2zgib+5vqfhbaj3Cuqb/F3+d7324vsMZx7U8PsP065rL4FsJbYwCo+j6z0RqqDGbY9KjKGWvtbnqeZP9lyU5t/RrmkQlqV4p7+Qg9Pt2sJrSCU0DmqDooal2Lb8CqeHd6jySvn2X2P5kE9u1XuL8mZt2zKGpkpvI2JUJSjbbAzfv8KT/AESj9SKOW+3KDPzyeywwpy1q4oJ3dx6WYHbZs5sfu0nNWYmw2p/e7lybPWJjkL6dnwLs4uEzeTsPGMAVbtElUwrj1nUm0cbBaTJrNpevHYvK03j3aj0qkyF90vzGA7irnbT3qSvvqq X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: From: "Matthew Wilcox (Oracle)" Reduce write_cache_pages() by about 30 lines; much of it is commentary, but it all bundles nicely into an obvious function. Signed-off-by: Matthew Wilcox (Oracle) [hch: rename should_writeback_folio to folio_prepare_writeback based on a comment from Jan Kara] Signed-off-by: Christoph Hellwig Reviewed-by: Brian Foster Reviewed-by: Jan Kara Acked-by: Dave Chinner --- mm/page-writeback.c | 61 +++++++++++++++++++++++++-------------------- 1 file changed, 34 insertions(+), 27 deletions(-) diff --git a/mm/page-writeback.c b/mm/page-writeback.c index 3a1e23bed4052c..4bc55ce9597d13 100644 --- a/mm/page-writeback.c +++ b/mm/page-writeback.c @@ -2360,6 +2360,38 @@ void tag_pages_for_writeback(struct address_space *mapping, } EXPORT_SYMBOL(tag_pages_for_writeback); +static bool folio_prepare_writeback(struct address_space *mapping, + struct writeback_control *wbc, struct folio *folio) +{ + /* + * Folio truncated or invalidated. We can freely skip it then, + * even for data integrity operations: the folio has disappeared + * concurrently, so there could be no real expectation of this + * data integrity operation even if there is now a new, dirty + * folio at the same pagecache index. + */ + if (unlikely(folio->mapping != mapping)) + return false; + + /* + * Did somebody else write it for us? + */ + if (!folio_test_dirty(folio)) + return false; + + if (folio_test_writeback(folio)) { + if (wbc->sync_mode == WB_SYNC_NONE) + return false; + folio_wait_writeback(folio); + } + BUG_ON(folio_test_writeback(folio)); + + if (!folio_clear_dirty_for_io(folio)) + return false; + + return true; +} + /** * 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 @@ -2430,38 +2462,13 @@ int write_cache_pages(struct address_space *mapping, for (i = 0; i < nr_folios; i++) { folio = fbatch.folios[i]; folio_lock(folio); - - /* - * Page truncated or invalidated. We can freely skip it - * then, even for data integrity operations: the page - * has disappeared concurrently, so there could be no - * real expectation of this data integrity operation - * even if there is now a new, dirty page at the same - * pagecache address. - */ - if (unlikely(folio->mapping != mapping)) { -continue_unlock: + if (!folio_prepare_writeback(mapping, wbc, folio)) { folio_unlock(folio); continue; } - if (!folio_test_dirty(folio)) { - /* someone wrote it for us */ - goto continue_unlock; - } - - if (folio_test_writeback(folio)) { - if (wbc->sync_mode != WB_SYNC_NONE) - folio_wait_writeback(folio); - else - goto continue_unlock; - } - - BUG_ON(folio_test_writeback(folio)); - if (!folio_clear_dirty_for_io(folio)) - goto continue_unlock; - trace_wbc_writepage(wbc, inode_to_bdi(mapping->host)); + error = writepage(folio, wbc, data); wbc->nr_to_write -= folio_nr_pages(folio); From patchwork Thu Feb 15 06:36:43 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christoph Hellwig X-Patchwork-Id: 13557442 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 96C2CC48BEB for ; Thu, 15 Feb 2024 06:37:34 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 89D986B00B3; Thu, 15 Feb 2024 01:37:21 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 8243E6B00B4; Thu, 15 Feb 2024 01:37:21 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 69F3A6B00B5; Thu, 15 Feb 2024 01:37:21 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0014.hostedemail.com [216.40.44.14]) by kanga.kvack.org (Postfix) with ESMTP id 506FA6B00B3 for ; Thu, 15 Feb 2024 01:37:21 -0500 (EST) Received: from smtpin11.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay02.hostedemail.com (Postfix) with ESMTP id 0350A120482 for ; Thu, 15 Feb 2024 06:37:21 +0000 (UTC) X-FDA: 81793081482.11.6FBA515 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) by imf14.hostedemail.com (Postfix) with ESMTP id 58AF4100016 for ; Thu, 15 Feb 2024 06:37:19 +0000 (UTC) Authentication-Results: imf14.hostedemail.com; dkim=pass header.d=infradead.org header.s=bombadil.20210309 header.b=ojz1xsKL; dmarc=none; spf=none (imf14.hostedemail.com: domain of BATV+a252b21bd4a653ddb6e6+7480+infradead.org+hch@bombadil.srs.infradead.org has no SPF policy when checking 198.137.202.133) smtp.mailfrom=BATV+a252b21bd4a653ddb6e6+7480+infradead.org+hch@bombadil.srs.infradead.org ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1707979039; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=E+OSD9VSpQpoZ28pgBfOHWK/m45gq5ZINg4N5qkBC0Q=; b=tCUDZVpY+hrQbF1O/Jfap2/Ut9kV+EGrMyS+1t50Wb+xMu+6P9Vvgbi6Awz9GlTks/RUFg w7aBsWkeXCSIiB3qyCKk5awELZWmcqE3mzLZwcuBOMAY7vEBzo06kmonKLbpdkUXMpKfYH seGxL1NDA+mYP2W8RNXNo0yL3CIju68= ARC-Authentication-Results: i=1; imf14.hostedemail.com; dkim=pass header.d=infradead.org header.s=bombadil.20210309 header.b=ojz1xsKL; dmarc=none; spf=none (imf14.hostedemail.com: domain of BATV+a252b21bd4a653ddb6e6+7480+infradead.org+hch@bombadil.srs.infradead.org has no SPF policy when checking 198.137.202.133) smtp.mailfrom=BATV+a252b21bd4a653ddb6e6+7480+infradead.org+hch@bombadil.srs.infradead.org ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1707979039; a=rsa-sha256; cv=none; b=7wSP/uPRWAOGgLx5u31/EXlnKc9E+iTcT6qB8eSwm6yo8l0TzLcvMAN++YFqa1Ek3yksro T0rh8p5Pi0bOT4q068E2BK/rLQms/bgj7rBpB5jhScYCczUDJO9BMcNkxKl7ZcUcV9DPno mD6fnrLQe3XTcerLWr4P3RpiXcQENdE= 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=E+OSD9VSpQpoZ28pgBfOHWK/m45gq5ZINg4N5qkBC0Q=; b=ojz1xsKL7yLiHr6HXkyeNSFyTs OzRaeuK4Hzu442qbSfBX+k4xEMaeju2pg+s/VA1GbW61KuexcJPAMmRVDz98mv4JU5KrmEfGKx3I6 4+exbkMiG7vHaFI4/i2IEbv2T6JBKtVN8F9jVZcwj1+d7ASZrHA3PF5hCBG+cng0XmWbe47JiLXvt LGhgnrtuaMKcpcOPKInsOMpHOK1lE261LPZK/QKFw2zE+p9c2cn9Nlm+Jnm2bF5843Cg85H6Bfeb4 8UmSpoyIKkBNE0dvO0L3HJH1d/Y67uY/hRugC1oESNSjvMTgRUDsDw8PkBdn1n1OVx1Kv02rCVBJd jEEfLK7g==; 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.97.1 #2 (Red Hat Linux)) id 1raVN0-0000000F6vb-0F0x; Thu, 15 Feb 2024 06:37:18 +0000 From: Christoph Hellwig To: linux-mm@kvack.org Cc: Matthew Wilcox , Jan Kara , David Howells , Brian Foster , Christian Brauner , linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org, Jan Kara , Dave Chinner Subject: [PATCH 08/14] writeback: Factor writeback_get_batch() out of write_cache_pages() Date: Thu, 15 Feb 2024 07:36:43 +0100 Message-Id: <20240215063649.2164017-9-hch@lst.de> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20240215063649.2164017-1-hch@lst.de> References: <20240215063649.2164017-1-hch@lst.de> MIME-Version: 1.0 X-SRS-Rewrite: SMTP reverse-path rewritten from by bombadil.infradead.org. See http://www.infradead.org/rpr.html X-Rspamd-Queue-Id: 58AF4100016 X-Rspam-User: X-Rspamd-Server: rspam05 X-Stat-Signature: 5d9r347amn7ib7s6xpz4rurzg99xf19s X-HE-Tag: 1707979039-387097 X-HE-Meta: U2FsdGVkX18vfVCC987fy3d4H4EageRnAywk3J/UdgY/TAlQ8awCWVLmsew7wp/xbMD1fIZ/nhZXgVY6SUjddmU22kS+BJmImUJ8E6cZDnLQjdFDtKDPFG90AQzLFcWZpznGB0lYtTAin5RmqoUseTs+36aVNQ/j1FYNqU2Fsit9FU8DGnZaGQTXy944DUyP/jEB84jcpsSG14kqKC11IyVw1n6oY2hm/f8VI4T+XpaTXvbOhBdKwefKu3IUg0KgCLOu1XgzRoCIJtroOU2TR9mSB11TB1SadBVJTGNB1xafmRoDh3vYcaoACMhLxcMyFi1qv/i1adadPXZyL0bTGN6jQccDF6I8YuHTJz6nPQjGhWTFGT6ZRBa8af0zkyLrc2eRMq2Z1yLo8G6yaRVAwEjC+INB89PidmqTkzqvdnqAYU/motNavMsBjqZXZSaOwtIfdrQ1Ja1e+Ii4n3lG30YNDCbki12KsfVehf1B47z74V1yvy2lTNPsBzTSUFmiEqqA2s/iU7+Q3hsflhr5VrJkyT5Qx8b3gBEQ2Adf9c6fekBnPA0evo4sctLbz2BlLdVjbLvVpNDmTjZazOO0vQxUwTEr29xtD2e2qp7rjcZgUfOAPSM/zoBwMVtouLHsZygtg0Utqbxaxl2WE+KOQLE2DdPzkI089L0exUDUJrTgFJwbciLkTfPQblLtFZ5qkX+SMWpHtKIQ5WhUcg8W83Fy8tdVkAerkCEngqiTZ3z4Bi6RZg3mJeumN+YaGbiFeYXxzrxY3dTrs2qC9mrglppirbkCFUFiAzCUne8Kc/HOvUAufiqbx0kRuhiEUPckIAX20/EHje+xILfPuP0aCz354mMmEbyY+Jm8Pboq7pSAuDCtr+pfIy9CNx6OROruGfw5rgXI0pe6xC4psyt1KGVJWvpGk5FYeU6G2snTgznWWFmGq2281CQYBvpabkDrSNHbWeWLDLEyg6NbQ8u jVWwtM6J 1oVqvNGNpOmYx9k/ny0Jl4Y68t8Bc/u3uVxay6KtnTPAMyWKwewwXnJppXQmAR0TP4vIigg9OMgVJsYQRXYEAhWwOglru0Y/a7O+EJ5WE4eex+gm8RJcAVbSc6qrPi2O62XhWOjJM3OzCmg6PjxUAkUzW5Ru3lu350SSva7GPYlMNtchwMLB330h+DHKo0InualDfkVPZJEvbTqPW+ob5Rx2ie+xGjBvIf+RF916ywMqwL03vaKCpAeiCrZd7qhrZSNhYJsxevGdrbdnBAW0z5MEvvWq7LuRgsLIzPLaDlTI3y8Bp/JcaDb/1LR7sXIEtoeqv+7PXlVAPu5OUhlfUm5xHUVcrDrKYHxtcOApFrhg0I+p1JQSPYIozGbKSVprSx0PLB6pnlVnqZojO1Wxdy6NPX9ITBhPKPl5To+F0VwV+iZujzP0Fn4R74wko4WIzOq4TuxKHRI2FkeRHSIjOpt62x1lgYXowjCGShM7+LnnH6h4UM1GF5Vw1BAckvhMht7DA2IHrD1skQwX7zapCVHNMxHrEum2fAKe0fdrv0CZQ3F2g48fCGUqoSDnSTVr0utfD X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: From: "Matthew Wilcox (Oracle)" This simple helper will be the basis of the writeback iterator. To make this work, we need to remember the current index and end positions in writeback_control. Signed-off-by: Matthew Wilcox (Oracle) [hch: heavily rebased, add helpers to get the tag and end index, don't keep the end index in struct writeback_control] Signed-off-by: Christoph Hellwig Reviewed-by: Brian Foster Reviewed-by: Jan Kara Acked-by: Dave Chinner --- include/linux/writeback.h | 6 ++++ mm/page-writeback.c | 60 +++++++++++++++++++++++++-------------- 2 files changed, 44 insertions(+), 22 deletions(-) diff --git a/include/linux/writeback.h b/include/linux/writeback.h index 4b8cf9e4810bad..f67b3ea866a0fb 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; + pgoff_t index; + #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 4bc55ce9597d13..5b8dbbef713722 100644 --- a/mm/page-writeback.c +++ b/mm/page-writeback.c @@ -2392,6 +2392,29 @@ static bool folio_prepare_writeback(struct address_space *mapping, return true; } +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 @@ -2429,38 +2452,32 @@ int write_cache_pages(struct address_space *mapping, { int ret = 0; int error; - struct folio_batch fbatch; struct folio *folio; - int nr_folios; - pgoff_t index; pgoff_t end; /* Inclusive */ - xa_mark_t tag; - folio_batch_init(&fbatch); 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; - } - while (index <= end) { + if (wbc->sync_mode == WB_SYNC_ALL || wbc->tagged_writepages) + tag_pages_for_writeback(mapping, wbc->index, end); + + folio_batch_init(&wbc->fbatch); + + while (wbc->index <= end) { int i; - nr_folios = filemap_get_folios_tag(mapping, &index, end, - tag, &fbatch); + writeback_get_batch(mapping, wbc); - if (nr_folios == 0) + if (wbc->fbatch.nr == 0) break; - for (i = 0; i < nr_folios; i++) { - folio = fbatch.folios[i]; + for (i = 0; i < wbc->fbatch.nr; i++) { + folio = wbc->fbatch.folios[i]; + folio_lock(folio); if (!folio_prepare_writeback(mapping, wbc, folio)) { folio_unlock(folio); @@ -2498,8 +2515,6 @@ int write_cache_pages(struct address_space *mapping, goto done; } } - folio_batch_release(&fbatch); - cond_resched(); } /* @@ -2512,6 +2527,7 @@ int write_cache_pages(struct address_space *mapping, * of the file if we are called again, which can only happen due to * -ENOMEM from the file system. */ + folio_batch_release(&wbc->fbatch); if (wbc->range_cyclic) mapping->writeback_index = 0; return ret; @@ -2519,7 +2535,7 @@ int write_cache_pages(struct address_space *mapping, done: if (wbc->range_cyclic) mapping->writeback_index = folio->index + folio_nr_pages(folio); - folio_batch_release(&fbatch); + folio_batch_release(&wbc->fbatch); return error; } EXPORT_SYMBOL(write_cache_pages); From patchwork Thu Feb 15 06:36:44 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christoph Hellwig X-Patchwork-Id: 13557443 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 4B23CC48BEF for ; Thu, 15 Feb 2024 06:37:37 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id C4B916B00B4; Thu, 15 Feb 2024 01:37:23 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id BA8816B00B5; Thu, 15 Feb 2024 01:37:23 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id A21056B00B6; Thu, 15 Feb 2024 01:37:23 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0016.hostedemail.com [216.40.44.16]) by kanga.kvack.org (Postfix) with ESMTP id 8685F6B00B4 for ; Thu, 15 Feb 2024 01:37:23 -0500 (EST) Received: from smtpin30.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay10.hostedemail.com (Postfix) with ESMTP id 67C22C01B6 for ; Thu, 15 Feb 2024 06:37:23 +0000 (UTC) X-FDA: 81793081566.30.5857CCC Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) by imf22.hostedemail.com (Postfix) with ESMTP id C834DC0005 for ; Thu, 15 Feb 2024 06:37:21 +0000 (UTC) Authentication-Results: imf22.hostedemail.com; dkim=pass header.d=infradead.org header.s=bombadil.20210309 header.b=2Hb8gleW; spf=none (imf22.hostedemail.com: domain of BATV+a252b21bd4a653ddb6e6+7480+infradead.org+hch@bombadil.srs.infradead.org has no SPF policy when checking 198.137.202.133) smtp.mailfrom=BATV+a252b21bd4a653ddb6e6+7480+infradead.org+hch@bombadil.srs.infradead.org; dmarc=none ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1707979041; a=rsa-sha256; cv=none; b=ea0mLivnq7I5+BbMws3KXoNf76ZeSejNA4nHxXaFLpwh6CF7EM4T/u6FJCfKELTKpb9rGk o+5k+sIWzfBGcQi2QmwEgysYylkOk0bkQWlwNwvEctwin9c/qRDqiUJj+97SLIwO3W3wU/ NWTf+d502KFj98NFpQAIEFrrz7DAljI= ARC-Authentication-Results: i=1; imf22.hostedemail.com; dkim=pass header.d=infradead.org header.s=bombadil.20210309 header.b=2Hb8gleW; spf=none (imf22.hostedemail.com: domain of BATV+a252b21bd4a653ddb6e6+7480+infradead.org+hch@bombadil.srs.infradead.org has no SPF policy when checking 198.137.202.133) smtp.mailfrom=BATV+a252b21bd4a653ddb6e6+7480+infradead.org+hch@bombadil.srs.infradead.org; dmarc=none ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1707979041; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=b/HeiHwTP7z/dof0nC109V5KNfZOpyqOTU+/Ww2V0js=; b=kI9mMspc4VkkPiOXKzx/hevxywJMWDEsJS1023I6w/I6W5GDkbu4UiQP40X7IFDbWWXdxN ETROSk8kBd9ViW4d/uFuPl1MsqialdwSNXDtvDQJfZGW7lQJyUmVnqFcUbnm0yJRoz3PPm Qk0cQfWoA5LcZu0hjs/oc8M7C0qa9Ao= 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=b/HeiHwTP7z/dof0nC109V5KNfZOpyqOTU+/Ww2V0js=; b=2Hb8gleWOzQe5exsn5y/mKp9Ox /SuEWtlPLPCxQdOjSVxz7E1vtD4RI5qWp4IJED5LPSKGQ3cOsKa3x78FCuhqmr5F6D5L6vrb37jyv w3aVx/zOgWsdutOwjTqRJ+pYH2PSbEQca3HmptcnZn5SUGAu011innlqbaylzOdNd59TQXbRkP1sC t6k64b6CgXg8HsUjhyAiUvPhDuljvJ+7J9g60YXt8OobmkTpyT7J0hWy2NuTuuX9kslh52twKq2kU gPpnqPdRDZX++7CVDy2k0RDETWR9llFk8/yc6fPnL2jNPGUYyTYKAL9ztaEsJwfS3Uh/qdy8Whcsw 9i9zOULQ==; 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.97.1 #2 (Red Hat Linux)) id 1raVN2-0000000F6wx-1XgJ; Thu, 15 Feb 2024 06:37:20 +0000 From: Christoph Hellwig To: linux-mm@kvack.org Cc: Matthew Wilcox , Jan Kara , David Howells , Brian Foster , Christian Brauner , linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org, Jan Kara , Dave Chinner Subject: [PATCH 09/14] writeback: Simplify the loops in write_cache_pages() Date: Thu, 15 Feb 2024 07:36:44 +0100 Message-Id: <20240215063649.2164017-10-hch@lst.de> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20240215063649.2164017-1-hch@lst.de> References: <20240215063649.2164017-1-hch@lst.de> MIME-Version: 1.0 X-SRS-Rewrite: SMTP reverse-path rewritten from by bombadil.infradead.org. See http://www.infradead.org/rpr.html X-Rspamd-Server: rspam08 X-Rspamd-Queue-Id: C834DC0005 X-Stat-Signature: dq5nga8mtxkbperx937b4ktyqn31ypgb X-Rspam-User: X-HE-Tag: 1707979041-599982 X-HE-Meta: U2FsdGVkX19kTzH/JxnwJ1g4Y5oE//J6QmIw5MetZvMgK9zn00CkOqK6QBw6auiamTnAbxsL7dh0c8aG+j3Pjgnx8/cN8VXz/cmpJSZIVZD4FOj3zmgTB3OdoiYuFhncooUxLWYoal9MGZZwi1RCFHOXnPyk5h7lzUbN7apGGyBI/ohRQ43lovYPzN9uiaTK0oWJr0yTA/e5Vw+pMBwVXp/hfJLqgK9BT9hvFGdRQJLRaKgt/mdHpyMYqbAagRlv+WD1lm6xyumN55puxzjUdhPkdcp6hV9G2ST4vwOccWjeYxmvtHaAZwuXgBKkDhmzIMiy9IXxf7Ey3XEmbSBn0y3caUpA0t2FnmbLs7c85WmgX2HJmbpzg+Dz8Cz+oCnDs0Ao3A4aA5ED45yL6cLB9EqCOkLKzboerZVAUIa0EEuCeKitZdxp3A8pXJkX7dTSIpb4FhAjvfKqIFw5NFysHkN1M4UlN+lusNvBci0D+s08djwZCnTlrjCYIf0voNRlv/h6lesfSRymUxn+Rhv5xopywgZ3OG/DIlbqZPEQCHcWO5i37n2q9iJUZ6o3l3rh1GBdoumDOkohAk2cKiIoQfhJTw+4oTqMBU53/EleZ5eQl+iBygYHANLIGFX4hgaBPlOEDOzJ6V66AbOH/sB7CQZpe45rBfIyDpmytQVBj+eYmr2euFSCoKpKuj9YYbFS0gyGgU5N4sdfqTuRlKler+EGc0FKYeoGyYy4Dc6BIdXZnf8xLT7hEpLCPrGDWTbYROCAKK1hjECCN92awbcldnXkhmnn0snDIFPE5jZkUvOOeOugPSnznIR4wyyiYBixoybTiOqSNQ1gS6XfnzQhpYkmnYjHl/ITGKlP3OdIqN/QTfWG8NI/l4YMlZfuHpRpnAO24KFKum9Jc2CBs0CDvjqkZBmK3qfAAbuV/xW1VGpQ1Eys964LzznmN1xEZci0sGWtHJTO9DilX2qMtEJ 18zAWVFB UFqZY4REceocghyq9chZnMpzpgMhKdSUQTElOkqi7+o+MA1381UgztvZhpK/AnFi/oIT4LDoj3E1xOxrZvgMKhHozUON9bJ+D0wScGIvqNNF79CuEyElfV1TPJU/jv5rkqveSidkwhl6fFRcnScSGNNwdgHehIf0Onb0FMcYXVruk9A9Zmayzp9WwWR95kzEUlr7zadSm5lsG9WgXKMyRlNzTiA== X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: From: "Matthew Wilcox (Oracle)" Collapse the two nested loops into one. This is needed as a step towards turning this into an iterator. Note that this drops the "index <= end" check in the previous outer loop and just relies on filemap_get_folios_tag() to return 0 entries when index > end. This actually has a subtle implication when end == -1 because then the returned index will be -1 as well and thus if there is page present on index -1, we could be looping indefinitely. But as the comment in filemap_get_folios_tag documents this as already broken anyway we should not worry about it here either. The fix for that would probably a change to the filemap_get_folios_tag() calling convention. Signed-off-by: Matthew Wilcox (Oracle) [hch: updated the commit log based on feedback from Jan Kara] Signed-off-by: Christoph Hellwig Reviewed-by: Brian Foster Reviewed-by: Jan Kara Acked-by: Dave Chinner --- mm/page-writeback.c | 75 ++++++++++++++++++++++----------------------- 1 file changed, 36 insertions(+), 39 deletions(-) diff --git a/mm/page-writeback.c b/mm/page-writeback.c index 5b8dbbef713722..358ce3ade9ad1e 100644 --- a/mm/page-writeback.c +++ b/mm/page-writeback.c @@ -2454,6 +2454,7 @@ int write_cache_pages(struct address_space *mapping, int error; struct folio *folio; pgoff_t end; /* Inclusive */ + int i = 0; if (wbc->range_cyclic) { wbc->index = mapping->writeback_index; /* prev offset */ @@ -2467,53 +2468,49 @@ int write_cache_pages(struct address_space *mapping, folio_batch_init(&wbc->fbatch); - while (wbc->index <= end) { - int i; - - writeback_get_batch(mapping, wbc); - + for (;;) { + 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++) { - folio = wbc->fbatch.folios[i]; + 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); - wbc->nr_to_write -= folio_nr_pages(folio); + error = writepage(folio, wbc, data); + wbc->nr_to_write -= folio_nr_pages(folio); - if (error == AOP_WRITEPAGE_ACTIVATE) { - folio_unlock(folio); - error = 0; - } + if (error == AOP_WRITEPAGE_ACTIVATE) { + folio_unlock(folio); + error = 0; + } - /* - * For integrity writeback we have to keep going until - * we have written all the folios we tagged for - * writeback above, even if we run past wbc->nr_to_write - * or encounter errors. - * We stash away the first error we encounter in - * wbc->saved_err so that it can be retrieved when we're - * done. This is because the file system may still have - * state to clear for each folio. - * - * For background writeback we exit as soon as we run - * past wbc->nr_to_write or encounter the first error. - */ - if (wbc->sync_mode == WB_SYNC_ALL) { - if (error && !ret) - ret = error; - } else { - if (error || wbc->nr_to_write <= 0) - goto done; - } + /* + * For integrity writeback we have to keep going until we have + * written all the folios we tagged for writeback above, even if + * we run past wbc->nr_to_write or encounter errors. + * We stash away the first error we encounter in wbc->saved_err + * so that it can be retrieved when we're done. This is because + * the file system may still have state to clear for each folio. + * + * For background writeback we exit as soon as we run past + * wbc->nr_to_write or encounter the first error. + */ + if (wbc->sync_mode == WB_SYNC_ALL) { + if (error && !ret) + ret = error; + } else { + if (error || wbc->nr_to_write <= 0) + goto done; } } From patchwork Thu Feb 15 06:36:45 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christoph Hellwig X-Patchwork-Id: 13557444 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id A46C0C48BEB for ; Thu, 15 Feb 2024 06:37:39 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 4084C6B00B7; Thu, 15 Feb 2024 01:37:26 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 259CA6B00B6; Thu, 15 Feb 2024 01:37:26 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 05E0F6B00B7; Thu, 15 Feb 2024 01:37:25 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0015.hostedemail.com [216.40.44.15]) by kanga.kvack.org (Postfix) with ESMTP id DE7166B00B5 for ; Thu, 15 Feb 2024 01:37:25 -0500 (EST) Received: from smtpin18.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay08.hostedemail.com (Postfix) with ESMTP id 824A0140D65 for ; Thu, 15 Feb 2024 06:37:25 +0000 (UTC) X-FDA: 81793081650.18.380EF32 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) by imf22.hostedemail.com (Postfix) with ESMTP id D9F07C0005 for ; Thu, 15 Feb 2024 06:37:23 +0000 (UTC) Authentication-Results: imf22.hostedemail.com; dkim=pass header.d=infradead.org header.s=bombadil.20210309 header.b=oocpZKdd; dmarc=none; spf=none (imf22.hostedemail.com: domain of BATV+a252b21bd4a653ddb6e6+7480+infradead.org+hch@bombadil.srs.infradead.org has no SPF policy when checking 198.137.202.133) smtp.mailfrom=BATV+a252b21bd4a653ddb6e6+7480+infradead.org+hch@bombadil.srs.infradead.org ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1707979043; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=M5Qvp5zNKGHXjXReg58hQjrWh/GgxzXP5maEkxrO/YI=; b=lqsE9e9g/aV1IX8p5q9WkClTU9w4LCBRqnjTTL0vuQZNT5CYEYeh3bQJ0qES2M2ix+4Z2y hnmIzr/CEGJilEy/3tP45pS1dddrxmxe18WmkHiOUJ5eOKYPqv1e61dnxl9Ak/YdcuLGvx SKZ9ImlNmH0YfKtT3jas/uZuO/uY6b8= ARC-Authentication-Results: i=1; imf22.hostedemail.com; dkim=pass header.d=infradead.org header.s=bombadil.20210309 header.b=oocpZKdd; dmarc=none; spf=none (imf22.hostedemail.com: domain of BATV+a252b21bd4a653ddb6e6+7480+infradead.org+hch@bombadil.srs.infradead.org has no SPF policy when checking 198.137.202.133) smtp.mailfrom=BATV+a252b21bd4a653ddb6e6+7480+infradead.org+hch@bombadil.srs.infradead.org ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1707979043; a=rsa-sha256; cv=none; b=7THl9yZ6jD8YYWbSjnS0P4Xf+Un1/hGFkZoJURCy771KYRmWvMgU/Zhmb/6l10+yr9nwxF 6DBHlozwdGDiQHpzNbuWYaE2edmRA34hO3ywSxNky9HVaEtpvRGRf2pm1hb+inEt20fR22 8QboGGDc3y5a4qw4oJH3wu/LuRyp7oE= DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=bombadil.20210309; h=Content-Transfer-Encoding: MIME-Version:References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From:Sender :Reply-To:Content-Type:Content-ID:Content-Description; bh=M5Qvp5zNKGHXjXReg58hQjrWh/GgxzXP5maEkxrO/YI=; b=oocpZKddbVY6RivLE2iFbVbswr +U/BXlpxFleRHdXUV6ZMR2h0ZR8BOy5nKcJJJ/GUEaAExDlL9pX5lAZXTSltOaS9OTTnJDvTzQcQv eL1jmtI9M2tdt2PMmW371ExOcZVdcEKOWF1jU1tTp+uIg57k2D50vxNDLOWMnvi1qZxUQArDazn3j FituwDoNFLW7LSflofvpYgyI9EICnaZCJIC8q4Z2M5xgJUStQXHSMa8GMpchZls5wuGh++UqPRyMm pRCmsqHqfq9HrJ5bKPZnZ1XJoD4MvnwuyYa2HZbnR1PaeCY3pQwDmE40RCjh6kW3u2J3T1zTDC95D nTwbtk9g==; 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.97.1 #2 (Red Hat Linux)) id 1raVN4-0000000F6yZ-2rwu; Thu, 15 Feb 2024 06:37:23 +0000 From: Christoph Hellwig To: linux-mm@kvack.org Cc: Matthew Wilcox , Jan Kara , David Howells , Brian Foster , Christian Brauner , linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org, Jan Kara , Dave Chinner Subject: [PATCH 10/14] pagevec: Add ability to iterate a queue Date: Thu, 15 Feb 2024 07:36:45 +0100 Message-Id: <20240215063649.2164017-11-hch@lst.de> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20240215063649.2164017-1-hch@lst.de> References: <20240215063649.2164017-1-hch@lst.de> MIME-Version: 1.0 X-SRS-Rewrite: SMTP reverse-path rewritten from by bombadil.infradead.org. See http://www.infradead.org/rpr.html X-Rspamd-Queue-Id: D9F07C0005 X-Rspam-User: X-Rspamd-Server: rspam05 X-Stat-Signature: 5nkkd9btbmwff88kesxxasnukyx7b36b X-HE-Tag: 1707979043-501707 X-HE-Meta: U2FsdGVkX18JenJDzycID3rXzwHpDCpGivO/t8T58pQ7kbDvCz7c1R+tyOrm5I1/t4rm+N15QJHX34AEU0KFPjJHwoFqLtZPYU7gfp0Qo36OPA4FvMgY16aJOVIicZo8/qk2tlyqV7iiLGL0Pwd/m0+5KVnKMjMsffSUfdmPBe0+8JU9azTo5V+gaaTxTelztPEKH11iKYWiABCoDmTL7CIuBo1yiBO0l6nrRrtgIjliXSxlJBUgU4ML298J89W+HC3739sLZOHOTi/PHBCsgqrx9eRwhDSWUtD0pjQvp1+emF4WSMaQ7X/889gRX3sIIeHbn12iUpv1C9uT6wIX2UrDRMiv5dU9Eyxt7rzcEF9Ku06LwqpA/osaC9VkAN6Z/D5E9W/GaUt0SibP8UG1gn38q3Fas6ZuKhlu2vStfyl6a3Oqsc9oNfUMZGHW9yQCIpdL2lEbj5mGha6TxGWEF4MlDOD1ZkUBKxFUlA5JncJefCOs21Pb1nmy+Aqt/odLD4loDKFFtLsbB9mnprwSk8/e7DCcxM92moZHyUevgGNY0RVUn6o73u0jYZW/8XDipakx5KnoIqfdtun+SyM7HkYOM3lwkg2elsl4cXFbYLcvz+HgYb1KKJHPMH9Re13vVgTrflOXil7GYA3l7akNHfT/j51hHd5qxhE5f707H/HvBAK76Lre2jr1l1SBcSH7Pwe7RNpzh+E3kc6G6QAa5MKaAVpKA/rGfxTuaIYaRK6Oi4pjPxufTxHNN12gJjNoAgOUmk7gP/B7qqhwnN42uwOH9OZ86GjUdjo9nvc4URIbKxxz0DHPK2Dw1b/5HIfw7lClMHGtsCNS5T8x+Ylw/WlYl9ti9/Wn2lHSby3kDLb1s6GqruKPzx04Uor6GHAD3UHiBtTT5XWR853AaK+vxSXGb7epmhfWGVrDm0Uy0nZJ0auRlFtJ/2j9fyPAAHIMt6XdOnyiM25XN8fDMF1 yZ/Ib553 6IwCFeno5K1RyEDq73UzP4cNslhRPl4ZDD3+mLFfpP6cRCqPHTDdgM1CoSOClCZd1Bn62LHG6fHP28Oj5WiTAv4rltGjRvXPICssb0lXnxP8QXXmO8dSs8/CzRv6w1D4+gXvupp4GcaVRenwktSvxd7/cqWmj7Ve2e3IhuX6JLKQbb8pCfg0Z1Qya6si2cZC/DBLIOTckM5Pz8x/o7Oa/GZ1PiWUua+TnuV8WTO5uDKk3FhUkgiHXk06iET6082HTo8NskchXi6iyYEhER2QBSkd+NNnx5Ua8VfQ/dm4s/SzVYINVJUFAIkNVM7y2RHS6ijgY/XHOF8er6Ji1OFtlwCFd+wskrMPjWf7HkhYtkQHU1uM6LPsmOY9i+1noS4KqrfcjgCh6+lNVv0Xs3HoiE14obS+S0afp98EY2T9rQwE1a7i6QiFOarz1cjrlMBFXBI0/x3mkgmU1w08drQXZ6lS3XfEo9vkqa8r6n58gd9yBQzvY8AXpJ3jBOQ== X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: From: "Matthew Wilcox (Oracle)" Add a loop counter inside the folio_batch to let us iterate from 0-nr instead of decrementing nr and treating the batch as a stack. It would generate some very weird and suboptimal I/O patterns for page writeback to iterate over the batch as a stack. Signed-off-by: Matthew Wilcox (Oracle) Signed-off-by: Christoph Hellwig Reviewed-by: Brian Foster Reviewed-by: Jan Kara Acked-by: Dave Chinner --- include/linux/pagevec.h | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/include/linux/pagevec.h b/include/linux/pagevec.h index 87cc678adc850b..fcc06c300a72c3 100644 --- a/include/linux/pagevec.h +++ b/include/linux/pagevec.h @@ -27,6 +27,7 @@ struct folio; */ struct folio_batch { unsigned char nr; + unsigned char i; bool percpu_pvec_drained; struct folio *folios[PAGEVEC_SIZE]; }; @@ -40,12 +41,14 @@ struct folio_batch { static inline void folio_batch_init(struct folio_batch *fbatch) { fbatch->nr = 0; + fbatch->i = 0; fbatch->percpu_pvec_drained = false; } static inline void folio_batch_reinit(struct folio_batch *fbatch) { fbatch->nr = 0; + fbatch->i = 0; } static inline unsigned int folio_batch_count(struct folio_batch *fbatch) @@ -75,6 +78,21 @@ static inline unsigned folio_batch_add(struct folio_batch *fbatch, return folio_batch_space(fbatch); } +/** + * folio_batch_next - Return the next folio to process. + * @fbatch: The folio batch being processed. + * + * Use this function to implement a queue of folios. + * + * Return: The next folio in the queue, or NULL if the queue is empty. + */ +static inline struct folio *folio_batch_next(struct folio_batch *fbatch) +{ + if (fbatch->i == fbatch->nr) + return NULL; + return fbatch->folios[fbatch->i++]; +} + void __folio_batch_release(struct folio_batch *pvec); static inline void folio_batch_release(struct folio_batch *fbatch) From patchwork Thu Feb 15 06:36:46 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christoph Hellwig X-Patchwork-Id: 13557445 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 39A55C4829E for ; Thu, 15 Feb 2024 06:37:42 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 4F1FD6B00B6; Thu, 15 Feb 2024 01:37:28 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 4523D6B00B8; Thu, 15 Feb 2024 01:37:28 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 280A56B00B9; Thu, 15 Feb 2024 01:37:28 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0015.hostedemail.com [216.40.44.15]) by kanga.kvack.org (Postfix) with ESMTP id 1245B6B00B6 for ; Thu, 15 Feb 2024 01:37:28 -0500 (EST) Received: from smtpin07.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay10.hostedemail.com (Postfix) with ESMTP id ED86CC01B6 for ; Thu, 15 Feb 2024 06:37:27 +0000 (UTC) X-FDA: 81793081734.07.7CF67E7 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) by imf28.hostedemail.com (Postfix) with ESMTP id 571CBC0011 for ; Thu, 15 Feb 2024 06:37:26 +0000 (UTC) Authentication-Results: imf28.hostedemail.com; dkim=pass header.d=infradead.org header.s=bombadil.20210309 header.b="sA9hTm/g"; dmarc=none; spf=none (imf28.hostedemail.com: domain of BATV+a252b21bd4a653ddb6e6+7480+infradead.org+hch@bombadil.srs.infradead.org has no SPF policy when checking 198.137.202.133) smtp.mailfrom=BATV+a252b21bd4a653ddb6e6+7480+infradead.org+hch@bombadil.srs.infradead.org ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1707979046; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=cxMaD8CgzKPWpzzBQiYSiO7ZuZ6eZs5SBgKJwTWN/r4=; b=rdOvGX58QK/7NhGs1luYCVjsr0i6mJTntWjvincROB6KqG1yX9gPeUsw/9iK+ZHhMkNh9Q 1pvUALayyajSJ8dAQtoyadp0IpmwEJvSfKQlsEN83T4kUlzUG71RnBm4QC0Z+1cWDyT59Z bJRiToLorVMsJ2hV3c1nTp45jXXlOQw= ARC-Authentication-Results: i=1; imf28.hostedemail.com; dkim=pass header.d=infradead.org header.s=bombadil.20210309 header.b="sA9hTm/g"; dmarc=none; spf=none (imf28.hostedemail.com: domain of BATV+a252b21bd4a653ddb6e6+7480+infradead.org+hch@bombadil.srs.infradead.org has no SPF policy when checking 198.137.202.133) smtp.mailfrom=BATV+a252b21bd4a653ddb6e6+7480+infradead.org+hch@bombadil.srs.infradead.org ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1707979046; a=rsa-sha256; cv=none; b=InJ9/Vwwp4+WzPPbnXWV2APCWLV1ez1rjOp+PCtJSxX84cnCc491zA6VN/Xq9StRVngOjc nrweHzpdmctpskU+vpj+kRX5t4tbmXgr8IkM6g4BdKLYHMHL0jEEa+VBwZE66WKhYBCOQI s3DRvGe/oyQABQY/uPNDSm6ZphPPV60= 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=cxMaD8CgzKPWpzzBQiYSiO7ZuZ6eZs5SBgKJwTWN/r4=; b=sA9hTm/gXewYmu74Y6HKN+nure pK/w8ImihQ8or1SXbOQU1BH8PnFwBJmpIvkG7mc1M4U5tyoniQYrq05Bf/igP3fq+tdtzlcAvRwF5 aKhKqLpa4MTE7ek+bRUa/cWrAwbNaTWZVcuZ4SrcXEE4OeerQG44/4LyCbkIZBfyv83FA41XFpg4w +WlAzXEYKo/bdm3jraGgGMznibtKSzdPgNUAv4zXOdzla+VVoJ7lA7cWDe+tQxf+1kpi1nfeS38o3 mXM2Pa2LbWZG+mZD7u5jlmUOv5hzQPlc3rwSUF+MQxOPauTPE/I5kLQSIeqa8lIjeOCEJ/PUHi/HJ cOHPVvIg==; 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.97.1 #2 (Red Hat Linux)) id 1raVN7-0000000F6zU-00HA; Thu, 15 Feb 2024 06:37:25 +0000 From: Christoph Hellwig To: linux-mm@kvack.org Cc: Matthew Wilcox , Jan Kara , David Howells , Brian Foster , Christian Brauner , linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org, Jan Kara , Dave Chinner Subject: [PATCH 11/14] writeback: Use the folio_batch queue iterator Date: Thu, 15 Feb 2024 07:36:46 +0100 Message-Id: <20240215063649.2164017-12-hch@lst.de> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20240215063649.2164017-1-hch@lst.de> References: <20240215063649.2164017-1-hch@lst.de> MIME-Version: 1.0 X-SRS-Rewrite: SMTP reverse-path rewritten from by bombadil.infradead.org. See http://www.infradead.org/rpr.html X-Rspam-User: X-Rspamd-Server: rspam12 X-Rspamd-Queue-Id: 571CBC0011 X-Stat-Signature: gjsdrufzwxuctrjhazd3pxwxmk7q7psx X-HE-Tag: 1707979046-363105 X-HE-Meta: U2FsdGVkX19HxajkM/w3dM1prTOMbhX4rMRnBavjfoJSDqT4HZxLeQs2mUag55Vdagsb2gb3sfSlHv/8CMQ7sUWMtsCWucq2f5mKZcuh39nRWvbQFIl8rYdXMCvd5xHpXgCHqql7TpxslC3HxwjDmJLkuTucdwXVE3O1TRQeyPvqedrzjl45C/NVo1mgdlADkJidQXl3oETpQY34BSrQhZq+CkiWRijXnY5Qe6LwzXTwJtLY/5e3+QUr6/Hno2HExB6SAGGGBRUapXC9uRPDiNr28ez0bHp5hdGmuEU51azSRWr6VY8Rd8rvvpkigWfum0kuLopoO7olkZKrYEMBCaCo15AxRrgkYDPqt6Ukb4BJgdW+U+CF6ypyhOCRNitcfMaYjnPV2xhNkosvRxcuiAXpvzJB9/BGyW5k5MNlK1JNwCo1gRkzM+BHEhu2bd0BhIRIfwR7XPJX0HO8uszwKZCep4nRAigg5sTG3T8Zhddx+YRV6nd3wLAaSNvFomJgUJmoMqhNJXXJRpIbPqHIBVinoc2StLb3wCIb+c+ky2ToDLPtUZnGMNQJQGF/e6ZOuBBlekB6L615qKBam6iVJ4MJ0AJ1jznjpoepyW8Sbt3SSVx7VHoOY7TsSfJVeZKd+ag0qizW9nbrVMWfijMYZgZYHylDitUTWTSkIqHFOQo6u9P3zYljWzzlJn2ONZJO++wr7ztVEQHNbwnNrSQ9VykcbFZ1HRxGhkQtneU+J49z6agLhcCCzTj7ccORQzQzxScqfrQURqrxC2WTtAtwZbKL5e8HinjHobEki/TdlIkhqhBHSrCFq1PwtrRbobLhKlN46jNEDU45BIGEuNKmi88XtHFLe2vUa2KVlo/iFxyyfDuwjFoOdsuC9WSg8I36G72byn1k3sYkRY7Ou7wUJVfpleSQxlnLud/4+iq8uUyL0lSzk+MmosFumfq6hmkLTPpL1/I353ThVRZ+BRV lVPYAr+B vi2YxCwTijYVdC6xpDp2G/XKmfryujCEVGkZw1DXbgh32KRMy5Qdn33YDVHT/ZikU6y+sEcwkS1gJCxZtmPH6bYffYw6jccoIx7lvHYzCetyVpjAnhRcLRIMWVAxXMdwRNbNjAeWRzp6OaEBK9zukDAMw7RiAl/ye8iAYxw0GVrLBXDvjSlVY5xp1ndSrf0Fuhk7H9ReTKLZMEOd1teTpfYDlHohQzQi12g7NyI6RaMFJjpHK6WpXPxt8DJ3PZ3+lr4mbvvD/rweaCjQGhYBilNC/8wB5iQQyG1MG4dtOfiHOFMSNv+eLx7qbIHIM0ALT9FqqMbsmBr/yMdV88m5Io/83GTK1SstmXGMIeFvG/XnET+U9p5+UdLqF02t26md5qsV3wY+QRntUEChoK4wOrYeB5p+8LgrmATV5fpVy+Urok+3/vXgtBT/TbmHsyeh4n6zvoW3wxJfRRBgAHK+2OGnUvCHVGGbaRq9mN8zVQMqj7zEM2M80oDtFHJS6kEcCjGXWYQIaX2qIeLD4KXYBwOcYsE7i9amWdEYN X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: From: "Matthew Wilcox (Oracle)" Instead of keeping our own local iterator variable, use the one just added to folio_batch. Signed-off-by: Matthew Wilcox (Oracle) Signed-off-by: Christoph Hellwig Reviewed-by: Brian Foster Reviewed-by: Jan Kara Acked-by: Dave Chinner --- mm/page-writeback.c | 28 +++++++++++++++------------- 1 file changed, 15 insertions(+), 13 deletions(-) diff --git a/mm/page-writeback.c b/mm/page-writeback.c index 358ce3ade9ad1e..3cbe4a7daa357c 100644 --- a/mm/page-writeback.c +++ b/mm/page-writeback.c @@ -2406,13 +2406,21 @@ static pgoff_t wbc_end(struct writeback_control *wbc) return wbc->range_end >> PAGE_SHIFT; } -static void writeback_get_batch(struct address_space *mapping, +static struct folio *writeback_get_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; } /** @@ -2454,7 +2462,6 @@ int write_cache_pages(struct address_space *mapping, int error; struct folio *folio; pgoff_t end; /* Inclusive */ - int i = 0; if (wbc->range_cyclic) { wbc->index = mapping->writeback_index; /* prev offset */ @@ -2469,15 +2476,10 @@ int write_cache_pages(struct address_space *mapping, folio_batch_init(&wbc->fbatch); for (;;) { - if (i == wbc->fbatch.nr) { - writeback_get_batch(mapping, wbc); - i = 0; - } - if (wbc->fbatch.nr == 0) + folio = writeback_get_folio(mapping, wbc); + if (!folio) break; - folio = wbc->fbatch.folios[i++]; - folio_lock(folio); if (!folio_prepare_writeback(mapping, wbc, folio)) { folio_unlock(folio); From patchwork Thu Feb 15 06:36:47 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christoph Hellwig X-Patchwork-Id: 13557446 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id B3570C4829E for ; Thu, 15 Feb 2024 06:37:44 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id BACB96B00B8; Thu, 15 Feb 2024 01:37:30 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id B0C316B00B9; Thu, 15 Feb 2024 01:37:30 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 95E266B00BA; Thu, 15 Feb 2024 01:37:30 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0017.hostedemail.com [216.40.44.17]) by kanga.kvack.org (Postfix) with ESMTP id 791C46B00B8 for ; Thu, 15 Feb 2024 01:37:30 -0500 (EST) Received: from smtpin20.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay04.hostedemail.com (Postfix) with ESMTP id 55EEF1A0DA7 for ; Thu, 15 Feb 2024 06:37:30 +0000 (UTC) X-FDA: 81793081860.20.99CBB90 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) by imf02.hostedemail.com (Postfix) with ESMTP id A61A280016 for ; Thu, 15 Feb 2024 06:37:28 +0000 (UTC) Authentication-Results: imf02.hostedemail.com; dkim=pass header.d=infradead.org header.s=bombadil.20210309 header.b=IE6GYCQF; spf=none (imf02.hostedemail.com: domain of BATV+a252b21bd4a653ddb6e6+7480+infradead.org+hch@bombadil.srs.infradead.org has no SPF policy when checking 198.137.202.133) smtp.mailfrom=BATV+a252b21bd4a653ddb6e6+7480+infradead.org+hch@bombadil.srs.infradead.org; dmarc=none ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1707979048; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=dpEY7SmyA34rLmNMjZVpGv1HVhFTICw5Hhe2kQSv81M=; b=HLkO0tPSCRmC1BGFBOGJEiWc6zP8DexZx43ZX5g7sfDtnqpVuv2LHQ8W+eDcs+9SAuLZiG wZtadC+wheSwXk+ocbsWgvXbp+5y/vgPCW+HJg8hF8xxB+dThy7HqKgsM5xk5h8VVaEOkj 0+XjLeDYjbcAHeqm524Dgpu+ke2s3GE= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1707979048; a=rsa-sha256; cv=none; b=TGXR89KJ7DgTgAsqwYwuk1nU90PWGO1jBnk2FS375fCXFEWLRUHiEkAV+y6jtEXwUrpgFI IPN2F/H4121okO24sb7u0Lm3LLCFAoHaaU7Z5IcwUT1nE1nKhBzsbTK/8i/gjsH1qlYEMC MUP3xHDnXOWG/uAZvF0NWGTnAmTyVCU= ARC-Authentication-Results: i=1; imf02.hostedemail.com; dkim=pass header.d=infradead.org header.s=bombadil.20210309 header.b=IE6GYCQF; spf=none (imf02.hostedemail.com: domain of BATV+a252b21bd4a653ddb6e6+7480+infradead.org+hch@bombadil.srs.infradead.org has no SPF policy when checking 198.137.202.133) smtp.mailfrom=BATV+a252b21bd4a653ddb6e6+7480+infradead.org+hch@bombadil.srs.infradead.org; dmarc=none DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=bombadil.20210309; h=Content-Transfer-Encoding: MIME-Version:References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From:Sender :Reply-To:Content-Type:Content-ID:Content-Description; bh=dpEY7SmyA34rLmNMjZVpGv1HVhFTICw5Hhe2kQSv81M=; b=IE6GYCQF3eV3lxuP59icZOXmbS +ZieiZz134xt6WwJJzwEPn739abiFT+QYhRmHkAw32tujHIHQHYaTqWK18UROqd9WFjuRrPe7e2tx gpFYSFBSmWjzvOzbpp4+OvsrWEKz3fKWswV/Zrm4Asux3Z2NCPWYpQ7gOdOlLV0EHf56ssi9QFmsK q7iPT2U8FwRCMtBDr7GcdQx219YFW7DS0GggsGgV2i/XgHXQnLt55fDdUF0bbhStSOweF6LucJ4bh eNFNVP2TLPuzZqh7+r2s7SHtmBzkiSMfVkTncMGSxRQLPZJFmcRiKLXjcQQLItfXLoMJfU/8tkReR qNWH7rHA==; 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.97.1 #2 (Red Hat Linux)) id 1raVN9-0000000F71D-1Lq2; Thu, 15 Feb 2024 06:37:27 +0000 From: Christoph Hellwig To: linux-mm@kvack.org Cc: Matthew Wilcox , Jan Kara , David Howells , Brian Foster , Christian Brauner , linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org, Jan Kara , Dave Chinner Subject: [PATCH 12/14] writeback: Move the folio_prepare_writeback loop out of write_cache_pages() Date: Thu, 15 Feb 2024 07:36:47 +0100 Message-Id: <20240215063649.2164017-13-hch@lst.de> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20240215063649.2164017-1-hch@lst.de> References: <20240215063649.2164017-1-hch@lst.de> MIME-Version: 1.0 X-SRS-Rewrite: SMTP reverse-path rewritten from by bombadil.infradead.org. See http://www.infradead.org/rpr.html X-Rspamd-Queue-Id: A61A280016 X-Rspam-User: X-Stat-Signature: nx3nzp51i5mhkyc9qngatgxfmeq4j4uf X-Rspamd-Server: rspam03 X-HE-Tag: 1707979048-367428 X-HE-Meta: U2FsdGVkX1+ZCjDk9vJfrjKtzGxs1UsGhnWbc9I+z77p+p/Juyd19SPAcgL7sLocWQj86RIUQHrUQIDE84+R+GmoogKUSzCaJtN3SSdmUpyA62hQ+DkjXarigDcZK09xgUam/4CxKsTb4z/AWDtHlIP1D3uqktpYOSMgjJzM5oT6vBec1obmwSvLWmsyv6r1u69wNRxqYr9INTJt8UgTUxDZ8DlTCjS47ABeQThJ3Ujxwx5Vb0TV/3Ee/RYCGaBSVnzYnk0ma6qp2z0vl/P11J0a/hOkVcV2jEK5pk4+0fN00mak4cDipgl7Yq3/M4/ygWjLrHlX4FMmgSc4n/JMXF2u2I4wn1b+1FzetRBwbFgz66/kuaoKDq4Q+tMi60z039Lc+0ioJWB1c7otrRmbGwrv5/JdHav02K4o8GejhE8R8iMTtj1sR21UaQZtRSCea/vygF7s/akcAscr2EaY3x++34ShSjubjDj3gNj6QWm/cQHn/LgUnPiEn4/BYG9JznmKZFfHRxb7iQh5Txe0CPWojAuuvV/ejF9gWkP/s2mR/BqUihd4bTTwgmQXcIR76iCQcvxPtDGGEQVoXrfjwGhJhqo+fA3rj1NZ50dzxbMuvKGoWBUQKOTZJAkjTGz2K3LHW4EVMeFOWz2OpbZfha2R9l2i39CTBO/P0RuY+BAJ/+x3KHonfkgOoA+Nt90HMwejhBU/MmEmqL8ulRY6yeaMSei+gGkKaL/uNpxFl+UQ9Ffp7zcNX9TkDQ6AhU2POmMJA8/ND45giNGfp0IJi052AZAqO9LU6/W31HmEqsRKm+hnWzF0DG5Q5LwsIQVrkzc6pHd0A/k8p1lCd37ZqwctlcxkwA9kK8PU1n8JDcu/tdBmA2uLv98QZx0PeoTD3fevFDHYUhTKCAy1ydD0a7X0BzpL4boBWPCmYQWhfVJp/ybUqGfz+NNsaQGYkYhxqkr21jUMzX87l0ojq/l OgB1+KqF 7iRgGTE8Y3Mb6DOE1nghajCayZGyR71rbD8N2I572/npKptCIfFNS9saQepDsz/47HOXlDQENQnnbfQxh0duNXWdE/WdwP/oP2kPge7pXq8tjKqZdZYElrbpdoDgL2KyF98UMnz8lCY8xGpqzxSpkkchtab32WDFdAHBRhMl75Ts3yma5wUERSTL4eSVRwA4q/engVUSfuM+QDRGc8m+ntYntneXONqLPVcqGniSQ6qW0JCx2bKgCf4sq4iMk5YbXogO5Hx0lgazGtwAvWHGVRrDlCiLnLbiSeevEgi2JyU37+bkT+TB7t3tIYJN7yQMwoNGX4N3OVTj2GsInduPH3u3Us6vd/xOJvienrIM3epShla+J3tDHoiLDx+f8gpdqnC/cSgemAe/VBWHJaXEhI1o8XmB9VUK9TDDNJTflmw9SIgDTpFkFybcAW28vk63SVlwqgonme2IHlcBKdoJOx17Yrtdd0d51m0SCv5JBn3pzhr1YDoGKcXsCrwBBilD4tUtQFcMI/UUupK7md5fVoJkAMkB9ebKJkKtZ X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: From: "Matthew Wilcox (Oracle)" Move the loop for should-we-write-this-folio to writeback_get_folio. Signed-off-by: Matthew Wilcox (Oracle) [hch: folded the loop into the existing helper instead of a separate one as suggested by Jan Kara] Signed-off-by: Christoph Hellwig Reviewed-by: Brian Foster Reviewed-by: Jan Kara Acked-by: Dave Chinner --- mm/page-writeback.c | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/mm/page-writeback.c b/mm/page-writeback.c index 3cbe4a7daa357c..fc421402f81881 100644 --- a/mm/page-writeback.c +++ b/mm/page-writeback.c @@ -2411,6 +2411,7 @@ static struct folio *writeback_get_folio(struct address_space *mapping, { struct folio *folio; +retry: folio = folio_batch_next(&wbc->fbatch); if (!folio) { folio_batch_release(&wbc->fbatch); @@ -2418,8 +2419,17 @@ static struct folio *writeback_get_folio(struct address_space *mapping, filemap_get_folios_tag(mapping, &wbc->index, wbc_end(wbc), wbc_to_tag(wbc), &wbc->fbatch); folio = folio_batch_next(&wbc->fbatch); + if (!folio) + return NULL; + } + + folio_lock(folio); + if (unlikely(!folio_prepare_writeback(mapping, wbc, folio))) { + folio_unlock(folio); + goto retry; } + trace_wbc_writepage(wbc, inode_to_bdi(mapping->host)); return folio; } @@ -2480,14 +2490,6 @@ int write_cache_pages(struct address_space *mapping, if (!folio) break; - folio_lock(folio); - if (!folio_prepare_writeback(mapping, wbc, folio)) { - folio_unlock(folio); - continue; - } - - trace_wbc_writepage(wbc, inode_to_bdi(mapping->host)); - error = writepage(folio, wbc, data); wbc->nr_to_write -= folio_nr_pages(folio); From patchwork Thu Feb 15 06:36:48 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christoph Hellwig X-Patchwork-Id: 13557447 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 30AE3C48BEF for ; Thu, 15 Feb 2024 06:37:47 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id DD02C6B00B9; Thu, 15 Feb 2024 01:37:32 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id D2F546B00BA; Thu, 15 Feb 2024 01:37:32 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id B81216B00BB; Thu, 15 Feb 2024 01:37:32 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0011.hostedemail.com [216.40.44.11]) by kanga.kvack.org (Postfix) with ESMTP id 9EA986B00B9 for ; Thu, 15 Feb 2024 01:37:32 -0500 (EST) Received: from smtpin13.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay10.hostedemail.com (Postfix) with ESMTP id 7D0EEC017B for ; Thu, 15 Feb 2024 06:37:32 +0000 (UTC) X-FDA: 81793081944.13.716AF57 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) by imf28.hostedemail.com (Postfix) with ESMTP id D8E37C000C for ; Thu, 15 Feb 2024 06:37:30 +0000 (UTC) Authentication-Results: imf28.hostedemail.com; dkim=pass header.d=infradead.org header.s=bombadil.20210309 header.b=QjdPwyrd; dmarc=none; spf=none (imf28.hostedemail.com: domain of BATV+a252b21bd4a653ddb6e6+7480+infradead.org+hch@bombadil.srs.infradead.org has no SPF policy when checking 198.137.202.133) smtp.mailfrom=BATV+a252b21bd4a653ddb6e6+7480+infradead.org+hch@bombadil.srs.infradead.org ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1707979051; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=OECBbDLIiwPC3FYe8tkqoQZRVMW91GpPrLleij5hqbk=; b=4dt1DK2xFBgKzjQ2SOoqtasuSOhp9esA2YrpMTO2JzOO/e1bTNLG+kO06buRZKFBrO0DFy BtkXWybV4h3X80W5Jd+Y5sZDZhmSAPLYumjeMZz8ZMACaJ7mt/pVxaNHXMMMkv6yiY6l1f SkdZwdxzYN5kRREc13YOFRQTNR+JNWA= ARC-Authentication-Results: i=1; imf28.hostedemail.com; dkim=pass header.d=infradead.org header.s=bombadil.20210309 header.b=QjdPwyrd; dmarc=none; spf=none (imf28.hostedemail.com: domain of BATV+a252b21bd4a653ddb6e6+7480+infradead.org+hch@bombadil.srs.infradead.org has no SPF policy when checking 198.137.202.133) smtp.mailfrom=BATV+a252b21bd4a653ddb6e6+7480+infradead.org+hch@bombadil.srs.infradead.org ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1707979051; a=rsa-sha256; cv=none; b=aXksf47QlKP/H7uC6rylbXJZ4EGv2jeMsPhLBHy/6+QEtWBSxAuAtj4Q3FY/NuRwj/p5AZ Bh55KGh1nLa8gwZYs3ETk2w7Ld9UKie82xPp8W3TKZEB6b/9vDktRsnLCU/31P98HBcvZi hOiTxlUj7r+Qn8HNNviZNgiF2eE1h9g= 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=OECBbDLIiwPC3FYe8tkqoQZRVMW91GpPrLleij5hqbk=; b=QjdPwyrdAWQtgMvuz6HvA9OaPL +rJ+zC0xNw3KqgNiPdHKWpsrHoOXbjtlmCwBr7OU/IJ+LBKj7D8ZbteSOhfRdHIZyYpNZ5gZ6POcu 2gsFFj8UgqwQHL6YprBdHZYIvZKHpnFb0SA/DISEiWAY7XU/3S/k+DBBLCBM5OaV8EDFTY8qgZcFi 1ci70GwBs3EQTYtReC0VoeEPJXxMJksS0IR23qonnVZvPnPOydv/NWt/cN0V2T4GNZsUqQ1Y/ei3t H+8lJCxYF4Q6V78mLVu52f3+FjyjDVtOG5//o7xN5BMjEk56XY/2OrNgp/bDZeuoxnAkCQj/BqJfY W9MdGamA==; 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.97.1 #2 (Red Hat Linux)) id 1raVNB-0000000F72u-2aI7; Thu, 15 Feb 2024 06:37:29 +0000 From: Christoph Hellwig To: linux-mm@kvack.org Cc: Matthew Wilcox , Jan Kara , David Howells , Brian Foster , Christian Brauner , linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org, Jan Kara Subject: [PATCH 13/14] writeback: add a writeback iterator Date: Thu, 15 Feb 2024 07:36:48 +0100 Message-Id: <20240215063649.2164017-14-hch@lst.de> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20240215063649.2164017-1-hch@lst.de> References: <20240215063649.2164017-1-hch@lst.de> MIME-Version: 1.0 X-SRS-Rewrite: SMTP reverse-path rewritten from by bombadil.infradead.org. See http://www.infradead.org/rpr.html X-Rspam-User: X-Stat-Signature: rtk4ntenutogitt6signts41if111gz1 X-Rspamd-Server: rspam07 X-Rspamd-Queue-Id: D8E37C000C X-HE-Tag: 1707979050-77841 X-HE-Meta: U2FsdGVkX1/GYS09VSkuVKO+1ZDic6++SltO9htX7ahaJFxw0uvSaXC7WDti2kx2WyVufRLsyVhi3PwDOWELF3jEWtPRAF7ZRDeO2F5XTeagBUq3kdz2HQ/G3n6iMNddG9DQANWckSiSjfWuhwJalWRn5TizgkHcLpqnjS3qdi0tbooStj4GNdE3CB0qrDUuihGZAyp6IBDdHH2J7vbgO61rvn8E28Js0gPgTuDmlqwU5nTKfi4D+hJhxU63Cx1N7yzI59PAn4kIG24+lF6KYJSIO3hLgYPztYF6Nz/E1BGtmxeaZTaw2NlwHoalVsC3aaDuTSBynS7CYZTC1jy2Az94rm+ZEHkrT9AUhjmkXcmUP2fe3A5oDUV7JD82AkXABVVL2SjZ/EQ+AxGJl4n5n6hHPuv0yk1Wd3mqIRnAYEs1DHwN/H0fBXc3XlKOmrXeqJOuDaOZs+W38+a/PAPAvBO+zP41uJXuma7T2HHvofx+lHrh+cVqnuWgj5prUoaEnwmOP8d65cbHIVp8XzdpMNF1GhSCd18qOezZlix7CUyHIukoEiZUr9EDY5HFpOf8Ghy6xD8uyKjKzs7mMlKWx/j3ISo8HZtyB8AXtlSsMUCtwyre3SpCrMFRRwbfqzOguhkeLcWkj4lMMJ+c0NZyURACElKQD71zMsa/1e9Hd0Ppm9Q5CrQujMseTzE4xth8dfduQLf67VrifOdbyQZirfcyRcNmxhWY/1N/RgfrbUMT7xGbeh1j+lBpjN6xfE6w3jPm2EcOjXU+lGO5U/L/XHH5P6jm8dOhvV2ABkkW8MV9w9AJZwcZhWs/FlPJ1bNCoQ3sINmIu3kmdgf+MSrsZkig9vFTBQf474f4OeyXaE6yC5XOyGZtt+9+lKsEcrZhMMvdmMRiT22KIPQbnuITmWRKBSpjbTDCVPpleA0yzrqQJuPAkkmQMdigSonGhlpuMzKQ/sKfhcmeyIZBMSs bSlg34PR sKFF4zLw5g83xxJn0d8xVDLhfcpSXE5yPtzPVR7Jx223D64ztH+TOMoKNy48N/2oJ9DJ0qob4EE0rMqsUcQTI5sCrbA4zhe7NQw391iKMdiOecFyWnSzC7zOrDKAlvzZTfoxw1AGL7ym2vXD51JTXD48XyhKPSIOuDC/1Ps5kvYyOphT3uWSDaY15gSNOC8WUZc7ESJmFlKWCbBFaLVJrrRaPb4gI74TUUET2nFUvXjZch4/o2Sa8zsRC6zmTJNGyM6iaIfbUlpjsFQv2CPV4Dg24G586qDrRAa0hHqBKsjxTJufuSKb3wJIvRrChB0OV4L0/GZZN6Hd3Bs3ORXty9Hy7AsKyBRuyEj1wzS9j++WArEk1N7F69Wq4OU7sCoSXShqhRe8iVpKgLhd474a4mWqeIHpzB/xoQob/aBhybxZ+hFhXWZHmdzmt+g== X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: Refactor the code left in write_cache_pages into an iterator that the file system can call to get the next folio for a writeback operation: struct folio *folio = NULL; while ((folio = writeback_iter(mapping, wbc, folio, &error))) { error = ; } The twist here is that the error value is passed by reference, so that the iterator can restore it when breaking out of the loop. Handling of the magic AOP_WRITEPAGE_ACTIVATE value stays outside the iterator and needs is just kept in the write_cache_pages legacy wrapper. in preparation for eventually killing it off. Heavily based on a for_each* based iterator from Matthew Wilcox. Signed-off-by: Christoph Hellwig Reviewed-by: Brian Foster Reviewed-by: Jan Kara --- include/linux/writeback.h | 4 + mm/page-writeback.c | 192 ++++++++++++++++++++++---------------- 2 files changed, 118 insertions(+), 78 deletions(-) diff --git a/include/linux/writeback.h b/include/linux/writeback.h index f67b3ea866a0fb..9845cb62e40b2d 100644 --- a/include/linux/writeback.h +++ b/include/linux/writeback.h @@ -82,6 +82,7 @@ struct writeback_control { /* internal fields used by the ->writepages implementation: */ struct folio_batch fbatch; pgoff_t index; + int saved_err; #ifdef CONFIG_CGROUP_WRITEBACK struct bdi_writeback *wb; /* wb this writeback is issued under */ @@ -366,6 +367,9 @@ int balance_dirty_pages_ratelimited_flags(struct address_space *mapping, bool wb_over_bg_thresh(struct bdi_writeback *wb); +struct folio *writeback_iter(struct address_space *mapping, + struct writeback_control *wbc, struct folio *folio, int *error); + typedef int (*writepage_t)(struct folio *folio, struct writeback_control *wbc, void *data); diff --git a/mm/page-writeback.c b/mm/page-writeback.c index fc421402f81881..3da4345f08a335 100644 --- a/mm/page-writeback.c +++ b/mm/page-writeback.c @@ -2325,18 +2325,18 @@ void __init page_writeback_init(void) } /** - * tag_pages_for_writeback - tag pages to be written by write_cache_pages + * tag_pages_for_writeback - tag pages to be written by writeback * @mapping: address space structure to write * @start: starting page index * @end: ending page index (inclusive) * * This function scans the page range from @start to @end (inclusive) and tags - * all pages that have DIRTY tag set with a special TOWRITE tag. The idea is - * that write_cache_pages (or whoever calls this function) will then use - * TOWRITE tag to identify pages eligible for writeback. This mechanism is - * used to avoid livelocking of writeback by a process steadily creating new - * dirty pages in the file (thus it is important for this function to be quick - * so that it can tag pages faster than a dirtying process can create them). + * all pages that have DIRTY tag set with a special TOWRITE tag. The caller + * can then use the TOWRITE tag to identify pages eligible for writeback. + * This mechanism is used to avoid livelocking of writeback by a process + * steadily creating new dirty pages in the file (thus it is important for this + * function to be quick so that it can tag pages faster than a dirtying process + * can create them). */ void tag_pages_for_writeback(struct address_space *mapping, pgoff_t start, pgoff_t end) @@ -2434,69 +2434,68 @@ static struct folio *writeback_get_folio(struct address_space *mapping, } /** - * write_cache_pages - walk the list of dirty pages of the given address space and write all of them. + * writeback_iter - iterate folio of a mapping for writeback * @mapping: address space structure to write - * @wbc: subtract the number of written pages from *@wbc->nr_to_write - * @writepage: function called for each page - * @data: data passed to writepage function + * @wbc: writeback context + * @folio: previously iterated folio (%NULL to start) + * @error: in-out pointer for writeback errors (see below) * - * If a page is already under I/O, write_cache_pages() skips it, even - * if it's dirty. This is desirable behaviour for memory-cleaning writeback, - * but it is INCORRECT for data-integrity system calls such as fsync(). fsync() - * and msync() need to guarantee that all the data which was dirty at the time - * the call was made get new I/O started against them. If wbc->sync_mode is - * WB_SYNC_ALL then we were called for data integrity and we must wait for - * existing IO to complete. - * - * To avoid livelocks (when other process dirties new pages), we first tag - * pages which should be written back with TOWRITE tag and only then start - * writing them. For data-integrity sync we have to be careful so that we do - * not miss some pages (e.g., because some other process has cleared TOWRITE - * tag we set). The rule we follow is that TOWRITE tag can be cleared only - * by the process clearing the DIRTY tag (and submitting the page for IO). - * - * To avoid deadlocks between range_cyclic writeback and callers that hold - * pages in PageWriteback to aggregate IO until write_cache_pages() returns, - * we do not loop back to the start of the file. Doing so causes a page - * lock/page writeback access order inversion - we should only ever lock - * multiple pages in ascending page->index order, and looping back to the start - * of the file violates that rule and causes deadlocks. + * This function returns the next folio for the writeback operation described by + * @wbc on @mapping and should be called in a while loop in the ->writepages + * implementation. * - * Return: %0 on success, negative error code otherwise + * To start the writeback operation, %NULL is passed in the @folio argument, and + * for every subsequent iteration the folio returned previously should be passed + * back in. + * + * If there was an error in the per-folio writeback inside the writeback_iter() + * loop, @error should be set to the error value. + * + * Once the writeback described in @wbc has finished, this function will return + * %NULL and if there was an error in any iteration restore it to @error. + * + * Note: callers should not manually break out of the loop using break or goto + * but must keep calling writeback_iter() until it returns %NULL. + * + * Return: the folio to write or %NULL if the loop is done. */ -int write_cache_pages(struct address_space *mapping, - struct writeback_control *wbc, writepage_t writepage, - void *data) +struct folio *writeback_iter(struct address_space *mapping, + struct writeback_control *wbc, struct folio *folio, int *error) { - int ret = 0; - int error; - struct folio *folio; - pgoff_t end; /* Inclusive */ - - if (wbc->range_cyclic) { - wbc->index = mapping->writeback_index; /* prev offset */ - end = -1; - } else { - wbc->index = wbc->range_start >> PAGE_SHIFT; - end = wbc->range_end >> PAGE_SHIFT; - } - if (wbc->sync_mode == WB_SYNC_ALL || wbc->tagged_writepages) - tag_pages_for_writeback(mapping, wbc->index, end); - - folio_batch_init(&wbc->fbatch); + if (!folio) { + folio_batch_init(&wbc->fbatch); + wbc->saved_err = *error = 0; - for (;;) { - folio = writeback_get_folio(mapping, wbc); - if (!folio) - break; + /* + * For range cyclic writeback we remember where we stopped so + * that we can continue where we stopped. + * + * For non-cyclic writeback we always start at the beginning of + * the passed in range. + */ + if (wbc->range_cyclic) + wbc->index = mapping->writeback_index; + else + wbc->index = wbc->range_start >> PAGE_SHIFT; - error = writepage(folio, wbc, data); + /* + * To avoid livelocks when other processes dirty new pages, we + * first tag pages which should be written back and only then + * start writing them. + * + * For data-integrity writeback we have to be careful so that we + * do not miss some pages (e.g., because some other process has + * cleared the TOWRITE tag we set). The rule we follow is that + * TOWRITE tag can be cleared only by the process clearing the + * DIRTY tag (and submitting the page for I/O). + */ + if (wbc->sync_mode == WB_SYNC_ALL || wbc->tagged_writepages) + tag_pages_for_writeback(mapping, wbc->index, + wbc_end(wbc)); + } else { wbc->nr_to_write -= folio_nr_pages(folio); - if (error == AOP_WRITEPAGE_ACTIVATE) { - folio_unlock(folio); - error = 0; - } + WARN_ON_ONCE(*error > 0); /* * For integrity writeback we have to keep going until we have @@ -2510,33 +2509,70 @@ int write_cache_pages(struct address_space *mapping, * wbc->nr_to_write or encounter the first error. */ if (wbc->sync_mode == WB_SYNC_ALL) { - if (error && !ret) - ret = error; + if (*error && !wbc->saved_err) + wbc->saved_err = *error; } else { - if (error || wbc->nr_to_write <= 0) + if (*error || wbc->nr_to_write <= 0) goto done; } } - /* - * For range cyclic writeback we need to remember where we stopped so - * that we can continue there next time we are called. If we hit the - * last page and there is more work to be done, wrap back to the start - * of the file. - * - * For non-cyclic writeback we always start looking up at the beginning - * of the file if we are called again, which can only happen due to - * -ENOMEM from the file system. - */ - folio_batch_release(&wbc->fbatch); - if (wbc->range_cyclic) - mapping->writeback_index = 0; - return ret; + folio = writeback_get_folio(mapping, wbc); + if (!folio) { + /* + * To avoid deadlocks between range_cyclic writeback and callers + * that hold pages in PageWriteback to aggregate I/O until + * the writeback iteration finishes, we do not loop back to the + * start of the file. Doing so causes a page lock/page + * writeback access order inversion - we should only ever lock + * multiple pages in ascending page->index order, and looping + * back to the start of the file violates that rule and causes + * deadlocks. + */ + if (wbc->range_cyclic) + mapping->writeback_index = 0; + + /* + * Return the first error we encountered (if there was any) to + * the caller. + */ + *error = wbc->saved_err; + } + return folio; done: if (wbc->range_cyclic) mapping->writeback_index = folio->index + folio_nr_pages(folio); folio_batch_release(&wbc->fbatch); + return NULL; +} + +/** + * write_cache_pages - walk the list of dirty pages of the given address space and write all of them. + * @mapping: address space structure to write + * @wbc: subtract the number of written pages from *@wbc->nr_to_write + * @writepage: function called for each page + * @data: data passed to writepage function + * + * Return: %0 on success, negative error code otherwise + * + * Note: please use writeback_iter() instead. + */ +int write_cache_pages(struct address_space *mapping, + struct writeback_control *wbc, writepage_t writepage, + void *data) +{ + struct folio *folio = NULL; + int error; + + while ((folio = writeback_iter(mapping, wbc, folio, &error))) { + error = writepage(folio, wbc, data); + if (error == AOP_WRITEPAGE_ACTIVATE) { + folio_unlock(folio); + error = 0; + } + } + return error; } EXPORT_SYMBOL(write_cache_pages); From patchwork Thu Feb 15 06:36:49 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christoph Hellwig X-Patchwork-Id: 13557448 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id EBBE5C48BEB for ; Thu, 15 Feb 2024 06:37:49 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 5B40F6B00BA; Thu, 15 Feb 2024 01:37:35 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 53E486B00BB; Thu, 15 Feb 2024 01:37:35 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 31AFB6B00BC; Thu, 15 Feb 2024 01:37:35 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0015.hostedemail.com [216.40.44.15]) by kanga.kvack.org (Postfix) with ESMTP id 157206B00BA for ; Thu, 15 Feb 2024 01:37:35 -0500 (EST) Received: from smtpin04.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay09.hostedemail.com (Postfix) with ESMTP id EA90D80F4B for ; Thu, 15 Feb 2024 06:37:34 +0000 (UTC) X-FDA: 81793082028.04.B9DF613 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) by imf07.hostedemail.com (Postfix) with ESMTP id 30F1D4000D for ; Thu, 15 Feb 2024 06:37:32 +0000 (UTC) Authentication-Results: imf07.hostedemail.com; dkim=pass header.d=infradead.org header.s=bombadil.20210309 header.b="UwOda/+U"; spf=none (imf07.hostedemail.com: domain of BATV+a252b21bd4a653ddb6e6+7480+infradead.org+hch@bombadil.srs.infradead.org has no SPF policy when checking 198.137.202.133) smtp.mailfrom=BATV+a252b21bd4a653ddb6e6+7480+infradead.org+hch@bombadil.srs.infradead.org; dmarc=none ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1707979053; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=qyeWxkzxkEHhHoHK3zWehsRuRg4lFsIMJWfUKexFKxM=; b=tsODBXlnA06T+wsJkuJzMpV2QZPA811tJTVN8T5AKvCeJtwqxmQiyVMuI7KsJv7EiMeJHK 7mKHCjHJ6bB9jcvaNztFBtMRqNAXd0j4k9aukHaUcrg9UGDww+UhJaRoIBK/B6FblKa9MP S5Ja3uHTAgCdirBnOwUQleaYzuSUecg= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1707979053; a=rsa-sha256; cv=none; b=l44NBSn5ZOgMODb2WV+J/A+9lJmhH6GAUWRegrZwztwsVIANAf4lCZzsUD0fdtFDT6ctRM lKgmLZ+0LGn2SvBUMPjmpU4f2k6JtGQt4YQ+DmB+f28cpRfa4xdyZZijYwask+Ws2vXZxP ohko6ExSLxU4TmAZUsh1/7bz5MhnyG0= ARC-Authentication-Results: i=1; imf07.hostedemail.com; dkim=pass header.d=infradead.org header.s=bombadil.20210309 header.b="UwOda/+U"; spf=none (imf07.hostedemail.com: domain of BATV+a252b21bd4a653ddb6e6+7480+infradead.org+hch@bombadil.srs.infradead.org has no SPF policy when checking 198.137.202.133) smtp.mailfrom=BATV+a252b21bd4a653ddb6e6+7480+infradead.org+hch@bombadil.srs.infradead.org; dmarc=none DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=bombadil.20210309; h=Content-Transfer-Encoding: MIME-Version:References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From:Sender :Reply-To:Content-Type:Content-ID:Content-Description; bh=qyeWxkzxkEHhHoHK3zWehsRuRg4lFsIMJWfUKexFKxM=; b=UwOda/+UIz7ZD9dTkjlRkVaWv8 BWyV6iZujMnIJ6XzWpZUfU3pVZyrYpLVeDr2j1dT98vNxZwx+F68FuPWm1GYmmmafxg61VsF198h/ GbkpZ13apJgwrnyEzYelBVG/igddDpAHlkj8APo9yuiXnMkPfZ4maR/X4PE/jgT7bYI9d0aHNkN1B le6OpSRgWaeiaw8k3kzD6BlSuMVrfYjljZybQw88yGpIKXWXFTXNn6SbT5mdJXYoQuM4c9Gz76mIz zCqOzR+cEcZviPmZHWqEiM4Tp4RyhRbUK5E4Mm+ZI9VFSwjiHnW/eV/Refh3ZBgN7CVpr5CHh989H wQBZ/r6g==; 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.97.1 #2 (Red Hat Linux)) id 1raVND-0000000F74L-3wZ0; Thu, 15 Feb 2024 06:37:32 +0000 From: Christoph Hellwig To: linux-mm@kvack.org Cc: Matthew Wilcox , Jan Kara , David Howells , Brian Foster , Christian Brauner , linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org, Jan Kara Subject: [PATCH 14/14] writeback: Remove a use of write_cache_pages() from do_writepages() Date: Thu, 15 Feb 2024 07:36:49 +0100 Message-Id: <20240215063649.2164017-15-hch@lst.de> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20240215063649.2164017-1-hch@lst.de> References: <20240215063649.2164017-1-hch@lst.de> MIME-Version: 1.0 X-SRS-Rewrite: SMTP reverse-path rewritten from by bombadil.infradead.org. See http://www.infradead.org/rpr.html X-Rspamd-Queue-Id: 30F1D4000D X-Rspam-User: X-Stat-Signature: djkzw4bym8kyri3m91837es8txfdaiai X-Rspamd-Server: rspam03 X-HE-Tag: 1707979052-968359 X-HE-Meta: U2FsdGVkX1/Vh2DLg38zxyszTlbMwVU436Q2liXb8OYShH7m1+EmVtQ1T2t5LjN6bwVQOkjfvktHlBXs6cGyKyKN3Nyrl3y2yexkcXHXg8hKK5QliBXpnYaONXU+j8A2B8VXnitvcnbKFxPn87+nypAXc4sRKGKyCC2ZEdwblEQy6nprjXClp8DucxUta46atzJMsxiPX2nAhwXuePiRrP6ttgTCQWiwp97rFTCi6BuvWZz96R4mQlVWWUiCQH3L87FF68RJhQLVEfFNmc7n/84x8DUsF6CgTUPj51hHFjYtF0sEnxAmlJgFTA5mDXrPH2KvhrFgjSjHlLuYcuevckjUWyXd8IzXL1pY61fGq58BfQ4zsPR+/vqucu/Tv/eXtwIv2ulh4rFbcc8Km0PYRrcVmCdNcMYqLwZ72H0lBgcQtGBPUUSEyBEqcOQgxHUZCx1ehdqjRf9aAaEmRUwpts0r67i8/66WQ4ONZvDynkEKu+lMfIaUiJ+SQQgjiHeRp+7qnRmLm6H1zI3jpDdWAzsM6O3KgEXjjY8V5LnFdOhuEPuxyD+JxV4AUGNtwi3cGGkvDh93g72ZDEW4wCGEj+rmYocnzZSuEXt25zyCaOIrjJYNFD0CH7Y+AgZ9LpzkeFwK6MVE37lCjT9OGACg3yz1J3p1pf3zw47rIa7jSyllsxLlmydCNYitnZvaRdl07so4hX3bxVX8haE/AZEj+unPYMdUsXb4oKli/TDFjbfi/oVliJAhiBR0KuuisXbxqk6CbzGw4lQG9ab3ZqOILpZ+56aouw2BMgFbIT+AomESwNFz0mgyyWz+/okhsaMXiYlqgsAAJDpF1/nruEyvrihpjSDU4iIbFReLiYbIIYyx+XHzT/daHna1GRM6C7WFBmlkKw9ufT+Zlrdo4Nm90C7d5IUF55zVNwXMQOiAtlR7glkxRswPcySQdDL+Mr5XVIKP177+fDwoDWTfRb3 6qhHrfdu ZiYmiRGXscZo+iwN4GgKaP2zHX6HMXBk0S1tkj2hS6d+YaAbZxw0YJ9daQfnyBziQOO1lfaYQNwHZ6vpiOjhYrKjscQ1V3HxiD/5GdBEjyuMoaUIUyk8Mf/ktYV6Mo4UAXG7tde9o421ebznvNCFyK7RicUnXzQH/9nYgfGDlrYWAx6NU/JIwgexsBaWTYM6IWWt0SaTOwqlioyZW156KbyelH/DXFlDYQZLQTX3rtBu7N+t8V+pDeKUxtacIxjxaBQs0qaiYhkPzH6G4+RrgSwmvx8+Ylx2F8UclwwoT8OE2Wk1jufynNOnW3B17XE4Kr5YqP05v+xbCD8fyhmUoAUDO5jjjwOq/3QoRDCg4A/ONHotY3hbSHemTHMpNfqo90Z1lFZINFTx2V7ByPHTgpNwyLw7KOb3MgZwZIeTKrrCOerEiXm9eYlamdllB9GIN8hZQ6HF1Aq+ePKhK1dAXHE+RTMm9nhH7wXbAnebsqtcDP2Rztw+HhSD0Ko03ALsDorsWe0hrrGtMg9l2GezRxHAdVgU79Rbwu4A2 X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: From: "Matthew Wilcox (Oracle)" Use the new writeback_iter() directly instead of indirecting through a callback. Signed-off-by: Matthew Wilcox (Oracle) [hch: ported to the while based iter style] Signed-off-by: Christoph Hellwig Reviewed-by: Brian Foster Reviewed-by: Jan Kara --- mm/page-writeback.c | 31 ++++++++++++++++++------------- 1 file changed, 18 insertions(+), 13 deletions(-) diff --git a/mm/page-writeback.c b/mm/page-writeback.c index 3da4345f08a335..3e19b87049db17 100644 --- a/mm/page-writeback.c +++ b/mm/page-writeback.c @@ -2577,15 +2577,25 @@ int write_cache_pages(struct address_space *mapping, } EXPORT_SYMBOL(write_cache_pages); -static int writepage_cb(struct folio *folio, struct writeback_control *wbc, - void *data) +static int writeback_use_writepage(struct address_space *mapping, + struct writeback_control *wbc) { - struct address_space *mapping = data; - int ret = mapping->a_ops->writepage(&folio->page, wbc); + struct folio *folio = NULL; + struct blk_plug plug; + int err; - if (ret < 0) - mapping_set_error(mapping, ret); - return ret; + blk_start_plug(&plug); + while ((folio = writeback_iter(mapping, wbc, folio, &err))) { + err = mapping->a_ops->writepage(&folio->page, wbc); + if (err == AOP_WRITEPAGE_ACTIVATE) { + folio_unlock(folio); + err = 0; + } + mapping_set_error(mapping, err); + } + blk_finish_plug(&plug); + + return err; } int do_writepages(struct address_space *mapping, struct writeback_control *wbc) @@ -2601,12 +2611,7 @@ int do_writepages(struct address_space *mapping, struct writeback_control *wbc) if (mapping->a_ops->writepages) { ret = mapping->a_ops->writepages(mapping, wbc); } else if (mapping->a_ops->writepage) { - struct blk_plug plug; - - blk_start_plug(&plug); - ret = write_cache_pages(mapping, wbc, writepage_cb, - mapping); - blk_finish_plug(&plug); + ret = writeback_use_writepage(mapping, wbc); } else { /* deal with chardevs and other special files */ ret = 0;