From patchwork Sat Feb 3 07:11:35 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christoph Hellwig X-Patchwork-Id: 13543896 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 B6A8EC4828F for ; Sat, 3 Feb 2024 07:12:10 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 2A6A06B0071; Sat, 3 Feb 2024 02:12:10 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 2553C6B0072; Sat, 3 Feb 2024 02:12:10 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 0F3DB6B0074; Sat, 3 Feb 2024 02:12:10 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0013.hostedemail.com [216.40.44.13]) by kanga.kvack.org (Postfix) with ESMTP id EC4C66B0071 for ; Sat, 3 Feb 2024 02:12:09 -0500 (EST) Received: from smtpin27.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay01.hostedemail.com (Postfix) with ESMTP id 905451C1272 for ; Sat, 3 Feb 2024 07:12:09 +0000 (UTC) X-FDA: 81749623578.27.62E417B Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) by imf23.hostedemail.com (Postfix) with ESMTP id E1CB814000F for ; Sat, 3 Feb 2024 07:12:07 +0000 (UTC) Authentication-Results: imf23.hostedemail.com; dkim=pass header.d=infradead.org header.s=bombadil.20210309 header.b=ZOhz2dNr; dmarc=none; spf=none (imf23.hostedemail.com: domain of BATV+a0ed29cff9639d748e7e+7468+infradead.org+hch@bombadil.srs.infradead.org has no SPF policy when checking 198.137.202.133) smtp.mailfrom=BATV+a0ed29cff9639d748e7e+7468+infradead.org+hch@bombadil.srs.infradead.org ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1706944327; a=rsa-sha256; cv=none; b=CcF95cp9+eu/h0eCLFlyejH17Dn3JXZL7NF08OuhbgJe9BP6uRcRYBkRrxOrrgB13e2aZK J9ohHc3DCgDIRHDyGthz03jWs3QJvBGnvGbZ3OosRKwwa0Tk9XU3/SRAPJ/gh2Zq7RjjV/ /BdnRnHdxnAA+ays6HBJ37cKiYj+OEA= ARC-Authentication-Results: i=1; imf23.hostedemail.com; dkim=pass header.d=infradead.org header.s=bombadil.20210309 header.b=ZOhz2dNr; dmarc=none; spf=none (imf23.hostedemail.com: domain of BATV+a0ed29cff9639d748e7e+7468+infradead.org+hch@bombadil.srs.infradead.org has no SPF policy when checking 198.137.202.133) smtp.mailfrom=BATV+a0ed29cff9639d748e7e+7468+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=1706944327; 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=xhrwIWNpjcQIv5YO2nMtvhtYdhPm7I4EvNqSbIwvYpwgr/usKt/IKOQ8W4MEbAM7ttJmB/ s6uhtrg35g5q+VDduenClAgETOmTuNOSFK8gXWfvzw18Q6dD3ZyjZxCL76gopdl8aV699I 7afL5OHWmPTC4LoadKgcdifwa3GhYqw= 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=ZOhz2dNrO2v9ls+tKOcQisMqRw d5QuM/23JepzSn1b7ipMDrTGniaboVzWpHlnXVcGXa/5j3pXzLv+92C4aMfdx5zI3LbWA1MpvxCKY bo5W1UBMWQIb6eFnzTI/vzwvbwoBSgimQvqAnr4GR3VdEvx2+dwJV10G4DEkR22tfac+AReRnaJYt h8GYwOYQFl5wxKZuROP6cuiRFwtrXGNKDtwvUJ/AVmUSktYdhaOMlOIIiUBh0PUyP/XuwiXXGy5pe XAktdBAhJf6YF2Km1CmRkcfi4sKlQTSHJQ5IcNX27jo73jG7Abl322/EiFmIEHqxYUnLKATMNc3uf Qhck81Xg==; Received: from [89.144.222.32] (helo=localhost) by bombadil.infradead.org with esmtpsa (Exim 4.97.1 #2 (Red Hat Linux)) id 1rWAC3-0000000Fjy5-2qvp; Sat, 03 Feb 2024 07:12:04 +0000 From: Christoph Hellwig To: linux-mm@kvack.org Cc: Matthew Wilcox , Jan Kara , David Howells , Brian Foster , Christian Brauner , "Darrick J. Wong" , linux-xfs@vger.kernel.org, linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org, Jan Kara , Dave Chinner Subject: [PATCH 01/13] writeback: remove a duplicate prototype for tag_pages_for_writeback Date: Sat, 3 Feb 2024 08:11:35 +0100 Message-Id: <20240203071147.862076-2-hch@lst.de> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20240203071147.862076-1-hch@lst.de> References: <20240203071147.862076-1-hch@lst.de> MIME-Version: 1.0 X-SRS-Rewrite: SMTP reverse-path rewritten from by bombadil.infradead.org. See http://www.infradead.org/rpr.html X-Rspam-User: X-Rspamd-Server: rspam06 X-Rspamd-Queue-Id: E1CB814000F X-Stat-Signature: ui4z6hdy5htgd3hmqotwbpwnxh6y6n98 X-HE-Tag: 1706944327-238275 X-HE-Meta: U2FsdGVkX19TMjAmN4u/dHMNhfn5P65oriAYB/jC9KvlW6oJKH4QgUG+Uvf44qH9j/0ePldFNdHqEntza8NyvhMSZcsM3IX8a+WKMW4MxzW7F6W8pXK/t00AV9WPx2KKdccKrJsCRRB2ZzJVY9FHVAsAB1YE/nrMKiIMWyExMIVhqcpJLtXz6Lqbn5KuR7z/03MDgIN9xv1jb2GbIA/k31g9TpM/EEJypsaLjPjYt2GzRN0HB+lvTIgTBfEWBg7VsLdWr8YCsGZXJ+yGR9/FbjK3Pxd0ySdI7eP75FgWaqbdPRG6eZ/YN6ot80adTgVw4sWBvvC9vSIEQkcaL5VC+owDemj1HTEbabGQkLsdE+ZRQisSRGLrXqs1GZQDfC8sWb2lpOJI1dVLt1ItloCkaKVY3yTiyXlUTn3BSyoHbLv7t+ATyFk4ymbm5YKIZhsuEgHeIqHijR2gqU+xObhoPl1mzZbV9HvubcH78KgpSOPFdoAb+ke9g7UHXHJHispagLwBgEsQnJMQaadApHbaSS0VUs/C/w4EOuK+WfM0JXYV1R/mx32JcgQSoGyDsRaI+37H/vqSUihrmHBy1dwNZlelLcx23Fvjmrn7IICYx2V41r59LC5BvTp1H1pikARmPkEfndfmmFLZ18m/iOTHp9nnIJkSSYT0KvBc9do81d1Z8121vU8QI/k7PdvZWEYbLYMJeTz/Vlw0MWdZ9htKFvC+JDcfn/Deq0b6aFrOhWIYfpVVq4abTvKeIxRKzVbrB024J4upC+RUWzVJI6Di+PrAFPbatf5RuIBTKdir1KxCunV7UT38eyXyIPofZEH2JMm44VYghaNWcrP4jDheJM4bqeHyxC5kxYkTtQLjPFIjjpaEOfLxiwidAdXjUc3TqiXIppp4skT07LESe+kBhCl17Q2MrmBHeHjT94pmle8mlxD8loTnTDotqeemS9SlYS4JNWWGSP0SZ0hVj4F 8S73Xr6I erj3qTAlC+DqApp/lo1hEVDP3gsZai1bNj5ZEOZEUBEd5x/MbSBo35MX+IgxY1bnJWOOAdv3Slvr/BXdpbjC2AjAwQwM7xdmxJCVqpDpG26Av73MIaOKTq13Jgzio47a/jYUbIikN5Jtj8sRqIgCq6DTAI6H5zPaIhCW96NowJWk9leVqIsP890Cmc14cUHXAsn8O4YJl2F0mZ7+UeH4zlOH/iAAL1v6s5UgkXrkmpdJu6HbOxvbYQWdV0mYL6P/liCcBim3H5mtZB0EpxRwpaBFFrAX+nMSWLBIH3d+LGchiLPPmvrWZ49M8+iE21CUSk8NYPp9AazTzHrWZoKdW9gVR3Eg1trCIneQxf0lUNLtoh8824rDNSBCHCD0Nn06NE494al8NG4dwktwZg5aAW84W/fdIWu5AgjJjJS0xsWinYehRKo+aPwkW7Hy6oajXvGZaRAFZcZ0ZC9daS2cKz1XK1v2ghtR8OBfGv/h59acd/0yfNOvfvFa/Tkidd2NF378A39AWEIlvePk= 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 Sat Feb 3 07:11:36 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christoph Hellwig X-Patchwork-Id: 13543897 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 047ABC4828D for ; Sat, 3 Feb 2024 07:12:13 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 8986B6B0072; Sat, 3 Feb 2024 02:12:12 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 848CF6B0074; Sat, 3 Feb 2024 02:12:12 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 6C17E6B0075; Sat, 3 Feb 2024 02:12:12 -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 550ED6B0072 for ; Sat, 3 Feb 2024 02:12:12 -0500 (EST) Received: from smtpin14.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay03.hostedemail.com (Postfix) with ESMTP id 33968A0530 for ; Sat, 3 Feb 2024 07:12:12 +0000 (UTC) X-FDA: 81749623704.14.73BBABE Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) by imf13.hostedemail.com (Postfix) with ESMTP id 8F44520003 for ; Sat, 3 Feb 2024 07:12:10 +0000 (UTC) Authentication-Results: imf13.hostedemail.com; dkim=pass header.d=infradead.org header.s=bombadil.20210309 header.b=iE2Qy9x6; dmarc=none; spf=none (imf13.hostedemail.com: domain of BATV+a0ed29cff9639d748e7e+7468+infradead.org+hch@bombadil.srs.infradead.org has no SPF policy when checking 198.137.202.133) smtp.mailfrom=BATV+a0ed29cff9639d748e7e+7468+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=1706944330; 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=Ir6qdgwpiudHSGvIqZf3UZHrrrbsMgA9iIwYL6Ldf0U=; b=IZhR9dXzySNVgxQ+MlKHfvzaabBsGVvO8POogEH2jACPgC8+ZMbX7eW5mudWFI1WJJfo+c NpH6QlPr/xY1+OBIuWgDGTlajfseq8yLK/f9Tbt50F2n4Oye0vHfoBEdVUsgTJohqM6fMp Oh8YTHb/pGASVp6KhG+dmsQPzSvRaqA= ARC-Authentication-Results: i=1; imf13.hostedemail.com; dkim=pass header.d=infradead.org header.s=bombadil.20210309 header.b=iE2Qy9x6; dmarc=none; spf=none (imf13.hostedemail.com: domain of BATV+a0ed29cff9639d748e7e+7468+infradead.org+hch@bombadil.srs.infradead.org has no SPF policy when checking 198.137.202.133) smtp.mailfrom=BATV+a0ed29cff9639d748e7e+7468+infradead.org+hch@bombadil.srs.infradead.org ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1706944330; a=rsa-sha256; cv=none; b=RhbJAt4z1RpVM9IQhO6tq3O+jH0PPsxsFZLbVSH6wtrg+AmOk+HQyxX2emYFFdvFGTHWZO 7IvzfpYIycB2fR5QHn5MtCu63Llcrs1F9a1fLKimJqNrdXWd7Hi9kfJGlQIn3QIl5BcJdn mtXpt/SJ0ob3ZWgNIQT89bV5MX8XCVY= DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=bombadil.20210309; h=Content-Transfer-Encoding: MIME-Version:References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From:Sender :Reply-To:Content-Type:Content-ID:Content-Description; bh=Ir6qdgwpiudHSGvIqZf3UZHrrrbsMgA9iIwYL6Ldf0U=; b=iE2Qy9x6Sg4y+wDEl3bj4dxn64 gCZM+M5CKCFy/pvjW1p2OkT8q39b+HPLnqpeQFtfQGA7LIQT455VsNCXAFevt/ZFQdlwY6+lV/T08 hi9wUOIqd5dzHOSzIBC2F2C1en3bkkET7N+8OxgSq2ZP6UymsXcY5AHMrDYarIBXr43S1FjEAqJwL tnWLV4DaRWtSn8qD6VOyT5NExzUXn7LolYKSrpLFNKsSD9ZMMwOWlGrlASjgnLrSgjA6/9i6nUia2 SO3m5CYQbkwfuUV+eCZiDRKzYLJuG2c9DuxAxC2a3HR2vl2ucCFG25/X7aUlQeXm0S5RF82fcXR7Y 9YjRd9ow==; Received: from [89.144.222.32] (helo=localhost) by bombadil.infradead.org with esmtpsa (Exim 4.97.1 #2 (Red Hat Linux)) id 1rWAC8-0000000Fjz1-3cgJ; Sat, 03 Feb 2024 07:12:09 +0000 From: Christoph Hellwig To: linux-mm@kvack.org Cc: Matthew Wilcox , Jan Kara , David Howells , Brian Foster , Christian Brauner , "Darrick J. Wong" , linux-xfs@vger.kernel.org, linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org, Jan Kara , Dave Chinner Subject: [PATCH 02/13] writeback: fix done_index when hitting the wbc->nr_to_write Date: Sat, 3 Feb 2024 08:11:36 +0100 Message-Id: <20240203071147.862076-3-hch@lst.de> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20240203071147.862076-1-hch@lst.de> References: <20240203071147.862076-1-hch@lst.de> 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: 8F44520003 X-Rspam-User: X-Rspamd-Server: rspam05 X-Stat-Signature: 4brt6f6chomrmrx98w46dmpuu5s5bgs3 X-HE-Tag: 1706944330-993721 X-HE-Meta: U2FsdGVkX1+l3fkg5xcwoxxPLGFmD1/v330iZIhZJn++s9o1zsMHVVvIob6dDg9RSeB7/Vb/x7aWiI47PQmn//InPdPE47jUbAuWlNWTMpvzE21Uk0qR4T1bA7cewvxq5WoXRJhc9naz9tRr8r5jimLqXAMBT2TRS2zodWKB6d3kp6DICtF5vGog3hZhTVecR1sCwe5LETHiz6eA8Hc0ns0s8MXFc9aqrh9ylpzdNuH7tFy9MeE3nyaZZNIKJ9VnvJ/YnNIauPGCr6owKVyD/UXf+MzwbA/awh4VGIaWHU+atA/OT2qcaEbNO+ECZQzL/VwHCJXA92pJQSBMQxuQU3o16rlqrSKLzho0zjAsyRNSV0b9Mdma5nenHoB5jC37QsLJuITMO4aepsMMcN/RVuXiZpoCo+/7UzTec+eFUusONhhGGBKJ0IiAQ6JQcfBu5Jsxp9LNHN4P5chOIZlkpr5rCaXkwQd/ExWInI4SKZV6P1IjTzYUBRE87vkwW8vALCpabFh3L6jPv4KXou+Uxa9TGYDlxw3ckzMLQ/N6qFDvaWJe8giZ4gcTjRD7FByZZSisxnZ+CGYRBKwTXpK139K44iQar0kSrqIiTVBrHjvgi1uQlZA2NxfeHPhL2KfQlDEUJgAabFmr67YGRJF8XyOlLDnqHP5Z3NT6myYXfYyfgjH+icR8M13sMZ0RW5+TEphINJQZmb/cQwjkOC8hU6ESKFpY+QhCULFj61WfjMMTQEc70/Kjdk8A9RjL7v4HQTdZBR8TTfQDQwRTMArHDfdpcZkW8KOA+4WRwlXBYfqVgyayIV23bfkW1SigQSZfp6a4FDHzPnM7YEfXA3+WiQYd0YUqtDaubhGnJSNOBIA22ktlEcQj1SyVIrK9vFx8eODHY0z2pckwB4Yxjsv0oiUDa6leHs7YyLjeJI+Ah3bo+k63XvsgNW7InWR0KC29ljDBA5nIq7bFi7VdegV AZn/btnU ivBUT0oI05ohy3/dAIJgJTlH1GwV0qUF4QGek68I6yjg1keRfSD8iZDzAW+UbFDKfgIWLwvGAmdUJ5IkNIrygvizPFA0w+vYbu4YCAQ9yOrGMIZG1YvZX1G80Wuiz5IdyuPFa527e5+SMF6lrGRVkoSSjSO20JGYaHD0dztHvmkD2+Gvr833nFLyuQ+aM38hdzXHcTe7ytMW1buYlhC1/M3kSRyn7tVU8rme2Zssn7QvEF5Dmimi5fGwYByJ6WMmc039ze6lBYcdEQp9bYLeq2dbS+zaPp+3xHwZ+tNTivkf2jvZ7GQcEXAG6xgZNY0m8K9vHoB5uzWc9PNs2RUBveeiX5zQpxPhSYUaj/lZwdcZy2CvwtmxxxRIZ+2RQx/zOt7UH8gB1O9+9cuvdaCT5csRGPbt2EVcT8/481kEYytpZibIRSMP9PnWSMFE7gVqJ0qjaWdehxOpoDC8= 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 02147b61712bc9..b4d978f77b0b69 100644 --- a/mm/page-writeback.c +++ b/mm/page-writeback.c @@ -2505,6 +2505,7 @@ int write_cache_pages(struct address_space *mapping, * keep going until we have written all the pages * we tagged for writeback prior to entering this loop. */ + done_index = folio->index + nr; wbc->nr_to_write -= nr; if (wbc->nr_to_write <= 0 && wbc->sync_mode == WB_SYNC_NONE) { From patchwork Sat Feb 3 07:11:37 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christoph Hellwig X-Patchwork-Id: 13543898 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 18A71C4828F for ; Sat, 3 Feb 2024 07:12:18 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 980F86B0074; Sat, 3 Feb 2024 02:12:17 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 90A086B0075; Sat, 3 Feb 2024 02:12:17 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 7FA3C6B0078; Sat, 3 Feb 2024 02:12:17 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0013.hostedemail.com [216.40.44.13]) by kanga.kvack.org (Postfix) with ESMTP id 711526B0074 for ; Sat, 3 Feb 2024 02:12:17 -0500 (EST) Received: from smtpin16.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay05.hostedemail.com (Postfix) with ESMTP id 4C4CE40204 for ; Sat, 3 Feb 2024 07:12:17 +0000 (UTC) X-FDA: 81749623914.16.383AF85 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) by imf06.hostedemail.com (Postfix) with ESMTP id D76E9180005 for ; Sat, 3 Feb 2024 07:12:15 +0000 (UTC) Authentication-Results: imf06.hostedemail.com; dkim=pass header.d=infradead.org header.s=bombadil.20210309 header.b=XlUtYVzv; dmarc=none; spf=none (imf06.hostedemail.com: domain of BATV+a0ed29cff9639d748e7e+7468+infradead.org+hch@bombadil.srs.infradead.org has no SPF policy when checking 198.137.202.133) smtp.mailfrom=BATV+a0ed29cff9639d748e7e+7468+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=1706944335; 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=49fgiBCP04epsyHu4VZLFhJdGCRmLlr7ZEyZXKDtz3E=; b=uQr+90aLq6tJvGcEeQKPkkhckvAlF98QTDd0CrkUGdBfk1/ONNt2FiB1U5Czee48DwmnpR y+42DeFJ8H5knezJmm7I9PjM2gwkyZC3eNCJCine8nWycDXtd28rDi69na1BGPeuLAUWn1 MSi7gFx6jpbXfnLC5+R0vtojUJLiEK0= ARC-Authentication-Results: i=1; imf06.hostedemail.com; dkim=pass header.d=infradead.org header.s=bombadil.20210309 header.b=XlUtYVzv; dmarc=none; spf=none (imf06.hostedemail.com: domain of BATV+a0ed29cff9639d748e7e+7468+infradead.org+hch@bombadil.srs.infradead.org has no SPF policy when checking 198.137.202.133) smtp.mailfrom=BATV+a0ed29cff9639d748e7e+7468+infradead.org+hch@bombadil.srs.infradead.org ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1706944335; a=rsa-sha256; cv=none; b=czIAWpM7Cx//KN8ZIBCdI7QgYr6tXO5HLlim/8BrpahdWgK5RoP5RCu0+aGXSCvK73Fi8f 9nss7IDcNHJdfXrmbypGmGhkYEkSn8F+7TqI1cfqdf/fT09xzEBul2S60fmru4zx3Qo1pq MWNoxLvlaOEhBGwHHkTmZNLQx/lFMUU= DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=bombadil.20210309; h=Content-Transfer-Encoding: MIME-Version:References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From:Sender :Reply-To:Content-Type:Content-ID:Content-Description; bh=49fgiBCP04epsyHu4VZLFhJdGCRmLlr7ZEyZXKDtz3E=; b=XlUtYVzvEHslYCkKcXL+kLKkWh 9WTLKLOLzxgooVTG83weTxXHEkwnSz4ybyLAeTF63d9qpkg5/3QqKB1r0fiaxhUO3cVx09NH+5Eo5 QFGjAEPz/oAvFBpRtC9I0fpdDPAIDkdv9qsZ/o2Yk6jT1RW6Z8Qoa81kLjYtsh7/LoSy3GUxUHyIz MQ0OFbDNGbmshBa1RhuYyufJiFWc9kY5FoAub/R7AI5Ep+JcunFwqr5QsPuqV2eofrvNuVUc7kq0H mfFJrDAX6yoOt/HhTtIfyWWS9UVv6ptOAdSuTkYnPQpb3GhIL9zWe/+GHCh8en4saFjCp4gzKTqae RAaS1RPw==; Received: from [89.144.222.32] (helo=localhost) by bombadil.infradead.org with esmtpsa (Exim 4.97.1 #2 (Red Hat Linux)) id 1rWACE-0000000Fk0K-0UzU; Sat, 03 Feb 2024 07:12:14 +0000 From: Christoph Hellwig To: linux-mm@kvack.org Cc: Matthew Wilcox , Jan Kara , David Howells , Brian Foster , Christian Brauner , "Darrick J. Wong" , linux-xfs@vger.kernel.org, linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org, Jan Kara , Dave Chinner Subject: [PATCH 03/13] writeback: also update wbc->nr_to_write on writeback failure Date: Sat, 3 Feb 2024 08:11:37 +0100 Message-Id: <20240203071147.862076-4-hch@lst.de> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20240203071147.862076-1-hch@lst.de> References: <20240203071147.862076-1-hch@lst.de> MIME-Version: 1.0 X-SRS-Rewrite: SMTP reverse-path rewritten from by bombadil.infradead.org. See http://www.infradead.org/rpr.html X-Rspamd-Server: rspam09 X-Rspamd-Queue-Id: D76E9180005 X-Stat-Signature: wq7dg9xgzjat5iwoqpqj6xtansswmznt X-Rspam-User: X-HE-Tag: 1706944335-794486 X-HE-Meta: U2FsdGVkX18RCEQSLUDWx+SB30G6WYaPaPcihcLAnNmwSq1VlmVMJPOexmcVv/WCSlpkpqyzoH54Jj2btsfBu53cNa10uir3Jsl2fCexO2lyRoilbII5DW5nVrM1W2s574b3/BXAgxhmILNgSlljfri2TbfXQQp5esPy1rqT0k/Y0i7gkSK0nG0LN8BLpe5ws85/3pXroeYuQpiSBX3kftZf9fTtK1hPVtJYrW7IhUz93ph9s3ktUzkwc/CCqsZ6McI8mQWAQdjofDzXXrAHRgg12dvHOZKqnHXj5sqY+HzDeFqYkqWluOF6qdKaKQ1OePgyd6P0awFoHin6A++Z5HUzouN7FkwA1qLOjMs6A/1xvhcIq/ZNmogPxw8A8tz7vWnZQsc2jHgj9lurdgx4iY3sY/4a+v9Tsje/28rWsbYVUcU1zM/n2cu9mSH3PGLbgU9DrXBW5UXQLMyuTZWu1YkVlBNV7+973utDnsjlwcCoM9RZBvZu8oYSKqN6DU2PuyKvyu2iwzFof/oAR8k5LnaSx7ButSburk+xkdQ0rA0xjFX+MI/LOyR7U+uQkCuVW8JK/s8e/09WkopuGoJ5F5d4Kl/irzFrlO1DvbqIepsXUBcOZ1vVqPBKW4vTbQZtdxu45LAkUhVF6N5X7Q2qijp/6/I+e/mLlX2lxjHuHG8UlQ2/4QM3/lznUWxlVIZsdRZQuKkkMsipVgPTM0FzwiJPjjonrnFNmjqZ7TyIDTOclwv3Dt3xV/8/uJ+EN7mKd7HfmnVOUljpLW4cbKE5nTRRusizN6NgPkeXVVdcexIlRQLV7DL3JAg9PiVvSuu3A+PPl3EYrQGaNz2DIeDqvf0NqI6KrRbV8S5fiL5N9acnz1F878esx+yyWsNEK9wR4wigKgzwlYpp5FQwjfq6PFLTCJ2i69ESDK/+w3qgibn4rXZpOds4R/t6neFqp87uZXoDmR5OVcvP/xOOWxi ah2x7Zpk hmvL5oxRfIDrNOBVWw7KaaRCE6JVhWaj0cS8KbmiOB+w3IBRUbUoHE8FLvrIG2dxWd2odUEbCxPFwXEvReetMxL66B2PiS/QuWaM0Zmv5hNw4smQRgHU+HtbdLz1jLoC/zI+m5lFMZqJGFxk1Dc8ujZ4vsZl7tD75MrdNOv6S7vfTDqPyW9TZ85BYKnz/PlUVbNRT+Lnq1NNfmzBGR6RTgf0hUQ== 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 b4d978f77b0b69..ee9eb347890cd3 100644 --- a/mm/page-writeback.c +++ b/mm/page-writeback.c @@ -2473,6 +2473,7 @@ int write_cache_pages(struct address_space *mapping, trace_wbc_writepage(wbc, inode_to_bdi(mapping->host)); error = writepage(folio, wbc, data); nr = folio_nr_pages(folio); + wbc->nr_to_write -= nr; if (unlikely(error)) { /* * Handle errors according to the type of @@ -2506,7 +2507,6 @@ int write_cache_pages(struct address_space *mapping, * we tagged for writeback prior to entering this loop. */ done_index = folio->index + nr; - wbc->nr_to_write -= nr; if (wbc->nr_to_write <= 0 && wbc->sync_mode == WB_SYNC_NONE) { done = 1; From patchwork Sat Feb 3 07:11:38 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christoph Hellwig X-Patchwork-Id: 13543899 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 08AFEC4828F for ; Sat, 3 Feb 2024 07:12:24 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 849A06B0075; Sat, 3 Feb 2024 02:12:23 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 7F9246B0078; Sat, 3 Feb 2024 02:12:23 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 6E7D26B007D; Sat, 3 Feb 2024 02:12:23 -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 61CED6B0075 for ; Sat, 3 Feb 2024 02:12:23 -0500 (EST) Received: from smtpin21.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay10.hostedemail.com (Postfix) with ESMTP id E8E17C0545 for ; Sat, 3 Feb 2024 07:12:22 +0000 (UTC) X-FDA: 81749624124.21.BA7F66A Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) by imf22.hostedemail.com (Postfix) with ESMTP id 49C82C0014 for ; Sat, 3 Feb 2024 07:12:21 +0000 (UTC) Authentication-Results: imf22.hostedemail.com; dkim=pass header.d=infradead.org header.s=bombadil.20210309 header.b=QH+FHNxv; dmarc=none; spf=none (imf22.hostedemail.com: domain of BATV+a0ed29cff9639d748e7e+7468+infradead.org+hch@bombadil.srs.infradead.org has no SPF policy when checking 198.137.202.133) smtp.mailfrom=BATV+a0ed29cff9639d748e7e+7468+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=1706944341; 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=GhmEmGUPN5iqiwr7bHV2cU1PJLEobcTODedxESHF4Gc=; b=IP5uQ/g8zUa4khJlAdSxwKwkYeF67fAM7uCRF3deuJz2eFP2+eYrqoYcOvHIC1/0KXXOET D6UklFvSiKUlZ1FaKIN2pPPRLWr2wWrU2S+p3XJeLC19Vc20R2qdtKR43HTz/vf9jgv9/u Pu+jdIQjHzHl6R3fLNsP4a534P6J/K4= ARC-Authentication-Results: i=1; imf22.hostedemail.com; dkim=pass header.d=infradead.org header.s=bombadil.20210309 header.b=QH+FHNxv; dmarc=none; spf=none (imf22.hostedemail.com: domain of BATV+a0ed29cff9639d748e7e+7468+infradead.org+hch@bombadil.srs.infradead.org has no SPF policy when checking 198.137.202.133) smtp.mailfrom=BATV+a0ed29cff9639d748e7e+7468+infradead.org+hch@bombadil.srs.infradead.org ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1706944341; a=rsa-sha256; cv=none; b=YqorvsTsv7KZ6oeGRW15wuvkNaL+qCof6pPI3HPROtN3uQ4hAwZb37HQO6IVsggsLM7w4t hyLxC8U3ItFck3J/HEuzqSqvmvgKy86GsjdminDzBRtmEE4uCNybyjSZmDVZ0uUlGuAS0R 3fN1PCZg7ph9FphCTkC1PmNXf14AFv8= DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=bombadil.20210309; h=Content-Transfer-Encoding: MIME-Version:References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From:Sender :Reply-To:Content-Type:Content-ID:Content-Description; bh=GhmEmGUPN5iqiwr7bHV2cU1PJLEobcTODedxESHF4Gc=; b=QH+FHNxvkAB6h4KM2iyT9Hyvsg AfE8Wt9IRK/c15fUAWzpoE0OtkarSrAESliln8xwuU91uqBJnw3VO1ZVOQoYwX84FrKLJob4M3jMF oRjd2HOh1Yp7g+s/i/D020aM/XNuc5Ou1E5OqSB+BoPXYnmXsysVl04sBQn+hyb0r/W9HefFlUQas cX5zi8ABK7rKKEQCa4O6ZDOWajvyMxkBX+pdPcVSoLre58AnwYKNwkfkYrngCfhD9mRSaR7RQeW3j +ZFwoC5ArTW4txv7BDS1lqNVD7QtwiapVkQzDgkl/LFVurH1ZDwJQeCF5Z4DWpsunH5mT9eRUoK2y SAl/WSOA==; Received: from [89.144.222.32] (helo=localhost) by bombadil.infradead.org with esmtpsa (Exim 4.97.1 #2 (Red Hat Linux)) id 1rWACJ-0000000Fk2d-1AV7; Sat, 03 Feb 2024 07:12:20 +0000 From: Christoph Hellwig To: linux-mm@kvack.org Cc: Matthew Wilcox , Jan Kara , David Howells , Brian Foster , Christian Brauner , "Darrick J. Wong" , linux-xfs@vger.kernel.org, linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org, Jan Kara , Dave Chinner Subject: [PATCH 04/13] writeback: only update ->writeback_index for range_cyclic writeback Date: Sat, 3 Feb 2024 08:11:38 +0100 Message-Id: <20240203071147.862076-5-hch@lst.de> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20240203071147.862076-1-hch@lst.de> References: <20240203071147.862076-1-hch@lst.de> 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: yk55fei95apazh7tzctr9szx533w1r51 X-Rspamd-Server: rspam07 X-Rspamd-Queue-Id: 49C82C0014 X-HE-Tag: 1706944341-558161 X-HE-Meta: U2FsdGVkX1/ijEPVQzsn0gEEAX580QDkcUqdGCPF+RcMXHn8RaxL3j2TqmOyWfaqDt+sF/cjJCpYGCuTrhFVyIQsC51QAb2yZmGgaS3CKu1TyvomxLLON+mWDMmbMTEKx9BmcnJIKdr1KHXkOqvc+qAri6zpP+0WYV90NIVihRkxp920X3XW6ZF6ufCZw3TRHVrJdyDHTvTq9GAB3uDHadUPQSCJsrFphXtIFQqyLmyG6siiM5UmI9rTb+hAVj15wq62DJyzR1eDjxsNjnez+7H9v2P8uxNSWWPaeL7GfDyCFYnftU+x/q3fCEXuCkJF/raFlZ2CO8woWeM+e9SV6kgnF0vRNEfvT6Ca5AP2Cep9kgct2Vq+xKat3fzVjF+F0mjlEh/CCcD6zLEm7ju7ghgFTZpO9Z+1aN/XF/Q4+hHPJaKLedsE70p8yXTrnwLYTT1T94Kstf/zCQR9pppfGPtFJublnB+8a1KJU/pOcTv8EAKfWcNiaQbZ3bj2yH8oJ5OWYaSzF2FwiRND7zVbXiBggRnSGvuqjC2FcDOQs9Ppm5OWpQmOtaBrgko9uOByuuITKRG1DVJZ8gjOQXwJTG7w+7M/nFm8/pG+M3/UW37YHawA5bHDqVMWIVj6mjMKXpdgbCeogfEyT4kyHo1EoEeHjl7dD91qb74ZIO8muGkJ+Bjq85oMLWpxXwol0I8utS+1pW37MKvfM3NPhR+UpZmvwZWGcsJe33xEm46Yna79mZJ+zegX3p0CxARvBdgxGBlvyiLHdDO+dxrxz+n0Shevh143syepLkvxZropxt1de8zdGEc+2KgfvZ9FV+rHjFGMt9Ce46ljH+icycZOVhDIWJ+0xgl6G3swDVHAd1LQIC6HEpODXsaQaJVAa1WtFbCoHtwMqPKbspmq+Z0ZAanK6LoNxHdy9aSFaKfrACs9rQCGVrj+lY2/5VstbJLCPq3GY4ci4klQP6YiZ8G OvnUhNy3 lT5GDIIp0Gdv2+BUsyuEvlDP9QkmaaJI6WFl2PnKR/3GnskilVsLVY+yfyKSibowxlRh1U5ZEG3PkabyBuEpeP9lFpIur7fUMXyK8ulENwR67ob0FHxjy6/6GindbJGH9g+8idr15sdBeZeTjxzknq2hqtkZXUCCMIaTeEJOY6XUIMLr1Y8MZ2ILaVWVKtAc8Xlt73cRgu2Y0NGmbE8kukh/W+f9b3jxYESQqzGID71bKapP4hsA14VzTarPEaSHd9RF5VkGdstQWig98Mvlgt9r6xoYyXJn/fHwqyAx3nu+wq17uTu0+u+IPdnNBAVta22mtl2YrkcXFLcGubMhu2o2qlik+xp7GUDd+yt20MTDwF0XwAZjlIGSwjYCLPnroKuA/9d/CE/vcb7TikECfQNdKtUmmmBTW0j7UPktoiBZ3Zbr00l1HNICgJ70ba6PqPgXhU0Nrdjv0SaQ= 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 ee9eb347890cd3..c7c494526bc650 100644 --- a/mm/page-writeback.c +++ b/mm/page-writeback.c @@ -2403,7 +2403,6 @@ int write_cache_pages(struct address_space *mapping, pgoff_t index; pgoff_t end; /* Inclusive */ pgoff_t done_index; - int range_whole = 0; xa_mark_t tag; folio_batch_init(&fbatch); @@ -2413,8 +2412,6 @@ int write_cache_pages(struct address_space *mapping, } else { index = wbc->range_start >> PAGE_SHIFT; end = wbc->range_end >> PAGE_SHIFT; - if (wbc->range_start == 0 && wbc->range_end == LLONG_MAX) - range_whole = 1; } if (wbc->sync_mode == WB_SYNC_ALL || wbc->tagged_writepages) { tag_pages_for_writeback(mapping, index, end); @@ -2518,14 +2515,21 @@ int write_cache_pages(struct address_space *mapping, } /* - * If we hit the last page and there is more work to be done: wrap - * back the index back to the start of the file for the next - * time we are called. + * For range cyclic writeback we need to remember where we stopped so + * that we can continue there next time we are called. If we hit the + * last page and there is more work to be done, wrap back to the start + * of the file. + * + * For non-cyclic writeback we always start looking up at the beginning + * of the file if we are called again, which can only happen due to + * -ENOMEM from the file system. */ - if (wbc->range_cyclic && !done) - done_index = 0; - if (wbc->range_cyclic || (range_whole && wbc->nr_to_write > 0)) - mapping->writeback_index = done_index; + if (wbc->range_cyclic) { + if (done) + mapping->writeback_index = done_index; + else + mapping->writeback_index = 0; + } return ret; } From patchwork Sat Feb 3 07:11:39 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christoph Hellwig X-Patchwork-Id: 13543900 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 875CFC4828F for ; Sat, 3 Feb 2024 07:12:27 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 194286B0078; Sat, 3 Feb 2024 02:12:27 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 0CE216B007D; Sat, 3 Feb 2024 02:12:27 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id ED7456B007E; Sat, 3 Feb 2024 02:12:26 -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 DF85E6B0078 for ; Sat, 3 Feb 2024 02:12:26 -0500 (EST) Received: from smtpin02.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay01.hostedemail.com (Postfix) with ESMTP id 8A2BE1C126A for ; Sat, 3 Feb 2024 07:12:26 +0000 (UTC) X-FDA: 81749624292.02.DF9108F Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) by imf27.hostedemail.com (Postfix) with ESMTP id D24CE40009 for ; Sat, 3 Feb 2024 07:12:24 +0000 (UTC) Authentication-Results: imf27.hostedemail.com; dkim=pass header.d=infradead.org header.s=bombadil.20210309 header.b=DB0SbFi6; spf=none (imf27.hostedemail.com: domain of BATV+a0ed29cff9639d748e7e+7468+infradead.org+hch@bombadil.srs.infradead.org has no SPF policy when checking 198.137.202.133) smtp.mailfrom=BATV+a0ed29cff9639d748e7e+7468+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=1706944344; 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=5NQ5foZwClGdjirNb4QF1J+mdWuoRYsiFuyY0APWPYw=; b=GzmwiiK9hsAZfis70/AKgV3tvymR9JSYQ2JTYK4Mulva8VD2cYfM+bgu/+rNBZuQSFIgh6 PXlu3K9P6zed1lwAmOfAFVlIC8CrYDbQeVf3XYZ+GQLzwSxKPYbVlxn49I5H2KxQkirlQZ biAXAL0lVSD6RtHttx0cfyaTrU2UntY= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1706944344; a=rsa-sha256; cv=none; b=MxFyGXp+q2mq0Tx+dH2kJiBN2qUcvs22H+2qCX5igR6AZkghgOUR04Vod/yXsirGEi4u43 +QYZY6wGl3OejoDcQLJOeLdAT5zSILDZxdSgAEUE8+qX5eDROPM1/b3LTNAfGZYcENqlqL vA7jQxcTn5aJhZXuyvH6zfdo4WOdhFc= ARC-Authentication-Results: i=1; imf27.hostedemail.com; dkim=pass header.d=infradead.org header.s=bombadil.20210309 header.b=DB0SbFi6; spf=none (imf27.hostedemail.com: domain of BATV+a0ed29cff9639d748e7e+7468+infradead.org+hch@bombadil.srs.infradead.org has no SPF policy when checking 198.137.202.133) smtp.mailfrom=BATV+a0ed29cff9639d748e7e+7468+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=5NQ5foZwClGdjirNb4QF1J+mdWuoRYsiFuyY0APWPYw=; b=DB0SbFi6hUnk1R7j5iigmiLr5N wGakeqVDiyg/3UEtSiSGuXyTjawI0qc+3zilFXplt0yfm3V6765hxCRtqBaCEEbXRu6PmcijL0EwD ohFv1B6Ru53npud78X2mRjKDz+W8KfKClXbYz//sS9Rlej5EBI3FYmzdI0NGMiwddOLtapEwUWLxn xOakmAfp6pz1HZvZdZCjEVNJYQ8OON7wbu3bQautPLcydnJS0vvYHgPkMCCowSEe3fNMXKbop8vzO KCGYuP5WzsvA6ReigLFIw1MRl26nXVPe05zKKDjdM/xBnxIJJYynLn8OYg9q/pGoHyGTfCW9NxHyR jxtv/EuA==; Received: from [89.144.222.32] (helo=localhost) by bombadil.infradead.org with esmtpsa (Exim 4.97.1 #2 (Red Hat Linux)) id 1rWACN-0000000Fk4w-1KJm; Sat, 03 Feb 2024 07:12:23 +0000 From: Christoph Hellwig To: linux-mm@kvack.org Cc: Matthew Wilcox , Jan Kara , David Howells , Brian Foster , Christian Brauner , "Darrick J. Wong" , linux-xfs@vger.kernel.org, linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH 05/13] writeback: rework the loop termination condition in write_cache_pages Date: Sat, 3 Feb 2024 08:11:39 +0100 Message-Id: <20240203071147.862076-6-hch@lst.de> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20240203071147.862076-1-hch@lst.de> References: <20240203071147.862076-1-hch@lst.de> 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: D24CE40009 X-Rspam-User: X-Rspamd-Server: rspam11 X-Stat-Signature: n193iun53w86y76hd4ky4qqux8jkocfp X-HE-Tag: 1706944344-444210 X-HE-Meta: U2FsdGVkX1+TTNxBlvDJg4v7+jFxzn8UDIKBM2x+8Is7EGte4kOfDBmA9EfcC646QsPg5roZy3wvNVGi4tlzlNV0NNT9AaPENrTVwOXupRmADNSUH70BPFSzJI5mSyXj1obmPx6eEWhet3LwQnZgei6zxVk0CTR+7HueumQWLUDOQz86mxlnshjAB3vGL/51/s1Jo4sawzfhfIsinrTbfl/got4NspntooI6qe6KRqK7g+tT8ZDckNKPZVZm5iPDNA+UNIXvbGd0aTgXIsGshHCjs8BEDi9iMQY9ycda1jIAoZ58OYX6Iou5R5us36SpafH+rhi11cP2ewlXt5sHxxlOdjBzuzmwCYWolqw5Lz9b4QTZbaU4Z11EHn1Ex2lNN2U4toCCJPg8kUnkBYEpv4X5PT93uUcKc05aQ0b417aP/hGONRNAJ5NRHKigzoLe5F+RjWTipI+LJHEz09CZflcKWCfG7s82+l9pUPkTRMvy6OEd+7kQoWvq9VHVTVy2zOJWPpxRkK8YLu+SSSH6LdKmxHr2NUFKwPrM7Dy2h8JSkCBRvMOsQlB3uwcZ25bfV/WymqNOFwiQUvGbIvxwKTQxahfR3joys66giSISer/wqC53jXHMfAw0ultL0htusuphjqa2M9/h9GE1+CzPMLlDaf2It53bHc+8t64osaBbf1lT3W6Y7M1Ft2glJWmK/iX1bP/ba3VWPRi+mWqx9YSzXV1+5n5Jlulq0PUAlhjOPEUvCu57s/Dii5JWHWy4Dg/Lh2jM6h3XJYeddclxFPKFeorKx4j2owA2Yeo3XADWyEnU8urW4ZJIvyA0i+UCxToXHKU2JVioPb3+XNSKFtAkLpcu5iVzVYrVhcC7tsOVctPt4ZiYwXYmrh2ZeuCi3+FJjUM9BfUcwpOgafxQBQR/M9eA4aZMV568MhsOjAHAeGA2iirP7tJl1noSQJq/mnz7+I2c6IzKaPsNwo0 FDWtoPqy rtZAAsHYI8l8ktIcLp6FXP+3iajJg0TE1P0/BztE8Ehor5owyEivimyKoLikhnhWq4kB9ugbiRa0usa1ydh/z/j0ckvqUqQMiomsImlJvERgxFr0aDOPABJKsEGmnv8X5g4bIKrN3eK498UPSYi9LLuCUyAfudQ8YhFvlP7mqVzP8R2usPyaTOCS85U7m7GbqZUAUYymXUaAD4UNgO8bE+KClhjzCx4AItwvOAmGvw+nfQqVkEjq9f095bBVSK+RHzCYTyzp8PXqSGk6Fz2hTJjGmGvbkKPo9cqNUJq9Jk1L7vz83adUyzlJury2+DYQRD+0ZTwF/juITasmYH0ggCGQ1HAVhb9f7sSlLvyrVsr4JxkfhuzoJHGQdoszSi/b4KtP7/scshwI3vrRRNnHXuIovIHh2IRuujvhU/H2xx+PByk2dbSlIlkw3vg== 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: Jan Kara Reviewed-by: Brian Foster --- mm/page-writeback.c | 84 ++++++++++++++++++--------------------------- 1 file changed, 33 insertions(+), 51 deletions(-) diff --git a/mm/page-writeback.c b/mm/page-writeback.c index c7c494526bc650..88b2c4c111c01b 100644 --- a/mm/page-writeback.c +++ b/mm/page-writeback.c @@ -2396,13 +2396,12 @@ int write_cache_pages(struct address_space *mapping, void *data) { int ret = 0; - int done = 0; int error; struct folio_batch fbatch; + struct folio *folio; int nr_folios; pgoff_t index; pgoff_t end; /* Inclusive */ - pgoff_t done_index; xa_mark_t tag; folio_batch_init(&fbatch); @@ -2419,8 +2418,7 @@ int write_cache_pages(struct address_space *mapping, } else { tag = PAGECACHE_TAG_DIRTY; } - done_index = index; - while (!done && (index <= end)) { + while (index <= end) { int i; nr_folios = filemap_get_folios_tag(mapping, &index, end, @@ -2430,11 +2428,7 @@ int write_cache_pages(struct address_space *mapping, break; for (i = 0; i < nr_folios; i++) { - struct folio *folio = fbatch.folios[i]; - unsigned long nr; - - done_index = folio->index; - + folio = fbatch.folios[i]; folio_lock(folio); /* @@ -2469,45 +2463,32 @@ int write_cache_pages(struct address_space *mapping, trace_wbc_writepage(wbc, inode_to_bdi(mapping->host)); error = writepage(folio, wbc, data); - nr = folio_nr_pages(folio); - wbc->nr_to_write -= nr; - if (unlikely(error)) { - /* - * Handle errors according to the type of - * writeback. There's no need to continue for - * background writeback. Just push done_index - * past this page so media errors won't choke - * writeout for the entire file. For integrity - * writeback, we must process the entire dirty - * set regardless of errors because the fs may - * still have state to clear for each page. In - * that case we continue processing and return - * the first error. - */ - if (error == AOP_WRITEPAGE_ACTIVATE) { - folio_unlock(folio); - error = 0; - } else if (wbc->sync_mode != WB_SYNC_ALL) { - ret = error; - done_index = folio->index + nr; - done = 1; - break; - } - if (!ret) - ret = error; + wbc->nr_to_write -= folio_nr_pages(folio); + + if (error == AOP_WRITEPAGE_ACTIVATE) { + folio_unlock(folio); + error = 0; } /* - * We stop writing back only if we are not doing - * integrity sync. In case of integrity sync we have to - * keep going until we have written all the pages - * we tagged for writeback prior to entering this loop. + * For integrity writeback we have to keep going until + * we have written all the folios we tagged for + * writeback above, even if we run past wbc->nr_to_write + * or encounter errors. + * We stash away the first error we encounter in + * wbc->saved_err so that it can be retrieved when we're + * done. This is because the file system may still have + * state to clear for each folio. + * + * For background writeback we exit as soon as we run + * past wbc->nr_to_write or encounter the first error. */ - done_index = folio->index + nr; - if (wbc->nr_to_write <= 0 && - wbc->sync_mode == WB_SYNC_NONE) { - done = 1; - break; + if (wbc->sync_mode == WB_SYNC_ALL) { + if (error && !ret) + ret = error; + } else { + if (error || wbc->nr_to_write <= 0) + goto done; } } folio_batch_release(&fbatch); @@ -2524,14 +2505,15 @@ int write_cache_pages(struct address_space *mapping, * of the file if we are called again, which can only happen due to * -ENOMEM from the file system. */ - if (wbc->range_cyclic) { - if (done) - mapping->writeback_index = done_index; - else - mapping->writeback_index = 0; - } - + if (wbc->range_cyclic) + mapping->writeback_index = 0; return ret; + +done: + folio_batch_release(&fbatch); + if (wbc->range_cyclic) + mapping->writeback_index = folio->index + folio_nr_pages(folio); + return error; } EXPORT_SYMBOL(write_cache_pages); From patchwork Sat Feb 3 07:11: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: 13543901 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 DD968C4828D for ; Sat, 3 Feb 2024 07:12:31 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 64CDD6B007D; Sat, 3 Feb 2024 02:12:31 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 5D57D6B007E; Sat, 3 Feb 2024 02:12:31 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 450886B0080; Sat, 3 Feb 2024 02:12:31 -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 322356B007D for ; Sat, 3 Feb 2024 02:12:31 -0500 (EST) Received: from smtpin10.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay07.hostedemail.com (Postfix) with ESMTP id C63F3160455 for ; Sat, 3 Feb 2024 07:12:30 +0000 (UTC) X-FDA: 81749624460.10.D4A517A Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) by imf17.hostedemail.com (Postfix) with ESMTP id 26BB140007 for ; Sat, 3 Feb 2024 07:12:28 +0000 (UTC) Authentication-Results: imf17.hostedemail.com; dkim=pass header.d=infradead.org header.s=bombadil.20210309 header.b=QtHTeuf+; spf=none (imf17.hostedemail.com: domain of BATV+a0ed29cff9639d748e7e+7468+infradead.org+hch@bombadil.srs.infradead.org has no SPF policy when checking 198.137.202.133) smtp.mailfrom=BATV+a0ed29cff9639d748e7e+7468+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=1706944349; 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=jfeyOGGqJMEhwjwDWY78Dxs/MD9XWP1Zn49OkkJuspU=; b=RX0ofPWOAKlahAOKfTcnS8/s3QHzSh4lHDt9/et4CGJahtybLmF0nzPpEFEfvsjQ3M4Uhe xDy3GgsjJrjVBdGd3xPpVdOCBYV6M7H5dozh+eEuVo18Qd6Moby7wQ1eDxrpsAfFObvRWT w9hC8qZhOD5U3Oe7eIfC3ev6VGstZjA= ARC-Authentication-Results: i=1; imf17.hostedemail.com; dkim=pass header.d=infradead.org header.s=bombadil.20210309 header.b=QtHTeuf+; spf=none (imf17.hostedemail.com: domain of BATV+a0ed29cff9639d748e7e+7468+infradead.org+hch@bombadil.srs.infradead.org has no SPF policy when checking 198.137.202.133) smtp.mailfrom=BATV+a0ed29cff9639d748e7e+7468+infradead.org+hch@bombadil.srs.infradead.org; dmarc=none ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1706944349; a=rsa-sha256; cv=none; b=kWueTmOIzPX7TUb0yLKuJQ6YUqe3QwzZd58irOyO1UeiAGed3xsj9zog32ARBB3OGh+EDJ cv3H8F33LCfTTdcTAZZXr8pVZc+cRsrbzOGV4p3pFf/QxVPR1r4prUeMYR+ECiqGBTsLtl aUoa38+NYHCMaAVfvLQl32WCoo9VsKY= 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=jfeyOGGqJMEhwjwDWY78Dxs/MD9XWP1Zn49OkkJuspU=; b=QtHTeuf+5e3JSMI6nOmskVdXn2 G8jz9FhabBgFanvh596iAi7noXgATwCi8VOdtCyLoUHl0L23Nt+Egfg2/qpZAHF/W78ZpJNpLkMwB tWjQjqHjUneWK8LK2zuwoMrnCEyUN+CmhqZ4ZRSFYbptSY4swVURu/4e3Wboeen9MkaDWNvQqFMcN dJYtx4TWqYx60UTzX1pE7h6Qqr6AZd0lfbtQep3EuRDdIA4AR7a8KjkW2ll/n7LfL6rU4nSfL1ow2 tWQyVWXrjWKzWGksYBzaHtM9g2dn5LHuKdQbFjjcm3XvN0izvhzgH9QM6RVm05E3b4IZ19SOjZh9w dmh0Pezg==; Received: from [89.144.222.32] (helo=localhost) by bombadil.infradead.org with esmtpsa (Exim 4.97.1 #2 (Red Hat Linux)) id 1rWACQ-0000000Fk6W-3iJc; Sat, 03 Feb 2024 07:12:28 +0000 From: Christoph Hellwig To: linux-mm@kvack.org Cc: Matthew Wilcox , Jan Kara , David Howells , Brian Foster , Christian Brauner , "Darrick J. Wong" , linux-xfs@vger.kernel.org, linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org, Jan Kara , Dave Chinner Subject: [PATCH 06/13] writeback: Factor folio_prepare_writeback() out of write_cache_pages() Date: Sat, 3 Feb 2024 08:11:40 +0100 Message-Id: <20240203071147.862076-7-hch@lst.de> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20240203071147.862076-1-hch@lst.de> References: <20240203071147.862076-1-hch@lst.de> 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: 26BB140007 X-Rspam-User: X-Stat-Signature: mprr9rymncih95ajw3a3yf3rde4koozr X-Rspamd-Server: rspam01 X-HE-Tag: 1706944348-228409 X-HE-Meta: U2FsdGVkX1+ZElTdqTLhRtUSUbj/1iqv06hya77DjTZqxg9tgUw3pnxmfk1E+QEIMf+b1Jw2ewZ6IPEX00l8/Uwi/aQ/vGZI7cZzzn5vWGgzd2lKPWzTRUo7c6Vk/uuQLoR/q9Nn27KJRxDX446Zgq7uUEbkv3JO0wuKl7nl2VsTtUn5E2X0fhzIQlHWI7kMDgbWNLdiNTS3fvEbjbRzV8ahIBv8OAv+ev5NrU8joXU+lR/iEfOZAqANqMkJIjXPiN/RWlew8ywzC21OTajIeCQ14WpEI0h9iPYf1TOMpo2ePqTxLqIARB2IwXnEcA9D95SWGBZD/SkVkbLAerONaPvaIi6VFLss3KXQwh3i9Z8TT9mF1GpM1IZ+mCANLcP0/da1g4xH2J61lDmUN/ASsNXa9Kkv2LsXDSrIO8InXEq15kYFj2vtCTAyqU/kfS94Fs0tkTvHxtkETPBaOGm2cQTAHe2bhCYAdKHgWUGpk5/NJ6OBS2sibsn1S3jxvADXaAS+nYRWGq6GgSF7AawEsMzd32Y99csZ2qpgF1gQgjkw7/xkk8HuHlzLhiH63zWL+8dlHuyOsh/xL8kYL2xyJ3p1+aXoelzZl+gqx/hwciQe1UPyveK/l8GNS7Vy0L0GHK+S8c4Z/5KZuMHgMVDG8sxXiYtOsI8guiqFgQQTyRVK85UWtIgfovsgmR4YGnFZ+Ok88kcfS6ixZFHJMup/BTQJWnt0HSJ3yYiugOH1VJE4K/mTfRAFEbwyUxphYf6afQDv4g6zGwfbVvxEoXtGw4E+pDMatyiKSTcp7S+ed9JDUGfpLssr/ntwmp7Ij9LnELQ4kp7LXOZR5ZsaphnfoioDEE9AcQXlaotdSZGEYqXYQNbaSvGMlUMAXWzIuhtRcvnXwu5fRSZJ4aoRZgdzdYZoGRuAYZSJg7ZMwNeDMynOjkCTLwPIHo5cNUOEd4X882p5E2jRVqvZjBCFK3U Npnb9U1J SE0YWvPRc4JXEBT8XertYGwhrGQHMD6tzFgtidhUZav375d1PdGaN92ZhfaNgpXEFe92QkSiiNqhtDbYLAeAdXAiRFyPjV85ZWPzfIMxzQ58BtluiS4/dvcRQ17DTyHApai9sD56qRcz8TExLCVB4hrcxWHH/17k8PwV7zgcQnzJ/ZoHlpUkok9Pv8nfF0+TE72RXRRJKtuTE3AWRMA+K+LeuBnTLGwt1V+ufQspwFq3of/S/TBQcN4joHB0yzannR5xRliXRa4ZYD61phwh3qXmrMX+SDziBo6Ld1eTO6R0hELb2zcznaKReazbJNh99vpx49lZjhlthqzvQzaS9UYPuTIf4ni7MRB5HrQoRu3esX62ZczX28extxpiZzJ5ZiYJdPw/BMK7ooD143IKUC2f3eMTEo9Dh3QL7BFVFVLazPdDffY7cJhZ30UVjGsVnckoov/3HSYnFPmXZw4wNjPCtJnJmaODK8GDAO3kLSOx0UfKYkn5cYRYstFAuyGQTgHGWRQkcHhkUICU= 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 88b2c4c111c01b..949193624baa38 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 Sat Feb 3 07:11: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: 13543902 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 87B03C4828D for ; Sat, 3 Feb 2024 07:12:35 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 11F626B007E; Sat, 3 Feb 2024 02:12:35 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 0A75C6B0080; Sat, 3 Feb 2024 02:12:35 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id E62016B0081; Sat, 3 Feb 2024 02:12:34 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0013.hostedemail.com [216.40.44.13]) by kanga.kvack.org (Postfix) with ESMTP id D48296B007E for ; Sat, 3 Feb 2024 02:12:34 -0500 (EST) Received: from smtpin18.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay04.hostedemail.com (Postfix) with ESMTP id 96E3A1A013E for ; Sat, 3 Feb 2024 07:12:34 +0000 (UTC) X-FDA: 81749624628.18.89D2160 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) by imf18.hostedemail.com (Postfix) with ESMTP id F3B251C0014 for ; Sat, 3 Feb 2024 07:12:32 +0000 (UTC) Authentication-Results: imf18.hostedemail.com; dkim=pass header.d=infradead.org header.s=bombadil.20210309 header.b=ZpxFIRF0; spf=none (imf18.hostedemail.com: domain of BATV+a0ed29cff9639d748e7e+7468+infradead.org+hch@bombadil.srs.infradead.org has no SPF policy when checking 198.137.202.133) smtp.mailfrom=BATV+a0ed29cff9639d748e7e+7468+infradead.org+hch@bombadil.srs.infradead.org; dmarc=none ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1706944353; a=rsa-sha256; cv=none; b=6vlCkyPgShnK3NUn51vWRaTWoYNqO8qF0Ozs5XV+LJPWte6OarLJXWiga+XvG/yW8jJEUD 02rGYxnSSfYk6Wm5iIFq6AWlJNmolXA7RUqDMf2rzcrT4BdDGLQUGY3UgJqC/QLCQ+645u L+nl26azg6w4i1/8IiGd1/VAc5a/Igo= ARC-Authentication-Results: i=1; imf18.hostedemail.com; dkim=pass header.d=infradead.org header.s=bombadil.20210309 header.b=ZpxFIRF0; spf=none (imf18.hostedemail.com: domain of BATV+a0ed29cff9639d748e7e+7468+infradead.org+hch@bombadil.srs.infradead.org has no SPF policy when checking 198.137.202.133) smtp.mailfrom=BATV+a0ed29cff9639d748e7e+7468+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=1706944353; 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=e37EqS2ZYYTeeuRHGuEE+Jp38DFAOi6vK8cHvx3Jpt4=; b=chdsZQSWdRf/urmTl1C14wHICnxc78R6HEuJwoGk8OeRUlRWt74YF1IxDCJfDGv7oKldvR rJTZMLl9vUEVcMLBgAERuGAvvXgC4gk+pkN3BwYdnRvwpTj8l0oxoncfJqISEsBJGrUC6s Mcf0x+VcfLiKy8roMeXqyb/UYXv3fAg= 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=e37EqS2ZYYTeeuRHGuEE+Jp38DFAOi6vK8cHvx3Jpt4=; b=ZpxFIRF0rwjTTxnnah1dH4r+g/ N+x8kCIzZ77fhJadth50deaJ77t6djMUAPPcuUsG1BbnsxFdWYEzisaWKSgIBC8xV1DytPxrky3Kq 4Bmxmc3DKJhdTBatFBqeQFMkzLwlbU0XxvcSsuXqZqOCepbKrwmBI3VW1YMpzQanXhV/rM5cjAK4n fNlo6Cd3ftcE74+bpOHcLUbnwvNg2EgWBQqWeGCkHKvr+yDL9l9MwidQlkyhRbp2WGHa63Zz95LHJ vaMEze6Ezzq8d+IedDrC8ow1o8kZucRlgXIPTCXgpzDvwGD0AuTEHieil/ddDKnJ6ZHMijpArgbhA gVVCUrpg==; Received: from [89.144.222.32] (helo=localhost) by bombadil.infradead.org with esmtpsa (Exim 4.97.1 #2 (Red Hat Linux)) id 1rWACV-0000000Fk90-2Gz9; Sat, 03 Feb 2024 07:12:32 +0000 From: Christoph Hellwig To: linux-mm@kvack.org Cc: Matthew Wilcox , Jan Kara , David Howells , Brian Foster , Christian Brauner , "Darrick J. Wong" , linux-xfs@vger.kernel.org, linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org, Jan Kara , Dave Chinner Subject: [PATCH 07/13] writeback: Factor writeback_get_batch() out of write_cache_pages() Date: Sat, 3 Feb 2024 08:11:41 +0100 Message-Id: <20240203071147.862076-8-hch@lst.de> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20240203071147.862076-1-hch@lst.de> References: <20240203071147.862076-1-hch@lst.de> 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: F3B251C0014 X-Stat-Signature: 4jxe4xw711qg5bxb3mj38pmf8sh1we86 X-Rspam-User: X-HE-Tag: 1706944352-106237 X-HE-Meta: U2FsdGVkX19qNYMnhQaLp3BlTSFImPYwoc7jvHkcdwXJ0ygIkyTr3U2uuObthRu6k5WXf9vVIg/DZDkmkFzFA5pWtb1ex+jJYlRLepCm++0Vl3fefP5WcH39NMWPUoGyRf8YeTuTi9qHquc2GP3UPvCftsOeSC0NWqXCLB+hoZ9UF69hw0HNZLe/hs3CN+YtCCR+BZniybSwjELFLBhSqpBJcHIHKaFd1oL2KfDSoTSQAFMsLFcRIl2vqSXvup/fK3KeGB3DdkKT8lZ68jsbEb2g39yVXrccyKoPzmXdo6uR/1PNc3mbNypuEzBS3PuBPC+pUnqKMEc8vsifnSfANOToqkEAEvH6sh+W9hwl9gHH4YfywOKcx/YBNiTv2C95WqQkF6pdDwZ28acX7YpmeoYjMsicx3r9jijOXvjii9u3oNuYu4uk6XZK0P0gLLwQG7c6axr3dNvXpQ7BJNTw13YV1v0UFgdxsX1B+Mf73LJF868NzIeD6ESudZnSm4NBTATj5HZeQo8rgXrE1zr/ru41kTLOftYo+lfjQGoTV/rGoX+3svud+c6Z6XJp6dUgAc7Y/iRj5p4DfDEqbgpnDD8HRwGo2MBCp20F2y7gbTZ9BOJ852iiPIryhVWQuTLy0EmNUP04A7mecyNvFIBvxaxcL1Iu7WZZ1lylLZ2HUe/KU2iIQuwW52ltmW7KJC+PoaAXs1jfsZsTjlmFj0BEl1gpfmRAxel4Ls43FNHAQILCxPF9kAW+hr7iLB/cHTCFpmKZMJ165wjVXdbDi/uq2mXRzekaXpz6NNwyos99r9rHaXVy55bou1DtWK9XNgOz6TUg017kwwnm007+SShY/LWXF9a/xFjuIVQD24bvReUOCpv5XbYoQazQ8WGSLHFCG0ys2E7p3DwfG3RQbbPPJ6T7crMOYUIK832rX3kWaOVu9jGNPu/k36QwIL01329SLEUvydaZKhZSAjhc08n CNbtEghB kVQDaRGLFXWriB+Ew0VU2B79ngdJc6+FciDM0c5bTlptX6qWGfzyXpFXkA2kwvnWfeY/nYopJTyrplt6gA+LEDMKwYlrNsfoa0O2KaEjg8VuyGsv2rxfHJo54uOYL6hzqaBnnUkAcX9zDM7ZTu5LVfFTciZgliGKcGYxF12ffh0G6K6H86QaLAZfJ3F2CJ351a5HIGT4X+pgWhu/0f3c2Cgs4fI6KzEaYWXWZLXC69fM4AsV5lswJuB1rx6EYs31zBzKtXzSiWQrk3HoN7MT07/gCFbXhwxz9JtvgXaRU+7+OpO8qNdUzxp2zvJglnD9YTQcYvuZp0bItPpl/2QJsjZfqKDYk+h23r6sHe4GhZDzryAuSxkzAafE853eASB8zBamxd/ohKgL+ItVhhxx2cRcOq+jwPQfpDThLXoZ93TC4rqpDbV2j5sNut9JlfccvFCM3EpbbhxisUsP5Mjd47TjgB4j0PXHl+KlTAGxAaAVzQ6AEOJu24RgTCt72/6FqJPVgsA5H02NycMbZYjGkBIchm3bgEzhC79mRROBfEbDgBcs= 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 949193624baa38..23363ed712f646 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,12 +2527,13 @@ 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; done: - folio_batch_release(&fbatch); + folio_batch_release(&wbc->fbatch); if (wbc->range_cyclic) mapping->writeback_index = folio->index + folio_nr_pages(folio); return error; From patchwork Sat Feb 3 07:11: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: 13543903 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 EBE64C4828F for ; Sat, 3 Feb 2024 07:12:39 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 340316B0080; Sat, 3 Feb 2024 02:12:39 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 2C90C6B0081; Sat, 3 Feb 2024 02:12:39 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 1425E6B0082; Sat, 3 Feb 2024 02:12:39 -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 01CA26B0080 for ; Sat, 3 Feb 2024 02:12:38 -0500 (EST) Received: from smtpin28.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay08.hostedemail.com (Postfix) with ESMTP id 924821407A6 for ; Sat, 3 Feb 2024 07:12:38 +0000 (UTC) X-FDA: 81749624796.28.8894E38 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) by imf02.hostedemail.com (Postfix) with ESMTP id D3D2F8000A for ; Sat, 3 Feb 2024 07:12:36 +0000 (UTC) Authentication-Results: imf02.hostedemail.com; dkim=pass header.d=infradead.org header.s=bombadil.20210309 header.b=BZP6RRlB; dmarc=none; spf=none (imf02.hostedemail.com: domain of BATV+a0ed29cff9639d748e7e+7468+infradead.org+hch@bombadil.srs.infradead.org has no SPF policy when checking 198.137.202.133) smtp.mailfrom=BATV+a0ed29cff9639d748e7e+7468+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=1706944356; 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=YJszH51EwdW2rUwhJ/fmC9DInqYvSSbYnjASxDZKqZ0=; b=nzT8Vudj2ONGOFypSm0mVDn9zT5Ibd4e8/qDYfz4/QI6XgNQvaGzzrdCjn61EM7CwOGu9U NiwM2WTFmY2mbxu90kkSMx0FalrLjKU8TfsLWsiWsOUqNdwL/DK0LUYTTTTDG+KGNR9ed2 zs3U7qBcKBetCsDGb7q260hqM9JV93c= ARC-Authentication-Results: i=1; imf02.hostedemail.com; dkim=pass header.d=infradead.org header.s=bombadil.20210309 header.b=BZP6RRlB; dmarc=none; spf=none (imf02.hostedemail.com: domain of BATV+a0ed29cff9639d748e7e+7468+infradead.org+hch@bombadil.srs.infradead.org has no SPF policy when checking 198.137.202.133) smtp.mailfrom=BATV+a0ed29cff9639d748e7e+7468+infradead.org+hch@bombadil.srs.infradead.org ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1706944356; a=rsa-sha256; cv=none; b=oblnFBc/49LC2T5+I2ubXeFMSE2jqhiRaUSYJAmQx1usC/XF7EiA3jQCQ6wecNUa8NEVMA 1AK0O+Wm6cQjpErxZloDjIDrdhq+weCXW8nr+6kpNXRHMDN+dGZWL+gpEkZ2PN4yHXk3m3 9s5jM72rT1LEBR6LnvlCQp9UvM2o/xg= 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=YJszH51EwdW2rUwhJ/fmC9DInqYvSSbYnjASxDZKqZ0=; b=BZP6RRlBDDpDvPXciqWZlZGJn5 oC+v7sIzJvcs21tF8kJfjVZUxi+rlyNMkbXo9XyOmN+I4iFNmzmF8RE4x6Adbipm2iFwKH0YFjQdA 9/nlcT5ORYA4i24NEohIRXfYMQHGG+tKQIlh8qPq1VUBvrwNdgJLkGI3T+hb+i9GBglSUhcAxX9Xq 01aj7FFKMTuwF5eQBQl5BVoEFAIoOLYL7DjnFNlp/5NFpxywbU++nEGUH4m1TKZzgN5N+mKnfs/jO LXaUZ4bnnWLEsSjwcWKrbME/Fb2QcL2hF3E4KWQ0BaYNZfCcRv1Ee/5ZlvfFK9xbwIOfldgQwV1Gx JYbz3wYA==; Received: from [89.144.222.32] (helo=localhost) by bombadil.infradead.org with esmtpsa (Exim 4.97.1 #2 (Red Hat Linux)) id 1rWACZ-0000000FkAd-0VnK; Sat, 03 Feb 2024 07:12:35 +0000 From: Christoph Hellwig To: linux-mm@kvack.org Cc: Matthew Wilcox , Jan Kara , David Howells , Brian Foster , Christian Brauner , "Darrick J. Wong" , linux-xfs@vger.kernel.org, linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org, Jan Kara , Dave Chinner Subject: [PATCH 08/13] writeback: Simplify the loops in write_cache_pages() Date: Sat, 3 Feb 2024 08:11:42 +0100 Message-Id: <20240203071147.862076-9-hch@lst.de> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20240203071147.862076-1-hch@lst.de> References: <20240203071147.862076-1-hch@lst.de> 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: D3D2F8000A X-Rspam-User: X-Rspamd-Server: rspam04 X-Stat-Signature: rd9gxstn8tx3xapfoqe57t3qi5qx7b4r X-HE-Tag: 1706944356-767737 X-HE-Meta: U2FsdGVkX19jWG7YmYNTijXa2vShesMiNuuS/+gCn6hnyWVXI7fIK3bHdZaHHfLXgbkW7MzBW1LCVXi0yqPMzygqlNplU09GTa1DuvXmMmMQl45A8c5IQzebAbTggb0MglNAwB9Zzs0WBfQg7nF0z8a6bYgMJaPf4YQ+krCFoDlh8Un2dKtM6WX24pSbdIq7yFDABuy8V4CZKjVbuH3Du/h4dMoEYXCg0vdOMD978WyCvsLbIm28YsC9kMH8CvUtgrms8AgpHmzkV7jz25VKM+iTPKS7NOnuBd0BBLMN0twJ2Jxc9vqwjcwz+p5v+MMtro+3NkdPxsbdrM3dG91NPntCYrdJRypDNT7v2wjfrwKMWunXZib7SwNidQJUfqxBeX5MgHUxhHxV1S5zNfBJ7ZkU6G7Ahxdu/LMWSXSAzaKhJcp70ElXJ+IdInbdbkytsRX6mWaZRv7uDgPshqEJqAh+NRlhVgrH5nXsKty1vAx32pspNN1wbIvOW1gRRIsCoTjQgDPNFxmzOH+WAh9s+o9do+qonB1d+F9cRJh66FMc+4BOBwyz4bUozeY4DnOFG1w2dZGhz+Cmnvt9PY+4IxuiAvbZzvA/0/+qHPz4vSk7jhNKb8IFFY1aReO5sTatrzsODEW8rLlU/OHJu50ISeZ42GtEkQQ35dylPKGOSoVd3xF2xmcP9x0LhRj5HR6AToNAmzyYUToJRahaSDN/dUw8CQAtdpdzoioCr470zbzxc+UnQv4IcL1J+3neeeMyPRgDvJuz70oWf68bldgLzwLjHlPUIi3uwxIOnuf1f9tMgvj3pO9wtAF34w/gjW1sxln87V75/vT9T7UL1XHjHTl5aepxsCSa6D1J78Ii4YSnZY2ObOB+oWXONCKNYsMHUTb7bLyoML8Yghmxm/Zj8squqrVjXnWEGApD1kB+mmNrjCOZbeyHoKYQCuRmfhnZWVWKBUABg/s38tRDP2g IsGozzP1 7V/vD3PHhEVZVOjKOGpWwnixC8sTm/y4JPJob0MgbMxLMZktEt4lKPZt4B/B8KLJEYu00bFwxRgNKvcBLghCQMCks8jTIPGiW0RhbmeTdHY4E1JMtNXL9dcjFYBWDm7Y17K/uymFex/TfGT2h8S6918lhVCLv6w726p0ONx0MMSyUA1o6wkIPeeyUtB6TGesZ2cxA3sc5M2lxuNlhx2VO7yd9jhGQfd+ww+ZcHZgcn7m6U2dGWaxaZ7r33ep/pAPkxVv4GAzPPNLPSsSOwY0i4gQxbCiGrRZewdOvXq2eqFPKFUPHvK8jHCAovWvwswRK64ih/LPXA52czU0HR+awM5Krsgcb1g1bJHaF43QHkqn68ukSWdTOvtqV6yJx4h1pliUEz7SubueN6YDC7/aGPgJhiMlTaPB3wywTHcmbQhhFWASq6n4zya+YV5EJtv47YRa7cuJz4jyl0f48YwcEsK1OP2AKywRKkCHzEQP1DydGRmZ2nNwio50P5vo7Ql0AqTVMzLET75uAz5U= 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 23363ed712f646..d7ab42def43035 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 Sat Feb 3 07:11:43 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christoph Hellwig X-Patchwork-Id: 13543904 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 06C8CC4828D for ; Sat, 3 Feb 2024 07:12:44 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 8E4C16B006E; Sat, 3 Feb 2024 02:12:43 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 86DA26B0082; Sat, 3 Feb 2024 02:12:43 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 6C08E6B0083; Sat, 3 Feb 2024 02:12:43 -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 54FB86B006E for ; Sat, 3 Feb 2024 02:12:43 -0500 (EST) Received: from smtpin04.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay02.hostedemail.com (Postfix) with ESMTP id E754A120332 for ; Sat, 3 Feb 2024 07:12:42 +0000 (UTC) X-FDA: 81749624964.04.D8EB3CF Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) by imf05.hostedemail.com (Postfix) with ESMTP id 41E2A100005 for ; Sat, 3 Feb 2024 07:12:41 +0000 (UTC) Authentication-Results: imf05.hostedemail.com; dkim=pass header.d=infradead.org header.s=bombadil.20210309 header.b="0/r+7dmm"; dmarc=none; spf=none (imf05.hostedemail.com: domain of BATV+a0ed29cff9639d748e7e+7468+infradead.org+hch@bombadil.srs.infradead.org has no SPF policy when checking 198.137.202.133) smtp.mailfrom=BATV+a0ed29cff9639d748e7e+7468+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=1706944361; 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=zlWvshgk/KOYVW7wyhRP96jn/OI/viTAD8kHhWtavmb7fzLCi8uRLYPg6T/BLA18t+MgI1 mOjIwj3rja1RwW1xXt5FjbI+E/ad4sdYzGFZaX4MyLc+CxvT3eM5jRlluiIe+whGNP1Wxm zKZwC4VsE4hDEmGbE8p/dNqX+bURcIA= ARC-Authentication-Results: i=1; imf05.hostedemail.com; dkim=pass header.d=infradead.org header.s=bombadil.20210309 header.b="0/r+7dmm"; dmarc=none; spf=none (imf05.hostedemail.com: domain of BATV+a0ed29cff9639d748e7e+7468+infradead.org+hch@bombadil.srs.infradead.org has no SPF policy when checking 198.137.202.133) smtp.mailfrom=BATV+a0ed29cff9639d748e7e+7468+infradead.org+hch@bombadil.srs.infradead.org ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1706944361; a=rsa-sha256; cv=none; b=WsNcc0bQdXYDpc6g5qVteU00c6xIem6y09eWiYp/3l71y1n36pUx95PQR4tGtlDmJvfUZY CDyvPFYfrv/iXCD/lI0uknODK3T1vs6Xr6XY/Pl/pRK6g6C6WoJQsg44eldoBsCBdlr1VZ 2pwhTavc65Aa0XEqF9+FtZZaDUPNs8k= DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=bombadil.20210309; h=Content-Transfer-Encoding: MIME-Version:References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From:Sender :Reply-To:Content-Type:Content-ID:Content-Description; bh=M5Qvp5zNKGHXjXReg58hQjrWh/GgxzXP5maEkxrO/YI=; b=0/r+7dmm43M5Dn9pI478JvAC/4 oMa4a8isH3iYu7/DiNuxK8ticsjuP9iB3tDFkuLLDpkg6dtFVtGZrup7ew7Rnn5OM2HIv9tS6RfwK LqawRXjuztB1xFtFVyxTQO1HlsxCukxD2MXQPsnIdK7arkvSvDEEZFNyL7beFqM3neAWYFUFJ2s1C rXejoAV9Dgdly36z5qeDNo2SknFWyn45vn2vzB7BwJXJaJ2MzKYi37Fk32ni74PE30b7+Rqi/uaDS AvC5hBjkd/pVjcP1eTjIgMojnI0ey9H2nma+pU9cepPu814Hc9/zTDPLloxTU4xB4yUYmcDRrLuB4 C+xJMSdQ==; Received: from [89.144.222.32] (helo=localhost) by bombadil.infradead.org with esmtpsa (Exim 4.97.1 #2 (Red Hat Linux)) id 1rWACd-0000000FkDE-0QIe; Sat, 03 Feb 2024 07:12:40 +0000 From: Christoph Hellwig To: linux-mm@kvack.org Cc: Matthew Wilcox , Jan Kara , David Howells , Brian Foster , Christian Brauner , "Darrick J. Wong" , linux-xfs@vger.kernel.org, linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org, Jan Kara , Dave Chinner Subject: [PATCH 09/13] pagevec: Add ability to iterate a queue Date: Sat, 3 Feb 2024 08:11:43 +0100 Message-Id: <20240203071147.862076-10-hch@lst.de> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20240203071147.862076-1-hch@lst.de> References: <20240203071147.862076-1-hch@lst.de> 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: 41E2A100005 X-Rspam-User: X-Rspamd-Server: rspam02 X-Stat-Signature: us4a5i56ugcuzxxgkbkgmzty7m6zrigs X-HE-Tag: 1706944361-930588 X-HE-Meta: U2FsdGVkX1/wm1A4G/UHybX0oNSAyLFObAhN62e7Xcm7ngiSVHM86WiPsJyc0s1kDhyngSX/6phANytSl2f1L+qeka6ARMhAn7pelY12e3t7qBJfy978xzP5nyZFDS254xeX5/2B1p5Fvaaq8HkwqY8v9HF4VH2DB5CG+QTs4FQx8t2ULxBcKm57oLFELbXlsTD9DMkQ96OOhxUAYTIIYVTFVTDXOoEehv8SoJZan2rxq+bDAynZZ11dT9DNzbXmBf5ZeIzVuKFmxaxgMPvkUOyAecSKmZJeiYhFVtuiEeojxImBQkeSQpmSKvisVMiSFzJucKrnmrV0+LsugZBLCcQVH4perDet3AKHPWEjYVNmxgaXfE0eIbCLXXcQpl0u22FzZhcqbXuG034e/ku5aeXIRRsu0Wz4yRTUqHOBgg3MhkYgCAlyR7jGCmhAr87IU8RqelGoJHfpgjudKFlhphZJfFi+O3xl4coXWGrKhlTt2adsN1WjAIcTrEJLCHDmXqt72iqAWLCVXuun37MSzwC9tGrKwhToSiJ3DZ18/yYXRtZewPba+/g7b5A3E3I5S0sD/GaVtzW+FbSCGAyT0Eqcq5vbEpsVzSq00/ryS5nkIZA5YZillkZ6BDQdGav9AtuL8paMDha7w+CEM6YvlHsE6s0b/lvwL40S39NR4JALOxLl792aZv0VLQ0mO8CXPxeP/3IQ1k9zSiW/e/mPMR7mpo48Al15382e01HOdKMuepdF0IzocMhBIBar/Yr69dyxt/MGX9JRVjMm52SD+7ZGKfsk1EitZCY8S5q3sqYHJ/veCZEIiZ6Z/hV8QIn8dYwugsCfGSGgmyWfY2EUCUmDFZYlSLjCpew71TlYlVWjQ2NNw58rlJrC7WNKgDhjmFmSFlk62MKNbq024jVONV1Joq8mWBjTgWVXdW6A0aQ/O4dKZx/7gDA8aGU0wUorYupJIPgT4De6UX5CUrl b9tU5QMr /lGLmyCq2r8zL8jWbTu5+8IO3ccPDOBeokegL3fCQF2ZAfzIFIKqPV6yvy/ouqacmrYdsNvIIag9gGshhuk6KXCw9OZ5Fzs+Zx9tf2qlgWTyzADRoO0hG9ScaXoO8JXKTNNGgTRvv3SaemK7ZEKa5ft3f++OMOE2Bb6rCrzHdOTZozhk1thlIPqeCfr+ah/1vqRVXEZWqcw2tYWQpkReR2C9BDcYJvgl2U5guRfc41ZSObFC/gY3VyNFBxRIXwu61247CsKvx/YhnUkO+NJPqdNPCB3a2uFBjWcgomJw7gy0Ze/IiCcdzIuSdA8CvpkwQvyzysX+36RYFxLGkAdqOaL+q3uMaJh/+BzTAbLJyF1eUnpyrQuK0KndsM1IkAMwrjbT2dj5dOZ0/BVWcVDbn3C+sfnaRAvXrYZuVtQZ51WqtYm4qZF5mNx746CL4g7QdHHtr74lnOFzGeL7IE2TrvjZoqGa0QAPXt+rf 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 Sat Feb 3 07:11: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: 13543905 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 DAD3CC4828F for ; Sat, 3 Feb 2024 07:12:48 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 69E9E6B0083; Sat, 3 Feb 2024 02:12:48 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 625886B0085; Sat, 3 Feb 2024 02:12:48 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 4C4CD6B0087; Sat, 3 Feb 2024 02:12:48 -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 356486B0083 for ; Sat, 3 Feb 2024 02:12:48 -0500 (EST) Received: from smtpin09.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay09.hostedemail.com (Postfix) with ESMTP id 11D8D8091D for ; Sat, 3 Feb 2024 07:12:48 +0000 (UTC) X-FDA: 81749625216.09.B566371 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) by imf22.hostedemail.com (Postfix) with ESMTP id 71575C0012 for ; Sat, 3 Feb 2024 07:12:46 +0000 (UTC) Authentication-Results: imf22.hostedemail.com; dkim=pass header.d=infradead.org header.s=bombadil.20210309 header.b=UVZT0U8O; spf=none (imf22.hostedemail.com: domain of BATV+a0ed29cff9639d748e7e+7468+infradead.org+hch@bombadil.srs.infradead.org has no SPF policy when checking 198.137.202.133) smtp.mailfrom=BATV+a0ed29cff9639d748e7e+7468+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=1706944366; 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=vMuVWuEQ40U143WWo2Ps+rfcdCaB4a+PakD93tsqYPU=; b=irDXfDiOUakKDv2437zJccWASpMoPB/S+lvAf4XNqXzbb5ei7RrzyuOkkutsGJPV5cTkrd P1ZLMop2gWrFv3zvjZj+gRTOB/tB/FB5i311Cqj4aAFHw9NxEmjsP9Lm6x/3DqLNbLwRn6 tmt0FszAq1ufz72ZKBKc74ERnf/hVTA= ARC-Authentication-Results: i=1; imf22.hostedemail.com; dkim=pass header.d=infradead.org header.s=bombadil.20210309 header.b=UVZT0U8O; spf=none (imf22.hostedemail.com: domain of BATV+a0ed29cff9639d748e7e+7468+infradead.org+hch@bombadil.srs.infradead.org has no SPF policy when checking 198.137.202.133) smtp.mailfrom=BATV+a0ed29cff9639d748e7e+7468+infradead.org+hch@bombadil.srs.infradead.org; dmarc=none ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1706944366; a=rsa-sha256; cv=none; b=x4TVpWb0YPQzcHKQy0tzqpy3LjDL8MjneXkSDl5b8ssPt7GRPgNvmU0KnQic2vDOaCsSmG 6Hz6AibdrSD4dhzRBhPkaQc3szgdfSghafOO2uJ5W26wIh6oK52y2Q+9aAOwq3KSpyxVTn XAWah8KRDRueYMqkpXaF4CiobKwdFRw= 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=vMuVWuEQ40U143WWo2Ps+rfcdCaB4a+PakD93tsqYPU=; b=UVZT0U8O/OGsWBbA5J5L5DbkUG SmurBjpTmleDtvpw2bIr/rnEVzN8rjTX/aNoUn+C4KAtED42DW3RQVqwlvQC/yzmqGqoWaZxdSYXM GVzgszHwHO9An1ZeyUqAzpxJTAG+W+qouZ7Lgp9GpZyziDRqZHuPHOYf4ID+oxozldM2iGP1P+N6g tf9vH/pqi0+xMruv51PFKnq0+WgjmlKuqh4BdJMW/fNaqPe/lMFUsojx+nfiOqL87BxG6SMlcW+Pv OROo1W/J6KtBHth1yL+GCwFdhJuuVYMDmvSY6cBYYXdtFAjwyr5JEiYBZFU9qWweuDv9rL9io0lsI YA2ZqZhQ==; Received: from [89.144.222.32] (helo=localhost) by bombadil.infradead.org with esmtpsa (Exim 4.97.1 #2 (Red Hat Linux)) id 1rWACi-0000000FkF5-2eII; Sat, 03 Feb 2024 07:12:45 +0000 From: Christoph Hellwig To: linux-mm@kvack.org Cc: Matthew Wilcox , Jan Kara , David Howells , Brian Foster , Christian Brauner , "Darrick J. Wong" , linux-xfs@vger.kernel.org, linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org, Jan Kara , Dave Chinner Subject: [PATCH 10/13] writeback: Use the folio_batch queue iterator Date: Sat, 3 Feb 2024 08:11:44 +0100 Message-Id: <20240203071147.862076-11-hch@lst.de> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20240203071147.862076-1-hch@lst.de> References: <20240203071147.862076-1-hch@lst.de> 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: 71575C0012 X-Rspam-User: X-Stat-Signature: r3sq45ya5pcqzhggz1yos1ddn9kpcs8j X-Rspamd-Server: rspam01 X-HE-Tag: 1706944366-340217 X-HE-Meta: U2FsdGVkX1+eZqp80cKqLixon9op44K2UE6dmNEvegG0NeZ/KiXgDtjxhHPcMCCDlCZ+mVfcCrNUWhCX81SV8d9RfY4C3u8ymB7XzizEca8geFg6kraK0+Nl/gTtiuSn9Pb5G+jMwK4p2LgDNcw7+41ApfYmcZWsiD4lCCSkORDOBxvqvA3lTy3QbQGnPDynIpQ9UHph5Im/HNZaAFag8pv7VsQflC1UFnrH0hhvOThePBG1OPRRvKA9k37BKjWa7658ThLrG8F5CJJkXvnDX9a7JlR5KMOeckSIqQhK5vC1EQnxufugCCAgFdNFC2uK6PvI1TWMZcxaOPy/rSvPFykMtmQYGIPt3d6Kbh4sU96dKiRUlPKBvF96qkvbwu0SA7T8RbY/3oejtced8JN+KLiC3PI72fwYr6m465b0HtloJOwM0xO8rkBtBGFK1nHTod6JNps47E1gp7JtnFPep63Mu5gkEQvJItBgBc8PQV2s1RB/9eirlwpGOJAUzEF85YVWEXyRGntJ+s89Hc3shvk5Lvrb1NbdoFenNPtKz9QuWtPdYs3PwxJ6PC+rZzQE7Kil9Q9Vu6CxjKT8DxyfBr3v4VIRbhnDkkm/upGTf2HLgT9sf0o4/w1WOnq6hzSZ5bNhb0xLNjlw3Em+ClDbdf23kIseNSB9XMx8XC8SziGTEeAV1TubYHBekI3rJePM5SNPqnPUgvjMsvMbTAtIt447gd9dVy31gAp5RhHhkOjdR6pNISnpokDCHK1+92/i9mG0QotPEvR9mOAZJdi6lc54uyHkT8oQm1GnXS91/Blje2B2DAG9xCwVhwKIHDQ1pXrym4Mq686sWBkfKgZDnI7oJt1d0KrRXxqX876ValYBnqc0tr7TeuXXZkX0SATibNRbWwUYMhdY3UriG/SDTvF7qHnxGtTCcKbD9cwcwQ3ERrw8hJbigY83nbNmfR9Sag1GX9cF6Z5EsApRxR/ aqth4P3J BRple+K/0QSYQDTJ7L2lMdFlLQ40bl1a2ndc3Vnfwm9Pq2HzC5VOgYvxcZhjs7mdCe5+2QSqjEIp//Z7WxGCbioaIFwRb2sr8J4nKcmvd44DwYgSNOTgFdxcrRzIY617iWkZkt87ghK3BIDE/HS+pU5dYtsxZ1e6cecoysoK2IziMcujqSj7vB+MIk0a3LdfBykqO1oyqhXedYc57DVaugA6EUVkywI5fTczI8HASQYsUdW/B8/Na0JpXvw8ZZK7vuH06kU5exNrcg3MMhUba8csBsPPIYpiZMiecTPcobU29qozN9ow/pzGeCWJ1M2nMPf5bBM4klATyTMIWE0lMKT/gf0TTIsEkOofh8qMPuZD3BC+EwHki3A1vkyjbVgdFR0sKHjH6Ei7HW9u/zD9Eo0a5jYYGywmhx8CFxf5w+1EHujcRXW+OmuRHMf0PzTSBYfGN9Itzgv5UENoJAfPf9n2B7GX6HV4fiz1f2qMB6jFSyZ61jCNWXNSorRYTi1kkYqeGxTjsdM+C2ps= 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 d7ab42def43035..095ba4db9dcc17 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 Sat Feb 3 07:11:45 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christoph Hellwig X-Patchwork-Id: 13543906 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 046FDC4828D for ; Sat, 3 Feb 2024 07:12:54 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 8BF276B0085; Sat, 3 Feb 2024 02:12:53 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 847236B0088; Sat, 3 Feb 2024 02:12:53 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 70F2F6B0089; Sat, 3 Feb 2024 02:12:53 -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 5F6356B0085 for ; Sat, 3 Feb 2024 02:12:53 -0500 (EST) Received: from smtpin18.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay08.hostedemail.com (Postfix) with ESMTP id 0337A1402FE for ; Sat, 3 Feb 2024 07:12:52 +0000 (UTC) X-FDA: 81749625426.18.F223922 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) by imf11.hostedemail.com (Postfix) with ESMTP id 5A80F4000B for ; Sat, 3 Feb 2024 07:12:51 +0000 (UTC) Authentication-Results: imf11.hostedemail.com; dkim=pass header.d=infradead.org header.s=bombadil.20210309 header.b=vH0hdIAp; spf=none (imf11.hostedemail.com: domain of BATV+a0ed29cff9639d748e7e+7468+infradead.org+hch@bombadil.srs.infradead.org has no SPF policy when checking 198.137.202.133) smtp.mailfrom=BATV+a0ed29cff9639d748e7e+7468+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=1706944371; 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=AnG5GvoJfhWPvqWiitfZqai2sD2FuEVxQzhAIrm6KaA=; b=VwGyq7XGTLJkAqvE1d2rhdhHwO7qBFKMK/JqLwnMdOAvatGNBiSkr1y+X/qStvwbS3glAq JyRd9G/elr1coC7YqYrl0i1MRp2kY42u/euUEdVB6nuwRy/eOLr8XLdeHyFrZgbbxk066Q p5Qd7Qzwu0Jhs4lIGKZkXNj9nD7Q5q4= ARC-Authentication-Results: i=1; imf11.hostedemail.com; dkim=pass header.d=infradead.org header.s=bombadil.20210309 header.b=vH0hdIAp; spf=none (imf11.hostedemail.com: domain of BATV+a0ed29cff9639d748e7e+7468+infradead.org+hch@bombadil.srs.infradead.org has no SPF policy when checking 198.137.202.133) smtp.mailfrom=BATV+a0ed29cff9639d748e7e+7468+infradead.org+hch@bombadil.srs.infradead.org; dmarc=none ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1706944371; a=rsa-sha256; cv=none; b=reLGxeRziXF3PJKC3h3+nlS1pLZhcAFbNYqBKi8KdLkWvA4UqjYBiaoNf5Li3GVBee0U08 cDzt/83x/mF29Pl4QOZH9iGIlnwKkHLIx/2c6Vs9TAnETkDDyRVg7J3bNuVHZQZWJvJvZR oiMwhZm6Qekmzqmm6MZJWVt8IgMkV4w= DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=bombadil.20210309; h=Content-Transfer-Encoding: MIME-Version:References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From:Sender :Reply-To:Content-Type:Content-ID:Content-Description; bh=AnG5GvoJfhWPvqWiitfZqai2sD2FuEVxQzhAIrm6KaA=; b=vH0hdIAp6gB22asQhHw8fV4fL7 t7SMPnQ6UOZ06eB6iUc6QRiRN2CHY9Hoa3/Qt6lKZZW+1cVc05CzNKKIfNtKfWXE9n/0DIqp9pM41 tUdkoZyp1A/VSO+XZuNI8/iD1snj2iILh49fiFClyMMSrDYvZwMScjIzwLgLCAtb95yYimLLC6kZs 3uYxfZ9w1waMc6giSV8N33kIOCeAyPZBqp55YBUwZiocSMqmbEkiaPrGEeU7UtVNwsyGwiGTQe5eA t3RXkIGbnjSxOrBklgbZ7FsjwDnYiDV06ODpVc/+M3iEChRzlwXXkIMS44L9k65uCSyfj+bQtgnTP OJ4GTRbA==; Received: from [89.144.222.32] (helo=localhost) by bombadil.infradead.org with esmtpsa (Exim 4.97.1 #2 (Red Hat Linux)) id 1rWACn-0000000FkIF-1VWY; Sat, 03 Feb 2024 07:12:50 +0000 From: Christoph Hellwig To: linux-mm@kvack.org Cc: Matthew Wilcox , Jan Kara , David Howells , Brian Foster , Christian Brauner , "Darrick J. Wong" , linux-xfs@vger.kernel.org, linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org, Jan Kara , Dave Chinner Subject: [PATCH 11/13] writeback: Move the folio_prepare_writeback loop out of write_cache_pages() Date: Sat, 3 Feb 2024 08:11:45 +0100 Message-Id: <20240203071147.862076-12-hch@lst.de> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20240203071147.862076-1-hch@lst.de> References: <20240203071147.862076-1-hch@lst.de> 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: 5A80F4000B X-Rspam-User: X-Stat-Signature: aaphrpztp13mab1keerd6mdr4jjmousk X-Rspamd-Server: rspam01 X-HE-Tag: 1706944371-982538 X-HE-Meta: U2FsdGVkX18zVuTNp11qWw9QJCX5KM+1iaIv6DMIWNdASqsVxa3R3TCFJ0jNnpUpaVMbeW8v7x6E83lLK1HNG9ZxPg+KANKAuGo2qRNwecECr9fG+qBppvsTngZuyU2huLJQlrxsUyNKzYD52x/4H3UN9oyFSVCudOdfh+9AO9jQGzHE2OKRDmX6cYbPBEvpZ9mjRGsOM/gYnaL1piwNo0C/LQPYiE3h95x++pdC78lxM9JuFrJHBsW0CLCEijSvBT5w969Z2ZxofN5uxmmeBhh99wcQs3DXzF3rqfJ74Q4VzO+4z24HgQvzn0f+oEoA8nVJMaByRJwKsSdZePQ/98RufMuQtduQfi47okxGeR6qlUEKNPTXvJQuu0WJuNsSeLaMn1Sws1uCrJD8Z9hQqnLaP3CqFK6byYQzh0K7MAXIM2byxtiUJyeNitz251paDoaqJemWX3yaZimmnQ6xddjRS2aMRkQhwRf9+qEaUan/tFbDrWw2oCPVmaWZmbGEk2HwJFm39dnBO0XQUYuhLgpFlm65qwxeMRzDRB5zpsA0QqvIajBxmXSp0HDnk5Ty04OVnktZUFAQfTt7VDYDHX0+sUjhHZdtP8RQpWQJvSPvXcKSA/Npnj44TpkLt75Ib8Yap4Xk+gbs4iX5DltzlaxB7ksh8FFbQIDG0keeecyH/GMMJrCzeXA7RrBXNUfks2TFymeD5XqtQAiUuSKWUpdbF0gDhk3662Rw009WS/q3JtUAHCt0LSVuOLJUBLk1nmuIlj7ukznHqCTX8qFEwGv/MeTUsFThoUXxyUQx8gdnWDgSEDN/9dHTIDu+LvRZJRWoGyhl0D3X3gdkpfUMG8QvtyZ3f+QPjOePr6wtKgC1igTPq+fuOgnDqgmVKc8B1UpLRfRjBAqdEe8rg+TesLkOH/LEOGtqDJ2QWoMgaS0xqzKAqjlO0vthHQWZrrlYSSgotodHnU6unfJly9t hkWjFzuY sSYy8MAWOQfPPo/dmqa6B3ObPLDGoxd8lvXnKXwDfPRzj4bNTzQyjKS5NpUY6UyymxsOYpprPtFM96VeO85++HPfnTNnZS3gxle0Vgigm7bi8SMWB2/8lPRfz6MNierK4T+7TUP2ShzFVcDmczjVpcHebf4sDAJyaL+zWTvlOW0424C8JzjiN+L9BWPVjBe2Edsz26ZEeLOl0bTlKVqYNh0jSeyI+VfobmfZ7xmF1vhafTUc1OBLrLKqLdLjw2w7gtd1ltReUXw79a1cndIs0tqELvJErDSS1q2oGkA0NUNUkW1s5nlIe5TWB/nAIuQ6iH5R7Uxak8H5qLccDKk8peZm6WDmr0U5puR+21Mdkq2xKlmiAg/2CQJHXBss2V0KdiU+fHo1ZKd4DnLlNUP0PgiwRqxdUJ+bX6o9F2fP93sjCgGHNUiDnLNgVaISft8/ftlinleNdqhP8pvuPAyNJzcAK/ALDqjMJozqfUjVPgE6IKaDFq/L5Eq2m7uQJrK7LIoTjOzfVKdNKcB0= 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 095ba4db9dcc17..3abb053e70580e 100644 --- a/mm/page-writeback.c +++ b/mm/page-writeback.c @@ -2411,6 +2411,7 @@ static struct folio *writeback_get_folio(struct address_space *mapping, { struct folio *folio; +retry: folio = folio_batch_next(&wbc->fbatch); if (!folio) { folio_batch_release(&wbc->fbatch); @@ -2418,8 +2419,17 @@ static struct folio *writeback_get_folio(struct address_space *mapping, filemap_get_folios_tag(mapping, &wbc->index, wbc_end(wbc), wbc_to_tag(wbc), &wbc->fbatch); folio = folio_batch_next(&wbc->fbatch); + if (!folio) + return NULL; + } + + folio_lock(folio); + if (unlikely(!folio_prepare_writeback(mapping, wbc, folio))) { + folio_unlock(folio); + goto retry; } + trace_wbc_writepage(wbc, inode_to_bdi(mapping->host)); return folio; } @@ -2480,14 +2490,6 @@ int write_cache_pages(struct address_space *mapping, if (!folio) break; - folio_lock(folio); - if (!folio_prepare_writeback(mapping, wbc, folio)) { - folio_unlock(folio); - continue; - } - - trace_wbc_writepage(wbc, inode_to_bdi(mapping->host)); - error = writepage(folio, wbc, data); wbc->nr_to_write -= folio_nr_pages(folio); From patchwork Sat Feb 3 07:11:46 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christoph Hellwig X-Patchwork-Id: 13543907 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 C1718C4828F for ; Sat, 3 Feb 2024 07:12:57 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 515B16B0088; Sat, 3 Feb 2024 02:12:57 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 49E356B0089; Sat, 3 Feb 2024 02:12:57 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 316D06B008A; Sat, 3 Feb 2024 02:12:57 -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 209AB6B0088 for ; Sat, 3 Feb 2024 02:12:57 -0500 (EST) Received: from smtpin25.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay08.hostedemail.com (Postfix) with ESMTP id 00D2A140536 for ; Sat, 3 Feb 2024 07:12:56 +0000 (UTC) X-FDA: 81749625594.25.5448A4D Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) by imf24.hostedemail.com (Postfix) with ESMTP id 4A14F180005 for ; Sat, 3 Feb 2024 07:12:55 +0000 (UTC) Authentication-Results: imf24.hostedemail.com; dkim=pass header.d=infradead.org header.s=bombadil.20210309 header.b=0fuITZBJ; spf=none (imf24.hostedemail.com: domain of BATV+a0ed29cff9639d748e7e+7468+infradead.org+hch@bombadil.srs.infradead.org has no SPF policy when checking 198.137.202.133) smtp.mailfrom=BATV+a0ed29cff9639d748e7e+7468+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=1706944375; 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=GezxIWW+q+u2zC46RjSY4N2DxF7mdi1d7/13SlWu4e0=; b=M66CgJbzVMOHfcY+M7Iz1+P3rBmIT1jhjyn8X4iHvB/Xks3NuViuou+VziOOf1rdiwfPWV 2NuoHZo0wywV6DaoOMTHPrGEKKy/csYgV4BMaANBoWQXF5ekLQqrcP776xWiVIixvQpOEJ ds+gxH63gDAUyMWFuzMoHHnr/vlvSsc= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1706944375; a=rsa-sha256; cv=none; b=4SYCZDMljCR/X9u49DYzZCU+Tk3iiEX3OoNBK4IaBjBemr+M1U7hXgRTn4HhY6rI06tYrZ fkfwawpa4+yhI3RoXRo4GrJTfbWybytmbn9blcz0TJzJBCbSLi95B+UX6dk0Nev/x+dfgN a0lghirIJWCJApjx1bibp/Kw7Qb8+gc= ARC-Authentication-Results: i=1; imf24.hostedemail.com; dkim=pass header.d=infradead.org header.s=bombadil.20210309 header.b=0fuITZBJ; spf=none (imf24.hostedemail.com: domain of BATV+a0ed29cff9639d748e7e+7468+infradead.org+hch@bombadil.srs.infradead.org has no SPF policy when checking 198.137.202.133) smtp.mailfrom=BATV+a0ed29cff9639d748e7e+7468+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=GezxIWW+q+u2zC46RjSY4N2DxF7mdi1d7/13SlWu4e0=; b=0fuITZBJrufOpvkZIZVTWLsXDG Tb1yRAHTRSZM10wbA9mMQmPVY7Dc/QPRmF7qOsXh9cUUf9u8BZ4kCuh0PsgskRbJvPn1EXAWIHPo/ 2lUsRZffOvsZzX/H8/b9ym45gzAp3Xs0w0hhnCArnihPgDVLNKiYo/O+eRsH5bw/DH4TgV9psc3II Ri+1RmASwfnAIZaowi8VPt9u+QXKPsK7mH9qI+9Bnz/jojbY9mOU/Z1FWHmh4z/tvtaZZmu7dVmrK mTYhghZYwghLpblIlUFbA1bxNC9ycEhtE3cNU/inSmeuTiqmjjbnkEOFTaPl0XNmjuDmFeuE1ihUx NqEc+Dew==; Received: from [89.144.222.32] (helo=localhost) by bombadil.infradead.org with esmtpsa (Exim 4.97.1 #2 (Red Hat Linux)) id 1rWACr-0000000FkKP-28zg; Sat, 03 Feb 2024 07:12:54 +0000 From: Christoph Hellwig To: linux-mm@kvack.org Cc: Matthew Wilcox , Jan Kara , David Howells , Brian Foster , Christian Brauner , "Darrick J. Wong" , linux-xfs@vger.kernel.org, linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH 12/13] writeback: add a writeback iterator Date: Sat, 3 Feb 2024 08:11:46 +0100 Message-Id: <20240203071147.862076-13-hch@lst.de> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20240203071147.862076-1-hch@lst.de> References: <20240203071147.862076-1-hch@lst.de> 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: 4A14F180005 X-Rspam-User: X-Stat-Signature: eg1jwa6upppmj8huiadm68rhkk5a6c4e X-Rspamd-Server: rspam03 X-HE-Tag: 1706944375-783204 X-HE-Meta: U2FsdGVkX1/S4kt3baM9e7eCdCPKk0cd6M7eiBizrU4qOI4Mkb+f5LOEXUV4IZ4cSLSBcHdpQKeRTq8v/grrKN6OqeOriVGSV3u26EY2N5vS1BMfM7LGCxElTqwipcDiKcobgkM1T1x01aYApQDcXepdhMqDVTtAH0Z5BGJgF4C/rnkFQGNp4UsCdRN2RFUGm+gUrcVoFT0bucC93lleesf9Y4KS46fUvr8z7QlUTwqD7Favhzmvwt/k5c05Hq2rUJO96Uvfavn/O8h3RfrIsYm2yosMBOpNuB8M69AIk0ySbqZvHDT9x8BtXf5L6VNE0CcuL2jJWAsP5ssZG15rs/a8LufkPhbfkwrcW08HXUQgsIgBGGYwKs02q+fYc+OCmnqGA1fCVNo7/6g2iE1mytUPWJbaRtdTDHesF6epBzFDd6ofM4NCK61pTAWnvp7J84X/HGm8wZ00RqjmYem9HWHMbX4o1Gi9NI9zOQiZAUn5EIuMje5yAutFELVur3bOKr54O7HDXf4IksXeCzUKMqINzHzjdL1hGHe0jSjRyiE3iGGERBw92l5O1+jFt972+7YGVCv4rQ7RwcypgZieBrYe5mUMt1U8eD3Ygv3oiWCHHxiWu7HCiHlo3lTHiTA9wu+jPiIprn41NREcm3E0Zsvol0wualZgviA9hfMAbPvV20Dayac6LOvb5VHRSAkN2VGNXhhji5nyyaGiqY4JKMl7V+WuI2c3plv7Ak2uhD2d7Ik0YiqdIahHCr7QR3Yqvq4cV4dJb5FyyJ5wz4PSaNaaMll/A7reYcyKg5xE0KGU0AyQ6MbVVkf4AFUjIfKeWhkGTyIBkgz886BzsBQvzQd8eUG9ycLrYJ5On6+F236SRNnYrFln9NLVUNQOPIWiMxmfZS9nb7bZFhA/W6XJDuK6lHTRwfT9FDAF36d+cZbhtH0voMp8EPvv39K/lICMM0i4qT6BLUSQ4z1ZXha eghLz6dX +5JGmi1ZOPONiwPdHyctQvhsgPldKMX22keCrmk5/NqNvAb7jZ8ivIPs3Z/A5pxCC75qpmtO/fYuzuNRvqsNSmonoiAdyS53vIjZpAEFa3h9kzFoH55lSAJBz5tophEYJUTg3GNV0w8c6B2pBm9Ux0oQ1ikeHXsnJsJhMwbZjcTq3aKHt7TXrx/4aqev/0ifn+mFbxClvsdZxWKtAkowwecizek7Aikfdd9MKvNTls8vJiJ5TMkEl2GPGTMc+IAt2tX9B21AUXcSuRDb8fnkxBJb8GVM/s910ue6re+TZeTXe5UIW9FtIYd1+n6Bsjn8/uA1I80eis52UYnDacS6vw62pkXPEnwi3iafKJkouspVBf82/G4bB0X8TwNGyAvb0xAStE/VtR4RdUW8= 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: Jan Kara Reviewed-by: Brian Foster --- include/linux/writeback.h | 4 + mm/page-writeback.c | 192 ++++++++++++++++++++++---------------- 2 files changed, 118 insertions(+), 78 deletions(-) diff --git a/include/linux/writeback.h b/include/linux/writeback.h index f67b3ea866a0fb..9845cb62e40b2d 100644 --- a/include/linux/writeback.h +++ b/include/linux/writeback.h @@ -82,6 +82,7 @@ struct writeback_control { /* internal fields used by the ->writepages implementation: */ struct folio_batch fbatch; pgoff_t index; + int saved_err; #ifdef CONFIG_CGROUP_WRITEBACK struct bdi_writeback *wb; /* wb this writeback is issued under */ @@ -366,6 +367,9 @@ int balance_dirty_pages_ratelimited_flags(struct address_space *mapping, bool wb_over_bg_thresh(struct bdi_writeback *wb); +struct folio *writeback_iter(struct address_space *mapping, + struct writeback_control *wbc, struct folio *folio, int *error); + typedef int (*writepage_t)(struct folio *folio, struct writeback_control *wbc, void *data); diff --git a/mm/page-writeback.c b/mm/page-writeback.c index 3abb053e70580e..5fe4cdb7dbd61a 100644 --- a/mm/page-writeback.c +++ b/mm/page-writeback.c @@ -2325,18 +2325,18 @@ void __init page_writeback_init(void) } /** - * tag_pages_for_writeback - tag pages to be written by write_cache_pages + * tag_pages_for_writeback - tag pages to be written by writeback * @mapping: address space structure to write * @start: starting page index * @end: ending page index (inclusive) * * This function scans the page range from @start to @end (inclusive) and tags - * all pages that have DIRTY tag set with a special TOWRITE tag. The idea is - * that write_cache_pages (or whoever calls this function) will then use - * TOWRITE tag to identify pages eligible for writeback. This mechanism is - * used to avoid livelocking of writeback by a process steadily creating new - * dirty pages in the file (thus it is important for this function to be quick - * so that it can tag pages faster than a dirtying process can create them). + * all pages that have DIRTY tag set with a special TOWRITE tag. The caller + * can then use the TOWRITE tag to identify pages eligible for writeback. + * This mechanism is used to avoid livelocking of writeback by a process + * steadily creating new dirty pages in the file (thus it is important for this + * function to be quick so that it can tag pages faster than a dirtying process + * can create them). */ void tag_pages_for_writeback(struct address_space *mapping, pgoff_t start, pgoff_t end) @@ -2434,69 +2434,68 @@ static struct folio *writeback_get_folio(struct address_space *mapping, } /** - * write_cache_pages - walk the list of dirty pages of the given address space and write all of them. + * writeback_iter - iterate folio of a mapping for writeback * @mapping: address space structure to write - * @wbc: subtract the number of written pages from *@wbc->nr_to_write - * @writepage: function called for each page - * @data: data passed to writepage function + * @wbc: writeback context + * @folio: previously iterated folio (%NULL to start) + * @error: in-out pointer for writeback errors (see below) * - * If a page is already under I/O, write_cache_pages() skips it, even - * if it's dirty. This is desirable behaviour for memory-cleaning writeback, - * but it is INCORRECT for data-integrity system calls such as fsync(). fsync() - * and msync() need to guarantee that all the data which was dirty at the time - * the call was made get new I/O started against them. If wbc->sync_mode is - * WB_SYNC_ALL then we were called for data integrity and we must wait for - * existing IO to complete. - * - * To avoid livelocks (when other process dirties new pages), we first tag - * pages which should be written back with TOWRITE tag and only then start - * writing them. For data-integrity sync we have to be careful so that we do - * not miss some pages (e.g., because some other process has cleared TOWRITE - * tag we set). The rule we follow is that TOWRITE tag can be cleared only - * by the process clearing the DIRTY tag (and submitting the page for IO). - * - * To avoid deadlocks between range_cyclic writeback and callers that hold - * pages in PageWriteback to aggregate IO until write_cache_pages() returns, - * we do not loop back to the start of the file. Doing so causes a page - * lock/page writeback access order inversion - we should only ever lock - * multiple pages in ascending page->index order, and looping back to the start - * of the file violates that rule and causes deadlocks. + * This function returns the next folio for the writeback operation described by + * @wbc on @mapping and should be called in a while loop in the ->writepages + * implementation. * - * Return: %0 on success, negative error code otherwise + * To start the writeback operation, %NULL is passed in the @folio argument, and + * for every subsequent iteration the folio returned previously should be passed + * back in. + * + * If there was an error in the per-folio writeback inside the writeback_iter() + * loop, @error should be set to the error value. + * + * Once the writeback described in @wbc has finished, this function will return + * %NULL and if there was an error in any iteration restore it to @error. + * + * Note: callers should not manually break out of the loop using break or goto + * but must keep calling writeback_iter() until it returns %NULL. + * + * Return: the folio to write or %NULL if the loop is done. */ -int write_cache_pages(struct address_space *mapping, - struct writeback_control *wbc, writepage_t writepage, - void *data) +struct folio *writeback_iter(struct address_space *mapping, + struct writeback_control *wbc, struct folio *folio, int *error) { - int ret = 0; - int error; - struct folio *folio; - pgoff_t end; /* Inclusive */ - - if (wbc->range_cyclic) { - wbc->index = mapping->writeback_index; /* prev offset */ - end = -1; - } else { - wbc->index = wbc->range_start >> PAGE_SHIFT; - end = wbc->range_end >> PAGE_SHIFT; - } - if (wbc->sync_mode == WB_SYNC_ALL || wbc->tagged_writepages) - tag_pages_for_writeback(mapping, wbc->index, end); - - folio_batch_init(&wbc->fbatch); + if (!folio) { + folio_batch_init(&wbc->fbatch); + wbc->saved_err = *error = 0; - for (;;) { - folio = writeback_get_folio(mapping, wbc); - if (!folio) - break; + /* + * For range cyclic writeback we remember where we stopped so + * that we can continue where we stopped. + * + * For non-cyclic writeback we always start at the beginning of + * the passed in range. + */ + if (wbc->range_cyclic) + wbc->index = mapping->writeback_index; + else + wbc->index = wbc->range_start >> PAGE_SHIFT; - error = writepage(folio, wbc, data); + /* + * To avoid livelocks when other processes dirty new pages, we + * first tag pages which should be written back and only then + * start writing them. + * + * For data-integrity writeback we have to be careful so that we + * do not miss some pages (e.g., because some other process has + * cleared the TOWRITE tag we set). The rule we follow is that + * TOWRITE tag can be cleared only by the process clearing the + * DIRTY tag (and submitting the page for I/O). + */ + if (wbc->sync_mode == WB_SYNC_ALL || wbc->tagged_writepages) + tag_pages_for_writeback(mapping, wbc->index, + wbc_end(wbc)); + } else { wbc->nr_to_write -= folio_nr_pages(folio); - if (error == AOP_WRITEPAGE_ACTIVATE) { - folio_unlock(folio); - error = 0; - } + WARN_ON_ONCE(*error > 0); /* * For integrity writeback we have to keep going until we have @@ -2510,33 +2509,70 @@ int write_cache_pages(struct address_space *mapping, * wbc->nr_to_write or encounter the first error. */ if (wbc->sync_mode == WB_SYNC_ALL) { - if (error && !ret) - ret = error; + if (*error && !wbc->saved_err) + wbc->saved_err = *error; } else { - if (error || wbc->nr_to_write <= 0) + if (*error || wbc->nr_to_write <= 0) goto done; } } - /* - * For range cyclic writeback we need to remember where we stopped so - * that we can continue there next time we are called. If we hit the - * last page and there is more work to be done, wrap back to the start - * of the file. - * - * For non-cyclic writeback we always start looking up at the beginning - * of the file if we are called again, which can only happen due to - * -ENOMEM from the file system. - */ - folio_batch_release(&wbc->fbatch); - if (wbc->range_cyclic) - mapping->writeback_index = 0; - return ret; + folio = writeback_get_folio(mapping, wbc); + if (!folio) { + /* + * To avoid deadlocks between range_cyclic writeback and callers + * that hold pages in PageWriteback to aggregate I/O until + * the writeback iteration finishes, we do not loop back to the + * start of the file. Doing so causes a page lock/page + * writeback access order inversion - we should only ever lock + * multiple pages in ascending page->index order, and looping + * back to the start of the file violates that rule and causes + * deadlocks. + */ + if (wbc->range_cyclic) + mapping->writeback_index = 0; + + /* + * Return the first error we encountered (if there was any) to + * the caller. + */ + *error = wbc->saved_err; + } + return folio; done: folio_batch_release(&wbc->fbatch); if (wbc->range_cyclic) mapping->writeback_index = folio->index + folio_nr_pages(folio); + return NULL; +} + +/** + * write_cache_pages - walk the list of dirty pages of the given address space and write all of them. + * @mapping: address space structure to write + * @wbc: subtract the number of written pages from *@wbc->nr_to_write + * @writepage: function called for each page + * @data: data passed to writepage function + * + * Return: %0 on success, negative error code otherwise + * + * Note: please use writeback_iter() instead. + */ +int write_cache_pages(struct address_space *mapping, + struct writeback_control *wbc, writepage_t writepage, + void *data) +{ + struct folio *folio = NULL; + int error; + + while ((folio = writeback_iter(mapping, wbc, folio, &error))) { + error = writepage(folio, wbc, data); + if (error == AOP_WRITEPAGE_ACTIVATE) { + folio_unlock(folio); + error = 0; + } + } + return error; } EXPORT_SYMBOL(write_cache_pages); From patchwork Sat Feb 3 07:11:47 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christoph Hellwig X-Patchwork-Id: 13543908 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 6657EC4828F for ; Sat, 3 Feb 2024 07:13:02 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id ED97A6B0092; Sat, 3 Feb 2024 02:13:01 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id E611E6B008C; Sat, 3 Feb 2024 02:13:01 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id CDB646B0092; Sat, 3 Feb 2024 02:13:01 -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 B8A376B008A for ; Sat, 3 Feb 2024 02:13:01 -0500 (EST) Received: from smtpin03.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay01.hostedemail.com (Postfix) with ESMTP id 99A101C1272 for ; Sat, 3 Feb 2024 07:13:01 +0000 (UTC) X-FDA: 81749625762.03.5FAEE63 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) by imf09.hostedemail.com (Postfix) with ESMTP id 05029140009 for ; Sat, 3 Feb 2024 07:12:59 +0000 (UTC) Authentication-Results: imf09.hostedemail.com; dkim=pass header.d=infradead.org header.s=bombadil.20210309 header.b=FDgMugVo; dmarc=none; spf=none (imf09.hostedemail.com: domain of BATV+a0ed29cff9639d748e7e+7468+infradead.org+hch@bombadil.srs.infradead.org has no SPF policy when checking 198.137.202.133) smtp.mailfrom=BATV+a0ed29cff9639d748e7e+7468+infradead.org+hch@bombadil.srs.infradead.org ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1706944380; a=rsa-sha256; cv=none; b=FRMnNqL8eYuuLrF7f9VHPaxeH5QBRuh7/5vWOqw0UHbcVQVhZ99Go2aqHJD5jJBYdG9KQx pdtpBp9RCzYWOct3ixr1+fVAyaqxLf4ARirHTc7J6I5f9ag+eOFh0Yk63if/66suTbT/u5 6NtdCSqmJ6WWq6JlEytYk+LtuHmvtOA= ARC-Authentication-Results: i=1; imf09.hostedemail.com; dkim=pass header.d=infradead.org header.s=bombadil.20210309 header.b=FDgMugVo; dmarc=none; spf=none (imf09.hostedemail.com: domain of BATV+a0ed29cff9639d748e7e+7468+infradead.org+hch@bombadil.srs.infradead.org has no SPF policy when checking 198.137.202.133) smtp.mailfrom=BATV+a0ed29cff9639d748e7e+7468+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=1706944380; 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=aBLx8GrPTTpnrFrYwat6koWXvCPglp7/mI2LOOfVaJQ=; b=D86wwg+UvIOdlhmEjEaGOtLja+HRy30JiSB2913S7alda9R8RxA6cRF1a6udqkfjw1SAFE yruZPQKqnL39EJ5kKEHXp2UZCj1A0deXv17eZuiCShLXdnDlRPlOJoEYJW8+vX//6DYA46 EuIGvZVxyhBCiMHl5An1yepCCWHQQPk= DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=bombadil.20210309; h=Content-Transfer-Encoding: MIME-Version:References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From:Sender :Reply-To:Content-Type:Content-ID:Content-Description; bh=aBLx8GrPTTpnrFrYwat6koWXvCPglp7/mI2LOOfVaJQ=; b=FDgMugVoB7MSUNHernp01Fwg/x MO+pR9JFMoCL9rwCqYotraUCpxDX06NW4fyeZ6vX5JPS0X8tpbgo7moefxhXVI67QAr0Xxmzp5E37 psFmoZYeys27ykwrnviTUvz/SmbokAZR4N9bZEyFSFJOJlxuJ2QZbK1SuEFbb8Vdsk7p/XGeR7TL8 +XGOB5d0OGem8uOS4FN4sM1iYvLyTDpZ+wlMffmwZiv2yPxszrIZH53rlSPctCCQy5qXCcVdpqrYW 3kZ1BMlFOw32O9rX7U/qB7G4p6dLZExzOJuw2VLdjcwXSgL2j1i6HzWGmXtoS3nBfwUSXDi/FI0fc ndPdGBiw==; Received: from [89.144.222.32] (helo=localhost) by bombadil.infradead.org with esmtpsa (Exim 4.97.1 #2 (Red Hat Linux)) id 1rWACv-0000000FkMz-41QH; Sat, 03 Feb 2024 07:12:59 +0000 From: Christoph Hellwig To: linux-mm@kvack.org Cc: Matthew Wilcox , Jan Kara , David Howells , Brian Foster , Christian Brauner , "Darrick J. Wong" , linux-xfs@vger.kernel.org, linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH 13/13] writeback: Remove a use of write_cache_pages() from do_writepages() Date: Sat, 3 Feb 2024 08:11:47 +0100 Message-Id: <20240203071147.862076-14-hch@lst.de> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20240203071147.862076-1-hch@lst.de> References: <20240203071147.862076-1-hch@lst.de> MIME-Version: 1.0 X-SRS-Rewrite: SMTP reverse-path rewritten from by bombadil.infradead.org. See http://www.infradead.org/rpr.html X-Rspam-User: X-Rspamd-Server: rspam06 X-Rspamd-Queue-Id: 05029140009 X-Stat-Signature: m1rkkcy1otgr4ipygc6474dcezaw3a4z X-HE-Tag: 1706944379-962684 X-HE-Meta: U2FsdGVkX1+BKFkCSUKgM7xWmZaaQ0y/uBpwDkVUUuuiLSwSqeNKHgmaRmS2QUEkrROlknzLs7fMALFAog/xD073rMejMKfDf37eJH3JE7ltxGlm4/TKZl2q7fPhpsIM354X1tBN1t9ovtSGtU3t1AyX9O7oiP4I/2OuMl1YatAxmmsnqgvzuDldfJ2lHLBvSBBveeZ4caj1mZ+D+KSa0Ee7m/lRqH5kCoJ1mBuRxZUYG/CK2g6cvel4ouSo3ENRXhk+klvbhCdGhXBmoRlBAZq5qugxNMLp8XHmJonLWxU8rb6lhl2JLDA+aLims6mvv/JEzc1VmqoAQCGH5+x//Zbl6bs5cYuDzyRwlf35U5JvAc6I+CrUov2YENsXjK3TUqPpKtMNX2yrHiO1dXYP30eTWhkw0oOrrvWGtd6RNcyytAjyoP5dam44ICRIW9ULanhzITE9/GvuNqu02AfDsDYP3D8LcZCXq9E0s8UTbSxoDyAd8M/LVWLeIlt+j+4lgf3WSLo6rGNnNeYbZFVRGlA8te9GEatvweVE16CM+FW6v5Bx806xftsOQKflxDNweTW5RDydKdRoNLameXDWD1XRWGl03C/pLy1u/OmrohWtCDXxuLwC/Ozbrj0O2L+Jr1pomXqMlVazoQez5oriGHzSJu0tjcqSjH8CkaGwTilEJ/uLZX6fftuYNvvNy68qTClIuHbdSV9ndnFG5spFOxeskZjImgmCw5uQ5/VVrKwZxRLw3NJvHmyV+7rZnfvOJNYFn0/+I3sDfAARcZBvIFHJ0vPp2TgsMqDfx4g7HJytq+XqBCcGNLLh8tL/Lb7Or+zR05Tl9izSqhK0UCXZNgsHNUiLhCI6MEOS0uhDykTfaFoUDfcEsYrETQZy+1fRmN2ynVTZbzhPHjsG09jK4v0myJ2BBJUKg5VCscylVqS4ApK9LJzOEKFO+i6PQKgek2SpFHYa3mRQ5PtNz3l 3RT1fSkm 5KSrLQl43J1W87IK9BhdA3OxNKSA8AhQMkzJJPbae/XXbFMBZ+Zdl3deZ0YXQPfFwOZaqJ+No7vLTLSMJ+JlKqg1h5/ppfcBwmB0ufdvc2zwaD4NPpReS4BEeNQvWzLb/aHZnDLYxC25WX0fiEuMgqQKGvynVVcWWNYjlzh6ItkWA1M/2vNW69yMswN++/J9hlOql3/2H8Zisv+9W//5aB79I2zLACUfoRrZaAyzheClaTYrae2CZACams0P5IFMCQcLRtTQ0wvAJQxGD4RmYwbYvJT/AbB+msJATMa7t5MNarEZv9UQaLm4rlUcehhDckU3xCuzX2MHZgw/d+Xd/KAv6c9WtghrauzyVA1qePNNOJkKbzElHHcA93v6VW/ZjICNbeWm/YSAperlpoXJB5oN6XBIV5LPrWknCMwRgsAP+ezHrsi/5fiz+3ltGidq1djs5yJ5y3mhW+wl1ZrQvpbLaKyWUm4Le+VZs2NmBtmksSjQUpZxjKxPDwQ== 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: Jan Kara Reviewed-by: Brian Foster --- mm/page-writeback.c | 31 +++++++++++++++++++------------ 1 file changed, 19 insertions(+), 12 deletions(-) diff --git a/mm/page-writeback.c b/mm/page-writeback.c index 5fe4cdb7dbd61a..53ff2d8219ddb6 100644 --- a/mm/page-writeback.c +++ b/mm/page-writeback.c @@ -2577,13 +2577,25 @@ int write_cache_pages(struct address_space *mapping, } EXPORT_SYMBOL(write_cache_pages); -static int writepage_cb(struct folio *folio, struct writeback_control *wbc, - void *data) +static int writeback_use_writepage(struct address_space *mapping, + struct writeback_control *wbc) { - struct address_space *mapping = data; - int ret = mapping->a_ops->writepage(&folio->page, wbc); - mapping_set_error(mapping, ret); - return ret; + struct folio *folio = NULL; + struct blk_plug plug; + int err; + + blk_start_plug(&plug); + while ((folio = writeback_iter(mapping, wbc, folio, &err))) { + err = mapping->a_ops->writepage(&folio->page, wbc); + mapping_set_error(mapping, err); + if (err == AOP_WRITEPAGE_ACTIVATE) { + folio_unlock(folio); + err = 0; + } + } + blk_finish_plug(&plug); + + return err; } int do_writepages(struct address_space *mapping, struct writeback_control *wbc) @@ -2599,12 +2611,7 @@ int do_writepages(struct address_space *mapping, struct writeback_control *wbc) if (mapping->a_ops->writepages) { ret = mapping->a_ops->writepages(mapping, wbc); } else if (mapping->a_ops->writepage) { - struct blk_plug plug; - - blk_start_plug(&plug); - ret = write_cache_pages(mapping, wbc, writepage_cb, - mapping); - blk_finish_plug(&plug); + ret = writeback_use_writepage(mapping, wbc); } else { /* deal with chardevs and other special files */ ret = 0;