From patchwork Mon Dec 18 15:35: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: 13497162 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 63F5FC35274 for ; Mon, 18 Dec 2023 15:36:23 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id BAF688D000F; Mon, 18 Dec 2023 10:36:20 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id B39A28D0009; Mon, 18 Dec 2023 10:36:20 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 9B13E8D000F; Mon, 18 Dec 2023 10:36:20 -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 84DF48D0009 for ; Mon, 18 Dec 2023 10:36:20 -0500 (EST) Received: from smtpin02.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay03.hostedemail.com (Postfix) with ESMTP id 65A20A01F2 for ; Mon, 18 Dec 2023 15:36:20 +0000 (UTC) X-FDA: 81580340520.02.56F5693 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) by imf10.hostedemail.com (Postfix) with ESMTP id A6607C0020 for ; Mon, 18 Dec 2023 15:36:18 +0000 (UTC) Authentication-Results: imf10.hostedemail.com; dkim=pass header.d=infradead.org header.s=bombadil.20210309 header.b=QbDL69GR; spf=none (imf10.hostedemail.com: domain of BATV+09f18f96a25a69770120+7421+infradead.org+hch@bombadil.srs.infradead.org has no SPF policy when checking 198.137.202.133) smtp.mailfrom=BATV+09f18f96a25a69770120+7421+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=1702913778; 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=FNt5drM75tskFSjmTVt5X4B1n0+AI4vg4FZ50KNwnlI=; b=JioPZFhUdLt3qNYcsqVQKpzTuIbPs0yl5PZZ5g94eAa211Pjk0LG0/rWhw0dZClecoIPTC Bw2M3EhwSt8IzqludiDS+T2NyIRw8ntQotPrvSwb1+NmxkYHAMOFPPtY9htZGrzQFrjD96 7tgShe/9I2syd+GeaJYXCHHQGya52gs= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1702913778; a=rsa-sha256; cv=none; b=kuab7/RWoZUHHFWF3nvvK9snjB9wQWmOwBmQmOQD25qcOGdDofRW5QOO5xmXyZN2F/SGc0 mmH1I+OozSRioXt+SL/HMYVO9KrMX8tytkd+/vYUfLiSl20PsRwkWFhD8X2kTK4ige4lN3 L2JGhQAlTTFyU3IjbTw4FG0GD6EyjUg= ARC-Authentication-Results: i=1; imf10.hostedemail.com; dkim=pass header.d=infradead.org header.s=bombadil.20210309 header.b=QbDL69GR; spf=none (imf10.hostedemail.com: domain of BATV+09f18f96a25a69770120+7421+infradead.org+hch@bombadil.srs.infradead.org has no SPF policy when checking 198.137.202.133) smtp.mailfrom=BATV+09f18f96a25a69770120+7421+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=FNt5drM75tskFSjmTVt5X4B1n0+AI4vg4FZ50KNwnlI=; b=QbDL69GRW7vcyaByv+sL4EM+jX e1QFZOSXKXPkEb+eHP3GiM6UxRPacz9vafLmcd5vlzhMaNWjnWNm72N3eC5D3DOMxmjaWumGDpjGr XM6FXOQJMz+HmusWg+1LvjoRZGZU2wpeb6PIpggTeUTU3a+7tMOXiJPs2b8G376PygzwpKTNPmEIs hMmgGXMFBpTBYKLuq7Eb1xdpwVhL/ExPQOMB+E9OezOoHgfinlWKM3AQzMwJIsUS75WJ0yGWCDtN5 eQcmtSldtT3O7o6PWVWQLoa8KFVGz3GXZDRsAm5iHAYmgw9nL9j365MYyfJKPnp5qDf1Z929i1sSr k+mKxi/w==; Received: from 2a02-8389-2341-5b80-39d3-4735-9a3c-88d8.cable.dynamic.v6.surfer.at ([2a02:8389:2341:5b80:39d3:4735:9a3c:88d8] helo=localhost) by bombadil.infradead.org with esmtpsa (Exim 4.96 #2 (Red Hat Linux)) id 1rFFfE-00BEOe-2o; Mon, 18 Dec 2023 15:36:17 +0000 From: Christoph Hellwig To: linux-mm@kvack.org Cc: "Matthew Wilcox (Oracle)" , Jan Kara , David Howells , Brian Foster , linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH 08/17] writeback: Factor should_writeback_folio() out of write_cache_pages() Date: Mon, 18 Dec 2023 16:35:44 +0100 Message-Id: <20231218153553.807799-9-hch@lst.de> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20231218153553.807799-1-hch@lst.de> References: <20231218153553.807799-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: A6607C0020 X-Rspam-User: X-Rspamd-Server: rspam11 X-Stat-Signature: ibspmk4tmkmngpxb4gb8ge1cpozc3wq8 X-HE-Tag: 1702913778-323974 X-HE-Meta: U2FsdGVkX1/KjbbPGVb6iiale19hXZtxJM94FurfO9OrWoAFrWuKUlagMShhjBGPywJi5/FdPNaoIRppt2hnT1I27DH6qlDf0xta2svd4vRA7nR2mBZDj5E441wverLgp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C1j4/vws8KeMwtbMWD4iEdetexzYXYa0iw46+8qZjB+GSv7psYFqWPJ9j7hKjHrhaeOuslI2mVYzsO9L6cq6I5DeNJrywuLQSpPbaogU8wIHIcoavp0btCqWyaXLY0p1vkIqXobxpWakFDxHhYCXnSx9TNzT+nfhmJhP7QH2lgR/SDcotLKNDUlqq9y+SZ1QzrmgAtXJoe+GEHj31Ts57ZTNrJ1EX52h300bR4CTAgC2dRSnoJdG9LICcBVJIjI4CDxkCIK+VyYFrg3ikC9N/B6sjRmLPD02I9KjCswlQPlgm5Mp+nrMCTb9Y7ztFsDulGIPhnaYuk9Em9fxgkTwCzI= 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 798e5264dc0353..2a004c0b9bdfbf 100644 --- a/mm/page-writeback.c +++ b/mm/page-writeback.c @@ -2406,6 +2406,36 @@ static void writeback_get_batch(struct address_space *mapping, wbc_to_tag(wbc), &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 @@ -2470,38 +2500,13 @@ int write_cache_pages(struct address_space *mapping, unsigned long nr; 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); wbc->nr_to_write -= nr;