From patchwork Mon Feb 12 07:13: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: 13552742 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 1BD4BC48297 for ; Mon, 12 Feb 2024 07:14:03 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 761136B0074; Mon, 12 Feb 2024 02:14:03 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 7117B6B0075; Mon, 12 Feb 2024 02:14:03 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 5DACE6B0078; Mon, 12 Feb 2024 02:14:03 -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 461D76B0074 for ; Mon, 12 Feb 2024 02:14:03 -0500 (EST) Received: from smtpin10.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay09.hostedemail.com (Postfix) with ESMTP id 187FE80957 for ; Mon, 12 Feb 2024 07:14:03 +0000 (UTC) X-FDA: 81782287566.10.71F451C Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) by imf05.hostedemail.com (Postfix) with ESMTP id 772B410000F for ; Mon, 12 Feb 2024 07:14:01 +0000 (UTC) Authentication-Results: imf05.hostedemail.com; dkim=pass header.d=infradead.org header.s=bombadil.20210309 header.b=fBxYIBr5; dmarc=none; spf=none (imf05.hostedemail.com: domain of BATV+56c964bc8172c8a9ee6e+7477+infradead.org+hch@bombadil.srs.infradead.org has no SPF policy when checking 198.137.202.133) smtp.mailfrom=BATV+56c964bc8172c8a9ee6e+7477+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=1707722041; 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=UWZt1qWFcFm+fzPf8IEKeJSyXZf+l++RirmcZF+UAzI=; b=JGzCcbGpvpJpoIQhoHHSRJx4mEpA+UWMPL2SABEFAoV1k0XDlVP7QKk1aPWFA3YgrsTiJv CC/Mv/m3f2rdvHQ/OecoCvr15NWK/UdKd1JatFwYDuGpXEo4WQKsdW6qh+NFkvh0igYURC RWc82/FRzpqdTlWFO3w1LSsNuH+p8Bk= ARC-Authentication-Results: i=1; imf05.hostedemail.com; dkim=pass header.d=infradead.org header.s=bombadil.20210309 header.b=fBxYIBr5; dmarc=none; spf=none (imf05.hostedemail.com: domain of BATV+56c964bc8172c8a9ee6e+7477+infradead.org+hch@bombadil.srs.infradead.org has no SPF policy when checking 198.137.202.133) smtp.mailfrom=BATV+56c964bc8172c8a9ee6e+7477+infradead.org+hch@bombadil.srs.infradead.org ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1707722041; a=rsa-sha256; cv=none; b=DMn3M6BLBfvgxqCUSgO4hcVX2RtmT3+IR+gGJfcdmHpd0vzWMjw9ZiqTx844WwZ9B4B/Gt L+tv7qPt+VS9CwfP5Ka7tC0OkXRgunouiYVDZohOjdGku2RrbllKH8u6bbCH4uHIFb4Lri pL8ssBinDS4JM0So9jlq1led3ClodUk= 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=UWZt1qWFcFm+fzPf8IEKeJSyXZf+l++RirmcZF+UAzI=; b=fBxYIBr50i75typXVRTy376Pn/ CQXblV/zQ6YusIu7nNdSNa4irkybtfukPQvmp93qD0JxWc9W6DZVzThYo50vrOq4Dwr7te99PFh3f vzYWhbE86of4eVstB9bX6ZqvUGSxRZlf5jabXXILmkHa2L17gOEj110mYC4ev4VI7z2JOVfYNksqC UEmRO/qWjT+mPYRCr6o514Qc2Y0rZlBM7rt6vQCVvmVi8GiGqCDnxmdlvCsfOWIi00QRG37mlCH50 DOtT3lNEwJoy+DtTN1lTNFOgaru1s+ViQ62OBfv0b/y3Sxwc5zWfuVV8e3nM9aGaGzHJh0tqVNpmV eVw6Q71w==; Received: from [2001:4bb8:190:6eab:75e9:7295:a6e3:c35d] (helo=localhost) by bombadil.infradead.org with esmtpsa (Exim 4.97.1 #2 (Red Hat Linux)) id 1rZQVr-00000004Smh-1CN2; Mon, 12 Feb 2024 07:13:59 +0000 From: Christoph Hellwig To: linux-mm@kvack.org Cc: Matthew Wilcox , Jan Kara , David Howells , Brian Foster , Christian Brauner , linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH 01/14] writeback: don't call mapping_set_error in writepage_cb Date: Mon, 12 Feb 2024 08:13:35 +0100 Message-Id: <20240212071348.1369918-2-hch@lst.de> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20240212071348.1369918-1-hch@lst.de> References: <20240212071348.1369918-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: 772B410000F X-Rspam-User: X-Rspamd-Server: rspam04 X-Stat-Signature: 4qxyzio35kb3u5tw568ks8shfouhdco9 X-HE-Tag: 1707722041-912876 X-HE-Meta: U2FsdGVkX19UMh7l5I/eJ3qt74PzH0vxfSwQL/8CvJJBvHYQatLvT94zPe6Gf0bT9LH1LBeBklsa1auLgYPTE7DwgwoZO8R8A4Y8JLX+E02EkBeHgobkT6dPnly/0Vk2sOcD5ZLT12tp5ue+SZjcRzgt8ulzqnkb0tdTIZmZ+SqIxZKrJaI3VurjHcw16bXGV9+jkVVl4Mfs5gL/OHfZ2hSOaYHdJ14JQK6AXgntRd1cjUYBO+o9OXvwYXYlU1qy/VmR8DWMJp7h2W6jt6g1hgZyG6c1rBEU59D6FvtSxejQ1spvNXx4XjMIbEr9zuSmprjit+ZCJA729mI7mM4HIqH0RyD6UcoG82aiZo060cbZFKiXE8LZ/50UoHtdsYEdPHKn3updKBhI8NQGlKq5kBhQEdQ6bl+gMSlCmdRuI/udWPBN5YtbzLHCyxzbhiCr/mbnen+vySa2pKbwAlHg5DlqpHTY8sZq1OZxP96mIpMfDI3+ZTOSembgd47JEI6AhqU797FXEXUOywP1GmbdlLs1IjOlDE/mP/djQjObV+rUaq76o9n4jDaovAWH++4+jepa3KVPWkAGqYSF/+SXhvH5RFpWl/fmTQG/NSodb+vom1B5eJKGQbRfmxLYhI9SM64uvhN6jIFIU7ixzV0PJKP9I4wUVFm4aHMIRhGWIhZSb6h6WRyuJ2sNDbPG1r6BwWlEStvzJ1CSI0wWP2vVHeFoGEayzRXM/oMtGyuZ8nXkJwbr5RIXeXaUay+DifUOKnCUW+EzESHw0SdSq573hp+SzEkv7YR4sgvIxWSHb/6zmR+58XqCRDI7P2dodandaakyspQPF6Od+EH/P/zTk8d8AtpmhW4R+EXAOkfnBeQ0tW4Y0Udf1QK4Yf6Glw48ItaW+FxXKb7VvE+VXNA9OUY/UKpTzU6coJ5JF/MLj5k6voObHIeU1g2b1ksznaLu1vbhkd8cTE/F6SnH+XA xs3Aq9bK RpOl7EBPDEi81HEOvbv/RGh1J8wQun1L+TOHD+EpxBwiIud5wK3KJ6KbGh93aVVgR7Da5WE/IPs1rkB0JtF4nMtjA1amzsHO1wh5VaJsUhf8JBaRpHpfFLJXtOJ4l+PUEHrl6Jpf+Yv5kO6tQUTQUdwMyLW3nbF6497QrqnVBEmWcK4nc4siI3Urf6g0t7JEGsC3IhsTV25yJ3GLDhyo85DE0t2SQrKmACqwhN3garPF5CRPK29LH/XkX2FTIOEfGfD5MV6Qp0TCy7FGeMhkn0kt5iuZrX/i6tJlbVkmiMD1o92saeDUctmLgiGv8Ujj/g3DWCuqYIVxwiu6zbcyjT8cTH6Hed45dyWrW+xIdA2QY3PqD3snwpmog1FP2Yaz2zq7quolObRtLkyCGMelQFQn5OjC6QS+wH4vlRt/UL4XTj6mE/0hGHmeQ42AmEHokFQmcSWU6gJMBFHU= 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: writepage_cb is the iterator callback for write_cache_pages, which already tracks all errors and returns them to the caller. There is no need to additionally cal mapping_set_error which is intended for contexts where the error can't be directly returned (e.g. the I/O completion handlers). Remove the mapping_set_error call in writepage_cb which is not only superfluous but also buggy as it can be called with the error argument set to AOP_WRITEPAGE_ACTIVATE, which is not actually an error but a magic return value asking the caller to unlock the page. Signed-off-by: Christoph Hellwig --- mm/page-writeback.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/mm/page-writeback.c b/mm/page-writeback.c index 3f255534986a2f..62901fa905f01e 100644 --- a/mm/page-writeback.c +++ b/mm/page-writeback.c @@ -2534,9 +2534,8 @@ static int writepage_cb(struct folio *folio, struct writeback_control *wbc, void *data) { struct address_space *mapping = data; - int ret = mapping->a_ops->writepage(&folio->page, wbc); - mapping_set_error(mapping, ret); - return ret; + + return mapping->a_ops->writepage(&folio->page, wbc); } int do_writepages(struct address_space *mapping, struct writeback_control *wbc) From patchwork Mon Feb 12 07:13: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: 13552743 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 32E3EC4829B for ; Mon, 12 Feb 2024 07:14:06 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id AE46F6B0075; Mon, 12 Feb 2024 02:14:05 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id A96176B0078; Mon, 12 Feb 2024 02:14:05 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 90E076B007B; Mon, 12 Feb 2024 02:14:05 -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 822BD6B0075 for ; Mon, 12 Feb 2024 02:14:05 -0500 (EST) Received: from smtpin28.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay08.hostedemail.com (Postfix) with ESMTP id 437F314092F for ; Mon, 12 Feb 2024 07:14:05 +0000 (UTC) X-FDA: 81782287650.28.C21726B Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) by imf23.hostedemail.com (Postfix) with ESMTP id 9EBBA140003 for ; Mon, 12 Feb 2024 07:14:03 +0000 (UTC) Authentication-Results: imf23.hostedemail.com; dkim=pass header.d=infradead.org header.s=bombadil.20210309 header.b="lhWVSV/4"; dmarc=none; spf=none (imf23.hostedemail.com: domain of BATV+56c964bc8172c8a9ee6e+7477+infradead.org+hch@bombadil.srs.infradead.org has no SPF policy when checking 198.137.202.133) smtp.mailfrom=BATV+56c964bc8172c8a9ee6e+7477+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=1707722043; 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=ytoz/KPvEi5RmjUfqJxVzxJSQTve+3RqSdhmEKjps94RP8U4ArpXmheppanD8VHPcf0TvY 5c0/NeCGxzPhDYNPXnvpsWwBWxoFpqOQ5BIDPJI96w0W0vw9Ec+OppUiQO1XoSCufout8K klma8LpUzcfQ+AQXJejlr6QU/3V8oVQ= ARC-Authentication-Results: i=1; imf23.hostedemail.com; dkim=pass header.d=infradead.org header.s=bombadil.20210309 header.b="lhWVSV/4"; dmarc=none; spf=none (imf23.hostedemail.com: domain of BATV+56c964bc8172c8a9ee6e+7477+infradead.org+hch@bombadil.srs.infradead.org has no SPF policy when checking 198.137.202.133) smtp.mailfrom=BATV+56c964bc8172c8a9ee6e+7477+infradead.org+hch@bombadil.srs.infradead.org ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1707722043; a=rsa-sha256; cv=none; b=zbVnDGnYv/yc3nT7VswVpMZdOlwwf5nvyXEuvl5b33B/OSoGkbmwgNv5ZWckSL58EJYU65 bWfYHatgEPnQwYgMUy9cC3/ZyAzhsNw7H+1tnQqEyWrbCW7bLObTP/MmZB4TZ3BUo/RAYf yt8/pAIy+vWY6FKvWeYeN8wLVl3f6a4= 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=lhWVSV/4NJ4gJRcE/4QSmGNsRr Heu4UlhYcFVsZC14064f5jmUtC5kEA1lwOPdwrtQf/Bd7PJ5yNt6me07tldTSZffNrXe9k9NZy+5B Q9u+5SQ1ktlUZn5sZQ8fUhl2Vnbn0E+3wvmBv13JFwaQXgdvnYDwIzTGHIinQdW+iQtDq8jmJTTrz g3wzeNkmBYPbwoft5gs6t2NdV9u2q9PCKcYUZVS3UVElrQHEBVTvNFaSYRv0dndWcI5M47ywQfpbR LDsxxgMQmNqqi/ArS94YpOJDoT+J02951fSMYJiE3fyr8JXxC0wQeiCpo3cdaZ3zkymXgD/xDHVRr BnWZab8w==; Received: from [2001:4bb8:190:6eab:75e9:7295:a6e3:c35d] (helo=localhost) by bombadil.infradead.org with esmtpsa (Exim 4.97.1 #2 (Red Hat Linux)) id 1rZQVt-00000004SoV-3u3n; Mon, 12 Feb 2024 07:14:02 +0000 From: Christoph Hellwig To: linux-mm@kvack.org Cc: Matthew Wilcox , Jan Kara , David Howells , Brian Foster , Christian Brauner , linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org, Jan Kara , Dave Chinner Subject: [PATCH 02/14] writeback: remove a duplicate prototype for tag_pages_for_writeback Date: Mon, 12 Feb 2024 08:13:36 +0100 Message-Id: <20240212071348.1369918-3-hch@lst.de> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20240212071348.1369918-1-hch@lst.de> References: <20240212071348.1369918-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: 9EBBA140003 X-Rspam-User: X-Rspamd-Server: rspam04 X-Stat-Signature: ud4db79g5ywu8nk1drd9dxxewk14or4c X-HE-Tag: 1707722043-380140 X-HE-Meta: U2FsdGVkX18B9L23Q21l/kEDEZ20lWhUdYJa2VO2q0pR6RiNF9CsLyDLNdMKY1td3taN5w1f0NVoUfn44qKCBZ710D17OnSW34z23OZmB4fA6mJTJJ6B/Hcu7C1/2q+2Hb2H1OX8dHsTqrgk12Fxa4ivZfHwHJA+2CM16C/RyIeiks9uhFTbDWi/7wrr0nwzV8w+EdpXzdaMn6r6z0Ba3WTvMGgMWORgj8icwSLSO2POcYbmrJSccsGHi0VhnAN6gOdOy4vdu23S/koMMic1crViqXqI12253rP2UUeiEKdGOL9llXpCc6fjdeqHJrQi1ul1KENrposWDVbj5RlRB4pWTTjF0Z3hb9FmYxXxJzxjyA2P53DxmIxWVK/9J8q+No0TIN7BqZgVMFQriqciV4GePACHjjW4GAmU8ynBRpqaCB1byD34BUwwjcRbTXStg8ofxbg35EE/9KriOa4otBpWm5RX+Jpph2gHmENnvDmBKaaiLKeyUE3z22n/uaytYBc4+7MHyZCf41370qR6HAVxfy+CbpdeMzzBZ/KkgfRwUJUlpHo98G3QfpAGEKEQtqmdmBYtw0D8OcztJxkvtmg73N8H+mqipn/dvbXiiiL3w/NXraxv+CzP43Jj9YvYhxD76x7DoM2AbCZdkM7ckxinzcYiRgNmVM1odNnCIirir/tYAMmPPcMNX8eJO1UGnRV+tGTnng4NYCcRRGXtjULNdxefEj9M6I88eH8MGukbZaonOipMJ8FMtT1iyln+HNrdSYIgIXWUW8RL7TgNnW9xa+0zJx41APbT9PKEAIrGmaOeEqDzC8GVwO/IWeG/mRGEq2rg/xxawehgvOmGPKKPXnKKGUFswveKHDA5xl9qHZdz3GnVP3lZI7mVEO4nHtrIvcEDJgNYe9GGi8KDI/pFVVVgRD+fMVer9yKK1gwCBkxahaHnWAT0T6RIx94xxaUDKls938KHrydKz0G 6qg28yU5 9yp823maDZqqEabARxi3kB/EFHlrbLkXH0uLtYlHK6hVk2XnZZavRewPh/e9bl2VjgtNDyqFXuoag8EZatcCk/7pOEaLT3tgzrla+EGflJHEjf44O/pC1spyLow88FQntNBBVXv/YCr9b+/WxNr08S4ZO9zPhzItGCk6Gwd1dLG9iNEByl5kGcOpv3+Zb4pJZJDK6ErP4yE9Nd70iOBOjdQB2/uNmnKzEAz/IYTj49B13rUlYBL45TSPOfAzNgR1/ymXUoVivKHO9ub9yHEA+4uxe54PnW6BxHNUZBaC0L+atK6RwO+84lKID5zJkiSr/62szuEriC0NiRrJZomm9KWGTSlV+LtZ8lQHucgRSJvZqV7Rtn5yUt6KAXbYQ5sDbHNXpPkOWwvfyBNk5hn1uaiHEYqHRu3q+Ma7Y5FQwiLBg1YAFOTpIZqS7M9jmr/Nng7NTbv3dyVJq4yZlE+QK7esQziEC4RkQ0uvlcq/HXzN9kDiKNXAS2Y4dI3ejUpVhzfUxJfAKcrVcC88Y010B3vLYT3HZtpqNE71v 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 Mon Feb 12 07:13: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: 13552744 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 A3C41C48297 for ; Mon, 12 Feb 2024 07:14:10 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 3DEDA6B0078; Mon, 12 Feb 2024 02:14:10 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 38E816B007B; Mon, 12 Feb 2024 02:14:10 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 22FF76B007E; Mon, 12 Feb 2024 02:14:10 -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 1568D6B0078 for ; Mon, 12 Feb 2024 02:14:10 -0500 (EST) Received: from smtpin07.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay07.hostedemail.com (Postfix) with ESMTP id BFC5916092B for ; Mon, 12 Feb 2024 07:14:09 +0000 (UTC) X-FDA: 81782287818.07.2B57470 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) by imf08.hostedemail.com (Postfix) with ESMTP id 28C01160009 for ; Mon, 12 Feb 2024 07:14:07 +0000 (UTC) Authentication-Results: imf08.hostedemail.com; dkim=pass header.d=infradead.org header.s=bombadil.20210309 header.b=hQnFDH25; dmarc=none; spf=none (imf08.hostedemail.com: domain of BATV+56c964bc8172c8a9ee6e+7477+infradead.org+hch@bombadil.srs.infradead.org has no SPF policy when checking 198.137.202.133) smtp.mailfrom=BATV+56c964bc8172c8a9ee6e+7477+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=1707722048; 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=64fRIZ4p3xI47I0UjDfQWbOQW89h4igNM/M4APDkPmk=; b=zStkI3pUgKJss0vdVbBWb+7Xn/SgTC9xWQKj7rEzHoBdX3H3gYbIBUzEgjNGjQL3Y0Fbdr hKdjZ6FQIwlh37Qj/HZJHNEUb38ViSuzz2IWYU+gXmP03XLqSmnITSYJx7jPsDDpkKAdYc 7OGblc9hqnUFMWsIMJSogCGgDZ8UWv0= ARC-Authentication-Results: i=1; imf08.hostedemail.com; dkim=pass header.d=infradead.org header.s=bombadil.20210309 header.b=hQnFDH25; dmarc=none; spf=none (imf08.hostedemail.com: domain of BATV+56c964bc8172c8a9ee6e+7477+infradead.org+hch@bombadil.srs.infradead.org has no SPF policy when checking 198.137.202.133) smtp.mailfrom=BATV+56c964bc8172c8a9ee6e+7477+infradead.org+hch@bombadil.srs.infradead.org ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1707722048; a=rsa-sha256; cv=none; b=xukHRctIkKPStabHDvchCh00I9YzsVmYaVW5vOgC9ZSiCzGOX1Gj4CyiNfwTlVxVzm6ZD6 VBsdpboLGkXZ97/7fuotvmN5RTWwV1g5sGdFuINZZ5pQN0uLWXz66Z2f3Pr3FhKVz8gWDr YOjDX1deY25/EgPo2HiBBul/Ya40R8s= 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=64fRIZ4p3xI47I0UjDfQWbOQW89h4igNM/M4APDkPmk=; b=hQnFDH252tFU20hQNpYyUplf2R jumeUc/X4ZUzuexuSNHm/zyXaPRqcggyQGFdoyLASrp+lMWu36MwQwZda9DfA0i/tGTxurxcVuYk2 7vQX8a5ep+6PGO+lgk/7ZmNu31DToIMDnMWWY+Inpo4BxJEsJm3nuNY2w1S2m/Udr5dnhsz4m+w3g hzaOAlGV33RWtrmBE7qG4n77S7sz8swMFa3bkYWn2FVEhrxmydbyy+8dvY+/NHpSd8nKTnUt5B4MC VAQhbSlVmXb6BrgLz0ZDBvn5840bRz3glHriIl64SpSG9IT83gI/0PvG0Y+zfo6FPqO9mOGthd9Ck GyUqemog==; Received: from [2001:4bb8:190:6eab:75e9:7295:a6e3:c35d] (helo=localhost) by bombadil.infradead.org with esmtpsa (Exim 4.97.1 #2 (Red Hat Linux)) id 1rZQVw-00000004SpN-2Uys; Mon, 12 Feb 2024 07:14:06 +0000 From: Christoph Hellwig To: linux-mm@kvack.org Cc: Matthew Wilcox , Jan Kara , David Howells , Brian Foster , Christian Brauner , linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org, Jan Kara , Dave Chinner Subject: [PATCH 03/14] writeback: fix done_index when hitting the wbc->nr_to_write Date: Mon, 12 Feb 2024 08:13:37 +0100 Message-Id: <20240212071348.1369918-4-hch@lst.de> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20240212071348.1369918-1-hch@lst.de> References: <20240212071348.1369918-1-hch@lst.de> MIME-Version: 1.0 X-SRS-Rewrite: SMTP reverse-path rewritten from by bombadil.infradead.org. See http://www.infradead.org/rpr.html X-Rspam-User: X-Rspamd-Server: rspam12 X-Rspamd-Queue-Id: 28C01160009 X-Stat-Signature: nytp3mn3pppc7mdq45uuu7m8d6ozmk3y X-HE-Tag: 1707722047-850174 X-HE-Meta: U2FsdGVkX1/aRV0X9Y5F2XQKje2OLi6qpo/fqVQyLyBWiENXxjjdCgyB60usIOmWyFdkNkVDlC7W8sYLU6fN4GssYXmM4pJlKQW2p6PE7WVsKIA3Vxv8NpF30/4l5l6HnVs0xw5b1h5A0cuobyr/kSsoyxoEz8UrxlUssz746HNxk//gjzDyW+VGB83UrWvXsInpgyvQz2ykIpcx4QUpW+o14axI9z99cto8LTNctchdhPkCDs/rNIcuvJiADp/kuxKkszEowv61iBuC/Om6ZsYlGTJgtTlvhLTl8585wj0Osia5AiUDwn9pYi61InKLuVOgfEL0djYadlUgeVKcwWm7TJbqHTX7GE0eVjUPvF97jd+znENvyO9XQ4O4dAJfJA/03EIj0UVdTmt8ZOMKAjTvpUtFYHoG8QsVEuNt2n2VevIxLzxLaOhnD5WjoJSsLWbZ2L0mCTa3g1ptKQeK/uLwP+U1+YWUMvQkrsAgvrvSgbPVFJeu2uF9Ju+AqiGNtAVfdZzLXrwVdSVOJaJxSsDpBKV3Gzy46BF+Bc3kkkzD5bd9WajYfH2yQHZILQVPb7obTalSe6x7COD3Vub+ZlpdhSVnw3HN/EJLqUtoIkYOiG0TVnFIK9hOTyuhvw+L85J2g3dLGc3mR02c2pAqv418DeMjB9Mm6UQQRfAJxQbYVv9W9YGg10VlILFyG4DNc7P0MBA8QI+2ksQGTf3yUY7QAeVmdleWp4e83l0IcxM4DtrFkAtXhHQ8W7FXy30+uGrn4IeLzboNHJl797wPU30UHND8Kc459PA8DcBMe3skx7i+OfNqlZZEyEzqoMQS39/VUi2VIHfjSuuWvjJuf2zgy8V1cyeH0BB0kzrBCAuucD3OyRY4tl2pIlaB4wrfduloB0MYrHVeCbGTFX3ogo6p6GwBcwMGaOF54hCCEJ8u3CKJDfsBkeqX3ZgwtsOAPFtCMDqPmwRr8PePLtR 9zQveNPL fS7cK0zpLoW/4Hlm+jB2PVkje00A4+LNqrwNWNBekdeU8Gnu+y1lvm+Xn0aUV6ghnaUnprT5kNCA7KtYbLvusrRKYCRp6645BEpgLK4bVAMYnTZ885WwQ7zCa5LyyiyjnxV9HO3/C4LxwlXvOniRLTCNOR0B2+K4LeKvMqa/kDpMPvmf+L8wRxGsU3o9fkJdCS0ujcZ2NnzaAk9b5Es/7I8n+gDrHAt4HGRt//hXmQMYZrR/6HEDTLUgBi9sFQdLksCnaC85KRzqEU1ZoySJU3y2EhJMCTQFAYtixRH+Cn/YH+XM/ojKLVSBFdyqf0J+JRNY0+wS/XItIio2bv05W87WA8mZFmcd92w3MgPalnpKdSNgRbyIGZJabNQPTrppsy4Nic5c1V4xF9V4VdQ0rAueOtqHWhHUWAoZg0qfXgxjpE/e6Ip5ffNJUdlrzpTJoko6Q7kh02fXA+K6DjcCyAgbb4OgaSs54GKM7HIshByoaIAI= 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 62901fa905f01e..aa3b432f77e37a 100644 --- a/mm/page-writeback.c +++ b/mm/page-writeback.c @@ -2505,6 +2505,7 @@ int write_cache_pages(struct address_space *mapping, * keep going until we have written all the pages * we tagged for writeback prior to entering this loop. */ + done_index = folio->index + nr; wbc->nr_to_write -= nr; if (wbc->nr_to_write <= 0 && wbc->sync_mode == WB_SYNC_NONE) { From patchwork Mon Feb 12 07:13: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: 13552745 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 56175C48297 for ; Mon, 12 Feb 2024 07:14:13 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id DCAF86B007B; Mon, 12 Feb 2024 02:14:12 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id D7C5D6B007E; Mon, 12 Feb 2024 02:14:12 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id C42F96B0080; Mon, 12 Feb 2024 02:14:12 -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 B57DA6B007B for ; Mon, 12 Feb 2024 02:14:12 -0500 (EST) Received: from smtpin22.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay10.hostedemail.com (Postfix) with ESMTP id 8BA97C08BB for ; Mon, 12 Feb 2024 07:14:12 +0000 (UTC) X-FDA: 81782287944.22.628DFFB Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) by imf25.hostedemail.com (Postfix) with ESMTP id DC320A0013 for ; Mon, 12 Feb 2024 07:14:10 +0000 (UTC) Authentication-Results: imf25.hostedemail.com; dkim=pass header.d=infradead.org header.s=bombadil.20210309 header.b=dJIvNT8i; spf=none (imf25.hostedemail.com: domain of BATV+56c964bc8172c8a9ee6e+7477+infradead.org+hch@bombadil.srs.infradead.org has no SPF policy when checking 198.137.202.133) smtp.mailfrom=BATV+56c964bc8172c8a9ee6e+7477+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=1707722050; 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=2QW1YOpfZggQarO2hJ9pUOEEOVq5PMz3pyBHLyK4cac=; b=PH6JZaNkfCoSrcCCTTNY9DrHiEU7duQ7JW9qfXnRe5YpVSdWyqYeHXqAvvaqdOCWbvWyOU eY0uys2AhOSJF3kHTcVnu/TO6faoHln/N5dlyDxzCME1++vQ9HOMm9o5ZEaR5ZwFzjNPWL tiOFID5wtn6MLTGsOfDIzlvRpGWIRGg= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1707722050; a=rsa-sha256; cv=none; b=wav/AHFEHYMX7pNQT/ckV0VHMj6vhaH2tKFQOcDQ0adLb/pTWvuASnkCyawnx1OO/RxDwZ Rw2A961pWj7qk4ZdIGz4tlgg9MooWtVz17e+o0rg2UohHucCAsrUlCsHJ9t6hKY/O/GNoK HaSzZTunUJPkeZ+0TOOgKqB5ocLMAJ8= ARC-Authentication-Results: i=1; imf25.hostedemail.com; dkim=pass header.d=infradead.org header.s=bombadil.20210309 header.b=dJIvNT8i; spf=none (imf25.hostedemail.com: domain of BATV+56c964bc8172c8a9ee6e+7477+infradead.org+hch@bombadil.srs.infradead.org has no SPF policy when checking 198.137.202.133) smtp.mailfrom=BATV+56c964bc8172c8a9ee6e+7477+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=2QW1YOpfZggQarO2hJ9pUOEEOVq5PMz3pyBHLyK4cac=; b=dJIvNT8iPWSyPAEA1cLuE0R6F/ +MI3j0k2PaFmoed7PIV31w4cjyiO/A9tRJ1wuYiDzg0P6+2xn9yGpkqkoU84H/uyqGDD8/8PxBBfQ AFkG/svjPlhqN9q9KovsSyxhMQnnhYP6eKBcGdGQ7cpErALum72bOaABOLi3nWI08NNWV6YIRTDM4 XaZWfmZtuFb7tRrSdMIatAztr8Wku7CuRHPn8WD52iMGkhxkDKK2RFyyLSDnYhpbrmDbaWIBV1wEY EM+HyvMdvT7MosOnjNsAmMCaAYPWgIVZa2GMzHwxyB+/wjpNd1Fa1LR87khgeDjw5xO/CjND/s9mR /fh/xOzA==; Received: from [2001:4bb8:190:6eab:75e9:7295:a6e3:c35d] (helo=localhost) by bombadil.infradead.org with esmtpsa (Exim 4.97.1 #2 (Red Hat Linux)) id 1rZQW1-00000004Sqd-1p3o; Mon, 12 Feb 2024 07:14:09 +0000 From: Christoph Hellwig To: linux-mm@kvack.org Cc: Matthew Wilcox , Jan Kara , David Howells , Brian Foster , Christian Brauner , linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org, Jan Kara , Dave Chinner Subject: [PATCH 04/14] writeback: also update wbc->nr_to_write on writeback failure Date: Mon, 12 Feb 2024 08:13:38 +0100 Message-Id: <20240212071348.1369918-5-hch@lst.de> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20240212071348.1369918-1-hch@lst.de> References: <20240212071348.1369918-1-hch@lst.de> MIME-Version: 1.0 X-SRS-Rewrite: SMTP reverse-path rewritten from by bombadil.infradead.org. See http://www.infradead.org/rpr.html X-Stat-Signature: f5apunoknugq71sjarpcdib73i1djqsa X-Rspamd-Server: rspam10 X-Rspamd-Queue-Id: DC320A0013 X-Rspam-User: X-HE-Tag: 1707722050-515096 X-HE-Meta: U2FsdGVkX1/I640h/t6dR+uLyH3LyFjQVkPiV8m9GN7/teEsoxFR8lzKprESfPfxliClKYPG7z3DsmhqI1/HbAe30biBa5IxeQsUD278lwV7gRbNDqhOLGZRDjj2rWkraiBhbjxqfoykeH1dQdSeVcWiyTvQiwmW1hJUAqMqSqsP0sJVmIXT5a3SnDocNWFRL8flteDbO0i29ipnhhW6MgFsqjXMoa46xemWrrIQpLXXOED0AMfe9Wi1K11/MMvI03GGohLNSrPHYcQyfUgeymjpLuegqQC3HGuUCpJeE0vOmSANx+lw0dMrsOYQEa+FOxWUM9jzOguWNZJL6kawBGGWPSmvekSzMuNO+QWGQXXw0cCU67/QAr0UC00ULDwFo9lX9tPK5CWxMMfL4xjwldjFvyMFvFONF6MdkAJ+vVGCflUd7nz6/Sxokifj3YNjor1hGCzj4tnseDprepZPqEj1tBm5Ezag6GAJ3Z7v+AojUPYrQjuhBX+8sGVipiMWb5XF+e6i3bHmEKl+OKVfOq2ZnutsRjxrzEho5YUjsStRPVNdmbc6Jxj7TJNqkGnWJ7oRt+JKMF1kCPeLNLw7AOMef3cLpll86BTNivd5fpRkzarTe6XO3XavlBriSCoADBA9tcWJGbMcl0F0Y88PDXRGXaud/ow3kGENaYSvTyTCaHPuwFKIj7nqd1Gh4n3ey5iPFR6ym6t2TyFmHiW87NgYv0ZB8vL0PUPMwJdY0K8kA8kaVAedBd6g8JS57WW28dFP5fDXuCQFM7l/BDSQ4/7fjHmoR0H4UHYyDkd1b5NRrfbZRs3NzfjjXcQXUjBqzAGkAZO/KK/V2Y3EIAu4T+ZqCFuE8BFy+OR1O+3q4HFC3AqtxCjwhY6SEJXOU7A8frIwsS8hnzvlm44WOv7vXS5Mr+ibdz4A4rEw2Iobuc8s747GJ6EIjcfXi5C0rI7a++Ta/Kp7hREs4eyFs3a j9+WNCCY JFaoB7BP/BdDQ/SJf7LlMA4HPq/wB7OFvSK/fAIXpTA1B88zrse0aokVy7v+WorFWLkJOtUBO2jdw7/Q6gOd2o/JA/CK9SbvyJ14QrPMe/5pzBcHCf3PMRv9znl5LrxvxAb+ZnwC88zh7dhSynbIEgHFMFEOeyT/gNCIMpnuUPAuX1AJmXFemErJGYPlS80ZqVzeX2PEXWtLTTPrSAzv4AbLGJdQe3aSWrHNSu3XBY7hTBCt080evBqYmkprWHWsF5cxyfQKUT8hdT5AXkyIx+4JkDSFE01BE39KTH726CpzV6ppoe4L425cal9Y2RCX7wFvNf1W1W/cb3PKeYEZmI3ndXXdBl/ss8f9QU2unYo4p3laU4ebo0ak88o2YDZUEKTMorpRPMxFSjF09QqXcOdh7Tgb37S0UPyM2HtPOY1zQfaC4UlAos5CekeWi3WnYf8eV5+oIuz5QhcWSeAaj2wA34CfiJmBsgAAT15PcunpBc6A= 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 aa3b432f77e37a..06afba8f078515 100644 --- a/mm/page-writeback.c +++ b/mm/page-writeback.c @@ -2473,6 +2473,7 @@ int write_cache_pages(struct address_space *mapping, trace_wbc_writepage(wbc, inode_to_bdi(mapping->host)); error = writepage(folio, wbc, data); nr = folio_nr_pages(folio); + wbc->nr_to_write -= nr; if (unlikely(error)) { /* * Handle errors according to the type of @@ -2506,7 +2507,6 @@ int write_cache_pages(struct address_space *mapping, * we tagged for writeback prior to entering this loop. */ done_index = folio->index + nr; - wbc->nr_to_write -= nr; if (wbc->nr_to_write <= 0 && wbc->sync_mode == WB_SYNC_NONE) { done = 1; From patchwork Mon Feb 12 07:13: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: 13552746 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 DD403C48297 for ; Mon, 12 Feb 2024 07:14:15 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 6C5F06B007E; Mon, 12 Feb 2024 02:14:15 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 600156B0080; Mon, 12 Feb 2024 02:14:15 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 4F10F6B0081; Mon, 12 Feb 2024 02:14:15 -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 3CE9C6B007E for ; Mon, 12 Feb 2024 02:14:15 -0500 (EST) Received: from smtpin04.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay07.hostedemail.com (Postfix) with ESMTP id 0E25716034C for ; Mon, 12 Feb 2024 07:14:15 +0000 (UTC) X-FDA: 81782288070.04.3272AAD Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) by imf04.hostedemail.com (Postfix) with ESMTP id 7485C4000F for ; Mon, 12 Feb 2024 07:14:13 +0000 (UTC) Authentication-Results: imf04.hostedemail.com; dkim=pass header.d=infradead.org header.s=bombadil.20210309 header.b=QMXkj9OR; dmarc=none; spf=none (imf04.hostedemail.com: domain of BATV+56c964bc8172c8a9ee6e+7477+infradead.org+hch@bombadil.srs.infradead.org has no SPF policy when checking 198.137.202.133) smtp.mailfrom=BATV+56c964bc8172c8a9ee6e+7477+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=1707722053; 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=KUIj5droJWBY9JuTDNlu6m/OZ7SC5gyUm02IKuKQE8M=; b=i+MfDeUC6DI16hVAMry8jEcbyOiPPnCmde8hiaM7mtAzF3dK8fU+8rpk2J4LzA5ZN39y/o TWgbRxvkRpgl5zyJdQsm6Ynic2LKIjMcXAg3vqshyIZXlOci4s/hjEQuYYugsfyEEXiSjd wDhICRc4c1tPnOsFNTz1StQVzYjuUeY= ARC-Authentication-Results: i=1; imf04.hostedemail.com; dkim=pass header.d=infradead.org header.s=bombadil.20210309 header.b=QMXkj9OR; dmarc=none; spf=none (imf04.hostedemail.com: domain of BATV+56c964bc8172c8a9ee6e+7477+infradead.org+hch@bombadil.srs.infradead.org has no SPF policy when checking 198.137.202.133) smtp.mailfrom=BATV+56c964bc8172c8a9ee6e+7477+infradead.org+hch@bombadil.srs.infradead.org ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1707722053; a=rsa-sha256; cv=none; b=AWDSsQEtc3AqDjmQ6GaLGZkWevr038bLYjLmwhVg5NI6WP1DHh+jt/UIRbJBjS5JO+jpwg 8dF6gYnMHAffLapVjx9rKRSUFXHTlq/QN/HUA4VHt/d0sn4Us7y06whBF3H/ja68bn7JbA isdQ1SyN1r0FEYTaYKZ9S41bpnJN+yU= 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=KUIj5droJWBY9JuTDNlu6m/OZ7SC5gyUm02IKuKQE8M=; b=QMXkj9OR68fUtzLzKk+BxuxP5V lLcsfARWxz3J73jW+4CgAYNChX8vH6k0bYjyje3Ka3UUp3oc6GxLgHxFAdgUXy8I3Q3cRXMjVbNo2 UTdZOTlyUdiKdDXVA+30f9Hz4sGb1b9PlTE9EOQ+6g0S36udj5BbdA6CafPZ9Po96XiHG8eDOgtKG FKwNEztpeIb/BiXUv4XWkKCconDCsJXg0G+1M929zR6uRK51QBCmXgoU2HM5G4xb+Jbb2b9r/568X TIwGtt07kVctUBqVnmuuBQ/x2I5CUpuUf0jYc9Ig1T/eFiRNpVsz+Ge0Z6jbgho4bypbjl34cJZtc ux8+JkwA==; Received: from [2001:4bb8:190:6eab:75e9:7295:a6e3:c35d] (helo=localhost) by bombadil.infradead.org with esmtpsa (Exim 4.97.1 #2 (Red Hat Linux)) id 1rZQW4-00000004SsL-0LR5; Mon, 12 Feb 2024 07:14:12 +0000 From: Christoph Hellwig To: linux-mm@kvack.org Cc: Matthew Wilcox , Jan Kara , David Howells , Brian Foster , Christian Brauner , linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org, Jan Kara , Dave Chinner Subject: [PATCH 05/14] writeback: only update ->writeback_index for range_cyclic writeback Date: Mon, 12 Feb 2024 08:13:39 +0100 Message-Id: <20240212071348.1369918-6-hch@lst.de> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20240212071348.1369918-1-hch@lst.de> References: <20240212071348.1369918-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: 7485C4000F X-Rspam-User: X-Rspamd-Server: rspam05 X-Stat-Signature: bf831dfmgthi9espnc1zzne66mwgdd8m X-HE-Tag: 1707722053-99672 X-HE-Meta: U2FsdGVkX1867sHkAq7X2Fwd5r66mASlDoD4pD3fTw8/yQCSn0PQphEz6XtpkeHK01KKoonaDVmLRWdo6n0C2yZwDVKP4l+XbgxyXJ1vYGns3biNCr8y/FrOzsJBhdEG8dVlrkJr3rnKYdNLxkwgjJwJvyoJx4m+aWnxJpRpJyQtLHkOWRvFfsdSieapP9331n8tiZuCeWiYf+ey2V5o+5lYOYaOTIagHRXrEd+VvEwk7q23h2scIqKE+wlD16U37i46Q+AegPbV8thIhq0zyA9B9BiSyzrTNHcwgN38CAC3uAj3WYbVSspajXRGABM8Dmaur/+QyiQwfike16KRbVMkqygETT64PgRdgyP93XR3ZrG9B23JklCLPY/B0evs3Vu8Lqfxwfu1cQZwbBf13g4Zhm0TFQb3GVut5im+5c6zy7jGEJ+0BRS0kDOWZt4jWf/Ys+wqY9a1VX9hEWUXpn/y7qYzsOQcXrcYfWKnT7oYHsxtVJyIYoQho6bpBOFItWx0xiMfyXCek1Pobee1ArjZNrK3MZfZbNx4OgPJuwgcY7qPOTO7/j7SO/aa/JLA+DXfYf3QrQ7m/3S5yHIznlLSZd9xhOhbJVDeT/YEUth/TkEcNyUNXzob9/Eg50m/RKgkJLp7reywka7qqQw2MtrtZA+MkLL05NoDDDXJtq0Qs/9oPm59k+lpfKWX5w62KIahC4hdXGBh3rNNzlg4OGh0LcOJVrxSJH2AeeLldjqJYmJ3P9zmuOsbht1pifraMwzgbZ5ob+VbLAhelbNaaZN61b2f5s8/4fbxFmLG1DjRaNY3MSf4y5VeVh0PwZ9PVtd4Vy5MedxY+ftOz+ICacnVVIIO8R3xJ38vafLYUSDcTNRE0C14ktHfE/Sof91iAwqM3fziP+Ki/d91kHqjv/hx95fm19cwfF8nx7LfDr4+mJphGW8tV2fakox1G6RiocWlEIEIgXaKDq9Fhv2 8aYV+7rq KoW9clVbUHcNeYA1/Ce8cWjLyB2k+9FASArASW4dxXf0gNZTf6fILG0gaRkUgFIbIkCP5q3Gh3j07kyFrhUnrXr5G7lbH2mRysmSCP4sMM2Q6gp8NylGEi2eHAg8BFfPFbC0EHls74BEcVrkNBMlyII1GOJ0uFKXmOb06Mc8t7ybaRaCMMGuDaVDaAKplE/LNZdZMMBeHzMXtEldrcPhnorrI30L8Ux7OAKVN18W7HvtAY7yTTS/33BxOmacKfhguKZOsLBYPVbYriA9+n9fnvzkler+9HDmh6A8nivQalQ5sNnW/af+9F6fWTHgMoiYl9xBENc9+oZRXraTBfx57KF6paMi6vBOhe5YC8URrk6D3yZ7cCK9PlKE4Q5qoH6aK5bukBdhThj7u9XqTpDdQahWG+GIYCedwJ634/QlfpLZehhBUFYc9r5mw95vhdTxtsoOmzjAH8MfFHyZNDBcrMbGyKLo4HWbRxeR3CCzXNAFQs7o= 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 06afba8f078515..4d862f196d1f05 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 Mon Feb 12 07:13: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: 13552747 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 499B4C48297 for ; Mon, 12 Feb 2024 07:14:19 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id D085A6B0080; Mon, 12 Feb 2024 02:14:18 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id CB85B6B0081; Mon, 12 Feb 2024 02:14:18 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id B59438D0001; Mon, 12 Feb 2024 02:14:18 -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 A37A66B0080 for ; Mon, 12 Feb 2024 02:14:18 -0500 (EST) Received: from smtpin11.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay03.hostedemail.com (Postfix) with ESMTP id 83A07A06A0 for ; Mon, 12 Feb 2024 07:14:18 +0000 (UTC) X-FDA: 81782288196.11.E5CF01B Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) by imf15.hostedemail.com (Postfix) with ESMTP id E419CA0011 for ; Mon, 12 Feb 2024 07:14:16 +0000 (UTC) Authentication-Results: imf15.hostedemail.com; dkim=pass header.d=infradead.org header.s=bombadil.20210309 header.b=nfOtutd8; dmarc=none; spf=none (imf15.hostedemail.com: domain of BATV+56c964bc8172c8a9ee6e+7477+infradead.org+hch@bombadil.srs.infradead.org has no SPF policy when checking 198.137.202.133) smtp.mailfrom=BATV+56c964bc8172c8a9ee6e+7477+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=1707722057; 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=To4jTyxCYxUY5wd7w+9Le458r9Ys3/VfyFqqGfNjFPc=; b=vBVKW9QimrGJaGNBudOit5d0YCZCTBqRj/MA/pC8uc//b2ynHxfv3GYqHyLADB9Um8KyQO jdzQTLXXE0K+gQYDTHlYAx74CqRkVtwN3y6okcyaoyRuhZfGwzd3MeWmr+ASXlostrZKQ5 iWQt4dWZieqPBxnSOQTT9m68ntH04yA= ARC-Authentication-Results: i=1; imf15.hostedemail.com; dkim=pass header.d=infradead.org header.s=bombadil.20210309 header.b=nfOtutd8; dmarc=none; spf=none (imf15.hostedemail.com: domain of BATV+56c964bc8172c8a9ee6e+7477+infradead.org+hch@bombadil.srs.infradead.org has no SPF policy when checking 198.137.202.133) smtp.mailfrom=BATV+56c964bc8172c8a9ee6e+7477+infradead.org+hch@bombadil.srs.infradead.org ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1707722057; a=rsa-sha256; cv=none; b=Pub+kPHpwXf23YdAuwbB9jjyaAix64fg53H2h2G96B+Uo1joSh3PF7YKhcabKHb9RtEGLb TdLcByir6v36PAOdwtLVGPXjYSrYp4kC/W3Ygz9oYVjyaUJsdV0cn98bgR0CIObE0dB+Id QU7aFWSqr9in4VgL+ExKHX/2198GSjY= 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=To4jTyxCYxUY5wd7w+9Le458r9Ys3/VfyFqqGfNjFPc=; b=nfOtutd8j/0yHOPqqs1KM8fcvG q75YNKjRHxoc4Blgsq58A8PsYUG7YdvL+tmtdrQdsxoxjEgr/IjOWJBkBvMs+l5cmHKgcjd8uv+Kp 6Ol6MRgsBc4zfotAveb+QxwCtqStBJfTcZsbd+o4cxI/Spis1YF5p1g67mL5OBPIwz1jE8rVpopVk +kfLdFl+bliXGifeP7QdRNGixZVQ7R48kHZkHkKkbNGGFGtUCLQRyqq9BHODEkvg0et9bymQbGSWO agC+LF8N1vhEkgfFNyGl7XtKg3Cl9fUsChZREhpyU0ujaUfgWS5nFXu0L8mJuYizPNtdFfLAfkXJN 8s709i4g==; Received: from [2001:4bb8:190:6eab:75e9:7295:a6e3:c35d] (helo=localhost) by bombadil.infradead.org with esmtpsa (Exim 4.97.1 #2 (Red Hat Linux)) id 1rZQW6-00000004Su2-363S; Mon, 12 Feb 2024 07:14:15 +0000 From: Christoph Hellwig To: linux-mm@kvack.org Cc: Matthew Wilcox , Jan Kara , David Howells , Brian Foster , Christian Brauner , linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org, Jan Kara Subject: [PATCH 06/14] writeback: rework the loop termination condition in write_cache_pages Date: Mon, 12 Feb 2024 08:13:40 +0100 Message-Id: <20240212071348.1369918-7-hch@lst.de> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20240212071348.1369918-1-hch@lst.de> References: <20240212071348.1369918-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: E419CA0011 X-Rspam-User: X-Rspamd-Server: rspam05 X-Stat-Signature: e5y9m64amiu5r8o6u7ndtphc6hffc7z1 X-HE-Tag: 1707722056-605495 X-HE-Meta: U2FsdGVkX19E10bU38fvLjbrTrZgs4nT04tt0xN12tV4TIiZraBl7h0+4u29VzLLfKdUoRIO5YJ3dhm4ZLE08t93FVf6gd64+X9U8H/smFtj9c2jpK7ECEmM0ZtB2u80G1tjWskJe2v37gOJEK2v0ecHzdnmVhksayYNOS1owfGetp9qZL7T8cqlxwFXQQve9xXY/+TfweoPf9mUmrQbaMS+Ye4fru4qzSml9biwaLGq+HViSFUWirOLOzKIrV/R/jtnMfowdWVgetAs7gn8UuAi2QkyWUp+IQpX/2kf4dnzaE3ekfPo5wEKeJ3JQm7GXIoFH72EzktG0AF3h+sfEPc4mShQdzHdcooO888eJrVJBPxwpblLMBeJUaWCAgXtPnu3rJsE+9dODEPw3K3m6i6sDW1ebV9kJNZ+geYZQC/iOrjesMSdXB2ZW5Mu2ibGL34IKHFTbtJcBR5satUx9Fa4HU2uqeG5HZA7tRvGSWgGLEm568UxJ0sMmiS6zT7/XHHYLL7n2xgNAUaXg5FNFm/56XXGvX8JLevu/O8ldgBBIaUzO9WYv1hINywZJDhueRHwevAU52ssKrjarT9IIlm4KbgQWsjN7v0FUmrwnwImt70Ia/c3wZ3i0d1CAMcRS71/eai6alQogz2P6LgUMDjPAwXhY7woH83OI3gM/EfrTu0CKaumd+EjRVhkAaYNO/m9h0P+fh7OoXR4+qPtE4vP74AasqHTjddG+WXYewDreRbe3wAk4TWrwOTRVxk9A0XWIa4qOtOZh7glaMqHvHrXO6uuYDUMj47qnWuy8TPJWCvelNHoFEIFnl7vGXHtekolJngKq0ECSKp9cGfs1AjcAZfcos6qJAPTCEhnhyPJYOZVMkZXCQtMLNfR9RvlLix6h6d/T9B4hHbrd0KGxjRNOb9NsqmdmG6jGtl24z02KLK1vBqehE3SF7VHzP73z4gsI8SVXC3GvyOWVjr Rf4eLTjt UdrY8kpjW7SQKF8zs8RHzANQO0dMCtLKZVucJP76yR4we6dh4hFUAAIiuJu2Qna4Z/tRQt9O3zp6a5P5c6dRFW2I9yKcZWlhGIm5Jkf5I+lgXp2LokuvrNkV/Eu5hmZtbwZSb8To6aIfO7tNpI/7JxGG/Tqn5nPJRWS7XpEME/BQHdBRfcv2KZ9saxGgIEQk3dfuM4gnZjPDhg6u5fVgNkEM+r+7x6NN8BUpYVTYepCHVSw2Fjx8hrZ9qNoe10XyicZgnGpCcJbV0OTrU/lUqdKuMEW6y0n6oFwcGV1WrMjgZ0D1MEDzxaKvvE1ex7EqlvWRK/bDLbp3dFQuvViVjYGSo1Puhw9nC9gFelanUXUBZfG8mgWOjuwHuHVN+go63BZl9pbXFgyD0GdnWl3gdSHQlm9B7F4wCoVHj4BARMtNwvxrtz55HqmQuvdzXikQZFj9M0eXkIayFf4N23+CZ1HlvCVwKPNHuW5uWx8xM5YJ7tDg= X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: Rework the way we deal with the cleanup after the writepage call. First handle the magic AOP_WRITEPAGE_ACTIVATE separately from real error returns to get it out of the way of the actual error handling path. The split the handling on intgrity vs non-integrity branches first, and return early using a goto for the non-ingegrity early loop condition to remove the need for the done and done_index local variables, and for assigning the error to ret when we can just return error directly. Signed-off-by: Christoph Hellwig Reviewed-by: Brian Foster Reviewed-by: Jan Kara --- mm/page-writeback.c | 84 ++++++++++++++++++--------------------------- 1 file changed, 33 insertions(+), 51 deletions(-) diff --git a/mm/page-writeback.c b/mm/page-writeback.c index 4d862f196d1f05..b49ee15a863e99 100644 --- a/mm/page-writeback.c +++ b/mm/page-writeback.c @@ -2396,13 +2396,12 @@ int write_cache_pages(struct address_space *mapping, void *data) { int ret = 0; - int done = 0; int error; struct folio_batch fbatch; + struct folio *folio; int nr_folios; pgoff_t index; pgoff_t end; /* Inclusive */ - pgoff_t done_index; xa_mark_t tag; folio_batch_init(&fbatch); @@ -2419,8 +2418,7 @@ int write_cache_pages(struct address_space *mapping, } else { tag = PAGECACHE_TAG_DIRTY; } - done_index = index; - while (!done && (index <= end)) { + while (index <= end) { int i; nr_folios = filemap_get_folios_tag(mapping, &index, end, @@ -2430,11 +2428,7 @@ int write_cache_pages(struct address_space *mapping, break; for (i = 0; i < nr_folios; i++) { - struct folio *folio = fbatch.folios[i]; - unsigned long nr; - - done_index = folio->index; - + folio = fbatch.folios[i]; folio_lock(folio); /* @@ -2469,45 +2463,32 @@ int write_cache_pages(struct address_space *mapping, trace_wbc_writepage(wbc, inode_to_bdi(mapping->host)); error = writepage(folio, wbc, data); - nr = folio_nr_pages(folio); - wbc->nr_to_write -= nr; - if (unlikely(error)) { - /* - * Handle errors according to the type of - * writeback. There's no need to continue for - * background writeback. Just push done_index - * past this page so media errors won't choke - * writeout for the entire file. For integrity - * writeback, we must process the entire dirty - * set regardless of errors because the fs may - * still have state to clear for each page. In - * that case we continue processing and return - * the first error. - */ - if (error == AOP_WRITEPAGE_ACTIVATE) { - folio_unlock(folio); - error = 0; - } else if (wbc->sync_mode != WB_SYNC_ALL) { - ret = error; - done_index = folio->index + nr; - done = 1; - break; - } - if (!ret) - ret = error; + wbc->nr_to_write -= folio_nr_pages(folio); + + if (error == AOP_WRITEPAGE_ACTIVATE) { + folio_unlock(folio); + error = 0; } /* - * We stop writing back only if we are not doing - * integrity sync. In case of integrity sync we have to - * keep going until we have written all the pages - * we tagged for writeback prior to entering this loop. + * For integrity writeback we have to keep going until + * we have written all the folios we tagged for + * writeback above, even if we run past wbc->nr_to_write + * or encounter errors. + * We stash away the first error we encounter in + * wbc->saved_err so that it can be retrieved when we're + * done. This is because the file system may still have + * state to clear for each folio. + * + * For background writeback we exit as soon as we run + * past wbc->nr_to_write or encounter the first error. */ - done_index = folio->index + nr; - if (wbc->nr_to_write <= 0 && - wbc->sync_mode == WB_SYNC_NONE) { - done = 1; - break; + if (wbc->sync_mode == WB_SYNC_ALL) { + if (error && !ret) + ret = error; + } else { + if (error || wbc->nr_to_write <= 0) + goto done; } } folio_batch_release(&fbatch); @@ -2524,14 +2505,15 @@ int write_cache_pages(struct address_space *mapping, * of the file if we are called again, which can only happen due to * -ENOMEM from the file system. */ - if (wbc->range_cyclic) { - if (done) - mapping->writeback_index = done_index; - else - mapping->writeback_index = 0; - } - + if (wbc->range_cyclic) + mapping->writeback_index = 0; return ret; + +done: + if (wbc->range_cyclic) + mapping->writeback_index = folio->index + folio_nr_pages(folio); + folio_batch_release(&fbatch); + return error; } EXPORT_SYMBOL(write_cache_pages); From patchwork Mon Feb 12 07:13: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: 13552748 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 2788DC4829B for ; Mon, 12 Feb 2024 07:14:22 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id B7FC86B0081; Mon, 12 Feb 2024 02:14:21 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id B31038D0001; Mon, 12 Feb 2024 02:14:21 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 9F9EB6B0083; Mon, 12 Feb 2024 02:14:21 -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 8F5776B0081 for ; Mon, 12 Feb 2024 02:14:21 -0500 (EST) Received: from smtpin25.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay08.hostedemail.com (Postfix) with ESMTP id 5C9C3140956 for ; Mon, 12 Feb 2024 07:14:21 +0000 (UTC) X-FDA: 81782288322.25.740EB8D Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) by imf11.hostedemail.com (Postfix) with ESMTP id 978344000F for ; Mon, 12 Feb 2024 07:14:19 +0000 (UTC) Authentication-Results: imf11.hostedemail.com; dkim=pass header.d=infradead.org header.s=bombadil.20210309 header.b=hYd1tnNc; dmarc=none; spf=none (imf11.hostedemail.com: domain of BATV+56c964bc8172c8a9ee6e+7477+infradead.org+hch@bombadil.srs.infradead.org has no SPF policy when checking 198.137.202.133) smtp.mailfrom=BATV+56c964bc8172c8a9ee6e+7477+infradead.org+hch@bombadil.srs.infradead.org ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1707722059; a=rsa-sha256; cv=none; b=PUJdFqm7/1T9tDT8+ElDNTs9TwQzMmBX3oZSgjKW9grIrvvm4Bq+Na5wyUood4Tn3EpvuH 3EEA/oNgNmcH5VFhYZjmA3xQEUoEzpCoZaPX+TjSliUXSVacFX7WoHeIK0RqCD6+291cgH xEhYQYEn/n8FDuJW2XhI7dt3b0hEvx4= ARC-Authentication-Results: i=1; imf11.hostedemail.com; dkim=pass header.d=infradead.org header.s=bombadil.20210309 header.b=hYd1tnNc; dmarc=none; spf=none (imf11.hostedemail.com: domain of BATV+56c964bc8172c8a9ee6e+7477+infradead.org+hch@bombadil.srs.infradead.org has no SPF policy when checking 198.137.202.133) smtp.mailfrom=BATV+56c964bc8172c8a9ee6e+7477+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=1707722059; 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=Vlqq71/8cVy7zsg5xjVrhlKjzr59zOQg5vGY/d9fuxQ=; b=lH1NUH6ACt2BSjem0qomDcdhY+d71oelsZmc1RuxBTPR7wI/Sa0l35LkMIV+jrepdCb3lW 4dl7QlIiW5ZtETqTyMilXDNGxDuieoPZi1dGqfVzlh+W4pUHxxS30tWb4RU5V1ZpfsJLgq 23bkgzum7Eg1cdcHW8USuthbBjUZAp8= 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=Vlqq71/8cVy7zsg5xjVrhlKjzr59zOQg5vGY/d9fuxQ=; b=hYd1tnNcGbUg+/gh3uTrVMVQBo 5C0owQ98hyLKCFuNzHZWKhpaK4i93rvDQf/YtRRosKmoQIatQX8GjBjLbNYU51u5x6BrMXyEwBThp V9v4bboxACxI4B64dBWWgcHn1ZmTMHYpFUfEuEK51eADVZ4JTtdT6uLwEFs67KWUM61jy+NECgrNs mqnGux6DoCpjC8K2uCNHmjf0eh9L9n4iEg9A171Z97uzfL7+T7QAwHc7wm2lqkpPjM1zbpyYt+M1j paXId343ZnCHv/8fufhVVqFEjQfGz33QP6rkneYGZt/dolem9SLOlXG2viWp/P2MLcPHEhc5JbcyF Tqs5/HMg==; Received: from [2001:4bb8:190:6eab:75e9:7295:a6e3:c35d] (helo=localhost) by bombadil.infradead.org with esmtpsa (Exim 4.97.1 #2 (Red Hat Linux)) id 1rZQWA-00000004SwH-0xZP; Mon, 12 Feb 2024 07:14:18 +0000 From: Christoph Hellwig To: linux-mm@kvack.org Cc: Matthew Wilcox , Jan Kara , David Howells , Brian Foster , Christian Brauner , linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org, Jan Kara , Dave Chinner Subject: [PATCH 07/14] writeback: Factor folio_prepare_writeback() out of write_cache_pages() Date: Mon, 12 Feb 2024 08:13:41 +0100 Message-Id: <20240212071348.1369918-8-hch@lst.de> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20240212071348.1369918-1-hch@lst.de> References: <20240212071348.1369918-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: 978344000F X-Stat-Signature: agwdmaufr97a6ujzrcuf1kzxhrro81cg X-HE-Tag: 1707722059-862961 X-HE-Meta: U2FsdGVkX1/HaVfSywRJdq/0x2gJXGZ4j6puiX/MHERt2oDIoakXYe0OEug9tqYqgug9VtxXUc0a+/cwnPwbW3un3jarcqMpfiZX9Qu5u+W1WZyj04d6b6kOlotYzAOgHUuF2Q7qym7hScXPXMMo7zF70LtNM7rkpAFNOWwPDwRcKCpfz9hd/Wlqct7r1OOqOWMwrzRkP3NmdN9WuvwNTA4z1mBwf/nrIRi7S3C9WqOoxaqywv2j/G2BOPWFfOWjYs4Z0OAhiwOTPDE7aBDhiiWeQ3N2DNwu5RN8H4eg0sHpICR9XuMrBB2CONRn7rc8eWnAipyPZwxYJ0suBLKhIcVZ2ts62Lk/0t/bHjlo0sQbrnMU7w7WRSEhB6R3rpwcsfGGtNqVFXCAWb/FT1WG5/vQDVxhZGpfZwOJusTEVMG5TV2WiojyyQ+GGEpRoiidTJb8NiutgD1yfp8r6cOIdg+HULbVtPaRYLkKQpICDaLuCs4QRnrI1rNIWKoPgnYGyz0+E50Wg7oAtegnfgUAoumfitvi5eHKxgzIjvmY2sGyDXmikoPMzmt2ZgchIlpB8dzq9S4acZ1WovZqeQxbg1zW0bFEmbV3IPjFc3NaVklhh6El8LHxXHVX5gHkiHI3XsavyYvuFMgmPCVlCAoU184CY/ob6QoB2V455jqOX0OkdkwYobKJExAzuhma/Gy3XscFd0/b0yYMKMgaKntBRWzsR6mIQQ/vu4KFnOfv03D9EduA+Jz2lbJtbtDEEvUykLkrFfP1AHWgWyf5Q8I2mSED8I1dBNL+jnntXptdZLLBmhqL0EXLVXGn4k9P/A6/AdDXl5AfE3UZBgeFm8TUPbstUsQBb7rw0GysSERZ5iBAtQFLb4x51hJMNMlWneM36rCCFhprU4Q3dg0HU/q0Frkvu3UG0DVHM62PGt/wCALWf+ZEE94CM0vDR/KfSzmUKTYY57t2LtnaNjoZp86 pApp/3+E 7865YZcU4tGi/gIQEEJn3p5CaapmaUGdnuPo+1aj6J1NCL2T3D/FIBPyuC21scjL1kdXXQVg+jrJZop6V5UoeXTOQO7vulGOVwplem74laHER6mHKmlznr/ULoW4KnYuRdQRvuAGaWdEK5ujM9zNz9Z4cVrGwCLs6TLl5zW+bYJO1zgRDBqV68j056ulmHKpy3AHVqf/QFKmCKdjYPrJ8emm0GSmOy8NHMZbUxUpb3n5EttQsimZnIOXMKBprbN1UAH7XW5jZlqPMrfAP4pl7YykKuLcedN9uLytuaH4SIMNYQI1SsJQxP5R2tAcpJ07rIRFdnIhgCdelUYTusANUxLK+5fmIp7pWJv2iTP9YYIRNJ5bRVmOiMSykDB3bkLsuWvJ3wZvrR7GIE033Nt6As0x1EHogszUh3aBNcBD2TzN62TLFhPtsFrU0ztjbbq5e7ABHUihHjnzhQV3Oeyj4rYCgK/HLt1QpinWEfuDU2G9TweP7IJjY0s8rt3m/U24hJV6cGqWS9vf7FAzG0ZgBHguYT6g3sgEyO3wT 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 b49ee15a863e99..20ff00c8be9d90 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 Mon Feb 12 07:13: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: 13552749 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 9ED17C48297 for ; Mon, 12 Feb 2024 07:14:24 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 2CF216B0082; Mon, 12 Feb 2024 02:14:24 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 2804F6B0083; Mon, 12 Feb 2024 02:14:24 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 11F7D6B0085; Mon, 12 Feb 2024 02:14:24 -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 F34ED6B0082 for ; Mon, 12 Feb 2024 02:14:23 -0500 (EST) Received: from smtpin12.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay01.hostedemail.com (Postfix) with ESMTP id D4A361C118E for ; Mon, 12 Feb 2024 07:14:23 +0000 (UTC) X-FDA: 81782288406.12.314E54D Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) by imf09.hostedemail.com (Postfix) with ESMTP id 35F9714002E for ; Mon, 12 Feb 2024 07:14:21 +0000 (UTC) Authentication-Results: imf09.hostedemail.com; dkim=pass header.d=infradead.org header.s=bombadil.20210309 header.b=3Wgal8GD; spf=none (imf09.hostedemail.com: domain of BATV+56c964bc8172c8a9ee6e+7477+infradead.org+hch@bombadil.srs.infradead.org has no SPF policy when checking 198.137.202.133) smtp.mailfrom=BATV+56c964bc8172c8a9ee6e+7477+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=1707722062; 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=H733Z/OisKZKsSfT6EaxuE1uZOfzplnZ1VkoSGD6LBY=; b=71p7RR/2FItCYJDNQiIrUZhoaPielQJJ49+jNYgaCGsg/SlyUuztc9l8xH2e0KEvRH20Ru Gq1y8nuiJCAnQDif3UFNh7kkVW1miCtUU0BKoDZqhzYOYB0u2ofWRw0m8dpQrvdPa/3nah sX8S2WL4ubqYbKaK0pi5V8lqBD3skaQ= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1707722062; a=rsa-sha256; cv=none; b=C/l3WthevM5IugEBoIL+MG9Zrsb2n0eDUKrCWf0WXWEPkzJy4jxxA1nKEwVHCN10MzETJA NLb3aNfw0AtadbJTXi8Xi1nhrPHt6Zw1WxAJflyTRK4R4p2xUPOyngiKnEitcjdEirBJzt oDlKwltLGgihPp++70JF+V77ul1U2cM= ARC-Authentication-Results: i=1; imf09.hostedemail.com; dkim=pass header.d=infradead.org header.s=bombadil.20210309 header.b=3Wgal8GD; spf=none (imf09.hostedemail.com: domain of BATV+56c964bc8172c8a9ee6e+7477+infradead.org+hch@bombadil.srs.infradead.org has no SPF policy when checking 198.137.202.133) smtp.mailfrom=BATV+56c964bc8172c8a9ee6e+7477+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=H733Z/OisKZKsSfT6EaxuE1uZOfzplnZ1VkoSGD6LBY=; b=3Wgal8GDp/OO9yjFp2rFlOqj97 HkjNBFs0/l40rFgt1jrEGxE8wnNu03bxBKTl3NTcTQuZO2IQ9whXrFw4ywFkPBVeGdRxlwT952/aY HUJZx5cwg5j+WUQy6PpgVM9QoYQxm7VM7J7CezwBeQ7OSkRI6Tl1alD4403gJfiTKV/OBTMfHnAG5 cHHon1/aXcJNCBKrycB3riZqjjN1xA33iCRxNaVsiib1eeCpk1GWuKFMDJuz1BxJjjk4ZWkSQ2QXS sCihHV3jAxBSfvV4E7dY3u4REiqg6qbcf74I1PFnXLQBFgrRStfMEtIZ3muezb+y0n/tRO0brIXPb Hv2IvJJg==; Received: from [2001:4bb8:190:6eab:75e9:7295:a6e3:c35d] (helo=localhost) by bombadil.infradead.org with esmtpsa (Exim 4.97.1 #2 (Red Hat Linux)) id 1rZQWC-00000004SyE-3a0i; Mon, 12 Feb 2024 07:14:21 +0000 From: Christoph Hellwig To: linux-mm@kvack.org Cc: Matthew Wilcox , Jan Kara , David Howells , Brian Foster , Christian Brauner , linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org, Jan Kara , Dave Chinner Subject: [PATCH 08/14] writeback: Factor writeback_get_batch() out of write_cache_pages() Date: Mon, 12 Feb 2024 08:13:42 +0100 Message-Id: <20240212071348.1369918-9-hch@lst.de> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20240212071348.1369918-1-hch@lst.de> References: <20240212071348.1369918-1-hch@lst.de> MIME-Version: 1.0 X-SRS-Rewrite: SMTP reverse-path rewritten from by bombadil.infradead.org. See http://www.infradead.org/rpr.html X-Stat-Signature: hwotck11jgk86zops86k4s3xi7d5588m X-Rspamd-Server: rspam10 X-Rspamd-Queue-Id: 35F9714002E X-Rspam-User: X-HE-Tag: 1707722061-931106 X-HE-Meta: U2FsdGVkX19WDHxWDwxMsMXXGFCNCEHwHcTwCv5u43zy9Do0kQMgrna4DfaQFP2olpyZZ1sjU83gAEwVpU66D5YnseqqfKETDBJPHpiFqEHR2Ri9jDdoJLvqLELynY4YkG8ngyufrMLUiz2r/I/qn0yP7S5ZGWisPKyENjUdTtibKcVVYM1LRpmqsf7ItaDE8AsH/GIG2p88q8B0ONjpeAoAbH1j5I1x38mo3LJ+o3odVOAWNy4fw8Cs8PNAOL6F06sEHNDwu/nnd+9PHBvcCSvflK1WsaUX529V4JWDzpax0ZKVBLBuypdbuVT2kzAH//dXD9R04MfB7N+kkYlIIYAFzrXUgQKXPLkhKzEs/fmGXnnUTxAOezbtYswP7ib1r4cyX9u97XOf1SfCiGdmxwnSqmhBHq3zeJl+YTZF1HhwMpaDXmFXs+NkAn4b4j4UEiBigbPWXPB4eYa/p/mQsZmnN4BntjSZEDOSMywvVcLqK4s20AR5lBYyGJBPW5nhCcZ0Z+fx0AXPyXpYAhZyNKxWymp4ATGTHJ5xTlaKso7su680hEviskAwDJgq+n9X/unFT89mQLdUkCxn70mWk35p5iASIrCJkzmc20VjCYqIW/c3L6ZX1Fe1SiYZ4uV8D4NdJPNTlovLiYlXZqwxylfyLCLiDa7tuiZaaDNMG/R1YZzNMqgnUWnbSJk8xkdHKHDzi2/HsnaN/qD10Ank7jATQWvax8QBxVg5c8VpddaKehRMg3B3agJlI6FF/b9dHYLTzMUbrc2C2yfqOQiM83ZH6RyaSy89rWVWbl3cqO18GDINlPsVgSWXnE9x99iPc6h+Z4iWpk67nQXFgcS2dnULZwzGs+BOJS1BJ9Iqw1B22JDU7EZISyYzDVCkci1Wt9b6BzMCGRI/qdv+OAQhJG0gXDi9LRxBluyz4gviYZ0I4vENypJAyPLLyPg/6aviOpMuXfih80tfkSbc1vz 9tHLjzFw c/9HyUQTAgfNmqo7eTijx/Erl3GqoHbuGgREh+qXW1utljUPiK7UjxUwF/go1kNWt3Io2p3QFDUNZ6iHFno/jVI8Yhzs4uN5BVYKSHw6oNmJCU+3RqljUbKEHTc0OFPOF5TO4T5YaAmqLEvmBnF+BZ+TVC9IsSAyxX//wZOIKD0IuUYgSg7XuCfjHq6Bz+xKTU2aJQDfRIpay0HCMl4/pDI7zVHZMae6VOdPF9YEmCDM+RVGg7wCkbFTIabBuJyqNhD2Fs6bQDuEK7LO7ACE3JBPmnXPZF/bU0YXblRGX9ftgv66cm38wmOOW7l4+V1aKN1V9BufO3qidKpjsqdvWnGeQ8RD10CMRWMzip/c5fy8+t6/iTVjudds7q3v9U0z1jv/fX8CF8ZA7baCCj+lD35OEtJC+UBI08aVXXOzsk1vO4a89KTYTV0w9HhoT1KyE5sdhmemE/lqcSScuoRpMPzoVROsTTwMboNUpR6+i2t70iGXHN0RekL5DVgeJhlT6BwnkZgL2rxhVyp97vBxYTUTYMee70snkKv1HXZIk8rklYOtWjLMSRppqS0ckK21PBteX 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 20ff00c8be9d90..045ca252c0423d 100644 --- a/mm/page-writeback.c +++ b/mm/page-writeback.c @@ -2392,6 +2392,29 @@ static bool folio_prepare_writeback(struct address_space *mapping, return true; } +static xa_mark_t wbc_to_tag(struct writeback_control *wbc) +{ + if (wbc->sync_mode == WB_SYNC_ALL || wbc->tagged_writepages) + return PAGECACHE_TAG_TOWRITE; + return PAGECACHE_TAG_DIRTY; +} + +static pgoff_t wbc_end(struct writeback_control *wbc) +{ + if (wbc->range_cyclic) + return -1; + return wbc->range_end >> PAGE_SHIFT; +} + +static void writeback_get_batch(struct address_space *mapping, + struct writeback_control *wbc) +{ + folio_batch_release(&wbc->fbatch); + cond_resched(); + filemap_get_folios_tag(mapping, &wbc->index, wbc_end(wbc), + wbc_to_tag(wbc), &wbc->fbatch); +} + /** * write_cache_pages - walk the list of dirty pages of the given address space and write all of them. * @mapping: address space structure to write @@ -2429,38 +2452,32 @@ int write_cache_pages(struct address_space *mapping, { int ret = 0; int error; - struct folio_batch fbatch; struct folio *folio; - int nr_folios; - pgoff_t index; pgoff_t end; /* Inclusive */ - xa_mark_t tag; - folio_batch_init(&fbatch); if (wbc->range_cyclic) { - index = mapping->writeback_index; /* prev offset */ + wbc->index = mapping->writeback_index; /* prev offset */ end = -1; } else { - index = wbc->range_start >> PAGE_SHIFT; + wbc->index = wbc->range_start >> PAGE_SHIFT; end = wbc->range_end >> PAGE_SHIFT; } - if (wbc->sync_mode == WB_SYNC_ALL || wbc->tagged_writepages) { - tag_pages_for_writeback(mapping, index, end); - tag = PAGECACHE_TAG_TOWRITE; - } else { - tag = PAGECACHE_TAG_DIRTY; - } - while (index <= end) { + if (wbc->sync_mode == WB_SYNC_ALL || wbc->tagged_writepages) + tag_pages_for_writeback(mapping, wbc->index, end); + + folio_batch_init(&wbc->fbatch); + + while (wbc->index <= end) { int i; - nr_folios = filemap_get_folios_tag(mapping, &index, end, - tag, &fbatch); + writeback_get_batch(mapping, wbc); - if (nr_folios == 0) + if (wbc->fbatch.nr == 0) break; - for (i = 0; i < nr_folios; i++) { - folio = fbatch.folios[i]; + for (i = 0; i < wbc->fbatch.nr; i++) { + folio = wbc->fbatch.folios[i]; + folio_lock(folio); if (!folio_prepare_writeback(mapping, wbc, folio)) { folio_unlock(folio); @@ -2498,8 +2515,6 @@ int write_cache_pages(struct address_space *mapping, goto done; } } - folio_batch_release(&fbatch); - cond_resched(); } /* @@ -2512,6 +2527,7 @@ int write_cache_pages(struct address_space *mapping, * of the file if we are called again, which can only happen due to * -ENOMEM from the file system. */ + folio_batch_release(&wbc->fbatch); if (wbc->range_cyclic) mapping->writeback_index = 0; return ret; @@ -2519,7 +2535,7 @@ int write_cache_pages(struct address_space *mapping, done: if (wbc->range_cyclic) mapping->writeback_index = folio->index + folio_nr_pages(folio); - folio_batch_release(&fbatch); + folio_batch_release(&wbc->fbatch); return error; } EXPORT_SYMBOL(write_cache_pages); From patchwork Mon Feb 12 07:13: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: 13552750 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 51254C4829E for ; Mon, 12 Feb 2024 07:14:27 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id E19026B0083; Mon, 12 Feb 2024 02:14:26 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id DA1D06B0085; Mon, 12 Feb 2024 02:14:26 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id C91F46B0087; Mon, 12 Feb 2024 02:14:26 -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 AB9B46B0083 for ; Mon, 12 Feb 2024 02:14:26 -0500 (EST) Received: from smtpin24.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay07.hostedemail.com (Postfix) with ESMTP id 7DF6C1606A1 for ; Mon, 12 Feb 2024 07:14:26 +0000 (UTC) X-FDA: 81782288532.24.560117C Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) by imf12.hostedemail.com (Postfix) with ESMTP id E01A340006 for ; Mon, 12 Feb 2024 07:14:24 +0000 (UTC) Authentication-Results: imf12.hostedemail.com; dkim=pass header.d=infradead.org header.s=bombadil.20210309 header.b=bWtEI6r6; dmarc=none; spf=none (imf12.hostedemail.com: domain of BATV+56c964bc8172c8a9ee6e+7477+infradead.org+hch@bombadil.srs.infradead.org has no SPF policy when checking 198.137.202.133) smtp.mailfrom=BATV+56c964bc8172c8a9ee6e+7477+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=1707722064; 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=Sdj3TuIooUnXttuDakRWtpzrehF7T0XwpBYd8+XY4jQ=; b=RFMti5YM8HNCJuz2ewfyuMVDfAnWwfLMu2b1u5jb6/oc5i5hclzHnw336FXtLk7GaDxxVy mFLEQQkWs+BhWE4Hu98WdLK18APU4jLmx5JMnqt6454B1/7Zm7qM38xFq61i2E3JyjO9n9 yQelSt2XhYfIFPEG7qhhNSn/Q7Myi6c= ARC-Authentication-Results: i=1; imf12.hostedemail.com; dkim=pass header.d=infradead.org header.s=bombadil.20210309 header.b=bWtEI6r6; dmarc=none; spf=none (imf12.hostedemail.com: domain of BATV+56c964bc8172c8a9ee6e+7477+infradead.org+hch@bombadil.srs.infradead.org has no SPF policy when checking 198.137.202.133) smtp.mailfrom=BATV+56c964bc8172c8a9ee6e+7477+infradead.org+hch@bombadil.srs.infradead.org ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1707722064; a=rsa-sha256; cv=none; b=Glo1yzvv6Xm5WsZFbVp/IHqk6zv182YpaLpBxBDmz1KSGO/e/0/KYWzpsqjyuJZFygaf1I z5UQlZv1j5kz1AKMUn6HM3lpB0KD614rKp76nj7hRMoNmpuiyKaxLuec7r496DwvhipAVt vZlkZ7MVOnnGDNolLrceb17Wr/XnBLM= 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=Sdj3TuIooUnXttuDakRWtpzrehF7T0XwpBYd8+XY4jQ=; b=bWtEI6r60ayNLZELpTZOYkI7ni V0YLes3NCWJScVbi3epGe0ytl7yZvhrutFXCXRDlgRfNSYcjDKED1urb/sMAXD2TtAWOT2t0SOKMD K56jZaVtX4m5/XF3bHchfDQ5+TyHEhxlaRD95cNyd7gkg2rkgPmbESs78s7lxoWGgGNgMBlygZS9n em5EpFhw6x5kD6xPyLFXSWxfrZMCZmBg5ksCZBQNvyOj58FJY9sBxyzKTaSEnV9qBViF8T2xl+0sh PfB0XRahp4DAw/qv2YFfVgEzx6/X0zRF1hjoGkeCTLsEl3dFTdqW8yCJwphVJzDOisjnV+TU79VBR 2iOpdZtg==; Received: from [2001:4bb8:190:6eab:75e9:7295:a6e3:c35d] (helo=localhost) by bombadil.infradead.org with esmtpsa (Exim 4.97.1 #2 (Red Hat Linux)) id 1rZQWF-00000004Sze-2F2g; Mon, 12 Feb 2024 07:14:23 +0000 From: Christoph Hellwig To: linux-mm@kvack.org Cc: Matthew Wilcox , Jan Kara , David Howells , Brian Foster , Christian Brauner , linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org, Jan Kara , Dave Chinner Subject: [PATCH 09/14] writeback: Simplify the loops in write_cache_pages() Date: Mon, 12 Feb 2024 08:13:43 +0100 Message-Id: <20240212071348.1369918-10-hch@lst.de> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20240212071348.1369918-1-hch@lst.de> References: <20240212071348.1369918-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: E01A340006 X-Rspam-User: X-Rspamd-Server: rspam02 X-Stat-Signature: i6rbtuhia8o3ig5z14id5groo4hszq89 X-HE-Tag: 1707722064-307141 X-HE-Meta: U2FsdGVkX18u1CcABuu3XP5Qkkqd3ZKmWZkF0Si5BFf+P6fd9YXR+fooEKOuABf5loBCtCSCt5hzzZDQb4X1fSjQKu5R+rbVbyZIfOawrVfdaGl5aFemkRFOYIQ5ZOtzXEEdi0G/DZ+YQ7IuqJg3o0AXWY0hKQLLkWlymuBH0iMypJPZEzn2TB793ORT565x2HpDc6Z/SyKdGGFimlr04X4/zSqFLsH2u7ZIQfAZz92wm0rWkG4f6+ovrNso27pIbvEY9XWJJUGajJrxHALptKQF+6opk25iJ+dEaiBKGNQ/FsJtKZBGlB6qUtsC5kq4rCpBwv/sXCTOi+iBa6UVGwHueMdQk9mSuxAkkM964LJWO1hQMi97zVoUeR7DUurYPDW8FOInF6NfIl7Et7anJyzEERiMdxnModgyok9zbUeh4VXBAICD4ej4mUqio714zMV8tLQ+HyUqCPxkpv4TjlMnKZ0XadKE/BFvsNRNrzHyI0k2WFwwvo8gRFOpaCQG16loeIGSEJ76zSBtFeuf1MkwmvHuJjQGWxUEyGZ1OAt4hybjv7W9BM0b0NpkgjSgIH9fet07R1h6fPKLURe1tt9OEBkZtVeEmQme2GHia3bVXkvk6bFKU7rmHggy5oVc73FKQ6FNlkSQbd+ugYHT4U935A9LTLu+EtMYiNG2aVZTqPuxWQT3JQFsECScMJ03PFPwJRBHTqWV/vyuxK3S89qFgl5GROdN7nAuF335V3Yo6x7RPcujuR4HIJ4el26MjxNH4t7Jh40IDnO1bZq20W/hXcLJKqks3SVujeG7l8CrXfDKf+JBAj4+kYm3/nqgvM4MC099UqkQmft5E2JfDNW5NcwKnm9J5x29l2QyapVGlB/skGWnvgYmjh3bwqdMS+CehhD36zcICeIk/QBv/C4dYySvko+c8fc3gUl+BVHy92rOVWan6VlHKGUm9encShL2aJKIkgT8otD8wuB cNCmTtk8 Ve6+5ZeOYBDoh/iABWhYyKCtRnuz1Tq4Zvv/JyH+izYW9UhIrZgYAGMXAFCtCZIYZ6kKoSa+lnDDAzFZhLPNIn+LBaahY64qfAjXixnvMr6mJdXi7XBDsn2BUhckRuIi8u5hQtryPTS9aLX1GmVIA32X6fRUts7l6WV4v8B76U3HipG4c2vanHFh8xgDe43xGdstanrFSHSbb8PqsyAzx4DZnYdx0Hw0RdqjNZCCfvNVcLcLO5VlTnrGAG7QtviYCZiymzAp3gPFOdrep3jP2UTJJfQsvVhACUYubGxvYm+H7iNR8/HornmcVOGPMuoOOPZa851NFzRfman1ywwdrTrfahOVjVhvpdlTPEmYg4H/jb9lXOUzWPCK2DOlUUaBjOjj2Q/THRSQ4oH2E5JMTpfUHXXg6zpvEas0pD1Xi8hQGY551YL4B+cuga+WG5J2lhwtN81regJawC5SaPD4McMqaAdMuA0FEEiFz8P63fLkYfrGxnH52PrUs1K0QNOgQLutegG9bz+5nv1GygW5p/mH++j8m812Mg0V8 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 045ca252c0423d..a94a77b1805969 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 Mon Feb 12 07:13: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: 13552751 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 426F0C4829B for ; Mon, 12 Feb 2024 07:14:30 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id CE0196B0085; Mon, 12 Feb 2024 02:14:29 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id C91086B0087; Mon, 12 Feb 2024 02:14:29 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id AE3C98D0001; Mon, 12 Feb 2024 02:14:29 -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 9A76C6B0085 for ; Mon, 12 Feb 2024 02:14:29 -0500 (EST) Received: from smtpin11.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay01.hostedemail.com (Postfix) with ESMTP id 75B2D1C118E for ; Mon, 12 Feb 2024 07:14:29 +0000 (UTC) X-FDA: 81782288658.11.BB2686C Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) by imf24.hostedemail.com (Postfix) with ESMTP id CB2FB180023 for ; Mon, 12 Feb 2024 07:14:27 +0000 (UTC) Authentication-Results: imf24.hostedemail.com; dkim=pass header.d=infradead.org header.s=bombadil.20210309 header.b=KSEDHvnP; dmarc=none; spf=none (imf24.hostedemail.com: domain of BATV+56c964bc8172c8a9ee6e+7477+infradead.org+hch@bombadil.srs.infradead.org has no SPF policy when checking 198.137.202.133) smtp.mailfrom=BATV+56c964bc8172c8a9ee6e+7477+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=1707722067; 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=z4ixvvDMaABgeR7GnBOm28eb2qdgQ6xM9LNDivmgN8d4oQipFf7TU0baF/qQ52MChaqta1 TvyhJmmZ1TdnyGIFMzhSqE2wfnPabw9q7cGJb00nr589aFx/tPCCg45RUs9s50XstQJ5/U W4UNWJiy0R3W8l7Em0RFSSQVpuJpoTg= ARC-Authentication-Results: i=1; imf24.hostedemail.com; dkim=pass header.d=infradead.org header.s=bombadil.20210309 header.b=KSEDHvnP; dmarc=none; spf=none (imf24.hostedemail.com: domain of BATV+56c964bc8172c8a9ee6e+7477+infradead.org+hch@bombadil.srs.infradead.org has no SPF policy when checking 198.137.202.133) smtp.mailfrom=BATV+56c964bc8172c8a9ee6e+7477+infradead.org+hch@bombadil.srs.infradead.org ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1707722067; a=rsa-sha256; cv=none; b=UhISIgS7gR68HT9UgQ96izK5P3g8+PUtU72tQsUOeHAxsuu9H05yh1wVRb0xZAdOzIeCD/ Bi2mirovCCx74C155gJadZDsnBrToGL9Mw4m19f/dyysUL5r93qfzriWOxi6IjaBXy9n1P 4GfpGvYRnKfuIoU0EwF0mwjfTpk/6NI= 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=KSEDHvnPO53cQSe7AW5PkM179C 0DYoyalxcn+DwuyW53dr955k4BfksGs0A/fvdpCrNU2v6RfJcoVVHZgjOJDRQSk6SLZW/h09KIfpl zmaOnPgCKkPSDxEUIpzJ5N6UpKlyouOnZ7yV02DDBXSQT4lDJFXjCuR22l7N5IlG95PluhMT+qC/E uMHRsQ+YRZRTuyzoAzCxKP4glZ3VsabLC+VtyKBS2vW4d6FWVD4CNp1cJ42IhVaHxcR3TMwfZ8W55 oRAplzCHTEm8E2EJI6uaS6wt3snHiqfPsgSmTI4PE/NgzauQVCyCcIuyvEnFJmHKKBXtr8ffw1NUB z92qXtog==; Received: from [2001:4bb8:190:6eab:75e9:7295:a6e3:c35d] (helo=localhost) by bombadil.infradead.org with esmtpsa (Exim 4.97.1 #2 (Red Hat Linux)) id 1rZQWI-00000004T1W-297p; Mon, 12 Feb 2024 07:14:26 +0000 From: Christoph Hellwig To: linux-mm@kvack.org Cc: Matthew Wilcox , Jan Kara , David Howells , Brian Foster , Christian Brauner , linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org, Jan Kara , Dave Chinner Subject: [PATCH 10/14] pagevec: Add ability to iterate a queue Date: Mon, 12 Feb 2024 08:13:44 +0100 Message-Id: <20240212071348.1369918-11-hch@lst.de> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20240212071348.1369918-1-hch@lst.de> References: <20240212071348.1369918-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: CB2FB180023 X-Rspam-User: X-Rspamd-Server: rspam04 X-Stat-Signature: t4r5qt4xj6ehujd3nw3nrjsn1xiqpq7j X-HE-Tag: 1707722067-610381 X-HE-Meta: U2FsdGVkX18zJYLhAahTTZEiZJ0vZ3sQD5D9JN8DEcQhcdiz7VxVA65jYR34leIrF1iFb2T/0MlHf969E7FqSd2ACcyos64DeXUnlmDS4tm7y2GJnZEoOyGHvh3knshpSZUk7a325cB8kUI8SKOFFsNYc6MZAYbQ6cJi26flADE4QTtYMCoLAIaJP4c1iM9uTLtLwlry+36xosraeldGBQrro83wiHfdEVAMslDSTgML3+umytoQEbxAGAVii4g/hJw+XoUriDeV/iG2diMPywVHZUqN/7X2Kc4M1jf5y5aE3/U/8BL0puaIFmoyroOOByvLlgypaE0OgQWLWRHMVUMeRkdUhm02WBTwLVvdSYEuOiivl6FGz0aXlyDXJM9d8BrPkEPUYJlzrebiw/90IZ4320IV9NXEDYbD1+TazlamQFi1ECrIiA6oELHkaEhw3TZZe9/eXLwwszPuwAEvg7lrTUJ71gHiTMO59HWQx8vabMP1OrxrnrvZABjZ40IaUfmNxo0KwxJdzKMqCR0q2BtayCpkM7/s1Sm+Nlksz9KLhVQrg+sgkMbu8sIwdWj24r7cftnoCgb8zRseDTeuDSdKlmv9w1N0CYBRpmxxkOKHX88+73N+bd1nxr3zZl0GUuUf0nvQuXmiMl0BtjUWAB6+O6atefH6HppGZsKWkBAcHIewzXKYMgEwJaVBtg1RQVv7S1iQvXqJ4yv3DALkGP7qYO7k1kS8upydBm6k9Fw6eiuHIK9RFve8KZIF0er7P6tToZjOwOC0UAGOSN6Hg+Vsqq37m90P4IoI4I3RIZwu31GtY5BznH6IF1fDpZZzoKZTPq5EEDa9nDn5p66Gdxp/xrpqj4Y/pZTWVsl/BhcwXQe+Qx+fK7dSXpJu9HveRSOIFPCJ5k5wryje8uwd5Hie10m9k6qt7BMp4p2WcsSlVfqwqSSFapuYe8fydtF5dqKfnlhgg6aR+7OLmOW TrUTQ7y6 SdbZlUpzx9Vigx3+jYCIms0K49HX4x9rqnSjN2Wu4rXK/Hx762yVkbSSaWTQ0P5bYfaDB2XENy8g0rz/TG6nNiPenARz5H5qV8dipINryrx+PvaSy3tDg2R35G3VVkQlpZTk78yCIbNEXi/HWcoTTCQHcXPPXbMij69oln9vdciDyflsNkzO91sJu/dGDrpX4bcQW0V4BDKsjQJQ14/1Ocx7abw+v1qBx6MgspKWahRrFuhBYNrHGJZJ/M6Iq5W5iDhuHFDoOToz9anmmE0f7EoRPevxKkNtp9cg8JlglQbxGULcsBxAtVwWC1fIwGMUcyKZA7c4IWrtubr3eoYu8A84fKQNLiy3J0zAAo5j8SxLnUYrY24HxD/8mJ0Y3uOBK9l203cTogRYhUP9Cv/lTUKntTzbCNNgpvWR532iW+jcrrZGYD195ln+dVNtGz3CaUANqgCgn6e7vHbSHrHtEo/YL9YPAQd+uR7GRjIXz82WlWi3gIyqK9X+oXw== 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 Mon Feb 12 07:13: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: 13552752 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 B73B3C48297 for ; Mon, 12 Feb 2024 07:14:32 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 4A3076B0072; Mon, 12 Feb 2024 02:14:32 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 42D268D0001; Mon, 12 Feb 2024 02:14:32 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 2F3A56B0088; Mon, 12 Feb 2024 02:14:32 -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 1FFD96B0072 for ; Mon, 12 Feb 2024 02:14:32 -0500 (EST) Received: from smtpin28.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay03.hostedemail.com (Postfix) with ESMTP id E486AA0950 for ; Mon, 12 Feb 2024 07:14:31 +0000 (UTC) X-FDA: 81782288742.28.34C4953 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) by imf29.hostedemail.com (Postfix) with ESMTP id 57F33120002 for ; Mon, 12 Feb 2024 07:14:30 +0000 (UTC) Authentication-Results: imf29.hostedemail.com; dkim=pass header.d=infradead.org header.s=bombadil.20210309 header.b=PPFKGKFd; dmarc=none; spf=none (imf29.hostedemail.com: domain of BATV+56c964bc8172c8a9ee6e+7477+infradead.org+hch@bombadil.srs.infradead.org has no SPF policy when checking 198.137.202.133) smtp.mailfrom=BATV+56c964bc8172c8a9ee6e+7477+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=1707722070; 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=+Lom8uD40NGvlqisQyOK8nFLP+lWD9RUXEqKKIbGSn4=; b=7bdbVjDRrYx/Q8QWJjd8yYH46UR3fxpmVGtdt0uTnRMOfm+lR/zuk4FMe38WOYEXOd1mtY b1EOtQYxbPZXITVInX7pWf2fJyWeZrU4BQPaIQ+gttAUTWSLOqBitV/I860IyQPeuN3ihC U28isTunrdX6Nl038QCeNumSiUVi7lY= ARC-Authentication-Results: i=1; imf29.hostedemail.com; dkim=pass header.d=infradead.org header.s=bombadil.20210309 header.b=PPFKGKFd; dmarc=none; spf=none (imf29.hostedemail.com: domain of BATV+56c964bc8172c8a9ee6e+7477+infradead.org+hch@bombadil.srs.infradead.org has no SPF policy when checking 198.137.202.133) smtp.mailfrom=BATV+56c964bc8172c8a9ee6e+7477+infradead.org+hch@bombadil.srs.infradead.org ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1707722070; a=rsa-sha256; cv=none; b=x2LkgQNj6Y+HnCtS9II3Up4WFqho1fmjhifIoZxRcOGH9fq70ohNTo4SqmYyyOnGmEy7wt obtL9Zc882o2DC9wGag4OQznQhi/JY0eX6DwFhT4ePIMZXk5ned5MH1vnjBtSc8Rx+31o5 u0BbjvTpJYAgVoIPwHAizAzqTyfTut0= 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=+Lom8uD40NGvlqisQyOK8nFLP+lWD9RUXEqKKIbGSn4=; b=PPFKGKFdog+pRhtnYVX3WRltrB ikV+4bwKtUpdsZ8JyPWOpR/eCx2IumzP/5BsTgIlB2axxAYRuMgIlbeJvtoS9crUEwioqaAVLIEy9 qe68HPx2+QSYY3d4+4EaLCUNFTjf6H5EsJ+Pf6Aic0UDbxShZgMHL2WP23oVmHjAD1RQyq5rOpy8j f90sfKpTzUAuob0zsJ8hcHxrSwQIiE9b6alk7Q0pmRALR7/PqiH3FBss+f4aY6y6jZnvQs41cJoJv PVW8Uvg/YNsq8/zUd6e/H02sDTt5aQbaw1r/Wu4Y+ATBQVVma61LebMzf/d0G6ueSwnLc0neemdyr lgavjWNQ==; Received: from [2001:4bb8:190:6eab:75e9:7295:a6e3:c35d] (helo=localhost) by bombadil.infradead.org with esmtpsa (Exim 4.97.1 #2 (Red Hat Linux)) id 1rZQWL-00000004T2h-0GbS; Mon, 12 Feb 2024 07:14:29 +0000 From: Christoph Hellwig To: linux-mm@kvack.org Cc: Matthew Wilcox , Jan Kara , David Howells , Brian Foster , Christian Brauner , linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org, Jan Kara , Dave Chinner Subject: [PATCH 11/14] writeback: Use the folio_batch queue iterator Date: Mon, 12 Feb 2024 08:13:45 +0100 Message-Id: <20240212071348.1369918-12-hch@lst.de> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20240212071348.1369918-1-hch@lst.de> References: <20240212071348.1369918-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: 57F33120002 X-Rspam-User: X-Rspamd-Server: rspam02 X-Stat-Signature: tx7yaykc8pxoepo96mbmocwxcybnj9z4 X-HE-Tag: 1707722070-171314 X-HE-Meta: U2FsdGVkX18E2vmjIAXnuTbScr9aYeHT99wkrbMUxcMJl7/ypMOaQconS98do1KoaKydjWuaaAOdpQp4iviH0NHMs2f+k+S3g7u1WiQ5nQN2BnywIEkPBVWjjVqk35kzq/0Zf4zEbKyZPuQ8UjiP4ZIHGLqOQI3ex6RIqct+rD5GuFv7LPNu5JDecpZ20GmZHi02ADmI7kq6wTs39G3fpBlf3ziqpDtLF59fxq5j+zrFdaq2Nq4Yrq6iQxswnelJHeY3SFmV2UMvJL7v11RmvmncK+EPBLpVTQ1T6xaJD53TxL7rSIeWkepkZl48R1foCEfMNSixMeJHRnnqnVmXeFxcMZ8cl9/Qtphll8ku7kPMKPUQUIn5cxOmf/RR65LgoZkY6qKRqYFU3CuhNfdZWwpPC15sM0+rjpyRfUNbnIvAj1qURM0a57gopJaHOJ/ER+LrGKVVvG8UY+IJoSVAuqIPwwYCxGM9uFzqv8gxHvksw1Mfnm/C2+hU+A/6din+bHx+XiMyrvKcJvTkYKmPyLQWO4CbwQ6jnymAiix0gmyiWQP/9bdV7gLbRRoes7X2z5In9VuauXm5o9N3q8Ibw2SJ6OCkdeZeD6juM0omBjBFKC3td/i1t3w6U0bjuJsai7V3ZUTXg0ov0jnu3fqEwQy3DlBROXLOAzm5z5IMRL4YuSkk/XJQoqqpAph6apNC+Pd4LB0HZPW4OTKPqEOS9xV9jvuP/Gs5MusZFDMGkvBdsjq3oCL0hFkSSt0oG6sMzi0rEJ9+l3qa9kGI9Br6m2ArPd/ZlTpi+unisD/FWPxy8ch/O78VCpEagSwRNwQcrZYUy0M7/eD87BCHf7IFVf5A6m9aFSbirSMoWkH54G5fdkmmUCuTy2XKbBSFLlBSYyRnNfwgUUUfuNI08MiA9hI0b+rIvfjtwdbAFUdE4IumKyP9o+bbMRffTSu9eIkKAtKpcWkYEif8+GMA0u5 iUE5etwt K9O5Ds0Qv1jM5Wnh+sQmzxSGU81RsFyNO7pPaSucUmNfnXnGtHNlCvM5MIFoX/W/Ke1mfSmdiJy0N1rIaH0/m6/plKXOAqYqA8Mal16YDd/eOxmrz9FiYM7NuTzPQi4OsbEJA9YveGg4iQKGHfnbDT+RMpgoqXK+7j5LSy2lfmYZmdifCERM5LME7X2Jo+g/fN0V/dEv5tSumw6on3KAyX7JXPolRtydDkZ/C90goroKC8n7w11h/K2nlzI0IQgutksEXiK3ha2K5OM9Gf2lAKumEhT3PCyVMnHOTOtEOHtx6FqqUI+/dWvrTW7iS042xuet1nahB6B1M9LrraKtVETVtke4LmcCjTikVYd92S+XdGMYbf11HeibMvF/Eiv98n/mT9oH+oyQd160bfqSM6xjnvSvp5VKibtNq8z00uiam/J+dSkUajA0NF2y/lprE8r1+tQ9Z7hC1UVIs0U+lYaX2oPyvYznmX2z2KyiI6ps80FOnNlh5mmuBgp9GRQM3WrUucOPRUrNld9AVvzg4bN6JH3f7bPjMqPum 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 a94a77b1805969..62b663debe713b 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 Mon Feb 12 07:13: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: 13552753 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 8C1DDC4829E for ; Mon, 12 Feb 2024 07:14:35 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 233AD6B0088; Mon, 12 Feb 2024 02:14:35 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 196506B0089; Mon, 12 Feb 2024 02:14:35 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id F024E6B008A; Mon, 12 Feb 2024 02:14:34 -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 DF1A56B0088 for ; Mon, 12 Feb 2024 02:14:34 -0500 (EST) Received: from smtpin14.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay10.hostedemail.com (Postfix) with ESMTP id B5B89C08C1 for ; Mon, 12 Feb 2024 07:14:34 +0000 (UTC) X-FDA: 81782288868.14.9255A77 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) by imf22.hostedemail.com (Postfix) with ESMTP id F290BC0017 for ; Mon, 12 Feb 2024 07:14:32 +0000 (UTC) Authentication-Results: imf22.hostedemail.com; dkim=pass header.d=infradead.org header.s=bombadil.20210309 header.b=XbHX1mZC; dmarc=none; spf=none (imf22.hostedemail.com: domain of BATV+56c964bc8172c8a9ee6e+7477+infradead.org+hch@bombadil.srs.infradead.org has no SPF policy when checking 198.137.202.133) smtp.mailfrom=BATV+56c964bc8172c8a9ee6e+7477+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=1707722073; 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=hDwf/sJTGlPIwBTRyPln6Zb1s+XpptYYA785c3w7vC4=; b=l3oGCSrX1lccxdtF6HdnLNjDIStEsTkHHoN8AwBx2WeqvwDUfJQ7uSLZlfZwhZbukpYfiI zZMcqKvYU1q5ptSL5t5HvRM6DpKJLVKpmePIoKuZKTt+EG9oQAYxuNnDpzjxCNOUk2BnPG NNAOMM7iORoFSjP4YRHKCamZOyKubac= ARC-Authentication-Results: i=1; imf22.hostedemail.com; dkim=pass header.d=infradead.org header.s=bombadil.20210309 header.b=XbHX1mZC; dmarc=none; spf=none (imf22.hostedemail.com: domain of BATV+56c964bc8172c8a9ee6e+7477+infradead.org+hch@bombadil.srs.infradead.org has no SPF policy when checking 198.137.202.133) smtp.mailfrom=BATV+56c964bc8172c8a9ee6e+7477+infradead.org+hch@bombadil.srs.infradead.org ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1707722073; a=rsa-sha256; cv=none; b=6EISi8/efjLKEKtBLEqhOclKuuASaWulN0+ERdNVbOzpBr+WDZ/7GwCUMA5qqGHW9e98Xt RR28YN1gXsYfTpq/X4mL0uZl1wIvLEE5oNE0K+dBQA1lEq0TwMBZWz67LK+I83gBQ+ZPfD XFDbrlIECRCrDswh/J+KzV2ePf8wPL8= 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=hDwf/sJTGlPIwBTRyPln6Zb1s+XpptYYA785c3w7vC4=; b=XbHX1mZCM5Mo7rShucMVsPQybi QYfeqa4nFaBzcM/DsAKy72s4D9gnZOQ+eZo15yg3xEHI7qigOLDFMavU0ZQlm8qdIdV8CBLgIYtNM gHhvHVUsTtsNGL+zE1jQLwkYVCj1Ruag3QbLwJ6Ta838iRkgnS1Lg6mE0P8nW/ZpIDmOytDpBIi4n yCMmI5JnIJvd0PcT1ZiaClUiaUlPN6MlYprQswFXIjkP/LX0Uli5B5o6UES3k6xUM87eJrAHtae9O FQP2lx8hKziZv9DQcZadgvj3xcrZEzcT3dQju6kWLLYmqNYz0W+KfaI8gVzCyx93dbRKa1wcqdpG3 r9C4E0cQ==; Received: from [2001:4bb8:190:6eab:75e9:7295:a6e3:c35d] (helo=localhost) by bombadil.infradead.org with esmtpsa (Exim 4.97.1 #2 (Red Hat Linux)) id 1rZQWN-00000004T3G-2raf; Mon, 12 Feb 2024 07:14:32 +0000 From: Christoph Hellwig To: linux-mm@kvack.org Cc: Matthew Wilcox , Jan Kara , David Howells , Brian Foster , Christian Brauner , linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org, Jan Kara , Dave Chinner Subject: [PATCH 12/14] writeback: Move the folio_prepare_writeback loop out of write_cache_pages() Date: Mon, 12 Feb 2024 08:13:46 +0100 Message-Id: <20240212071348.1369918-13-hch@lst.de> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20240212071348.1369918-1-hch@lst.de> References: <20240212071348.1369918-1-hch@lst.de> MIME-Version: 1.0 X-SRS-Rewrite: SMTP reverse-path rewritten from by bombadil.infradead.org. See http://www.infradead.org/rpr.html X-Rspam-User: X-Rspamd-Server: rspam12 X-Rspamd-Queue-Id: F290BC0017 X-Stat-Signature: k1ijp36axur8fj4ifgfe9srgz3yxnz8i X-HE-Tag: 1707722072-284792 X-HE-Meta: U2FsdGVkX18fCiIQer6Fz6UPliVxtk3sGqKZwXoxEU4a1yrBjNvaKWZv5+pnb1vBJvOxgSHloKc6bgZibMM3GNT7WSQ+QU/Fg9QyeRbCohgGT7nUebly7Rglx9DO2EiXPR0ePJfy38id9n9DmOvJX+kOKlnHcM878+T26vw+y23OAtnL57qMrxvFWn3mOJMs1RSpMpTc9AuAWZIs41whK12s/mG+wSU99H4A/bKbeCHhht5/o4zDfgkgkCV+GV2GtF40SEsjQn8xR5oN5B3WLiNMdwpzhyj0CpwyZUDk1OpIHoYBR59Xi9a+cUMEaravRg7W9HkVQF9jTsDazmBNxMaoRnO3+ZnkvrJcPMHGV6eHEDFeNW+spFbg4zH+qhlqpW+ChXyKgYhM7i1ZotV8fk0UQ37JtuLVwoO6AXOn9kvowh13PSW60kyCFufuw9hfaPKims/UfistumJVhVY0pehITu0jKx/ryfHRyWuetjKYqX1YwQmgQNrLpVfcIN6Hok4TMwK6hr1u+gUERWkY5WzwsSVLuIbKKGQQ2Gw6DVz+z41fMZ78urkAdf/rUTbX4xA5xDTzdHQDggksbcDUAeIjOhMn9oK74SFt2Ew8isu4uFlA268ELAN8crlvQv7QGw0r/tYh3BKQBveH9QeFuJetZqgU8meDUzJgXXZC+/ACk+3ygGzyk/gb7xZcVNBeTnKOPs/j78v9FExPWxrdETWyCi6MaVEpES85YX2OBrUTBhnUpw3xY7jdMoB6wwV3mQs+1TxFswiJSks0JKeYUvJKMwa3Uv0a7TEwmYivqOhm0LSkbZdT2VBTa4GR2KI+HIdV7KpXmHwe1NTWmTpewTYdHPd9T+HLIuvQFWXSe8BkzcM+qItO8LNfubR15ytDL57WStQUTfIoX2OM/NZLcu4hOZElgXBl06KKGgiNzmV+wzMPHv5MrUKSL1Hk/0tFm5uxQNXmqPKYaGz5dJx Fc9L833T TUYVEMChQt8Ml3jX6vnOzERNWC5M+p9jRoXVfSid4njiBxkdmrNnqNyU3BsrK0PLOImxB4VN1iwHuwf3H70VQl5g+//AKOiRVd7OoeDZbrLC/QjL0DQd725GCEVpBBTDp5ADXh0jd5Jy44i1MIWNRppfutmPUHVdixurNkehPLkYOREfHLsnGKxsM09RUign1G2VpFXd4Ev+2mZsYwLWUOmPdP7z5rZO5dnKkPhfXpZVrPpK68iJWeEKOOVRoKEQY5CkDxPNMhVlAt9XAvB7ce9eYZynYNneuq5kjpv05xy1XJoec98GYxKUpZmFRD2u+c2iEcHoKo2V5opcwkEuwOSKO9GgDxHyMJ/+zoF/7QOQfwtpkHvWHF0NmqRxQ0/nH6VIBDwdTtIwcYdzMBDQBuo3XtkaZ9iB4xwJ3LKaffzm1WGqYXMWteXkL0IhKIkyMLoHcyr7q55GOy74XJ/lO29OCWpOZMnm2rGEkhPFsnn3HjtVM7pe7Td/dSInCg2kiI4rbNbH/zfEZQBF553Lzy20uYzXgZS4R6rAV 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 62b663debe713b..01f076db4f2118 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 Mon Feb 12 07:13: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: 13552754 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 36A18C48297 for ; Mon, 12 Feb 2024 07:14:38 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id C1DF16B008A; Mon, 12 Feb 2024 02:14:37 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id BA5D86B008C; Mon, 12 Feb 2024 02:14:37 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id A205B6B0092; Mon, 12 Feb 2024 02:14:37 -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 8CF0D6B008A for ; Mon, 12 Feb 2024 02:14:37 -0500 (EST) Received: from smtpin02.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay09.hostedemail.com (Postfix) with ESMTP id 65C678096F for ; Mon, 12 Feb 2024 07:14:37 +0000 (UTC) X-FDA: 81782288994.02.C2F3E80 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) by imf29.hostedemail.com (Postfix) with ESMTP id B8148120008 for ; Mon, 12 Feb 2024 07:14:35 +0000 (UTC) Authentication-Results: imf29.hostedemail.com; dkim=pass header.d=infradead.org header.s=bombadil.20210309 header.b="J1Vpv/4r"; spf=none (imf29.hostedemail.com: domain of BATV+56c964bc8172c8a9ee6e+7477+infradead.org+hch@bombadil.srs.infradead.org has no SPF policy when checking 198.137.202.133) smtp.mailfrom=BATV+56c964bc8172c8a9ee6e+7477+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=1707722075; 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=3ps6DrUYY6joeRoCV3vXTg3akgu44JW6S1va7OwaCYU=; b=CrY6LqgoffdpboZUXuqx/zcoLNQW+07WLYlFk5fF0jCqGjgUp7P4h9gRi1RR288pUEG2ui ayIjWF6266PYVOwjMThYe7MnME5vT+R3lCdmpEb7+90MHuMMvla/i7tlul2DIEbmJ/fGqq MtVzQitP3p8wMlW6YD79YwOJacqiP7E= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1707722075; a=rsa-sha256; cv=none; b=Oj+QB3TWzA82XJ/5ety5l6NDsKgR01qQDojrP6TpFKHa2+uMebs0bBwd66034yS99YfXWE JiyjzG++DtmdjjmhRX/xMiZanRzkleTxPMwLmTKpZxkWrEI0VYVsEyNg716TkLeegOCFaT rDMoO0jnxJlfT8gbmW2wiwCbJ3300gI= ARC-Authentication-Results: i=1; imf29.hostedemail.com; dkim=pass header.d=infradead.org header.s=bombadil.20210309 header.b="J1Vpv/4r"; spf=none (imf29.hostedemail.com: domain of BATV+56c964bc8172c8a9ee6e+7477+infradead.org+hch@bombadil.srs.infradead.org has no SPF policy when checking 198.137.202.133) smtp.mailfrom=BATV+56c964bc8172c8a9ee6e+7477+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=3ps6DrUYY6joeRoCV3vXTg3akgu44JW6S1va7OwaCYU=; b=J1Vpv/4rTAbXBDrWBFtqLiozux yAh8D/yoZ6Q6bYS+XpZDbi9mUzzPzdz0zwxkt6zjj3ZBIN/FGdqVhwr6m9FQlhuAXa+bjd5gGQ0Xa Ni5nBeA6xwjmt7cUVDQJ60JYP5aMyMRBxqAIBTSreW5r72YJwR15vcnGdNBqjFOhgSOOUP2HNCJJy s6Fev43gNqoM3p47gmRrQt6mPNG1/FWfU9C3r+KewuO96GEwceTkX6AMzLJKO2uOSUbAe4Ilck70Y P0csjlPWIzKIvDbEiqOg6EN6xUzB3jAjJhpVeg32F9S6QMFCHv7WiTaseM18URlbhD0IEOR7zA8/Y bb8zv9BQ==; Received: from [2001:4bb8:190:6eab:75e9:7295:a6e3:c35d] (helo=localhost) by bombadil.infradead.org with esmtpsa (Exim 4.97.1 #2 (Red Hat Linux)) id 1rZQWQ-00000004T4B-1ZIv; Mon, 12 Feb 2024 07:14:34 +0000 From: Christoph Hellwig To: linux-mm@kvack.org Cc: Matthew Wilcox , Jan Kara , David Howells , Brian Foster , Christian Brauner , linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org, Jan Kara Subject: [PATCH 13/14] writeback: add a writeback iterator Date: Mon, 12 Feb 2024 08:13:47 +0100 Message-Id: <20240212071348.1369918-14-hch@lst.de> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20240212071348.1369918-1-hch@lst.de> References: <20240212071348.1369918-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: B8148120008 X-Rspam-User: X-Stat-Signature: 86rwbj18ie7ykp5gma5f3py7hcixfje4 X-Rspamd-Server: rspam03 X-HE-Tag: 1707722075-698652 X-HE-Meta: U2FsdGVkX1+FKb/ydsvxK85DqemXlcHiPA2Dz16uR5sX/xKLkX57cGaIeitA51OK/0le57ppLJa+iyFD1GTqHnx/GlMTMHzswNUi1Odmh0CbefLZ8MDVPTlNOUb9COfdbeahr/g/y5PzwNlKJUdsJasoKmp18pOOBh7jrRvH0c3pKEA/T9IedlXctIMJq75cWOTyUTLCRTsZlonHCv3ghxyJtmNPymDPvBETdIRp9vLqZz4xMHgXkLJb/PZiiIWfg0GSjBxvFM/pKisOov6LDuh6tomkUQAH+pE5EMnUVD9x1/CZPpRO2honI8ZMvFicgZrffEVxcvITVNIVf/S2lx8o9nAZGdwdHY7QAF7FVlS5QMuQpnQDVBzXbs9QrLLp8MO5b9fWErkKCRv+nZIquyeZJb2X3oDT+MKBNahtAvGwUL4Xzs5GVRV4v6ERaq3uWWRgE0jI7UPpNzohPsQHv9O5fFgI/BPlGiBNaHXYIeuvrWGjDSz4xMVbEUs0i5mikSh53onmvyMMQi/VVADrKUAx/SqawQOBSqCBtqsixX756ljBofIdhUG85a5+F4kRYc4e3z1JLirSvqXRLMjfiD17apRSTYmELEGIbJhw16oVxAc95X3tdLcMH58xWQG/YT9z8hcSgmSlPkmU6eaV6l1b7WxMp/p/XDl/PDZs7zdtNT2zJn+uHWIAB3r3ZyNbrIIRT4DqKViSpUq0cZ+85mlJoxTs4xsxfQh7NBwOUBU9Wl2B4zjjLs5s+HYb3UP3IYOem8fz7AtTzQQ6aiVvhNHrqibi1Bbz6ZjqJW1weIK1ESfY/YMwrgdosE2SB/qpULB9HXGCRQP/68pCZl3p7rB98SR+Id55oRwPc65J29fHKBprCGM/gjRzn2raN2x3OLy5cowoIt5u33atnTe+onPtNGG+QOzDKukIopY1sch4izC8HziknWfUUxTkj8GR9Lzw1SY6cLLLAGgnjKT dTay9rQN EIxeADdXbiZfhzv9jPxhxRVWZNQnSedR4jKWoc2Ye7UrvQANVzGXAeHLGaSb2O1veBBqfa+yDZlAq6LCV0eXMeNvWmFK3CqiSuhsowqwWrI99TozhymeS+VeWge/KAo8NkAxHxuCgHw7ooDFDk+zx2JXIKR78nARMJezJMJAu/cusGmvVKg3kXVChLQLAwFXcw1h+UtZYNuCG9LkU1qBpf8zIh+58EgfYamyXM0ZlPUqbRkjXKPIbuFR2vffkiJgYxDVrN36+GuRpHQTcPPCM8iI+YNGXF/qXzO79xSfmRu0lCpQmQxqTnKJ3BLgw8kaPrf9zHZJaESwGDeOJOgETk5L85MQ2NXj7l8JVbm+pwF2m+k88tURgHro2gKjcEMIxia11iTFItG1vPCRekWYlfYpQ4iX1BQJu7CwiM4Ty+l5Ij6QQAnHk1KtDUA== X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: Refactor the code left in write_cache_pages into an iterator that the file system can call to get the next folio for a writeback operation: struct folio *folio = NULL; while ((folio = writeback_iter(mapping, wbc, folio, &error))) { error = ; } The twist here is that the error value is passed by reference, so that the iterator can restore it when breaking out of the loop. Handling of the magic AOP_WRITEPAGE_ACTIVATE value stays outside the iterator and needs is just kept in the write_cache_pages legacy wrapper. in preparation for eventually killing it off. Heavily based on a for_each* based iterator from Matthew Wilcox. Signed-off-by: Christoph Hellwig Reviewed-by: Brian Foster Reviewed-by: Jan Kara --- include/linux/writeback.h | 4 + mm/page-writeback.c | 192 ++++++++++++++++++++++---------------- 2 files changed, 118 insertions(+), 78 deletions(-) diff --git a/include/linux/writeback.h b/include/linux/writeback.h index f67b3ea866a0fb..9845cb62e40b2d 100644 --- a/include/linux/writeback.h +++ b/include/linux/writeback.h @@ -82,6 +82,7 @@ struct writeback_control { /* internal fields used by the ->writepages implementation: */ struct folio_batch fbatch; pgoff_t index; + int saved_err; #ifdef CONFIG_CGROUP_WRITEBACK struct bdi_writeback *wb; /* wb this writeback is issued under */ @@ -366,6 +367,9 @@ int balance_dirty_pages_ratelimited_flags(struct address_space *mapping, bool wb_over_bg_thresh(struct bdi_writeback *wb); +struct folio *writeback_iter(struct address_space *mapping, + struct writeback_control *wbc, struct folio *folio, int *error); + typedef int (*writepage_t)(struct folio *folio, struct writeback_control *wbc, void *data); diff --git a/mm/page-writeback.c b/mm/page-writeback.c index 01f076db4f2118..1996200849e577 100644 --- a/mm/page-writeback.c +++ b/mm/page-writeback.c @@ -2325,18 +2325,18 @@ void __init page_writeback_init(void) } /** - * tag_pages_for_writeback - tag pages to be written by write_cache_pages + * tag_pages_for_writeback - tag pages to be written by writeback * @mapping: address space structure to write * @start: starting page index * @end: ending page index (inclusive) * * This function scans the page range from @start to @end (inclusive) and tags - * all pages that have DIRTY tag set with a special TOWRITE tag. The idea is - * that write_cache_pages (or whoever calls this function) will then use - * TOWRITE tag to identify pages eligible for writeback. This mechanism is - * used to avoid livelocking of writeback by a process steadily creating new - * dirty pages in the file (thus it is important for this function to be quick - * so that it can tag pages faster than a dirtying process can create them). + * all pages that have DIRTY tag set with a special TOWRITE tag. The caller + * can then use the TOWRITE tag to identify pages eligible for writeback. + * This mechanism is used to avoid livelocking of writeback by a process + * steadily creating new dirty pages in the file (thus it is important for this + * function to be quick so that it can tag pages faster than a dirtying process + * can create them). */ void tag_pages_for_writeback(struct address_space *mapping, pgoff_t start, pgoff_t end) @@ -2434,69 +2434,68 @@ static struct folio *writeback_get_folio(struct address_space *mapping, } /** - * write_cache_pages - walk the list of dirty pages of the given address space and write all of them. + * writeback_iter - iterate folio of a mapping for writeback * @mapping: address space structure to write - * @wbc: subtract the number of written pages from *@wbc->nr_to_write - * @writepage: function called for each page - * @data: data passed to writepage function + * @wbc: writeback context + * @folio: previously iterated folio (%NULL to start) + * @error: in-out pointer for writeback errors (see below) * - * If a page is already under I/O, write_cache_pages() skips it, even - * if it's dirty. This is desirable behaviour for memory-cleaning writeback, - * but it is INCORRECT for data-integrity system calls such as fsync(). fsync() - * and msync() need to guarantee that all the data which was dirty at the time - * the call was made get new I/O started against them. If wbc->sync_mode is - * WB_SYNC_ALL then we were called for data integrity and we must wait for - * existing IO to complete. - * - * To avoid livelocks (when other process dirties new pages), we first tag - * pages which should be written back with TOWRITE tag and only then start - * writing them. For data-integrity sync we have to be careful so that we do - * not miss some pages (e.g., because some other process has cleared TOWRITE - * tag we set). The rule we follow is that TOWRITE tag can be cleared only - * by the process clearing the DIRTY tag (and submitting the page for IO). - * - * To avoid deadlocks between range_cyclic writeback and callers that hold - * pages in PageWriteback to aggregate IO until write_cache_pages() returns, - * we do not loop back to the start of the file. Doing so causes a page - * lock/page writeback access order inversion - we should only ever lock - * multiple pages in ascending page->index order, and looping back to the start - * of the file violates that rule and causes deadlocks. + * This function returns the next folio for the writeback operation described by + * @wbc on @mapping and should be called in a while loop in the ->writepages + * implementation. * - * Return: %0 on success, negative error code otherwise + * To start the writeback operation, %NULL is passed in the @folio argument, and + * for every subsequent iteration the folio returned previously should be passed + * back in. + * + * If there was an error in the per-folio writeback inside the writeback_iter() + * loop, @error should be set to the error value. + * + * Once the writeback described in @wbc has finished, this function will return + * %NULL and if there was an error in any iteration restore it to @error. + * + * Note: callers should not manually break out of the loop using break or goto + * but must keep calling writeback_iter() until it returns %NULL. + * + * Return: the folio to write or %NULL if the loop is done. */ -int write_cache_pages(struct address_space *mapping, - struct writeback_control *wbc, writepage_t writepage, - void *data) +struct folio *writeback_iter(struct address_space *mapping, + struct writeback_control *wbc, struct folio *folio, int *error) { - int ret = 0; - int error; - struct folio *folio; - pgoff_t end; /* Inclusive */ - - if (wbc->range_cyclic) { - wbc->index = mapping->writeback_index; /* prev offset */ - end = -1; - } else { - wbc->index = wbc->range_start >> PAGE_SHIFT; - end = wbc->range_end >> PAGE_SHIFT; - } - if (wbc->sync_mode == WB_SYNC_ALL || wbc->tagged_writepages) - tag_pages_for_writeback(mapping, wbc->index, end); - - folio_batch_init(&wbc->fbatch); + if (!folio) { + folio_batch_init(&wbc->fbatch); + wbc->saved_err = *error = 0; - for (;;) { - folio = writeback_get_folio(mapping, wbc); - if (!folio) - break; + /* + * For range cyclic writeback we remember where we stopped so + * that we can continue where we stopped. + * + * For non-cyclic writeback we always start at the beginning of + * the passed in range. + */ + if (wbc->range_cyclic) + wbc->index = mapping->writeback_index; + else + wbc->index = wbc->range_start >> PAGE_SHIFT; - error = writepage(folio, wbc, data); + /* + * To avoid livelocks when other processes dirty new pages, we + * first tag pages which should be written back and only then + * start writing them. + * + * For data-integrity writeback we have to be careful so that we + * do not miss some pages (e.g., because some other process has + * cleared the TOWRITE tag we set). The rule we follow is that + * TOWRITE tag can be cleared only by the process clearing the + * DIRTY tag (and submitting the page for I/O). + */ + if (wbc->sync_mode == WB_SYNC_ALL || wbc->tagged_writepages) + tag_pages_for_writeback(mapping, wbc->index, + wbc_end(wbc)); + } else { wbc->nr_to_write -= folio_nr_pages(folio); - if (error == AOP_WRITEPAGE_ACTIVATE) { - folio_unlock(folio); - error = 0; - } + WARN_ON_ONCE(*error > 0); /* * For integrity writeback we have to keep going until we have @@ -2510,33 +2509,70 @@ int write_cache_pages(struct address_space *mapping, * wbc->nr_to_write or encounter the first error. */ if (wbc->sync_mode == WB_SYNC_ALL) { - if (error && !ret) - ret = error; + if (*error && !wbc->saved_err) + wbc->saved_err = *error; } else { - if (error || wbc->nr_to_write <= 0) + if (*error || wbc->nr_to_write <= 0) goto done; } } - /* - * For range cyclic writeback we need to remember where we stopped so - * that we can continue there next time we are called. If we hit the - * last page and there is more work to be done, wrap back to the start - * of the file. - * - * For non-cyclic writeback we always start looking up at the beginning - * of the file if we are called again, which can only happen due to - * -ENOMEM from the file system. - */ - folio_batch_release(&wbc->fbatch); - if (wbc->range_cyclic) - mapping->writeback_index = 0; - return ret; + folio = writeback_get_folio(mapping, wbc); + if (!folio) { + /* + * To avoid deadlocks between range_cyclic writeback and callers + * that hold pages in PageWriteback to aggregate I/O until + * the writeback iteration finishes, we do not loop back to the + * start of the file. Doing so causes a page lock/page + * writeback access order inversion - we should only ever lock + * multiple pages in ascending page->index order, and looping + * back to the start of the file violates that rule and causes + * deadlocks. + */ + if (wbc->range_cyclic) + mapping->writeback_index = 0; + + /* + * Return the first error we encountered (if there was any) to + * the caller. + */ + *error = wbc->saved_err; + } + return folio; done: if (wbc->range_cyclic) mapping->writeback_index = folio->index + folio_nr_pages(folio); folio_batch_release(&wbc->fbatch); + return NULL; +} + +/** + * write_cache_pages - walk the list of dirty pages of the given address space and write all of them. + * @mapping: address space structure to write + * @wbc: subtract the number of written pages from *@wbc->nr_to_write + * @writepage: function called for each page + * @data: data passed to writepage function + * + * Return: %0 on success, negative error code otherwise + * + * Note: please use writeback_iter() instead. + */ +int write_cache_pages(struct address_space *mapping, + struct writeback_control *wbc, writepage_t writepage, + void *data) +{ + struct folio *folio = NULL; + int error; + + while ((folio = writeback_iter(mapping, wbc, folio, &error))) { + error = writepage(folio, wbc, data); + if (error == AOP_WRITEPAGE_ACTIVATE) { + folio_unlock(folio); + error = 0; + } + } + return error; } EXPORT_SYMBOL(write_cache_pages); From patchwork Mon Feb 12 07:13:48 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christoph Hellwig X-Patchwork-Id: 13552755 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 F13A1C4829B for ; Mon, 12 Feb 2024 07:14:40 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 7B42C6B008C; Mon, 12 Feb 2024 02:14:40 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 73B4C6B0092; Mon, 12 Feb 2024 02:14:40 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 601B28D0001; Mon, 12 Feb 2024 02:14:40 -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 4D7EB6B008C for ; Mon, 12 Feb 2024 02:14:40 -0500 (EST) Received: from smtpin20.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay03.hostedemail.com (Postfix) with ESMTP id F0775A07C3 for ; Mon, 12 Feb 2024 07:14:39 +0000 (UTC) X-FDA: 81782289078.20.BDB9663 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) by imf06.hostedemail.com (Postfix) with ESMTP id 5927B180018 for ; Mon, 12 Feb 2024 07:14:38 +0000 (UTC) Authentication-Results: imf06.hostedemail.com; dkim=pass header.d=infradead.org header.s=bombadil.20210309 header.b=qGm4DgDh; spf=none (imf06.hostedemail.com: domain of BATV+56c964bc8172c8a9ee6e+7477+infradead.org+hch@bombadil.srs.infradead.org has no SPF policy when checking 198.137.202.133) smtp.mailfrom=BATV+56c964bc8172c8a9ee6e+7477+infradead.org+hch@bombadil.srs.infradead.org; dmarc=none ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1707722078; a=rsa-sha256; cv=none; b=WtHgDkN4pvM+BUeSqSEKVu4zZydTXZo16BDBf4vkoUJ1X111SNPf5StmLsieRohU/1R6Cs dXZBUc/vR+1a2O7fmRnO3QGLh7VM37jv6CtyjxikNguZoqn79vd7fzCF3kVDwA5jiClWQE KpLidUZo6YU7RJXIYfLBPPFNrODH93E= ARC-Authentication-Results: i=1; imf06.hostedemail.com; dkim=pass header.d=infradead.org header.s=bombadil.20210309 header.b=qGm4DgDh; spf=none (imf06.hostedemail.com: domain of BATV+56c964bc8172c8a9ee6e+7477+infradead.org+hch@bombadil.srs.infradead.org has no SPF policy when checking 198.137.202.133) smtp.mailfrom=BATV+56c964bc8172c8a9ee6e+7477+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=1707722078; 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=KFNTqb7k3Ymo30IuEwDaihs1yCQpUBV3RN+kFxOoV/I=; b=GaYHLwH/wbI82mIh0XWkkW5aSt5JzNUNc3BFNobtI4JG/b0+3yKKbEreCpIbS0PedU0gB/ nvycnIi0PR7OsAoF2/gaFMt7dpPJYkXJrcuK5+kraID2LOdBvShM29iv/NqzvslZDNBPyu l4awRIF/O1RJGVA321mEOpB0uXMQa3A= 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=KFNTqb7k3Ymo30IuEwDaihs1yCQpUBV3RN+kFxOoV/I=; b=qGm4DgDhGagw28iocodC5iIhS6 xsiMjPN63KLn6sFjMYCPL7iseVbubE2wS8w6bXJ+dcbmYvOHEWzOAZUcrSN0z9s6qgqeA4zE+v25Z Ieo4AhffrF+snI/gQkbKzpqjnhFvronw/KWUEfMYR/mvFkRA7Rkarbpg0iWyZZlXzrZJHp4jqfsi9 q9boZv/wYg0kxsnUDqX9688gwSdlI9bqz14Z3r5AjizGcXXBELXp/TxTAsBR1zhWDROEl8xd9MQ6z QcXvVjnwYut7/ExXvXXIN3edVcs960N7aYgwjVh71uI9ph52Edo7WhetgJdrGm5ARyCfAEeyxZjds ynVt7v1g==; Received: from [2001:4bb8:190:6eab:75e9:7295:a6e3:c35d] (helo=localhost) by bombadil.infradead.org with esmtpsa (Exim 4.97.1 #2 (Red Hat Linux)) id 1rZQWT-00000004T5c-0Fro; Mon, 12 Feb 2024 07:14:37 +0000 From: Christoph Hellwig To: linux-mm@kvack.org Cc: Matthew Wilcox , Jan Kara , David Howells , Brian Foster , Christian Brauner , linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org, Jan Kara Subject: [PATCH 14/14] writeback: Remove a use of write_cache_pages() from do_writepages() Date: Mon, 12 Feb 2024 08:13:48 +0100 Message-Id: <20240212071348.1369918-15-hch@lst.de> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20240212071348.1369918-1-hch@lst.de> References: <20240212071348.1369918-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: 5927B180018 X-Stat-Signature: ugjizqdghpmw8duhywwizo9ouyebwc31 X-Rspam-User: X-HE-Tag: 1707722078-386430 X-HE-Meta: U2FsdGVkX19m5rXeLXfrQ5GP8AiUm5xItHzCr9APtKP8YAVG6c+937WY/K0wIii0zsB/Eq00+dwdJdDPMNqLSFgz6zogtXhVFOgwjFT7l9s95GGIBu1AA5WizrEKl4qZkUxVR/7CXrkoVQnXpOUgDKXJS96a0tJ1khSgtwxky/G216fDf3WtMbjbhwfulwhkAgLkR628HLz0XNXya1Y2CBdYsm+I3cm+XTNBoD+2dIYDdw6oACktKNIorAnitqdlLZGqv2CiZiChwUrLVIERgH4ijnSMdPXapTjI4NOFLrw1SWLzZ77ZwdECW7xzTv4G3Flccj7Tppbh5G2ZfgtysFWS8YGISHD7bw3Jb5OkfrgMXWVMik8wdxD7VyOuy084h6k5IpDUQxLE9coXJPId4qtGJXyR/EZx4qJntzh2Zr7Ck3QuP441srqe9UcZ9cyArXH0RQ5o9UDE2fhdwB2kf6eGPDclw9I4UiZnqlW3MsHhxYNKki2x6gAN2WYexkaIRb4IimTEMrf4WwavU49J+sU5ZujLgf8cdLVl++D4Deh4D43oTmWrzQCFpi/UYGGo+RRVFVCz0sOPNpxEn9pTBeL5A+EOUYV+zX/rcCMtkgq9n4qjXs9khn9E9Q2BRdmcMDjTjxJ56nx2t2wPFO8Fk+/XqC35AaBqD+UqpazKWQs65RBj2TOQxtJZuBIk6YpsrRKdrd5ixKd5c5rVae8xqUrkvFC5NPr/8Rvde7qrpHOl2BUG8qFxHmy8OCYk00CfgJHeCU2kLBkcjRV8bClWqrstOv2GHbAUShC/EAjoJPbF5oJy0c++bISXfAgfBasxrPq31Qc7F8iF4QOh+G1cRDlOU57OVDckJDQLFBFcmc86Fp45wSNHbid5zgUmvrYABlgHIPoAJZGAK7hO0iJZ1Q5UutisgNbVvUC1gBNe6xoNUmWY2/BOVuOjG0Ob+QdX1Hf3LFe1ndEHScNcBov vRBZtv17 bGypHzur4LxOxTVAHGJ1pluoqFW7hgZnCZkVRa26x9uYU4VeAncWhCO4zBnNf871qHdpFxfpGsBB2xizHhJEpX6MvlEBuqAYIvpXAmlDYzvBV3tBT0TxfqHpNZGGfUu/Hrs4IEAVe6vYGK4s/wUbxr1wM9Utr3NgjprSFjjdkE0py5OdX/Fw5PG4Z6JsbhuiI/Hho/fFWLi/v+YJGt2bl1oX39KwdpANEa7HkFNE1Rjkvudapjiw2ukIRF2hgIaG/mFaxZuuGONXlSt+Bh6WviDRStR0Ynrxw97OVl3OO8fDSubAMQT9iw3THYfgj2EAUYTMm+TP/UDHgUvpHoQSoHZeUtxUiOhdJMWN45of90VnnK+0w8359cHkcvV9qkhiRwIjR9NMH8B1UYCu+SSq9NK8zP9C63u4mXocg/V6ayl71cCywK1wXdbuYmoKK61wSSCbtZ1p+hGsUumZ5GDLFHvQf7nsNux0FMKvmPHH8yITp8xC6+W7RprlZiXO7kCH9zSSkFUEtf5cU1DtXuoLpStgPOEXw4GYREnKA X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: From: "Matthew Wilcox (Oracle)" Use the new writeback_iter() directly instead of indirecting through a callback. Signed-off-by: Matthew Wilcox (Oracle) [hch: ported to the while based iter style] Signed-off-by: Christoph Hellwig Reviewed-by: Brian Foster Reviewed-by: Jan Kara --- mm/page-writeback.c | 27 +++++++++++++++++---------- 1 file changed, 17 insertions(+), 10 deletions(-) diff --git a/mm/page-writeback.c b/mm/page-writeback.c index 1996200849e577..2fd83d438f92bd 100644 --- a/mm/page-writeback.c +++ b/mm/page-writeback.c @@ -2577,12 +2577,24 @@ 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; + struct folio *folio = NULL; + struct blk_plug plug; + int err; - return mapping->a_ops->writepage(&folio->page, wbc); + blk_start_plug(&plug); + while ((folio = writeback_iter(mapping, wbc, folio, &err))) { + err = mapping->a_ops->writepage(&folio->page, wbc); + if (err == AOP_WRITEPAGE_ACTIVATE) { + folio_unlock(folio); + err = 0; + } + } + blk_finish_plug(&plug); + + return err; } int do_writepages(struct address_space *mapping, struct writeback_control *wbc) @@ -2598,12 +2610,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;