From nobody Mon Feb 9 16:17:21 2026 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 062DFEB64D7 for ; Mon, 26 Jun 2023 17:37:57 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231561AbjFZRhz (ORCPT ); Mon, 26 Jun 2023 13:37:55 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35964 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231175AbjFZRgS (ORCPT ); Mon, 26 Jun 2023 13:36:18 -0400 Received: from casper.infradead.org (casper.infradead.org [IPv6:2001:8b0:10b:1236::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 71AA32D4F; Mon, 26 Jun 2023 10:35:47 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=casper.20170209; 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=v6PqW+r7ocyNrYaEadNjC9yXbOPBKSknhOaHoHVmJpk=; b=GH5JrXCeoj/GgOPu3iWjttA4pE R9WD1MiCBTid7jEiZMHLeGsbpndBGL7pWST3FhxBWC5vruJtb8/vXrvH0+f62gbXnsXZRlsky8pJq 9+M9D8g1czSuBHKCI6CMEd9w5TLyOR/pLQ95L/J/rI+M7DmyKqKs1a6+MLyLQd2/ds8H1fO846FuZ n8cEC0dArDnoP6JGY1ECb59L60b5jQv8FpFk5u65nzfMXMt5F7+6Z/YkjT4frnabjEqYJXLozDGS7 3U7dQlvwCi5sQU/ji6nNPG8IbAEl5U5k7LHM+ju+XzD5CgDWD6fjTcbsn7X1Y6zVcs+D6Xlzu9mZ+ XAvaJBew==; Received: from willy by casper.infradead.org with local (Exim 4.94.2 #2 (Red Hat Linux)) id 1qDq7X-001vV3-FD; Mon, 26 Jun 2023 17:35:23 +0000 From: "Matthew Wilcox (Oracle)" 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/12] writeback: Factor should_writeback_folio() out of write_cache_pages() Date: Mon, 26 Jun 2023 18:35:12 +0100 Message-Id: <20230626173521.459345-4-willy@infradead.org> X-Mailer: git-send-email 2.37.1 In-Reply-To: <20230626173521.459345-1-willy@infradead.org> References: <20230626173521.459345-1-willy@infradead.org> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" 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) --- mm/page-writeback.c | 60 +++++++++++++++++++++++++-------------------- 1 file changed, 33 insertions(+), 27 deletions(-) diff --git a/mm/page-writeback.c b/mm/page-writeback.c index 67c7f1564727..54f2972dab45 100644 --- a/mm/page-writeback.c +++ b/mm/page-writeback.c @@ -2394,6 +2394,37 @@ static void writeback_get_batch(struct address_space= *mapping, &wbc->fbatch); } =20 +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 !=3D 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 !=3D WB_SYNC_NONE) + folio_wait_writeback(folio); + else + return false; + } + + 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 s= pace and write all of them. * @mapping: address space structure to write @@ -2461,38 +2492,13 @@ int write_cache_pages(struct address_space *mapping, wbc->done_index =3D folio->index; =20 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 !=3D mapping)) { -continue_unlock: + if (!should_writeback_folio(mapping, wbc, folio)) { folio_unlock(folio); continue; } =20 - if (!folio_test_dirty(folio)) { - /* someone wrote it for us */ - goto continue_unlock; - } - - if (folio_test_writeback(folio)) { - if (wbc->sync_mode !=3D 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 =3D writepage(folio, wbc, data); if (unlikely(error)) { /* --=20 2.39.2