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+zxrYvrgYb4OX7QI2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hhFd67KzLAVeH1bN6/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)) {