From patchwork Thu Dec 14 13:25:34 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christoph Hellwig X-Patchwork-Id: 13493055 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 D7C7CC4332F for ; Thu, 14 Dec 2023 13:26:00 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 71BCE8D00B4; Thu, 14 Dec 2023 08:26:00 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 6CBB18D00B1; Thu, 14 Dec 2023 08:26:00 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 593498D00B4; Thu, 14 Dec 2023 08:26:00 -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 4A4C98D00B1 for ; Thu, 14 Dec 2023 08:26:00 -0500 (EST) Received: from smtpin27.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay06.hostedemail.com (Postfix) with ESMTP id 22F77A22AB for ; Thu, 14 Dec 2023 13:26:00 +0000 (UTC) X-FDA: 81565496880.27.F18EAE5 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) by imf11.hostedemail.com (Postfix) with ESMTP id 6F4AC4000E for ; Thu, 14 Dec 2023 13:25:57 +0000 (UTC) Authentication-Results: imf11.hostedemail.com; dkim=pass header.d=infradead.org header.s=bombadil.20210309 header.b=ztKYDWSI; spf=none (imf11.hostedemail.com: domain of BATV+55581d165dda9d0af87b+7417+infradead.org+hch@bombadil.srs.infradead.org has no SPF policy when checking 198.137.202.133) smtp.mailfrom=BATV+55581d165dda9d0af87b+7417+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=1702560357; 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=dGiI8OkHMxqBpcMGTmwSGDbSvODrydoaDrjFK0YrpEE=; b=dzJJye7WIlN/DPrAO3LkvzPeeAblv2GMgRxlmNSr5ygsQQvjin3w2PwJAVfq5Y5TRe10+D Rj7BJZhrnThUyUVPFdoH0Gp8aF34p85U7Umd3IvTPEegwXEHaS8MfpVJOREEhdl2C2U/mj wmXVS6BO8QutSg8O3CGtelmUw6qJ1bs= ARC-Authentication-Results: i=1; imf11.hostedemail.com; dkim=pass header.d=infradead.org header.s=bombadil.20210309 header.b=ztKYDWSI; spf=none (imf11.hostedemail.com: domain of BATV+55581d165dda9d0af87b+7417+infradead.org+hch@bombadil.srs.infradead.org has no SPF policy when checking 198.137.202.133) smtp.mailfrom=BATV+55581d165dda9d0af87b+7417+infradead.org+hch@bombadil.srs.infradead.org; dmarc=none ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1702560357; a=rsa-sha256; cv=none; b=5MWxJkAqadzD9KtfbV7gmo6TDdPGqtk4uFkNGB81Ibcoc/h9Zk6HGQEiRsc3FP0hlU6B+q qR8Qn8pDafQaB4YQvRE+Nb1sxDvYgh/N/ZQrTC+/TxQG0Iz9wVLaCSa2vWp/yVbsbXCmOw Nbf0RMxJgymkJxSKEWu823QJCY7QEi0= 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=dGiI8OkHMxqBpcMGTmwSGDbSvODrydoaDrjFK0YrpEE=; b=ztKYDWSIzMbt21zCgDHn0IQVdR WEnQpPcfNE9IlRkh+DfxnVLV9Y7bB90QZSd/Lgm77je6hoN3kXz5/FjSVlwy075Pt5Qfc+OGTIGDA /RRDRJbdv3i7JmHPk6/sfyN27+59AhFDskZx5dg8aL2TD08X8OUYfLgW7aYfX/Zk6CX/bX53bbbSb iWXq5RbHXwlywgPE8elTNw4eOQlPgFXKwCnb2QiLjjeLh9DMPsJmIO6KbmVgsmrTBrVyM5Ucz9Kyu jeStapBP9fjfHrc+av6YzxBJtg9mqdk3JliqK0MEFezGFRPl+cEs7bc1E/jKgORcUtfPBSE/Ay7R0 KOPvYEGw==; Received: from [88.128.88.27] (helo=localhost) by bombadil.infradead.org with esmtpsa (Exim 4.96 #2 (Red Hat Linux)) id 1rDliu-000N0o-0h; Thu, 14 Dec 2023 13:25:56 +0000 From: Christoph Hellwig To: linux-mm@kvack.org Cc: "Matthew Wilcox (Oracle)" , linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org, Jan Kara , David Howells Subject: [PATCH 01/11] writeback: Factor out writeback_finish() Date: Thu, 14 Dec 2023 14:25:34 +0100 Message-Id: <20231214132544.376574-2-hch@lst.de> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20231214132544.376574-1-hch@lst.de> References: <20231214132544.376574-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: 6F4AC4000E X-Rspam-User: X-Stat-Signature: t8kks1h4zht6ifegzc3dnthxsrnxjymm X-Rspamd-Server: rspam01 X-HE-Tag: 1702560357-550505 X-HE-Meta: U2FsdGVkX1+CX5ACfjid/RmeU0NK81endrR36fxkUl4mbixT9yizVlKhiIA//w5oWSTspEUm2QdkjH4Q4J9c0UI/fTf2Ah1Eg6HfhK0GWdKLjJXpnQePnUfWqjYJjHr3yO/KtjtzRnu9cF2HySB7GIoTz0k4sRl2aUmL9KnBgX7NI3VTYOQ4pAgqyDkb/DDPc5bbxzyHtZ09OReB8WvTUq6iB9m29xdiaKPyUeUX9W1M+wzlg0TVbRMTp2L3gDCBx4Vsb2cwZ7DYh2Sy2WAGIcGsmqDDBqkDizmfbzJtkNz7EE4BjpB3qqiPahUIVRhBR4dDUIDTbSsOpFi+GkfDqCytj+3vvP2CWRfDimcnhtt9RkBdqTzyyw880gEcakHaD9fM+HZI66sNojdZrNSkslKqcQ2RV7mLcv4fgkliBGCLMI4OV0JLgh1qA7hUwXyIhvud/sJJlUdX/VXj9zTx0TAuq9f8grcdf1eU/zzu4uPZeQG5t002COLdPdOzWicIrxW6Wpe70X2V7MNA1vo8ACZ7xFEi+CZOSgn6+/VtICpUUPkkVp4xa7gV8q+R1qZZMCkhKNltdMgQPDcVWSPJJwC4f/gda3EV9UsvmCUT3NI4odOy569pCpFvnjwIdC8mYK6J68fGcCY36muQ2UPvmE5xT84ISRCvmce75emTvkIYJiLCdGvKsAfSpvKnNbjjNUtFFtlzH9dp/ZvG6vZvPJMy/QzAZdzRZz0+RtGwB9lIvcY3/aeKmZf6QywW54xQg+BsHTxGPjw/b1o9S6WPB00MzhRc3f/8s5d0G0vogDepBcNAL88ZI/CLoDCUn7mQDA1s3LDLl3tIIjvCIZNuoCsz+viA8Mt8Swme2xA9nOVaJMVcHD6V/aKi5s6IicLgeEWyKHNKYTF83XwWq4qlrU1jVxDKNLmTKIqonAa8NkdfNNOFMetR2QFEGeJNCLpnMeRiE8TXUcfSq9YQxPg v0ZVhA2J q0ot6/GX9DJhEm5KdGW/8Iw/MeVngi3G9kz0NZTX9SI7jR5vEpWXV4Rsv99nJfRJ+QIAY2oCG5hZ0UYN+/8TZ4Au8st1zDRvgyRuCH0rNX0EJlE7ts2T517DXcd3NPamIfUA9BYJO/CPizfwn4hOx+3+sQLv/bDPIbPqVLK2AVAOsLxP4rlEB7BiACnOGtxSvo2+h9SX0TH1JqKdRn7jItc16t1z2poMZA48j/SvvZuUE5jGqGwZz/u7mj90sgUYQiCRqUmml1zlnN9Uiptzxbz9FXOJexuTOqGBEE/Key1vtYP6JYIkYvUP4xJUtYMjpLCC/vrUfSQzFOC2ZQXKZx3xvrT5sFAoRg6tdZXJxiJB0ER9l5gdE3N8Lyq6ZtxLMGm/D0L27CvXvcDkZEHWem1Man9w6p682v+TCwTVxyS8njRtCFlEofZCjODH3CJpnNu+JD7J2ievofmbvFdEVA0s4+c8Zxj3hvMb3I2NtmTquhMEii5hKRsdz5wyGLxop+0hmW3QBRaa7PTc= 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 having a 'done' variable that controls the nested loops, have a writeback_finish() that can be returned directly. This involves keeping more things in writeback_control, but it's just moving stuff allocated on the stack to being allocated slightly earlier on the stack. Signed-off-by: Matthew Wilcox (Oracle) [hch: reorder and comment struct writeback_control] Signed-off-by: Christoph Hellwig --- include/linux/writeback.h | 8 +++++ mm/page-writeback.c | 72 +++++++++++++++++++++------------------ 2 files changed, 46 insertions(+), 34 deletions(-) diff --git a/include/linux/writeback.h b/include/linux/writeback.h index 083387c00f0c8b..05e8add4b5ae3c 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,12 @@ struct writeback_control { */ struct swap_iocb **swap_plug; + /* internal fields used by the ->writepages implementation: */ + struct folio_batch fbatch; + pgoff_t done_index; + int err; + unsigned range_whole:1; /* entire file */ + #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 ee2fd6a6af4072..45309f3b8193f8 100644 --- a/mm/page-writeback.c +++ b/mm/page-writeback.c @@ -2360,6 +2360,24 @@ void tag_pages_for_writeback(struct address_space *mapping, } EXPORT_SYMBOL(tag_pages_for_writeback); +static int writeback_finish(struct address_space *mapping, + struct writeback_control *wbc, bool done) +{ + folio_batch_release(&wbc->fbatch); + + /* + * If we hit the last page and there is more work to be done: + * wrap the index back to the start of the file for the next + * time we are called. + */ + if (wbc->range_cyclic && !done) + wbc->done_index = 0; + if (wbc->range_cyclic || (wbc->range_whole && wbc->nr_to_write > 0)) + mapping->writeback_index = wbc->done_index; + + return wbc->err; +} + /** * write_cache_pages - walk the list of dirty pages of the given address space and write all of them. * @mapping: address space structure to write @@ -2395,18 +2413,12 @@ int write_cache_pages(struct address_space *mapping, struct writeback_control *wbc, writepage_t writepage, void *data) { - int ret = 0; - int done = 0; int error; - struct folio_batch fbatch; int nr_folios; pgoff_t index; pgoff_t end; /* Inclusive */ - pgoff_t done_index; - int range_whole = 0; xa_mark_t tag; - folio_batch_init(&fbatch); if (wbc->range_cyclic) { index = mapping->writeback_index; /* prev offset */ end = -1; @@ -2414,7 +2426,7 @@ int write_cache_pages(struct address_space *mapping, 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; + wbc->range_whole = 1; } if (wbc->sync_mode == WB_SYNC_ALL || wbc->tagged_writepages) { tag_pages_for_writeback(mapping, index, end); @@ -2422,21 +2434,25 @@ int write_cache_pages(struct address_space *mapping, } else { tag = PAGECACHE_TAG_DIRTY; } - done_index = index; - while (!done && (index <= end)) { + + wbc->done_index = index; + folio_batch_init(&wbc->fbatch); + wbc->err = 0; + + while (index <= end) { int i; nr_folios = filemap_get_folios_tag(mapping, &index, end, - tag, &fbatch); + tag, &wbc->fbatch); if (nr_folios == 0) break; for (i = 0; i < nr_folios; i++) { - struct folio *folio = fbatch.folios[i]; + struct folio *folio = wbc->fbatch.folios[i]; unsigned long nr; - done_index = folio->index; + wbc->done_index = folio->index; folio_lock(folio); @@ -2490,13 +2506,13 @@ int write_cache_pages(struct address_space *mapping, folio_unlock(folio); error = 0; } else if (wbc->sync_mode != WB_SYNC_ALL) { - ret = error; - done_index = folio->index + nr; - done = 1; - break; + wbc->err = error; + wbc->done_index = folio->index + nr; + return writeback_finish(mapping, + wbc, true); } - if (!ret) - ret = error; + if (!wbc->err) + wbc->err = error; } /* @@ -2507,26 +2523,14 @@ int write_cache_pages(struct address_space *mapping, */ wbc->nr_to_write -= nr; if (wbc->nr_to_write <= 0 && - wbc->sync_mode == WB_SYNC_NONE) { - done = 1; - break; - } + wbc->sync_mode == WB_SYNC_NONE) + return writeback_finish(mapping, wbc, true); } - folio_batch_release(&fbatch); + folio_batch_release(&wbc->fbatch); cond_resched(); } - /* - * 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. - */ - if (wbc->range_cyclic && !done) - done_index = 0; - if (wbc->range_cyclic || (range_whole && wbc->nr_to_write > 0)) - mapping->writeback_index = done_index; - - return ret; + return writeback_finish(mapping, wbc, false); } EXPORT_SYMBOL(write_cache_pages); From patchwork Thu Dec 14 13:25:35 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christoph Hellwig X-Patchwork-Id: 13493056 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 2F36BC4167B for ; Thu, 14 Dec 2023 13:26:03 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id B88288D00B5; Thu, 14 Dec 2023 08:26:02 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id B39EC8D00B1; Thu, 14 Dec 2023 08:26:02 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 98B2F8D00B5; Thu, 14 Dec 2023 08:26:02 -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 8334D8D00B1 for ; Thu, 14 Dec 2023 08:26:02 -0500 (EST) Received: from smtpin19.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay04.hostedemail.com (Postfix) with ESMTP id 64D601A0BF7 for ; Thu, 14 Dec 2023 13:26:02 +0000 (UTC) X-FDA: 81565496964.19.3D3E0C7 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) by imf04.hostedemail.com (Postfix) with ESMTP id A715440005 for ; Thu, 14 Dec 2023 13:26:00 +0000 (UTC) Authentication-Results: imf04.hostedemail.com; dkim=pass header.d=infradead.org header.s=bombadil.20210309 header.b=iaO3zrW7; dmarc=none; spf=none (imf04.hostedemail.com: domain of BATV+55581d165dda9d0af87b+7417+infradead.org+hch@bombadil.srs.infradead.org has no SPF policy when checking 198.137.202.133) smtp.mailfrom=BATV+55581d165dda9d0af87b+7417+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=1702560360; 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=gFAfQ8RI4NZqa/9LCD+jS3TStiD980ne3/Qcf1aEZzA=; b=0FM5pNgVtavPvDwC864rgg6WuPNd9662pqzIbAZJMEhvDitXJVFuvfiZaV4DRqfXQlBHkW EEhxuDZp7SewNr+hMfCTfKuN76XnDWok51LvS7cgqOx0GwOTIrTKyWZfsMwk/ZKcruoxDw U9QU2INFqbCuWAXRYpiytWbHlkFfCjc= ARC-Authentication-Results: i=1; imf04.hostedemail.com; dkim=pass header.d=infradead.org header.s=bombadil.20210309 header.b=iaO3zrW7; dmarc=none; spf=none (imf04.hostedemail.com: domain of BATV+55581d165dda9d0af87b+7417+infradead.org+hch@bombadil.srs.infradead.org has no SPF policy when checking 198.137.202.133) smtp.mailfrom=BATV+55581d165dda9d0af87b+7417+infradead.org+hch@bombadil.srs.infradead.org ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1702560360; a=rsa-sha256; cv=none; b=ay/xzDW1ZNMWeKki+fOfzzbzCcoBPwmf0gklAqBNL+CAbezNRSUs5S4scmc2vEb3DjUV8w KE7yaLVK37aGFct9drIjbzXC7LcrhoYMQjdYVNO2ctvz8YBqKtAdbCpWprvdxI8SlCtX2a zAICBcYKedCSRP25T8HjCSfgfMsYXE0= 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=gFAfQ8RI4NZqa/9LCD+jS3TStiD980ne3/Qcf1aEZzA=; b=iaO3zrW79MSicmR2sZYKfRcxiH i6dP0SWuEvOwauQFGQNX6drc20R0mQporbqJK9Ae/EpSzZ2URWntRpkaHP0xigV0iDY5QuSJHIiCQ Mo7Rto/vqm0//OV5Akxwqp+GKF4VnjeKJIRrzyZvhXp1nfFHZo6clA6Ms2vyByRzAuCo5P769hI0E uuu0EStnwmU0hmRpVyXiiEKSAQSDbPs5OhXxok9vD7vVpTfFx0OyvSabAZzyGs9vLoBYXlH08ZvZw 9amAcoVDpwtwFO+Pq43XGabNC9cEhu43saMRnC8Zp09eKvIPBlEOZtG6iQCulLeEvzO1jHG5Xn8O+ yftaE4YA==; Received: from [88.128.88.27] (helo=localhost) by bombadil.infradead.org with esmtpsa (Exim 4.96 #2 (Red Hat Linux)) id 1rDlix-000N1N-1b; Thu, 14 Dec 2023 13:25:59 +0000 From: Christoph Hellwig To: linux-mm@kvack.org Cc: "Matthew Wilcox (Oracle)" , linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org, Jan Kara , David Howells Subject: [PATCH 02/11] writeback: Factor writeback_get_batch() out of write_cache_pages() Date: Thu, 14 Dec 2023 14:25:35 +0100 Message-Id: <20231214132544.376574-3-hch@lst.de> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20231214132544.376574-1-hch@lst.de> References: <20231214132544.376574-1-hch@lst.de> MIME-Version: 1.0 X-SRS-Rewrite: SMTP reverse-path rewritten from by bombadil.infradead.org. See http://www.infradead.org/rpr.html X-Rspam-User: X-Stat-Signature: 7u4rn439r5onuyc7fa6g476xysws4ar7 X-Rspamd-Server: rspam07 X-Rspamd-Queue-Id: A715440005 X-HE-Tag: 1702560360-195031 X-HE-Meta: U2FsdGVkX1+cGIXiBk4DCl6YNjIjN30qaw+NohO9CeMy+pGniKLgSCHRX0NGWLeUXspyyU//I6WLDdlSFa+5TYSMx03/rm4nTPt36vGOA2DLhvBJDXLBHa5ak+A6hxS8zIbw9ijFCZrS2ZosIGr3GIlGSa5Mu5/IafA6AcJa4bXmBBLli9UnT8oEeW8Jjbg24VMvLDnnNgC9AE2Yu1fn0P3WL02gQ336g3rxtMJX+X1+8GkCr1zsomB0U1cmuRtathjZl5YBA3I6OYoFbpqyJIoz+4aAwbcDQVl4NvQiguc2CWBT5MLlPOJH29IbHl9JwRbf1LJd57UIUqG5fVkYFzgrcozj97+nVf+G1el6+b+KrqESy22Smeq3ULWCk6uFvAIPl5tihApKAl+qikbvDJs0wv1gs3n7ZiAMAzrQRXYNX2fA4SQZ8mHPpsnGVcXAOm1xyRJ/UFOP9aHj4SaVm4x/1kkbaCX9leNJ06snihuspsQweKiH0nsvfo9hNuBX+B072bZs0pmrk9B9TaLEYiNj4oxYRz1rW2npOz9VR7t/6UsHYq5aB69/IITga707rUp0jebX3UJS8v4hpztmKWd9HkrogLP5Z34IOZ69eeLPW55p7s0CHDlr8jCsSQuHi7oFCMYYv170PN/SBqDjUds2ng+OTZHf/mDLdOFGZvMZqdmpHPJ6S6TCRYBaM5WcXzds2/TuX3Yo3vYrOG4YIvmK37QKVgbem1WRClZnP04z1B2fz3ZuMTfXZRpfj0O2NiPCgkqHn2435uJXfJD9cbobw3D+HqJ+lT+YwWBwx4Ql96kIPYTLNn2vo4hbMyf3Xb+KXN4kgEs7/XkHMtaENvbOCMyrgkP+wN5ACHCbPqZj0hTj4W6IOt42jwGUzoJMuStKi16i/o44BWrGs7JFyz8AOEfh+74Z/fBLy72wgxV3hMGpML3Pedebx/8w6IRwhPctvWEAqotS9TEOd+r 05+SnKCR dtdMJI/gnOhKtsMcx+LHmHP93PtrxHmqH4EH1oE2GPHBc+Ub9CCkEUH8i+SDkUJNDBgLoucs1C9jSCcchm3W+KVv2mrczGCPv1tGDjoaZVPhe9XpGWNCs0bI0T01nqHBf22mui+YxLaFcknAu1krWKZvaTR2PWK1Di3tJJECn1HR/RI2BR9APhp0eXVxmuAm6zkEp3P9n2qz+ju73Xi45bwmK6XH9b5Izl61QHJISyFNhyLpl8g8yLEZ6RFqOmsEdOCm5eyPW1RMZhgVwsH2xccxlYHyzA7iD4T3V1R6mAEbI8vm/STUKtArhUg7CmmQ370UGinsXl+8WM+JBRAglpchSbSE6bk4BpfTVcQ6/tXz+GA0ofAMz19b62bxwjWmVBMWe45OlV4bPDUJ+0FgLngDdvA3WHAqgQDINa/E2cnVAfx+JHRvMj7soQ0XaHS+kJINTL+Ju+auWfUCnUYRznarL4X9PyZO7Dpw3FFaMzNOBkhPzfRfEcOdQ5g== 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) Signed-off-by: Christoph Hellwig --- include/linux/writeback.h | 2 ++ mm/page-writeback.c | 49 +++++++++++++++++++++------------------ 2 files changed, 29 insertions(+), 22 deletions(-) diff --git a/include/linux/writeback.h b/include/linux/writeback.h index 05e8add4b5ae3c..be960f92ad9dbd 100644 --- a/include/linux/writeback.h +++ b/include/linux/writeback.h @@ -81,6 +81,8 @@ struct writeback_control { /* internal fields used by the ->writepages implementation: */ struct folio_batch fbatch; + pgoff_t index; + pgoff_t end; /* inclusive */ pgoff_t done_index; int err; unsigned range_whole:1; /* entire file */ diff --git a/mm/page-writeback.c b/mm/page-writeback.c index 45309f3b8193f8..5d33e7b468e2cc 100644 --- a/mm/page-writeback.c +++ b/mm/page-writeback.c @@ -2378,6 +2378,22 @@ static int writeback_finish(struct address_space *mapping, return wbc->err; } +static void writeback_get_batch(struct address_space *mapping, + struct writeback_control *wbc) +{ + xa_mark_t tag; + + if (wbc->sync_mode == WB_SYNC_ALL || wbc->tagged_writepages) + tag = PAGECACHE_TAG_TOWRITE; + else + tag = PAGECACHE_TAG_DIRTY; + + folio_batch_release(&wbc->fbatch); + cond_resched(); + filemap_get_folios_tag(mapping, &wbc->index, wbc->end, tag, + &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 @@ -2414,41 +2430,32 @@ int write_cache_pages(struct address_space *mapping, void *data) { int error; - int nr_folios; - pgoff_t index; - pgoff_t end; /* Inclusive */ - xa_mark_t tag; if (wbc->range_cyclic) { - index = mapping->writeback_index; /* prev offset */ - end = -1; + wbc->index = mapping->writeback_index; /* prev offset */ + wbc->end = -1; } else { - index = wbc->range_start >> PAGE_SHIFT; - end = wbc->range_end >> PAGE_SHIFT; + wbc->index = wbc->range_start >> PAGE_SHIFT; + wbc->end = wbc->range_end >> PAGE_SHIFT; if (wbc->range_start == 0 && wbc->range_end == LLONG_MAX) wbc->range_whole = 1; } - if (wbc->sync_mode == WB_SYNC_ALL || wbc->tagged_writepages) { - tag_pages_for_writeback(mapping, index, end); - tag = PAGECACHE_TAG_TOWRITE; - } else { - tag = PAGECACHE_TAG_DIRTY; - } + if (wbc->sync_mode == WB_SYNC_ALL || wbc->tagged_writepages) + tag_pages_for_writeback(mapping, wbc->index, wbc->end); - wbc->done_index = index; + wbc->done_index = wbc->index; folio_batch_init(&wbc->fbatch); wbc->err = 0; - while (index <= end) { + while (wbc->index <= wbc->end) { int i; - nr_folios = filemap_get_folios_tag(mapping, &index, end, - tag, &wbc->fbatch); + writeback_get_batch(mapping, wbc); - if (nr_folios == 0) + if (wbc->fbatch.nr == 0) break; - for (i = 0; i < nr_folios; i++) { + for (i = 0; i < wbc->fbatch.nr; i++) { struct folio *folio = wbc->fbatch.folios[i]; unsigned long nr; @@ -2526,8 +2533,6 @@ int write_cache_pages(struct address_space *mapping, wbc->sync_mode == WB_SYNC_NONE) return writeback_finish(mapping, wbc, true); } - folio_batch_release(&wbc->fbatch); - cond_resched(); } return writeback_finish(mapping, wbc, false); From patchwork Thu Dec 14 13:25:36 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christoph Hellwig X-Patchwork-Id: 13493057 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 4531FC46CA2 for ; Thu, 14 Dec 2023 13:26:11 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id B62478D00B6; Thu, 14 Dec 2023 08:26:10 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id B13048D00B1; Thu, 14 Dec 2023 08:26:10 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 9D92B8D00B6; Thu, 14 Dec 2023 08:26:10 -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 8F2BA8D00B1 for ; Thu, 14 Dec 2023 08:26:10 -0500 (EST) Received: from smtpin02.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay05.hostedemail.com (Postfix) with ESMTP id 7F7EC40C6A for ; Thu, 14 Dec 2023 13:26:09 +0000 (UTC) X-FDA: 81565497258.02.D1D97BF Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) by imf30.hostedemail.com (Postfix) with ESMTP id D08928001A for ; Thu, 14 Dec 2023 13:26:07 +0000 (UTC) Authentication-Results: imf30.hostedemail.com; dkim=pass header.d=infradead.org header.s=bombadil.20210309 header.b=Ymphf93h; spf=none (imf30.hostedemail.com: domain of BATV+55581d165dda9d0af87b+7417+infradead.org+hch@bombadil.srs.infradead.org has no SPF policy when checking 198.137.202.133) smtp.mailfrom=BATV+55581d165dda9d0af87b+7417+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=1702560367; 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=kn8CvxNi5qh4QD11jnSpjHpiIFyaVQYj8SeXOQ3UR/M=; b=YY+DZvktD7hU09vUpfsHGdt2022lCYZ9LOGTNI0Su8YwGlOBpiBr+90tN1v9Mi/Hm8z93V FXyPuLnOn4rMTYlhyBadcW39f9kKVkgnQMi7yb9YJcXs/gLMO1TrAGYPwhBZTDrdby97lV +0xp69Pr4wpkUfm9xLqcIc3UMfTiyrA= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1702560367; a=rsa-sha256; cv=none; b=0Kcoo6X+vbktEWfhrzmohZ0I/3iljpUk9PU2Q8MqAR2yJISLNKMmc4L40OZNrXxmuQ39hA 6aYkKBg/aVa5kaJIIzerKtevKN3hL3XRUO/rRyWI1bz8sQr5sn0Z1u2NUu9BDMM+kwkBv8 qO+DWpxYJdwEeUoKFu/VJZVr1TWmG6o= ARC-Authentication-Results: i=1; imf30.hostedemail.com; dkim=pass header.d=infradead.org header.s=bombadil.20210309 header.b=Ymphf93h; spf=none (imf30.hostedemail.com: domain of BATV+55581d165dda9d0af87b+7417+infradead.org+hch@bombadil.srs.infradead.org has no SPF policy when checking 198.137.202.133) smtp.mailfrom=BATV+55581d165dda9d0af87b+7417+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=kn8CvxNi5qh4QD11jnSpjHpiIFyaVQYj8SeXOQ3UR/M=; b=Ymphf93hcUsna9RWYEJ1i5FWvm QO6gwTupm7fmG37py0aAXd+CtC/OWntiYIUrRYG0S0iL4KGmW9loE7n35WfYgdg691tA0ruuq6o4g IeDqgCs8n01sx4MFcEbNm+2m0hZqKnCp7Zw9dtKciOW7NNtD0AEDtDyqISiSMDti0I1itZcbNUgD/ jMgr3PyeOqtJrmyP2pLCfONU1HegzPe9JqCZ9Csc0091UoP3UlDRA//18mMkH7b69/r2MpVkIq0Uo nDWtlbXZyGAC+4temfdUdkV73P7SE/c7vhXe5EQDsJCuWNGfcAJjCphLs5vTZ+zr6TS9uVwvaxdhL m8a+e+BQ==; Received: from [88.128.88.27] (helo=localhost) by bombadil.infradead.org with esmtpsa (Exim 4.96 #2 (Red Hat Linux)) id 1rDlj2-000N2I-1X; Thu, 14 Dec 2023 13:26:04 +0000 From: Christoph Hellwig To: linux-mm@kvack.org Cc: "Matthew Wilcox (Oracle)" , linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org, Jan Kara , David Howells Subject: [PATCH 03/11] writeback: Factor should_writeback_folio() out of write_cache_pages() Date: Thu, 14 Dec 2023 14:25:36 +0100 Message-Id: <20231214132544.376574-4-hch@lst.de> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20231214132544.376574-1-hch@lst.de> References: <20231214132544.376574-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: szngxtfz7j1a3m4kojd5yu3ksdki3mrc X-Rspamd-Server: rspam10 X-Rspamd-Queue-Id: D08928001A X-Rspam-User: X-HE-Tag: 1702560367-954265 X-HE-Meta: U2FsdGVkX189+V4YgZQJ2GWPla/SP+hxEP62E9KJWHeK5NO4GJWWY9r3uj6AK9mR7bNS1EqAk9djZOOyowPLxcZhDYHVD8Yqefrv3+4dAFUZCcSx7MFubQqYPZvgly960C6hcwFA2RPGzNRg0aI+CabiiLG1zi9F/+Wh+zxrYvrgYb4OX7QI2ILtlEj6Qwet86RL+xv2kDUvUEYXNmWDXZ+FmLmr12N/0xwA3F+z3uxGae8vanGAMQVvRqfakw+aixiAm0YYGZpsjQkVNBkRzg6utBHloXBzLrg+9pS6nG4oB+uugoP2wIcoWlVPYHjNXA0rY2KcRe0zaerrrFgstPFT14bUWbcNrOUvxZhFOanL3EGcCSDZB/ljxKwfZbzDzqwDkezVGh9IKMox4IFokHzxBxTTu9ICtWA4u+Nyn36wUrqhoJG0bgmykhVNSvApt5yVzKH9RcpbIzmncmR89f8KytAkZWnMn1rDfIb5MV5QC07XF/pk3YbJGp6Qtal8OqMreO82Bkhy7/RiTeOFLPfjJxe1EiggcOLok6kk4w9pqj+EQrCsDWZUQw0i2Uj3q2sqbz7z9hIcfwCzFN5lVDuVwnXAah/PV2GqhQTxD5CfCGf92xO7Jdw1ZkmZ2NKTDZt6TPynu6lLMRYPsEAZkzK+hc4z6LJnKKt1EAa2J/FwCmMpWo6D8LOBQF4RpMQ1O+IrLIDAvfoQAFwx/oI0tU/ENc13S5LWHTe6QELRFDM5K2M97TJYrDJmSmN/20DO+eGh9EP+6uQYz6/ZqIgWffERWuz8s5Z2CKWloNEH49NLSykJo9ZkNd+9hhOqsdcrQuVrw2OMww0rS6GN+NxzoDPkdqapUG4IAofHbjjlaZCteXPYScgTAIhrr5lK+5roybULVV4hcjaM/2ii5dq8qqxhZypqEkHYHpExIy4yjKDkibP1OP5++j3xFaNUxtt0xU5I/QIID9xQJQi9Cbf 1CAt3cBN sBeX94kyZF4ypK5cOOviM1KcR5gY8sS1Z9bwvQl8TzHFPun69Xx5gi8tiMT/6FFHQ9/8wL7xrYZApKWyur3i3Q6XMhB/dwCFXHU0KgvW1RTa91dGytr/NVCtY1Y9cZynMiECf9MLnOpufpzef4qfk6GHt9CGmFHiUjzh1Dl2rbOgd8MMKuwSAmjf+wcoaHNrCkRB3BWh+URWOAwHg0lpBqQYmN/FAnhTk/BRGJp/05H2GfYFVZ185Hq8Nbt6L+kiGjNO+lOzUhhFd67KzLAVeH1bN6/zgZmdwhja97tAZLIxSXNgn8TWtCutTzq4vHqozk1Lm5COwiz8+5Wq1zXTcSL67hqZG9e0HHkMDyAlxnvvdPl6kVR4ruCys3daeCfhj5QG0UbyEIWi/BuuYNSHc04ahdOI7xqvPSFrPbEcAxWX3Gdi99V4KjT+Ry2u1yWZn+4Ck4AXQ0lCL5Jyuz3Yk45wvcdEluE32LLtNZahajykYlfJUqsnd5FdUgg== 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) Signed-off-by: Christoph Hellwig Reviewed-by: Jan Kara --- mm/page-writeback.c | 59 ++++++++++++++++++++++++--------------------- 1 file changed, 32 insertions(+), 27 deletions(-) diff --git a/mm/page-writeback.c b/mm/page-writeback.c index 5d33e7b468e2cc..5a3df8665ff4f9 100644 --- a/mm/page-writeback.c +++ b/mm/page-writeback.c @@ -2394,6 +2394,36 @@ static void writeback_get_batch(struct address_space *mapping, &wbc->fbatch); } +static bool should_writeback_folio(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 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 @@ -2462,38 +2492,13 @@ int write_cache_pages(struct address_space *mapping, wbc->done_index = folio->index; 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 (!should_writeback_folio(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); nr = folio_nr_pages(folio); if (unlikely(error)) { From patchwork Thu Dec 14 13:25:37 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christoph Hellwig X-Patchwork-Id: 13493089 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 ECA46C4332F for ; Thu, 14 Dec 2023 13:43:41 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 861608D00BC; Thu, 14 Dec 2023 08:43:41 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 811378D00B1; Thu, 14 Dec 2023 08:43:41 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 6D87F8D00BC; Thu, 14 Dec 2023 08:43:41 -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 5A20E8D00B1 for ; Thu, 14 Dec 2023 08:43:41 -0500 (EST) Received: from smtpin22.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay03.hostedemail.com (Postfix) with ESMTP id 23FBDA0C8A for ; Thu, 14 Dec 2023 13:43:41 +0000 (UTC) X-FDA: 81565541442.22.3555CAE Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) by imf06.hostedemail.com (Postfix) with ESMTP id 21994180002 for ; Thu, 14 Dec 2023 13:43:38 +0000 (UTC) Authentication-Results: imf06.hostedemail.com; dkim=pass header.d=infradead.org header.s=bombadil.20210309 header.b=JZ6CWZpv; spf=none (imf06.hostedemail.com: domain of BATV+55581d165dda9d0af87b+7417+infradead.org+hch@bombadil.srs.infradead.org has no SPF policy when checking 198.137.202.133) smtp.mailfrom=BATV+55581d165dda9d0af87b+7417+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=1702561419; 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=zsw+wTmwL88dMqXlPcddKLu64UsXn5iiu6gG3sd2+gI=; b=LuNz5y3DGKwFsEVf++um2iPkzfPdeJjG4k3y6zNxF4d62v3Cocmhp1sGkBDH6c8qUq5OdR /Y2Wg8y38BPjq0ffcbIjig/U17I/f7A+asRMEDOyVluIZ7Bj0MsEnZiE+nLEElKU3JKkLd 7C4T/I3qH3UPvKkWAiCUog4pXg3vFPE= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1702561419; a=rsa-sha256; cv=none; b=pg2N6p2qxZYdGQ0sJ0ViD5Y7YHRW4meVmMpaTim/lcBBBhsPBaIuyF/vyustpMFeunHIt7 7hhzG0Jpd+Sko/LWO9rZANULz7uWFhHWyv15D1Nqrbl2KP9PyAJliGskIa83+bEp/2ghZL xVX0/J3ZhxUyiCihBAk4a31eCDIMsM8= ARC-Authentication-Results: i=1; imf06.hostedemail.com; dkim=pass header.d=infradead.org header.s=bombadil.20210309 header.b=JZ6CWZpv; spf=none (imf06.hostedemail.com: domain of BATV+55581d165dda9d0af87b+7417+infradead.org+hch@bombadil.srs.infradead.org has no SPF policy when checking 198.137.202.133) smtp.mailfrom=BATV+55581d165dda9d0af87b+7417+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=zsw+wTmwL88dMqXlPcddKLu64UsXn5iiu6gG3sd2+gI=; b=JZ6CWZpvcy4fuseqmY16OrM6T8 DbXX6t3lj9ucqim23WY1gzee/6CX0nKn2g1UGzhIl2Vjl8NqcFnlOjHFx+i9aShIaD+KleTN+MN9q X7T1cilqrP7e/fXlwM0bTTUjg9Iv4bOJiYqBzd7mvGl+LE8Uj5gfWVsCOyfKrYaFUuET31z4jAV7Y fm6r1Lcfc7Id7k+6JZ3terQhgtjm9suIj9kXItRzdauXLUZH0Z9wPJzul1PHW8hhpPBD0uiF9t3Cr hAI+CngOjGT9f/ip71qJ76kPXnqmTz2ydFkRfCHN+Umo8Ilu5I9VdRD4Zgntp4KrbwgzBzWBGx5uL kjRLq/yQ==; Received: from [88.128.88.27] (helo=localhost) by bombadil.infradead.org with esmtpsa (Exim 4.96 #2 (Red Hat Linux)) id 1rDlj5-000N3y-0Z; Thu, 14 Dec 2023 13:26:07 +0000 From: Christoph Hellwig To: linux-mm@kvack.org Cc: "Matthew Wilcox (Oracle)" , linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org, Jan Kara , David Howells Subject: [PATCH 04/11] writeback: Simplify the loops in write_cache_pages() Date: Thu, 14 Dec 2023 14:25:37 +0100 Message-Id: <20231214132544.376574-5-hch@lst.de> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20231214132544.376574-1-hch@lst.de> References: <20231214132544.376574-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: 21994180002 X-Rspam-User: X-Rspamd-Server: rspam11 X-Stat-Signature: 1k1p78nerhbp1b7y5h91tujzsfx9bxtb X-HE-Tag: 1702561418-343109 X-HE-Meta: U2FsdGVkX1/vxaZ1G1eMS/cW2bxKlEbQeHrbCONIR/I7/i8d8lLRYXJZ3UQ6ocAOzcsr2HPfpPqRNSzzU+2vidViVsMGD9fk0ZIn+GIGcZhtF/94sfuB9SOrVrHUXYrYgmfM6T6AX7/uHaA3IqPc3FT61Yg7I9JgQBLafCOzwsZzzuA5b/of3DSImsun/hY4nwcgaHWwHDd9UYCYAH3V228DrSVdCC9qmJkd/qE/Qq5EbIIEmOJqV8e/oEY0Cs72+X+vBrGirtRtH7EsrmT+3QRndOf6U847BfqmvNI/3mBC9M25oXC0FTuH4+5Ysm1pa1zLInx6slp198yrOMVSUvNFqWnjRuY80dvBqEIqZHVkY3QaEWBp/GRGzgw0ohI3Em/mFRj8TzdrRGFAStSbU0nGdX59cJDLOOFbm91QlcX+Rl7JPnWugJ3yxikmDgpx53nX0KEAyEwrYSU5SJlsqYm0vEEnjexNMw4zhbrY3iHtdPWGhmOEtUCqcU0z+ih0ixi2ehGpGR+NGxmdn5DLGDjQ7fxhEyaNZqTNeHouE9k3y6aX8jHahCEkg2mnRauFfM1HzN4QhV4e+aITwvNkR+aIOzrbcmlGYkfdeO7+yuLPoFxMwp/hVqbw3UDhMRnT+IaIZw6K27DRbCJhODjjpN4gVLxqEbEzLeO1oFlGzYfJavwrncYZSoDihezWGF+maI9YeubSZKhEhMLuBnARM4nyiOQ7CtijsGWESLhPEyrp5xpYO8G8UgAHpBG5ggVyu0FLgCNOo1KZUz0vmLEreNboigRxYcvdw2ljddpR//tRWPAHfbAxhQ6D1hV78xmqZs/ks1cx81VEXIAuOLQgXnNa4wAgZoibOqfs2g1Ve6hqcV7we3pZz6NsEfoHHv3KoB0ipyYVW0Q0e6ZXdf/Kzf484p2u7CvClMfMJuijfkthnrV4iI2vc4KDsA2ePqsiweCHSwk7Uw+MuNcJ1Ov txujEW/g LFWh+RSJIdP6b0hl5Z5e64GLD3QtvxyVsaTfBJyPRDdmKjFXh+c9gisrrMdCKyQHTz2D6XdbPiktUo+SSgK5gVnB9hNS/oGRNhLIdCHed9WpOe9h3akWFbslINh4iLGwqs8XAbf9JfOhUDz3zSmIlyHgowVF4vx/CyV+3UdvnqpLbqCIyN+j54S3tdJs0zmfB4hnjHEGRv5mPBHN5HsomAWR1P617d7d6K0IUP+2hRoCcETrzrK8UF94FtETwKw1CdpsIJg8G/cR53Or9jzjcdio6+z5BXiM7yyc730uW4zZIMWf5aQ5dnGdQPHBq+RuSZrKwcSOe4HDgTCW/7PNEox0tHtrc/WHwDddAMsEtOS6YQf9mFvJ412A0X64iUs8cScrZQCKac7LaSCg1oEMKMs+oZmeqCYT7LgsRvm1GvuhRSX10o4acxFgbzOOIbzLF8Y8/Onw+gkVBUGoGUHxtUp7VxGg5adPwEQCXP1W8lUCfrP1loiw3vWBciQ== 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. Signed-off-by: Christoph Hellwig Signed-off-by: Matthew Wilcox (Oracle) --- mm/page-writeback.c | 98 ++++++++++++++++++++++----------------------- 1 file changed, 49 insertions(+), 49 deletions(-) diff --git a/mm/page-writeback.c b/mm/page-writeback.c index 5a3df8665ff4f9..2087d16115710e 100644 --- a/mm/page-writeback.c +++ b/mm/page-writeback.c @@ -2460,6 +2460,7 @@ int write_cache_pages(struct address_space *mapping, void *data) { int error; + int i = 0; if (wbc->range_cyclic) { wbc->index = mapping->writeback_index; /* prev offset */ @@ -2477,67 +2478,66 @@ int write_cache_pages(struct address_space *mapping, folio_batch_init(&wbc->fbatch); wbc->err = 0; - while (wbc->index <= wbc->end) { - int i; - - writeback_get_batch(mapping, wbc); + for (;;) { + struct folio *folio; + unsigned long nr; + if (i == wbc->fbatch.nr) { + writeback_get_batch(mapping, wbc); + i = 0; + } if (wbc->fbatch.nr == 0) break; - for (i = 0; i < wbc->fbatch.nr; i++) { - struct folio *folio = wbc->fbatch.folios[i]; - unsigned long nr; + folio = wbc->fbatch.folios[i++]; - wbc->done_index = folio->index; + wbc->done_index = folio->index; - folio_lock(folio); - if (!should_writeback_folio(mapping, wbc, folio)) { - folio_unlock(folio); - continue; - } + folio_lock(folio); + if (!should_writeback_folio(mapping, wbc, folio)) { + folio_unlock(folio); + continue; + } - trace_wbc_writepage(wbc, inode_to_bdi(mapping->host)); - - error = writepage(folio, wbc, data); - nr = folio_nr_pages(folio); - 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) { - wbc->err = error; - wbc->done_index = folio->index + nr; - return writeback_finish(mapping, - wbc, true); - } - if (!wbc->err) - wbc->err = error; - } + trace_wbc_writepage(wbc, inode_to_bdi(mapping->host)); + error = writepage(folio, wbc, data); + nr = folio_nr_pages(folio); + if (unlikely(error)) { /* - * 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. + * 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. */ - wbc->nr_to_write -= nr; - if (wbc->nr_to_write <= 0 && - wbc->sync_mode == WB_SYNC_NONE) + if (error == AOP_WRITEPAGE_ACTIVATE) { + folio_unlock(folio); + error = 0; + } else if (wbc->sync_mode != WB_SYNC_ALL) { + wbc->err = error; + wbc->done_index = folio->index + nr; return writeback_finish(mapping, wbc, true); + } + if (!wbc->err) + wbc->err = error; } + + /* + * 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. + */ + wbc->nr_to_write -= nr; + if (wbc->nr_to_write <= 0 && + wbc->sync_mode == WB_SYNC_NONE) + return writeback_finish(mapping, wbc, true); } return writeback_finish(mapping, wbc, false); From patchwork Thu Dec 14 13:25:38 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christoph Hellwig X-Patchwork-Id: 13493058 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 21121C4332F for ; Thu, 14 Dec 2023 13:26:14 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id A9DC88D00B7; Thu, 14 Dec 2023 08:26:13 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id A4DE68D00B1; Thu, 14 Dec 2023 08:26:13 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 93E2C8D00B7; Thu, 14 Dec 2023 08:26:13 -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 84E838D00B1 for ; Thu, 14 Dec 2023 08:26:13 -0500 (EST) Received: from smtpin16.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay08.hostedemail.com (Postfix) with ESMTP id 59A13140CC1 for ; Thu, 14 Dec 2023 13:26:13 +0000 (UTC) X-FDA: 81565497426.16.F2CC833 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) by imf20.hostedemail.com (Postfix) with ESMTP id B39851C0025 for ; Thu, 14 Dec 2023 13:26:11 +0000 (UTC) Authentication-Results: imf20.hostedemail.com; dkim=pass header.d=infradead.org header.s=bombadil.20210309 header.b=uggU3y4f; spf=none (imf20.hostedemail.com: domain of BATV+55581d165dda9d0af87b+7417+infradead.org+hch@bombadil.srs.infradead.org has no SPF policy when checking 198.137.202.133) smtp.mailfrom=BATV+55581d165dda9d0af87b+7417+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=1702560371; 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=Ps3gOgcx63gp+vASNuJqnAAKIBRQ41EfNIZIAmlnf24=; b=kjTxLCTcdYADmdVsT9Z0i4M7ZWEUsHvFpLFt/dTctuK09i+8VoQfEqEfHiEjoWZi9tHKMI TAOk7hexaH/5G2uoqKGy4C/TveMpVr4H1q+ITETi+W+7o+TVjTo9YjI7lPvFz1ijP+JY6L mYsO7sm7fgQ06OfIMPUJY1CGt+3AGY4= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1702560371; a=rsa-sha256; cv=none; b=VygepA5XerntXNioJAG0FHhLo2DZzs3ufmmodGLBAoZWSRmrU+rv52/6hzdaDDFKYrZSrw +kSMUCXSVGDTXDBy+dc1h95FIYSrzvtAOAQh6C4wmmy+ef9yLp5OeHHI4GO960FQKj4Uh9 CSItwfA/8/r+SH3UwHH3LQ6CfuVRncg= ARC-Authentication-Results: i=1; imf20.hostedemail.com; dkim=pass header.d=infradead.org header.s=bombadil.20210309 header.b=uggU3y4f; spf=none (imf20.hostedemail.com: domain of BATV+55581d165dda9d0af87b+7417+infradead.org+hch@bombadil.srs.infradead.org has no SPF policy when checking 198.137.202.133) smtp.mailfrom=BATV+55581d165dda9d0af87b+7417+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=Ps3gOgcx63gp+vASNuJqnAAKIBRQ41EfNIZIAmlnf24=; b=uggU3y4fBWiCXTBEHx5MIrT6DE Rwcj/DmIWwKIJXJZeOj39Hyc3qKt59USXtl8gWutaJpmCNidyxQ6JdbypyM9+FdN5lrPD9KwEZBjC FtlmcDdPIF4tVCDzP5y7JZ2LDk7rSLCrikKAfcIYfGXtjjLDftVNDMAMYh3wVTSjui6YmnhR415rt DzXEuEmW7sWLCoskIiHHKwvEUXd/QnwxMxyfWuy0tLZ1Hs4+colIeuHyZBgighO8cIT+xOofAKBIy 3tz2gpPqZj0UbrFi7QCaaokGySo+SS+UDtxSseeUkYK0kUbMCXmiB2B8xFQ4KNF3jiZQp7HGwTomc xPV8yLiA==; Received: from [88.128.88.27] (helo=localhost) by bombadil.infradead.org with esmtpsa (Exim 4.96 #2 (Red Hat Linux)) id 1rDlj8-000N5b-1T; Thu, 14 Dec 2023 13:26:10 +0000 From: Christoph Hellwig To: linux-mm@kvack.org Cc: "Matthew Wilcox (Oracle)" , linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org, Jan Kara , David Howells Subject: [PATCH 05/11] pagevec: Add ability to iterate a queue Date: Thu, 14 Dec 2023 14:25:38 +0100 Message-Id: <20231214132544.376574-6-hch@lst.de> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20231214132544.376574-1-hch@lst.de> References: <20231214132544.376574-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: B39851C0025 X-Rspam-User: X-Rspamd-Server: rspam11 X-Stat-Signature: wabzcezcht3etbgh3mstdzsjpzfq1cq7 X-HE-Tag: 1702560371-277722 X-HE-Meta: U2FsdGVkX19JDAxOYtTE5fjVP/sjJLmognI+dFKU7fzF5UJWqkK5g97e0chti2WY76NsHWT0GsvWDSLGRb8eAKtu9jHMx8bfSTgHuaivLjnoxa1YeFx4wZYdYCnxBVDYH/TJnuPujhZZerQLYca9Sn9th6gpuXT/733PR3bZ5zOiorMimA9NxtndzGcW+vWpY387yh9VBHkM1LhRxu5ztk5HfUdL0J/kbEQojkHLJrmen1s6qdfCcc0QJ8FwFN4eJNxEr1U/SemP10FSDGBVwpfeSB5iPqERooexCBnqbiWfW1FUZNI0blfsQRspjHj8xUcf+mePmbjMhOvlQaiH2q26LBO9tiwyNbYNtmPSoWbhgJxUFlcv1Ln+K+QbpvQ2XuTy+2vo+oJIg0E9md2rOJAJJIIWhlOrzTL8zoJyOTfe9wA9fD4/gERMv8gSRNCBA3HeMKyo8VOxdOJSqJYX73WrAsoYHEHjZpvUwolPDkioIjzUFJQal9WfwP1P5O6jByDUoSwHz0nNMU69YjhEZkInn0JgjSoRb215gD2UuiZqtjY1jtVyTExbno2kqmz51uynjGEasW1ajUyjQEoptQfsHHJZJ91c3L0ld4B2ST1tTM8vU5haD4CKQKbwIEKUl/DutcOMuN5z+SWxEAT/tWIxg4AeCsHZAaOC88wYFFNhmqpp+E+7Kd5WquyVlfeodEDrqEs+WTahrU5sFB2LU5oDH5p3fgTvfT2yVdKEGwiQg17wNzzcq8pEIwj9UJtDO6QYDxoiRU0GhPsqNt7UogtWBPdAC/ZoOwgAn6nXQM86gFhhxrHAbe8kQAVjUFFHntYgZntIU2Y/gEOSG00WD/zGByrfChDyvXVpRtAhx1AV20I7X8KDM0yUD8rDTsS8FWhyD++ocdStELgB6rp409ZL+LGzey2pAU9X1AOOPlQZGV6FgbG/fCHWy9ZzlYpgWBs19q4STFcpDT9mYpG ymcrTJXc k9be8273OToJpOZWh8s5WTiLNvRFBxpSLw96nQJ8/z5mBwYKudnRMWzKCBY2hoJFs81HKZNDwGdUwRjBj+iReTth326I35Zfzc8aNdYVttk3D1diOj8ZQprZdIyjY4Va0W5PH5gkIEMNkoZg9RSseqDUdFW+cyh0+ngRQvcciz6cNzoiTecAfg1RLlyxgF49xyovdVFXSCJbpHVx1o2KNLbh7VMoY/UyPNpkivbna/3zkS6W+T1mIQ+PA4Gzkp+We0bsnaGypAsrjVQC9+8v6IOjHf3JF4vjS1bqYUbUFhsWp4aU78o4bPEwSuBCAFkHGDXFOdgh9YWf1SgeiBcwXvHPMLLsikqva8AzYo2EBVavHTO0Y+NW62//mBVeBfmvAWrdtHkH7VqLWkaZRCxw65dSu6xbS6jjoWauDC7tnd9SDcrXENRzh55sSPuGuyGdIG1VK 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 --- include/linux/pagevec.h | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/include/linux/pagevec.h b/include/linux/pagevec.h index 87cc678adc850b..fcc06c300a72c3 100644 --- a/include/linux/pagevec.h +++ b/include/linux/pagevec.h @@ -27,6 +27,7 @@ struct folio; */ struct folio_batch { unsigned char nr; + unsigned char i; bool percpu_pvec_drained; struct folio *folios[PAGEVEC_SIZE]; }; @@ -40,12 +41,14 @@ struct folio_batch { static inline void folio_batch_init(struct folio_batch *fbatch) { fbatch->nr = 0; + fbatch->i = 0; fbatch->percpu_pvec_drained = false; } static inline void folio_batch_reinit(struct folio_batch *fbatch) { fbatch->nr = 0; + fbatch->i = 0; } static inline unsigned int folio_batch_count(struct folio_batch *fbatch) @@ -75,6 +78,21 @@ static inline unsigned folio_batch_add(struct folio_batch *fbatch, return folio_batch_space(fbatch); } +/** + * folio_batch_next - Return the next folio to process. + * @fbatch: The folio batch being processed. + * + * Use this function to implement a queue of folios. + * + * Return: The next folio in the queue, or NULL if the queue is empty. + */ +static inline struct folio *folio_batch_next(struct folio_batch *fbatch) +{ + if (fbatch->i == fbatch->nr) + return NULL; + return fbatch->folios[fbatch->i++]; +} + void __folio_batch_release(struct folio_batch *pvec); static inline void folio_batch_release(struct folio_batch *fbatch) From patchwork Thu Dec 14 13:25:39 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christoph Hellwig X-Patchwork-Id: 13493126 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 3203BC4332F for ; Thu, 14 Dec 2023 14:22:50 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id A78EF6B06AF; Thu, 14 Dec 2023 09:22:49 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id A296B6B06B0; Thu, 14 Dec 2023 09:22:49 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 8F1E56B06B1; Thu, 14 Dec 2023 09:22:49 -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 7BBDC6B06AF for ; Thu, 14 Dec 2023 09:22:49 -0500 (EST) Received: from smtpin09.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay09.hostedemail.com (Postfix) with ESMTP id 4647880CA6 for ; Thu, 14 Dec 2023 14:22:49 +0000 (UTC) X-FDA: 81565640058.09.D4BB4FE Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) by imf01.hostedemail.com (Postfix) with ESMTP id 594EF4001D for ; Thu, 14 Dec 2023 14:22:46 +0000 (UTC) Authentication-Results: imf01.hostedemail.com; dkim=pass header.d=infradead.org header.s=bombadil.20210309 header.b=D9YSNoUn; dmarc=none; spf=none (imf01.hostedemail.com: domain of BATV+55581d165dda9d0af87b+7417+infradead.org+hch@bombadil.srs.infradead.org has no SPF policy when checking 198.137.202.133) smtp.mailfrom=BATV+55581d165dda9d0af87b+7417+infradead.org+hch@bombadil.srs.infradead.org ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1702563767; a=rsa-sha256; cv=none; b=NM9Nu3LXh0E7KlIFX+tU66FL+pVya330ly1Og1QpCvyXT7YcqUDvTFJd4Bnd1GpNxipcNg WWwi/lOKHRpUOBIciUYCyPF8EuRcgO6uXFVXKif7S54iBj4mpX4yuN5tP09mqR9uwCCzpq tp7SzHCaoRcFyYrlJ61/ZOaf492j0Q8= ARC-Authentication-Results: i=1; imf01.hostedemail.com; dkim=pass header.d=infradead.org header.s=bombadil.20210309 header.b=D9YSNoUn; dmarc=none; spf=none (imf01.hostedemail.com: domain of BATV+55581d165dda9d0af87b+7417+infradead.org+hch@bombadil.srs.infradead.org has no SPF policy when checking 198.137.202.133) smtp.mailfrom=BATV+55581d165dda9d0af87b+7417+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=1702563767; 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=MxYyShLiRKm/b2kgWMNr7J68lt6H7F1PYCAdmGQu21k=; b=WIhl1fyGcPoioMxfk7W7GZJ3eTszreLo4SZ8LWXXiQKrtg3quKSBu+yvYDvc55pVwDULNV luDWQ+2Ba30I1KnWNUx6sirlEWF4wP8rQaunnUFsY9UhKd0c4Spxxgj6ZYDJ96ako2eQQ/ 029VU9OcIBPJ4Aay7oWzsJad+u+JDNA= 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=MxYyShLiRKm/b2kgWMNr7J68lt6H7F1PYCAdmGQu21k=; b=D9YSNoUndTNHZOJBIIstgZm299 fqPapOf+sTH1GXW0IqUNd0YqzZtYfAXncK2PeCKGRRHmhuG09goKRpeMQWwnoW7FXknQOalV4l2fH uMjwqwUUmCi3br7beZe20CmuYsuPnXaM6VvFGr0zv6SNQZqvI5wZ9sv1+odmLUM63q3Fu85vAG2gf s/8DG9HAvLdUTA+2GNHp/WSl9Y/MqL5YMQytvl73whfVH0xPfqs91rWMXyaWVagm/AxS13FvHlweg mjFa5QkB005ny4hVt62BETy702qH2PMBV67OIuknvVwncXTerzZRoIe+aF+KZ8szfS1i+JuPt8KvI m8mTW8UA==; Received: from [88.128.88.27] (helo=localhost) by bombadil.infradead.org with esmtpsa (Exim 4.96 #2 (Red Hat Linux)) id 1rDljB-000N7L-0i; Thu, 14 Dec 2023 13:26:14 +0000 From: Christoph Hellwig To: linux-mm@kvack.org Cc: "Matthew Wilcox (Oracle)" , linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org, Jan Kara , David Howells Subject: [PATCH 06/11] writeback: Use the folio_batch queue iterator Date: Thu, 14 Dec 2023 14:25:39 +0100 Message-Id: <20231214132544.376574-7-hch@lst.de> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20231214132544.376574-1-hch@lst.de> References: <20231214132544.376574-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: 594EF4001D X-Stat-Signature: 41fbamnbpwf7kok49sof4qmd9gag5tey X-HE-Tag: 1702563766-752141 X-HE-Meta: U2FsdGVkX1+AjZ8IBdJjsEtSB26chofMmFgx156eNQkyEwPslnC0qtwCB75xiS3gcR0p3NbFf0wB9ty2l0EDenM2neRZAomfW3EqlmlUJTcCc0BQTxoVsQd9xxAGsWEKEhe5NkI+ljGejgt22ARJbnvqTQ82G0KXEddnYnKHoEC0ttfMPxWUrkuTX96dYDxbVqI11FevYW1tVh27l7qV4D7bMnTIhEbrXBNG0mQ8axPV6hGY2HmUobq1ZwWAHoFq0RBM+H4hTyzJok3ClkvbgP2nEsVJBYoMO7zfU5CkayDT4MCMUwrXm+2dk0KU5geI8dysmWbvpcxVvI+ZuvaFX36BwYZLiGGQZL79mQCmVJ6GiHcT+WFMFIkOw2H5ydTj5S8k8FUl739l7BeBCcPyvs6lkpg7I98Nm8SR23LNw1SLCXZTdsGyqM1x3rfxpYPB94z1qkwuNdY94Pl9p1cPAh9UvpnBkUcuZzTJHa+5PoCtaukaDc/VGD4cQN+QNnQW/ItaMsEy+x45mdbPW8Id626lvI3tm0drinmGpELtT0u8o2ubojOp2m6kbVMGC8gLllK1SXwAhUXXzeA1hCfNCC8J85lwWrESrqPQGTf6UADSt5CTkxtRCRbI3fcFOYI+KQqEcblRjloPmvuJ/QCHKtLxcubD6rwrsaiJ1mzIX44WgX1B+1HKTCqQKySKz0hH3PBMq9Ex1jsFjWgXT2pZn2zdFr7dZgPYARu6uet2mUxsIZy4Ja4HqxCtMMYFJrgS64nEUipJJ6LWlQ8ANWObZXyYouAyH/PEjKDKSkrJTa4SosoG7cCOcP9AIC5nDE7kIPNnr0Mwf6Wm+VepUQckMI1RJhK26FqbBTMcYxgDUjNxABvF6BpHS2P2xugiN6YWPITOdZOBKgisdMP20OcHB29TzwD85esJb8a89z2WYQfaB4AnMWXRhJiVKp+54fgbLs5CKRVRWsabukK2H7k X7SOMDZY Nr3+XmntTc04ncTloF5u/q56gmcpg7JhtqTssKXNQeQwxYRG6dHBAHnXcBR+1aEAaqVRkiugxauqiK/IUqlNK2yjS9WUU+5SmgWhVFJyQGk2e6K92qIiPeQSFLYnN1kYCda/kgDOTLncPqhDllmRXZqkhLsiDXT02JS115PnauHPvYprXHZcnP7g2pvT2YYNOdKZWk84dEl5nlaPgo5x/y/nmq3G+y77TGxrhjzA9QcftYEq1TwySGz/qHdUmQG4JZAC5hJWAMFxk++dinl71HQFIaidL7FLLb25R8FvWXZBMflm1aO7xPyqIViUotW7oVDfXISH8jNW5pyuhc0Ag49ib0X9HLTBMWzi6H4o1SIjd3oyf3Uw54bes8QkDdxBaPk7nYf5ilJzIg/SXMlJfewrzx7VyUlxn3ipQ0QIvVKfracC9F2kGGR0EPMnThl+WVU3BluuDSUigq9ZoVeh6NxfTDubhTNjwb2KIU0OYNCgAuQ1xXx4lZilc1w== 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 --- mm/page-writeback.c | 18 ++++++++---------- 1 file changed, 8 insertions(+), 10 deletions(-) diff --git a/mm/page-writeback.c b/mm/page-writeback.c index 2087d16115710e..2243a0d1b2d3c7 100644 --- a/mm/page-writeback.c +++ b/mm/page-writeback.c @@ -2378,11 +2378,15 @@ static int writeback_finish(struct address_space *mapping, return wbc->err; } -static void writeback_get_batch(struct address_space *mapping, +static struct folio *writeback_get_next(struct address_space *mapping, struct writeback_control *wbc) { + struct folio *folio = folio_batch_next(&wbc->fbatch); xa_mark_t tag; + if (folio) + return folio; + if (wbc->sync_mode == WB_SYNC_ALL || wbc->tagged_writepages) tag = PAGECACHE_TAG_TOWRITE; else @@ -2392,6 +2396,7 @@ static void writeback_get_batch(struct address_space *mapping, cond_resched(); filemap_get_folios_tag(mapping, &wbc->index, wbc->end, tag, &wbc->fbatch); + return folio_batch_next(&wbc->fbatch); } static bool should_writeback_folio(struct address_space *mapping, @@ -2460,7 +2465,6 @@ int write_cache_pages(struct address_space *mapping, void *data) { int error; - int i = 0; if (wbc->range_cyclic) { wbc->index = mapping->writeback_index; /* prev offset */ @@ -2479,18 +2483,12 @@ int write_cache_pages(struct address_space *mapping, wbc->err = 0; for (;;) { - struct folio *folio; + struct folio *folio = writeback_get_next(mapping, wbc); unsigned long nr; - if (i == wbc->fbatch.nr) { - writeback_get_batch(mapping, wbc); - i = 0; - } - if (wbc->fbatch.nr == 0) + if (!folio) break; - folio = wbc->fbatch.folios[i++]; - wbc->done_index = folio->index; folio_lock(folio); From patchwork Thu Dec 14 13:25:40 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christoph Hellwig X-Patchwork-Id: 13493160 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 AC3A0C4332F for ; Thu, 14 Dec 2023 14:54:13 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id DC4828D00B1; Thu, 14 Dec 2023 09:54:12 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id D4C458D00C7; Thu, 14 Dec 2023 09:54:12 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id B525B8D00B1; Thu, 14 Dec 2023 09:54:12 -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 91A8F6B051C for ; Thu, 14 Dec 2023 09:54:12 -0500 (EST) Received: from smtpin18.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay08.hostedemail.com (Postfix) with ESMTP id 464E5140CFC for ; Thu, 14 Dec 2023 14:54:12 +0000 (UTC) X-FDA: 81565719144.18.6BF7E17 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) by imf29.hostedemail.com (Postfix) with ESMTP id 63765120017 for ; Thu, 14 Dec 2023 14:54:09 +0000 (UTC) Authentication-Results: imf29.hostedemail.com; dkim=pass header.d=infradead.org header.s=bombadil.20210309 header.b="SFp/hA0f"; spf=none (imf29.hostedemail.com: domain of BATV+55581d165dda9d0af87b+7417+infradead.org+hch@bombadil.srs.infradead.org has no SPF policy when checking 198.137.202.133) smtp.mailfrom=BATV+55581d165dda9d0af87b+7417+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=1702565650; 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=Rss8E0TEJ5ZWP+w65Q90ToBr5MzQatBIEX9ecM3F1aY=; b=ZUqZlwoNCrvSRhL4aKWoQNXrgSAtDJNHeO5pVDbAFlfUp0aMvae0uB8OaUildgl/n7D+vn BYIxCOaqawEzBy1Q4ryV30I9jLf6sUzIiz5CB08I5GBA74m87qqJqj06E7msiEUpqWrbLt MRY0ItTQc7IaVgsNbkxt6DMv3zNs1tc= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1702565650; a=rsa-sha256; cv=none; b=GX6lnArhhEpuSVW6c8BQJW3D92qz+Mp7Bj2+OZ7eZfxmhaF7EN5pnalNoLok0GxDr6hGYY 8diiq7RTQ+rRfwe4tyYkt5dxpd1XAiaXlHQCd1Blye9Df21Ln87daBlZbIFRqrg7rEEjDi 2ss4CIrmrn3TAIRVOBmerUuP3Z/C7+0= ARC-Authentication-Results: i=1; imf29.hostedemail.com; dkim=pass header.d=infradead.org header.s=bombadil.20210309 header.b="SFp/hA0f"; spf=none (imf29.hostedemail.com: domain of BATV+55581d165dda9d0af87b+7417+infradead.org+hch@bombadil.srs.infradead.org has no SPF policy when checking 198.137.202.133) smtp.mailfrom=BATV+55581d165dda9d0af87b+7417+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=Rss8E0TEJ5ZWP+w65Q90ToBr5MzQatBIEX9ecM3F1aY=; b=SFp/hA0fghmYHxPZK8RDs0mSUs 2dvs2+f6lfbzUR4ZepQ8+lOvHkqOAptEtwte/LyANyBKUX+HZd6mcog/IExGHXKJfcdRoQzhSEDVK 9gl9L8NnOfFLsnDEvkTsvZZbvnfcHT60084SRlecI7C6UAQf90dwmCWmioA0g1syVyRezuHE2J+eF 21bWWbXPoewfgvDtZgt262UOaoMZWqrFo31EMV17CZ/D0kysdzJ+M4j1lDjO8XJ42vlch6Vq549hE 9UltZjPeJfE+jhxELs1O90Wb3pPSZRv3o+5Fg2ZUJ9i5WA/JSVcNZOnJTj+4nH5Fs+BxSmPDf0wae I2w0fc9g==; Received: from [88.128.88.27] (helo=localhost) by bombadil.infradead.org with esmtpsa (Exim 4.96 #2 (Red Hat Linux)) id 1rDljF-000N9J-2g; Thu, 14 Dec 2023 13:26:18 +0000 From: Christoph Hellwig To: linux-mm@kvack.org Cc: "Matthew Wilcox (Oracle)" , linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org, Jan Kara , David Howells Subject: [PATCH 07/11] writeback: Factor writeback_iter_init() out of write_cache_pages() Date: Thu, 14 Dec 2023 14:25:40 +0100 Message-Id: <20231214132544.376574-8-hch@lst.de> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20231214132544.376574-1-hch@lst.de> References: <20231214132544.376574-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: haiykttahwm6sng3p1qfesmjg7h8j5ce X-Rspamd-Server: rspam10 X-Rspamd-Queue-Id: 63765120017 X-Rspam-User: X-HE-Tag: 1702565649-535965 X-HE-Meta: U2FsdGVkX19ZguZmEO7PWoD5rbZ/WBogkWceWnNVkEtTN5gd/baK4Ka/zCA4QtXDIySq1XLji81JV+gD6vp/shEXt762z7xkUvvkohtwSOCssgOR63bBssKHnvlx0p6qJ44+QhAohNqMaGkUe80uWa6SgWx8BYxQCzFzm77sMwnO5w3aow7vGt82MmO982W+liddc4j+wCF78AUxCHCv8lNZSYruDMXYWJTGsiUuHPAkVsBZguxZRjAuvbGSIzyPzHS4yZryP4YaomrMjAZ22aPLtHvqxribwhkyNtlDY4/BD1kscPuuWGOY+WDH0M86RwSVXw/1m0bXslnahfCxoXAB9WYhPqxXmV226Z53oNSjHhQ3hmu8+8HyyYbbjJupqs+C2KtukB8ST+pKyJpNaujRwU/G2PkL9xsSmadlj/Wjc6qJ+4ruiq+hUsGzjvP6t1+zTLOb8QR87zvBU3Z14rqkQA34LPwGKasdRawxk0dxNOzmO2MGXJ4SSle/2JeaIqoLYXsEG5tmQ7WTg7r0Q3x0ZF8sTniZwIjNPk37ZuLBv35KejEJ7A3ogX4NoXuw/kxqkf4KARpZYQH6+n/TEbZNbv2oqL/t6tPZ0s+026BvPIiqMDYIMWTNKymTb953Rh+3gRZ2LwgDS6PloB7P1YJjv6GyfR+/yInxq+M2gVOD9UGbM6+Alj5ByIBIqIlrHtp4DF01NToddSy4zB87RcXb56Ea3eSES0ZskGFg4zN3m336P/GPtPRlz6H77dOomemEZr77i4F+qRgxk4SZVFP9L9jvHvAbnAtAytDAM7MSaUiTp1zx8Q/RbHB33pLH8sMrxf0HZwpezA61QND8mhJYJ5A3mh5ScUUm54VJnGCQmEaqjcAAfW/ZTL9XUn7Pd3pm1fVF9bqauRjyL35NjgutnTpl1GV6EEzAvYRoDVSBZvdquF487SUqMgduAWSfCvU+4xa6ZFC+DhmfFc1 +rSXv0A5 QWrmAlZDC/nJvKJICG8SRY9I6E6t1P7U1xGUeI3/FzyNT746Z6Iwp2la5Vt6UNjSeDyQ10d3EB579SnEEPqSMcOAyRQEn3CKhyjPVcSX6bqGeDt9UX31kTE+e0gczd1ZwYDvcyy1Q1wRh6AWcFsexcqd7wczDuj6ugsDuoGwzMZQuHs67n4FGykA3pKigmrgXFOegKp6uDu4o92KVGXRzLwDP4f3xafgCHC2nR3trSExKbhZEqVcHTrPuTZloBMg8/ch6roKTXz8bIAPyv0W6TarDtINmtHa7SpM2drJeOs1vc29ehzRcBu3gJChPflcIEIy/M9Gf8me3hTb+FtbAgE/kG8zrRdeW3lKV/I6zQOUaVGoG7idRxXS2OrvuPxg4cgujx1RHKM4rZm2fXZjkLeimxXM/+MgMoUib/R8gIkaO/OuSVdjqyBN6tHKtcRDBRzWJPkxeK/I4VCwCuNkI6NLvtS7yZFGblaiUaWzcOU+sNpGsuNq7gyVDZg== 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)" Make it return the first folio in the batch so that we can use it in a typical for() pattern. Signed-off-by: Matthew Wilcox (Oracle) Signed-off-by: Christoph Hellwig --- mm/page-writeback.c | 47 +++++++++++++++++++++++++-------------------- 1 file changed, 26 insertions(+), 21 deletions(-) diff --git a/mm/page-writeback.c b/mm/page-writeback.c index 2243a0d1b2d3c7..8c220c6a7f824d 100644 --- a/mm/page-writeback.c +++ b/mm/page-writeback.c @@ -2429,6 +2429,28 @@ static bool should_writeback_folio(struct address_space *mapping, return true; } +static struct folio *writeback_iter_init(struct address_space *mapping, + struct writeback_control *wbc) +{ + if (wbc->range_cyclic) { + wbc->index = mapping->writeback_index; /* prev offset */ + wbc->end = -1; + } else { + wbc->index = wbc->range_start >> PAGE_SHIFT; + wbc->end = wbc->range_end >> PAGE_SHIFT; + if (wbc->range_start == 0 && wbc->range_end == LLONG_MAX) + wbc->range_whole = 1; + } + if (wbc->sync_mode == WB_SYNC_ALL || wbc->tagged_writepages) + tag_pages_for_writeback(mapping, wbc->index, wbc->end); + + wbc->done_index = wbc->index; + folio_batch_init(&wbc->fbatch); + wbc->err = 0; + + return writeback_get_next(mapping, wbc); +} + /** * write_cache_pages - walk the list of dirty pages of the given address space and write all of them. * @mapping: address space structure to write @@ -2464,31 +2486,14 @@ int write_cache_pages(struct address_space *mapping, struct writeback_control *wbc, writepage_t writepage, void *data) { + struct folio *folio; int error; - if (wbc->range_cyclic) { - wbc->index = mapping->writeback_index; /* prev offset */ - wbc->end = -1; - } else { - wbc->index = wbc->range_start >> PAGE_SHIFT; - wbc->end = wbc->range_end >> PAGE_SHIFT; - if (wbc->range_start == 0 && wbc->range_end == LLONG_MAX) - wbc->range_whole = 1; - } - if (wbc->sync_mode == WB_SYNC_ALL || wbc->tagged_writepages) - tag_pages_for_writeback(mapping, wbc->index, wbc->end); - - wbc->done_index = wbc->index; - folio_batch_init(&wbc->fbatch); - wbc->err = 0; - - for (;;) { - struct folio *folio = writeback_get_next(mapping, wbc); + for (folio = writeback_iter_init(mapping, wbc); + folio; + folio = writeback_get_next(mapping, wbc)) { unsigned long nr; - if (!folio) - break; - wbc->done_index = folio->index; folio_lock(folio); From patchwork Thu Dec 14 13:25:41 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christoph Hellwig X-Patchwork-Id: 13493104 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 E4AB8C4332F for ; Thu, 14 Dec 2023 13:55:31 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 55D0F8D00C0; Thu, 14 Dec 2023 08:55:31 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 50CAA8D00B1; Thu, 14 Dec 2023 08:55:31 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 3D3CB8D00C0; Thu, 14 Dec 2023 08:55:31 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0015.hostedemail.com [216.40.44.15]) by kanga.kvack.org (Postfix) with ESMTP id 2C6C68D00B1 for ; Thu, 14 Dec 2023 08:55:31 -0500 (EST) Received: from smtpin18.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay06.hostedemail.com (Postfix) with ESMTP id F2390A15D0 for ; Thu, 14 Dec 2023 13:55:30 +0000 (UTC) X-FDA: 81565571220.18.AB6FF49 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) by imf30.hostedemail.com (Postfix) with ESMTP id 3B78C80017 for ; Thu, 14 Dec 2023 13:55:28 +0000 (UTC) Authentication-Results: imf30.hostedemail.com; dkim=pass header.d=infradead.org header.s=bombadil.20210309 header.b=fYKo14Qx; spf=none (imf30.hostedemail.com: domain of BATV+55581d165dda9d0af87b+7417+infradead.org+hch@bombadil.srs.infradead.org has no SPF policy when checking 198.137.202.133) smtp.mailfrom=BATV+55581d165dda9d0af87b+7417+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=1702562129; 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=kAPP6X55X6rvLdfMOtbLbsXeMDzuMOl2croRJo78UX4=; b=44gskunlsKuuG0/Peja9g/m2K+BSQpUfMc+d3czgwTihHJHBCzUCWcSYlEvcoQc1eG3oSZ XFNn17Cvr/8YFC+JSHJhUo+tz+BiOrbShGfRqxV8ztya2NvdV1zmW3nQPnYOOWuq9Amtbr AxE9aT1MZKwzOCPy7Z05JLCxV+UT6XY= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1702562129; a=rsa-sha256; cv=none; b=WjjhsGNxnU1Vd/QEvXfkdEQvlARwD0hjav/wpaIoYJIWUfFDUhxZ2aOdoo532MlvpRvFgb woaw96d4BkHZJDoYQwYuzXrXM+DqTs3PkL3BpygsoQhMjbqyA6QofvqOBwknxmEmM84Bf/ R0Vw9KkHlUyxim30b7/mAbXgQK06j28= ARC-Authentication-Results: i=1; imf30.hostedemail.com; dkim=pass header.d=infradead.org header.s=bombadil.20210309 header.b=fYKo14Qx; spf=none (imf30.hostedemail.com: domain of BATV+55581d165dda9d0af87b+7417+infradead.org+hch@bombadil.srs.infradead.org has no SPF policy when checking 198.137.202.133) smtp.mailfrom=BATV+55581d165dda9d0af87b+7417+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=kAPP6X55X6rvLdfMOtbLbsXeMDzuMOl2croRJo78UX4=; b=fYKo14QxQKLG96JxNh2gKkqwXa wsvp3uUwGV/Pnm6RVQ/FkMXvsez7eoeecA/pnOwd1vlL/3q7t/raPaZZEcb8RfyZEmpowiZMPLews ppeYWW2XD2womPwLiqiyZobEmdUTrc9J1baAEJ+PnEaO9wafX1ux6yu8ZSaE3ttElyNcNu5l7JyZ6 aE1PvkMIS0bXSJEWwBte6poJSIKKE0+N5v2kwDU42DTmDcVmeNJCjolZuPnbW6cySjI5L2MIe9N7t 820nBKAWHp+TfTTmFYqUoodssCijbcLm2oCZalIcEf11h3nd3Ltie7vsrHAttdJKjAc5duP5q0ioq LbAP1U3Q==; Received: from [88.128.88.27] (helo=localhost) by bombadil.infradead.org with esmtpsa (Exim 4.96 #2 (Red Hat Linux)) id 1rDljI-000NBD-36; Thu, 14 Dec 2023 13:26:21 +0000 From: Christoph Hellwig To: linux-mm@kvack.org Cc: "Matthew Wilcox (Oracle)" , linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org, Jan Kara , David Howells Subject: [PATCH 08/11] writeback: Factor writeback_get_folio() out of write_cache_pages() Date: Thu, 14 Dec 2023 14:25:41 +0100 Message-Id: <20231214132544.376574-9-hch@lst.de> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20231214132544.376574-1-hch@lst.de> References: <20231214132544.376574-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: 3B78C80017 X-Rspam-User: X-Rspamd-Server: rspam11 X-Stat-Signature: poyp1m4au9s5zaht4ur19xyx8u167tz1 X-HE-Tag: 1702562128-942979 X-HE-Meta: U2FsdGVkX19nTOV4s/ycVk8qD9wrC0i23Kpne3CojIL/lqeRDOjBgF16DSwVZcrXhyTu15pLDZKIKVNH145EKNbvkHutBL3JDAGaXsAHfYMTVoTy9TfYhagd7FckaWI9t4UZ/srI8O/OB7vrwoj4VWrQuxldF47li2CzCTFuKfCLhwpZQxdcsE1Le8FM5Xqn1O/f2BwFhYKd/QhWCB5Ri7rG7xSlDoQTr730WveBnLahsG0EY8lx2RuzccImDFwNxxEmTXCvXTovaA4fIdrU45fVA5XoFqie94jf3RJJkKF3BK5bIqqtleL3Ak+aYHrowzHLrjdjbcFESCoyHR5Mhw0MW+KCLwGdkZ7Mmt+bUvFvSQKRFAPcNdgYfuHqoZOfRoy4MXllZDcGUPnMDz/s0/PUdJFWAOxCYdN67tOxJ6Gc+GQeAvOkY68h9wqVZIcIJ/A7AWL/BoH7q+8B9k6SFfxCl/hpGAZpCjC5rk9mS0sT+876UQ0D8V39uPWHPwwNURvPMm4RoX6PT1saKJLVS65z2brAYBXkNpiXK0mo2m4FNPKcbVGHF/UoIMew8Yl8Wxbz1PYgPS8tz3TWhYsU6PE7k0idXe6JfFMwty0qZnmSFd/I1eSBu0kHUcW5AFFXReFxdu9AyLf/SGixAoyqroofRhOiSUNytp2Bl+R/OOhuAg/fuebOvh7QLPzEpyyNLQacq9bJ2F89eXWrWAsWwcOcxQmAhd2EJQMvU1aLbanlBPWiutQQkv5PSLfgM4DTB7j5QHwhgFQnVxBGhipZi9sLs+HSclhXxi3oRtZkSCUlpqWPisuWt+7yAncfI/1/QGg1IasxMfMVtyy/lJACtez5k28sm+ws1FlhEg5rIeixTVTT6A+cqpleawMipA3VWuTJlVLIGKZnDsd9fQJUm3H6IPsTZLlopWA36J7oIvQiwe9UGd9onChrDNcgtwSn0AaGZib9a1vYhFAwkkH u4je0Qq+ 6rLhHr5PBffWIc80vJHtj3YOs7GiigM3RV0j95Ah4YGyUuqqYGa5zpLybJWMomokEL4kmylqKqLVZlZ9P0tq9S908e+MmdXR00oXS2Eb0HrdAhQ3mV6o2TBc0NqExD2x/X0u+rWNWJG6ih682wx4TOkRuINrRh4OXL2wOy8a20SiTedagnxfDfSyWY2BgB393tbPeRQ1uPwufBGL75YsR9TDOGnXecc3h3e04SXCwvmuOqjqwaIKiKrziJyWTfAnl/4wiK6lsBDXZO184rpg3gUr9aZX77YA8povv3zhsPgBsUBM4qisGrW6gMrcRvHdOG0GdGyiccjAt4ESYklI8ucs/Qyf8Fs6dNy3UiwVq7PSyvMWAba/Nc+0/sgF7Lv5El+eKuUfzmtzTvPn3xtxG4NajnJ+9q3qxewOxSVbexqhO+bdIpJocxu3VJN6EJdgMYzv0HeLxlib1RmI7YxKAOZw1l7LhmTOPazKCPKaVMt2JGJD60J1WmRMr0A== 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 its own function. Signed-off-by: Matthew Wilcox (Oracle) Signed-off-by: Christoph Hellwig --- mm/page-writeback.c | 35 +++++++++++++++++++++++------------ 1 file changed, 23 insertions(+), 12 deletions(-) diff --git a/mm/page-writeback.c b/mm/page-writeback.c index 8c220c6a7f824d..b0accca1f4bfa7 100644 --- a/mm/page-writeback.c +++ b/mm/page-writeback.c @@ -2429,6 +2429,27 @@ static bool should_writeback_folio(struct address_space *mapping, return true; } +static struct folio *writeback_get_folio(struct address_space *mapping, + struct writeback_control *wbc) +{ + struct folio *folio; + + for (;;) { + folio = writeback_get_next(mapping, wbc); + if (!folio) + return NULL; + wbc->done_index = folio->index; + + folio_lock(folio); + if (likely(should_writeback_folio(mapping, wbc, folio))) + break; + folio_unlock(folio); + } + + trace_wbc_writepage(wbc, inode_to_bdi(mapping->host)); + return folio; +} + static struct folio *writeback_iter_init(struct address_space *mapping, struct writeback_control *wbc) { @@ -2448,7 +2469,7 @@ static struct folio *writeback_iter_init(struct address_space *mapping, folio_batch_init(&wbc->fbatch); wbc->err = 0; - return writeback_get_next(mapping, wbc); + return writeback_get_folio(mapping, wbc); } /** @@ -2491,19 +2512,9 @@ int write_cache_pages(struct address_space *mapping, for (folio = writeback_iter_init(mapping, wbc); folio; - folio = writeback_get_next(mapping, wbc)) { + folio = writeback_get_folio(mapping, wbc)) { unsigned long nr; - wbc->done_index = folio->index; - - folio_lock(folio); - if (!should_writeback_folio(mapping, wbc, folio)) { - folio_unlock(folio); - continue; - } - - trace_wbc_writepage(wbc, inode_to_bdi(mapping->host)); - error = writepage(folio, wbc, data); nr = folio_nr_pages(folio); if (unlikely(error)) { From patchwork Thu Dec 14 13:25:42 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christoph Hellwig X-Patchwork-Id: 13493131 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 C8827C4332F for ; Thu, 14 Dec 2023 14:24:48 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 636A96B014B; Thu, 14 Dec 2023 09:24:48 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 5E4706B014D; Thu, 14 Dec 2023 09:24:48 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 4AD0A6B014E; Thu, 14 Dec 2023 09:24:48 -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 3679A6B014B for ; Thu, 14 Dec 2023 09:24:48 -0500 (EST) Received: from smtpin01.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay02.hostedemail.com (Postfix) with ESMTP id F0A53120BC2 for ; Thu, 14 Dec 2023 14:24:47 +0000 (UTC) X-FDA: 81565645014.01.E911EB6 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) by imf13.hostedemail.com (Postfix) with ESMTP id 4919A20013 for ; Thu, 14 Dec 2023 14:24:46 +0000 (UTC) Authentication-Results: imf13.hostedemail.com; dkim=pass header.d=infradead.org header.s=bombadil.20210309 header.b=D7Kg0BZm; dmarc=none; spf=none (imf13.hostedemail.com: domain of BATV+55581d165dda9d0af87b+7417+infradead.org+hch@bombadil.srs.infradead.org has no SPF policy when checking 198.137.202.133) smtp.mailfrom=BATV+55581d165dda9d0af87b+7417+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=1702563886; 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=rO9jeRnP/+STXFpOLNVshKgFr5PxJQ0M9NIzpjYwpKk=; b=iG7bkR3VdSqJ/R6bxxma/j2ki8guGqfA/qtdbU4vfFve3WfZTYMI7hklWhA6UvyPuuA3BR WlXgtYbghGp89gkjeYrV35lzWA4uFt60Rv9+UQwiqzID4ViA5OKU60ySbK9XZV/RXeX7tT dAnwkxZaNGVuoORhfbsHTaD/QDo8qi0= ARC-Authentication-Results: i=1; imf13.hostedemail.com; dkim=pass header.d=infradead.org header.s=bombadil.20210309 header.b=D7Kg0BZm; dmarc=none; spf=none (imf13.hostedemail.com: domain of BATV+55581d165dda9d0af87b+7417+infradead.org+hch@bombadil.srs.infradead.org has no SPF policy when checking 198.137.202.133) smtp.mailfrom=BATV+55581d165dda9d0af87b+7417+infradead.org+hch@bombadil.srs.infradead.org ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1702563886; a=rsa-sha256; cv=none; b=dD9GHzw1fKjnYh2Y9ApUT+ky+osFvcHGILM9gXdOHEsXK3p3/ybNwJ71otOR8bLp3xXXut z1Pci7Q8+No/DLj7dNyykuP1xvSb6WKSx7kD3UfOa0xA1XDtzrjFrFwHzwbCnaQYUdZ8ge MQh8BjnCam/ECr2J+exQgX50QTqoQWc= 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=rO9jeRnP/+STXFpOLNVshKgFr5PxJQ0M9NIzpjYwpKk=; b=D7Kg0BZmQc0TuV5ZDIwkGWmB/U Zo/YYkysOcmLOYlozdFyDhxa/ft5aO9Cpo/k651xsSCKrfdaDuLo44vbjtNNrh2wJQ9+cchXfBLuq 52wt6O1lBjWPFKacUOOT0H6TFOCL9zAmeCIUotwrsb6M0Ls/iKQoZdgpswJlT/0ecl/g6lqqJ1eTD GBt+L35/mOQ6ziE4gdB/7Px8A2gzSuvP4JaXARqb3q50wAVbCEFXdR0tscS9tuCrax0JCmgiAdGRp WH627gbw6OvYJO1pQ4KXk9boZ03t3PQWs9UTlHu/z27Y8n4kE/5UKpUwziRa5Zf4TxcquJiO/5XKV BTZpC1JA==; Received: from [88.128.88.27] (helo=localhost) by bombadil.infradead.org with esmtpsa (Exim 4.96 #2 (Red Hat Linux)) id 1rDljM-000NCz-2K; Thu, 14 Dec 2023 13:26:25 +0000 From: Christoph Hellwig To: linux-mm@kvack.org Cc: "Matthew Wilcox (Oracle)" , linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org, Jan Kara , David Howells Subject: [PATCH 09/11] writeback: Factor writeback_iter_next() out of write_cache_pages() Date: Thu, 14 Dec 2023 14:25:42 +0100 Message-Id: <20231214132544.376574-10-hch@lst.de> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20231214132544.376574-1-hch@lst.de> References: <20231214132544.376574-1-hch@lst.de> MIME-Version: 1.0 X-SRS-Rewrite: SMTP reverse-path rewritten from by bombadil.infradead.org. See http://www.infradead.org/rpr.html X-Rspamd-Server: rspam09 X-Rspamd-Queue-Id: 4919A20013 X-Stat-Signature: rr4gxxmjp6zpegnxynkijgfey9ddhbne X-Rspam-User: X-HE-Tag: 1702563886-620077 X-HE-Meta: U2FsdGVkX19fEmDGuC8KUkrmUdCSpj7VAyKAJGHZy5yjVGGifeREuDPO7mKPUfLW3UBTGLtMx1bKFzRNpoO2+3kQEwCuwXldtnL/cD4dzCDkDSIz6TMiMQuwwI+3CIoT8PtwbalZeRchMjeZuOTQjhxsuv0BAaU7jWd0IlPN4u7SioP5tQicvB+0+3MvlqZceGYKVE3CHyVZVPHzRNPTHcAZpbx9jXahrrGRfHYrnle/Jw790L6dhSsabPUDuTHFe0VhowkH9nYDdw7ga/uyAINhDa48iV8PnA8JIiDtDRtFw0fb7NDiRsErgZHXj8Gm47ep+o5HVrc2zfUW2R1LwixN/OW9FO54HkBG4qD8yHAplNyWvBcZOZdspecZDGLl3tR562jXqoYhL0JAz5fYj3fv+t9WzJEC9K2+kvDgvKTA9IxfnQilz5zUVfKwiHujQzHfj1PNz3Rd8Djoxw/E0QaorT94+9sXv/Zlh+dm7bLnW0XldFh1bZoaPBlwafl/5KJNeThAGjLJiFLAF7tPVjhdjbYaEOHNwsrlksedVw9Mb6stxJDZRQo2Osy3YS2SiJX0gGh1wQNUE61CPr7EKLGy80vU8dOhuk4H2CTHlOzsJbxJfU/jCbKCvW6AUfiSN6QO0DJQP6ebFBwYmxezls/KTbYXudvwOJGQGu9KlPxUhHWYo44bs0ljHcEu5OvLA+BoLo27LrOssGu63kJz7zhkZkqr7ggjDaKVPPQ5xx0AxcEU/fIG1IepqLHjWV9wPPFj9+cVS8PxtNDe7QsAdzQSi5BYVf3wp8jLfcQDHqqSHnljZ3NuDgpngr//PzPGUWjXnvCaz/HfKvQaxKQR66P9f178ol9G3nLsfcO3uyI/nqgzQDaoBm+PWn4nBnObrsLRgSR7PQgr5Ka7yQw9HykBfdO8fWh2BknJ2ASlJ26gamWddF4zpUz8zEAE4hd+NmbOfZC7XzBBU9QSNGe PkGZoaX4 FbMQia5Ead1t2d4hMyX4UsjNb44lbjf9wZ96CMybWlmT4LU+XgLb2/1NL7onqU9BgEvNqOIF2acnRDte98xA9NBwyH0PpgCGeC+pfh07fMD/aKe3qJ3CUIzU3EQzi5my1Jm4FJ7uv2Su2L5nAvNZ8ZmsQPuyfL8ETzS84Ni77DwCxHFSZX9ZloMwag6ieBC1H0O/3qkaODzwT6KRYAzRCMXhvTUBVje+I9kQpDsTN0WwHrJnzjvluyRewcQGJxKxRsHjMlcqPN6wn4DUuhz0DIo+k7S10Z19ME+yeK7KFqUSPa9Kpr5/93i+B7ZqUfimTE8F6mL9iHv27LEeO0wKduRrVJ8szVIZNDsbb8FHyYf0sbE+arPoYfyzrW/IVgxbLWyJQ9ONWaEPHv2AsxWHGaRhYNQs+GE7JpKzlv5/VCRakxfsI1C6FvZEoORrdwUdHGXQrkXgUHQjLT20PY8OpFHWbPPGCb15Czf7v4AzERDaVdeHq2p/4tnxjNg== 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)" Pull the post-processing of the writepage_t callback into a separate function. That means changing writeback_finish() to return NULL, and writeback_get_next() to call writeback_finish() when we naturally run out of folios. Signed-off-by: Matthew Wilcox (Oracle) Signed-off-by: Christoph Hellwig --- mm/page-writeback.c | 89 +++++++++++++++++++++++---------------------- 1 file changed, 46 insertions(+), 43 deletions(-) diff --git a/mm/page-writeback.c b/mm/page-writeback.c index b0accca1f4bfa7..4fae912f7a86e2 100644 --- a/mm/page-writeback.c +++ b/mm/page-writeback.c @@ -2360,7 +2360,7 @@ void tag_pages_for_writeback(struct address_space *mapping, } EXPORT_SYMBOL(tag_pages_for_writeback); -static int writeback_finish(struct address_space *mapping, +static struct folio *writeback_finish(struct address_space *mapping, struct writeback_control *wbc, bool done) { folio_batch_release(&wbc->fbatch); @@ -2375,7 +2375,7 @@ static int writeback_finish(struct address_space *mapping, if (wbc->range_cyclic || (wbc->range_whole && wbc->nr_to_write > 0)) mapping->writeback_index = wbc->done_index; - return wbc->err; + return NULL; } static struct folio *writeback_get_next(struct address_space *mapping, @@ -2437,7 +2437,7 @@ static struct folio *writeback_get_folio(struct address_space *mapping, for (;;) { folio = writeback_get_next(mapping, wbc); if (!folio) - return NULL; + return writeback_finish(mapping, wbc, false); wbc->done_index = folio->index; folio_lock(folio); @@ -2472,6 +2472,47 @@ static struct folio *writeback_iter_init(struct address_space *mapping, return writeback_get_folio(mapping, wbc); } +static struct folio *writeback_iter_next(struct address_space *mapping, + struct writeback_control *wbc, struct folio *folio, int error) +{ + unsigned long nr = folio_nr_pages(folio); + + 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 folio 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 folio. 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) { + wbc->err = error; + wbc->done_index = folio->index + nr; + return writeback_finish(mapping, wbc, true); + } + if (!wbc->err) + wbc->err = error; + } + + /* + * 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 folios we tagged for writeback prior + * to entering this loop. + */ + wbc->nr_to_write -= nr; + if (wbc->nr_to_write <= 0 && wbc->sync_mode == WB_SYNC_NONE) + return writeback_finish(mapping, wbc, true); + + return writeback_get_folio(mapping, wbc); +} + /** * write_cache_pages - walk the list of dirty pages of the given address space and write all of them. * @mapping: address space structure to write @@ -2512,49 +2553,11 @@ int write_cache_pages(struct address_space *mapping, for (folio = writeback_iter_init(mapping, wbc); folio; - folio = writeback_get_folio(mapping, wbc)) { - unsigned long nr; - + folio = writeback_iter_next(mapping, wbc, folio, error)) { error = writepage(folio, wbc, data); - nr = folio_nr_pages(folio); - 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) { - wbc->err = error; - wbc->done_index = folio->index + nr; - return writeback_finish(mapping, wbc, true); - } - if (!wbc->err) - wbc->err = error; - } - - /* - * 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. - */ - wbc->nr_to_write -= nr; - if (wbc->nr_to_write <= 0 && - wbc->sync_mode == WB_SYNC_NONE) - return writeback_finish(mapping, wbc, true); } - return writeback_finish(mapping, wbc, false); + return wbc->err; } EXPORT_SYMBOL(write_cache_pages); From patchwork Thu Dec 14 13:25:43 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christoph Hellwig X-Patchwork-Id: 13493146 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 2F083C4332F for ; Thu, 14 Dec 2023 14:39:19 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 972D66B0487; Thu, 14 Dec 2023 09:39:18 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 8FBD86B0488; Thu, 14 Dec 2023 09:39:18 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 79C976B048A; Thu, 14 Dec 2023 09:39: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 6399A6B0487 for ; Thu, 14 Dec 2023 09:39:18 -0500 (EST) Received: from smtpin28.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay08.hostedemail.com (Postfix) with ESMTP id 2F18F1403D6 for ; Thu, 14 Dec 2023 14:39:18 +0000 (UTC) X-FDA: 81565681596.28.590A4C1 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) by imf15.hostedemail.com (Postfix) with ESMTP id 886D1A0023 for ; Thu, 14 Dec 2023 14:39:15 +0000 (UTC) Authentication-Results: imf15.hostedemail.com; dkim=pass header.d=infradead.org header.s=bombadil.20210309 header.b=FpcH5Bmf; dmarc=none; spf=none (imf15.hostedemail.com: domain of BATV+55581d165dda9d0af87b+7417+infradead.org+hch@bombadil.srs.infradead.org has no SPF policy when checking 198.137.202.133) smtp.mailfrom=BATV+55581d165dda9d0af87b+7417+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=1702564755; 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=+EjBTTu0WiLV+Q73nxsWHktHLf8xanuJ2SDeP86Fuu8=; b=jogn37ChvIjQFoosKi0qlUMa8BgQYem/wFYcgmHv1P2+rj+tbuoRZPpFo38JJxzotZaRN5 qfJ+v8Yl/nHGgBG/hsYjE7ChyH6s1i7rAUZSPJjc6Hrys4fHZltJ9o7raBm8Iq1ONi0j5G hoC5B6NpJVYFLQkqGUQu03iOX3BlAkc= ARC-Authentication-Results: i=1; imf15.hostedemail.com; dkim=pass header.d=infradead.org header.s=bombadil.20210309 header.b=FpcH5Bmf; dmarc=none; spf=none (imf15.hostedemail.com: domain of BATV+55581d165dda9d0af87b+7417+infradead.org+hch@bombadil.srs.infradead.org has no SPF policy when checking 198.137.202.133) smtp.mailfrom=BATV+55581d165dda9d0af87b+7417+infradead.org+hch@bombadil.srs.infradead.org ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1702564755; a=rsa-sha256; cv=none; b=5mdmsqw7vdMR+6ROLNvQLOXailmS6uXFUoStfOV4gdG38opP1yuXAfAfIJ9pmtLU8TDPrZ +7PApIvJeBo7CbdmoQ3G54Bt4IULpSyoS2EA7VW6/H2LDxk6QiENRCZ4QCflVQeHamRAo7 TZWKvtvOy+qHTsr4AGsUQuabqI6L5gU= 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=+EjBTTu0WiLV+Q73nxsWHktHLf8xanuJ2SDeP86Fuu8=; b=FpcH5BmfnsmbIgWMunX3/hZPox tLAIZ4W/GC6ayMAPNn5BY589vQNYhvpCUHsur984ldcZbvmNVmyABftvrU8KE0pxTLjrF/LT/lF6h SiflrOMvjG+E1PERscpCGlpvsObop7COIxi6gE91+X0cch22c4DoY7nQHyHRL1yFc2u2hfZZOFomB HXmpsS0q7VhQuYxeu8rRNY+C/aQRPGP9bmc3cMhWDWqkkF3gpfPUI9+2H4YOMkDdjkx2ZMV1YtHbc yBPNNlsuIhZzoQYxOnc6gtiz5hY+BMwSY0GP/N1RdxH7A7pmUVX/bJlYXECIOQmgGJr+9r7+K2c92 Wog0fx2Q==; Received: from [88.128.88.27] (helo=localhost) by bombadil.infradead.org with esmtpsa (Exim 4.96 #2 (Red Hat Linux)) id 1rDljP-000NEm-28; Thu, 14 Dec 2023 13:26:28 +0000 From: Christoph Hellwig To: linux-mm@kvack.org Cc: "Matthew Wilcox (Oracle)" , linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org, Jan Kara , David Howells Subject: [PATCH 10/11] writeback: Add for_each_writeback_folio() Date: Thu, 14 Dec 2023 14:25:43 +0100 Message-Id: <20231214132544.376574-11-hch@lst.de> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20231214132544.376574-1-hch@lst.de> References: <20231214132544.376574-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: 886D1A0023 X-Stat-Signature: fex7kw3z6g5i9ipx8qgamygssw8zxb4f X-HE-Tag: 1702564755-144497 X-HE-Meta: U2FsdGVkX1/srQw0rOf7c5zsVyBSk+EdU5Au/buUyx4Wh/PoNpXTSkJthKqlPUhzO+4CVVJdA5mJ1sUOr7SxX9i79Fa2AhRyWW/SMvXzDA3LDyboGZDNLydBfQDiHRgSJ26rO//n5znM0ejIS55G/SOmm2M/IFqjOjizTHQ75amaWycCALzPJppX182oJ1jvQsu92RXmjosh258sefT7ik0Bl/NHf12qCLqZbp0lU6sInBp3TY5Tw37btVWRA7Die5onNQVd01ReneuQJUulGGGYFrh+cLqWwSaJv87P6h4L6AIXa66scmTeHEkiyR4mmUTan8vQDBUj4OpPAQHXoRivlBjtOYDglWao0g3r2isJzHvDLm9aOiOHBYhn7/a20DTyLH0l4UeY3g1QCYyEBUAAy9/9zYvirw8GzGFOa7ggFm7yAkQalMO5scULDdsQE/b2TzpInJ0AnhPv9RmhDmndLeGVOZ4T4i3nAapYAdeWD9wK3ko7eDBqcXUjIqeRsEiOospOGz+0GlE1XSTarvNeQ4gvAFHaL9V7Gl+QGV8lx8F/nvtHAuRagyaX7eWTNnWKEGlT7+6q6ZkvdyKGXKiaTekdE4NteS+fslzBuGLEnZowzJaiEHF9PI79oMq8o9aTThnUBAr7aUh/1yPa/J9ReKqOVyAOkaj9s7NrFYe/O+c+OeQoieiF1famifRR0WjOJPEXeUsIigQaeN4DtILbGuiuyGGq0y9FYecF9F5Lleir1CsfpZmUYlBz/gZ/EQlhza+DaPEqyvTBl8auOULD4gafrVdVELH2yBkaPL/6Q0IdD+/cuTFBmLsR9E90Ce0QtK1IPiRYbJGxXkjlhezY8XYzlIGu3f1jIcL3vbT+uRpXes5RLYgplu6eAXMoTO/UvqS6zg4hMTqub7yP/HAGj0a/tr+1oUr6UwJ4z9dyp+tWcn1SKC/h4R9QhfLJeHJIlmy8rUV7eMnSsmg 0aOCD39/ El6+DTncx4vbyN450uHpVvzgqpuCMCAmjCgVT1Ego+ZBuwWL0Ol9xxCfSR/B7OyWOHsVZO1RHuYckyZChDydYgt92qMK8zf81cCmQsGZkIg6l2o+U72+wZ4704EcKpyQ+khqKe4x3QEhZ828se5Blv0MUU6O99cYGyx0BrTCXW4LshdTBUTS4Vq/luGCtW7WZdDFPbmc+MRQOSGPmzxR7ECWYzIiqusGPeVrKcVkUjLs9Flg+KhrxBx8OG3jWZ8i4EuHrhBvg4F3/rjzhHnXTdnwGgtCz4cmg8x0IJ93PtZJT3yCJUfvTssoWsUAxYFbXGkp/6lBItOW52tsMaaFeIMUIy2UPAUq7T2MRQ2M0uQBXq1UcoRMo7PHsBNslO+dmUbIRRpbtrR4Kos/AzKbRaOHRKc7yq4WHYsQtBMUGlzzJW+AYBctPkPC/XGhVwSHv24F3wypTynPMxaT5rQAS11buLSU8ddiDirm9N7NI3F71i8TdPaDhoSYdvA== 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)" Wrap up the iterator with a nice bit of syntactic sugar. Now the caller doesn't need to know about wbc->err and can just return error, not knowing that the iterator took care of storing errors correctly. Signed-off-by: Matthew Wilcox (Oracle) Signed-off-by: Christoph Hellwig --- include/linux/writeback.h | 14 +++++++++++--- mm/page-writeback.c | 11 ++++------- 2 files changed, 15 insertions(+), 10 deletions(-) diff --git a/include/linux/writeback.h b/include/linux/writeback.h index be960f92ad9dbd..b5fcf91cf18bdd 100644 --- a/include/linux/writeback.h +++ b/include/linux/writeback.h @@ -371,14 +371,22 @@ int balance_dirty_pages_ratelimited_flags(struct address_space *mapping, bool wb_over_bg_thresh(struct bdi_writeback *wb); +struct folio *writeback_iter_init(struct address_space *mapping, + struct writeback_control *wbc); +struct folio *writeback_iter_next(struct address_space *mapping, + struct writeback_control *wbc, struct folio *folio, int error); + +#define for_each_writeback_folio(mapping, wbc, folio, error) \ + for (folio = writeback_iter_init(mapping, wbc); \ + folio || ((error = wbc->err), false); \ + folio = writeback_iter_next(mapping, wbc, folio, error)) + typedef int (*writepage_t)(struct folio *folio, struct writeback_control *wbc, void *data); - -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); + int do_writepages(struct address_space *mapping, struct writeback_control *wbc); void writeback_set_ratelimit(void); void tag_pages_for_writeback(struct address_space *mapping, diff --git a/mm/page-writeback.c b/mm/page-writeback.c index 4fae912f7a86e2..e4a1444502ccd4 100644 --- a/mm/page-writeback.c +++ b/mm/page-writeback.c @@ -2450,7 +2450,7 @@ static struct folio *writeback_get_folio(struct address_space *mapping, return folio; } -static struct folio *writeback_iter_init(struct address_space *mapping, +struct folio *writeback_iter_init(struct address_space *mapping, struct writeback_control *wbc) { if (wbc->range_cyclic) { @@ -2472,7 +2472,7 @@ static struct folio *writeback_iter_init(struct address_space *mapping, return writeback_get_folio(mapping, wbc); } -static struct folio *writeback_iter_next(struct address_space *mapping, +struct folio *writeback_iter_next(struct address_space *mapping, struct writeback_control *wbc, struct folio *folio, int error) { unsigned long nr = folio_nr_pages(folio); @@ -2551,13 +2551,10 @@ int write_cache_pages(struct address_space *mapping, struct folio *folio; int error; - for (folio = writeback_iter_init(mapping, wbc); - folio; - folio = writeback_iter_next(mapping, wbc, folio, error)) { + for_each_writeback_folio(mapping, wbc, folio, error) error = writepage(folio, wbc, data); - } - return wbc->err; + return error; } EXPORT_SYMBOL(write_cache_pages); From patchwork Thu Dec 14 13:25:44 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christoph Hellwig X-Patchwork-Id: 13493103 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 619B2C4167B for ; Thu, 14 Dec 2023 13:53:40 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id E0D4B8D00BF; Thu, 14 Dec 2023 08:53:39 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id DBD6E8D00B1; Thu, 14 Dec 2023 08:53:39 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id CAC698D00BF; Thu, 14 Dec 2023 08:53:39 -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 B7E8A8D00B1 for ; Thu, 14 Dec 2023 08:53:39 -0500 (EST) Received: from smtpin26.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay09.hostedemail.com (Postfix) with ESMTP id 7FBEE80C99 for ; Thu, 14 Dec 2023 13:53:39 +0000 (UTC) X-FDA: 81565566558.26.8F53557 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) by imf09.hostedemail.com (Postfix) with ESMTP id D3CC8140026 for ; Thu, 14 Dec 2023 13:53:37 +0000 (UTC) Authentication-Results: imf09.hostedemail.com; dkim=pass header.d=infradead.org header.s=bombadil.20210309 header.b=WeEvgWpq; dmarc=none; spf=none (imf09.hostedemail.com: domain of BATV+55581d165dda9d0af87b+7417+infradead.org+hch@bombadil.srs.infradead.org has no SPF policy when checking 198.137.202.133) smtp.mailfrom=BATV+55581d165dda9d0af87b+7417+infradead.org+hch@bombadil.srs.infradead.org ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1702562017; a=rsa-sha256; cv=none; b=RNGSHRsanRTHvoO4rdSVRyBEcpOpSwYr8Wb3GVZyy7np+xD/JbJGkcJkm+uk+k7qCaB01g 1adGtqz+wmiCqCPDH16V0gJuy/5zACO2rq161tEWjLIST5Wbzo2hHQ0DzhdXOhVNfBg1hZ IOJqYYrAxZ39/dGOTw9NuuCda8pcGp0= ARC-Authentication-Results: i=1; imf09.hostedemail.com; dkim=pass header.d=infradead.org header.s=bombadil.20210309 header.b=WeEvgWpq; dmarc=none; spf=none (imf09.hostedemail.com: domain of BATV+55581d165dda9d0af87b+7417+infradead.org+hch@bombadil.srs.infradead.org has no SPF policy when checking 198.137.202.133) smtp.mailfrom=BATV+55581d165dda9d0af87b+7417+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=1702562017; 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=fSSCwYEFU0GoMDegAuKi55gdXGuKeNZB2TyfoMX/Y+w=; b=sKu1WL/CGEts08YsywC6/v8MYgq6S5f6ZPMG0Oi4V7DAdb5g1G5jjiXQWCq1PmvJ6IL4cz awAm2vk5fRqiR48Kej+4bXVwwyKKEjIqT17AppOHiBrcLH1zKcMTk6GjkMup4JhAP9m8N5 6Z99mgKmLpSPTmqYfhV6hJj9xpPdruc= 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=fSSCwYEFU0GoMDegAuKi55gdXGuKeNZB2TyfoMX/Y+w=; b=WeEvgWpqJWmJsBWQKrtwqaDcsx DdhfJGsb6lyX8JGqp2wBtNE8ntogWBaKjs0SOJvYsf4t1u1vtiknCwTL2Y5ngFQF0kHZAg2e/Wj3C /lKhI+vk7w1OAoB1r0oIpvJFGTE706ExEjmuIYhCM55Nj8hvhRQUA9mnbsQwwHBsnj+d7VdCtZaiz AY81oAYmK7szPOgEXKqDSPEWg+V3BHzPv5gMAzb2bezV/TCEPLMlfxFWEyiAH64GqL7CY0PY56S8R 8G4fBDbKysnieizxi5pWpxe++ocMLt+32i5pQpsFojwROwJzzgv1IQ/wHyjc0ZdcJzzDcdle2JPLh 7WwhmenQ==; Received: from [88.128.88.27] (helo=localhost) by bombadil.infradead.org with esmtpsa (Exim 4.96 #2 (Red Hat Linux)) id 1rDljT-000NGp-0B; Thu, 14 Dec 2023 13:26:31 +0000 From: Christoph Hellwig To: linux-mm@kvack.org Cc: "Matthew Wilcox (Oracle)" , linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org, Jan Kara , David Howells Subject: [PATCH 11/11] writeback: Remove a use of write_cache_pages() from do_writepages() Date: Thu, 14 Dec 2023 14:25:44 +0100 Message-Id: <20231214132544.376574-12-hch@lst.de> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20231214132544.376574-1-hch@lst.de> References: <20231214132544.376574-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: D3CC8140026 X-Stat-Signature: u9snfykgrmdt63fo7o1t99j34n7reu1d X-HE-Tag: 1702562017-147364 X-HE-Meta: U2FsdGVkX18MGqnClS4jsKeRkfy1etwhVri1Lr+Jq2gKnhuzYhn/pcVR2cDTC3JJr9WfBixMAK4/wQM+pZ7Fo4AhL0wsFFofHr92on/iipcbJXOkx9xSwCH/5vHMse4C7ji/c1gnqTV4cfNsYpQ068+hM7yfTau8OO8DwSVbUsiJWBLOh1FNSf6H6WZTzFRF4yFx5tC3raW1MdUEYCzR6MDSLPWFFt8BPjPcFen88DAihijTL+3lJsD66nPAan7wi7XfvDAZNpqQ1dPdXMBT4eLLBWF4UNfo+azXMW3AOWO5fTr2HT2qWcIxrzZuw5Ci3MPJ1Qgaqr0stRUoYl6KL20aPZpLKRV+pTs5/r8rcljRpVbmLKaZKHuixhWEPJ2ahZpHmAkfvIY/7yyvnEZxR6GlhrOWm6N3grC9L5Yc9JYXs3ub6AC5vZWrkkcgUcQRZr8uNN/apWBOXrKLutal8MraOTDYaC+yJBiszB/enG6VAVLv1638wb0rNkiYeXcJ0K1oO2kQFq+sm3QIBUvLTaiv5Lh/hkPBOk4DSAYFcD2R+gOPL6Pg73NdfqDJTUJI0f/Nk1iInpRu0DpG88RfaJXfvBK1IpAzsJQzXQjpRNzCYq0XCsqDbN7bvV4m8vxMwnVhWLKQoOcjLGMPPzyZTsqTRCgFf7IVMBNMmN06ytyzHsGHSwYxvNs4FqhyrGbEiOTkxkJ3V53RNxk2h4zitT1OT+4Sa2uf2wgcaZki8DdXFytW4sUvNiuyZAfSu6JwjNQFo7Mbs4ow4zsFRltwWa5nWTxG/GzNljqQjQfYJvl/76u9HWApNA+JG6fpbXWKaelqt+KGBA9c/GZ1MDnY7kNVuHf020t72FtvKp35XkAF9Q1xU0oYYWLpl7RnmrMoTqqsmI7livLjnSUJxIrM9tTt1Ppd9LZjdlaYuG2K+608arXfs6Jm275S+9XD7fnpvs7YfPlrJRiGY6YYGV8 +89Z12fl MEwRM6qwsQ8b5bZlapu+B40ztzc+TEFkbC9iI4/6D0baBBGODcTk/o0cgEBaXM0+tc1hedR4e6r262gkp+tHIn6mJZ1lt7OZubtvNbEE9xGvnZmXSLNAtXR/apkDTXV7yrmNbXaU7nYE+PONVtiNvBeU949PYsQ8tCdyjk0wfEVmcmgIq+tFHUsszrKirSNI0eR4qcwEuLoFI8delh39lrHkTebX2llGURgY3LkXM9vPFVCzgJcdmbN01y2aYaBSKdF1ifLJJh6f56uso9Wy67UzYDvuyhIv4qsODnPzbBCitpe7mtgxU0snFL8iBr89wTnurTXHtvtoCZKo0xJLX51PvdOqisLiZ+chdQFI4ueV6eFvKP7w3rZK1kLwH7dhnd+pUsGty6u1J3Xvm7zB5DMLdhGn02xTONKtOYXSLeWbxm+51+PcM45fRST6XQ0n3Z8lWOdn88HhDeodIaR6EANgbNWtsLYkql7d+wrjrFRb6Ad3Cy8rsl+opiQ== 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 for_each_writeback_folio() directly instead of indirecting through a callback. Signed-off-by: Matthew Wilcox (Oracle) Signed-off-by: Christoph Hellwig --- mm/page-writeback.c | 27 +++++++++++++++------------ 1 file changed, 15 insertions(+), 12 deletions(-) diff --git a/mm/page-writeback.c b/mm/page-writeback.c index e4a1444502ccd4..338021bdd136b9 100644 --- a/mm/page-writeback.c +++ b/mm/page-writeback.c @@ -2558,13 +2558,21 @@ int write_cache_pages(struct address_space *mapping, } EXPORT_SYMBOL(write_cache_pages); -static int writepage_cb(struct folio *folio, struct writeback_control *wbc, - void *data) +static int writeback_use_writepage(struct address_space *mapping, + struct writeback_control *wbc) { - struct address_space *mapping = data; - int ret = mapping->a_ops->writepage(&folio->page, wbc); - mapping_set_error(mapping, ret); - return ret; + struct blk_plug plug; + struct folio *folio; + int err; + + blk_start_plug(&plug); + for_each_writeback_folio(mapping, wbc, folio, err) { + err = mapping->a_ops->writepage(&folio->page, wbc); + mapping_set_error(mapping, err); + } + blk_finish_plug(&plug); + + return err; } int do_writepages(struct address_space *mapping, struct writeback_control *wbc) @@ -2580,12 +2588,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;