Received: by 2002:a05:6358:3188:b0:123:57c1:9b43 with SMTP id q8csp16533345rwd; Mon, 26 Jun 2023 11:14:44 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ7qT4qnYj8Mazm+dYC+HmRoP9XMYGzmgxIP7a16sKVi+BPa/O+Yi8s6wGqH1gZfD4D5Qyzh X-Received: by 2002:a17:902:c083:b0:1ac:5717:fd5 with SMTP id j3-20020a170902c08300b001ac57170fd5mr6958864pld.60.1687803284580; Mon, 26 Jun 2023 11:14:44 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1687803284; cv=none; d=google.com; s=arc-20160816; b=qDJ0qMN9EaFx8cQ1A5XvrswdopTlxDUuc8/27oJrAJOM/pTzhGhQlTI4B19U3EAcYX DaJY7w1fj+gIvtlsDb8DicCWUYYJudLj9IgaMWM8qtjeE+8LC7Jx339X5x+FxbbFDu5n CnFFKVfMtrsG81nZCkZ6zBznk3VcGfm/bI8GeeqDZWFBmhWXscsar3OndcViQPHPsAI/ pJH+GN+lzB97F0HYLx4gBEqPXD8pLHuZGQUc787GHVyXHMJYPEP1JzX5m3diaLjgmkfa pa52R4KKO6qEZumAaCwSZrgI4SeszN+2u4PHFV8GbQX6lRxLW4kBbj6IW2pKTmJ3xnTy 5bgw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=v6PqW+r7ocyNrYaEadNjC9yXbOPBKSknhOaHoHVmJpk=; fh=s6qbYcpKmY0AEsK/gKDpT3qiaGyyaU+hQ5h16uVwDEk=; b=sJkiDbuJAj3qK/CKD4KgReby+BcM3TPIBYFwxiiJE6KuGrfRW22IjMKcKNo86h1h9W /Iz9XEbYHiFBhYjx1agJifaPBkPkPx3xx+eSuTJvkjy7UAB9J/FknkLdaCBbJeIXz0jw 9/HltpOWcs/r3Umm2EBhlzh1qyZUB5fF2bSidaamxzqc/sUfIz2lDtWnP9/Rj64gHoEB sN2QrVjBOJYaAblXXlOUJoAEgTShYnzj2Ub0Y+tAOFBAx1PzcZIIGknA9k57YOqvvhUB FUVS7xAJz7uASxrFSSitK6IATGkAo4jMzQkt+oBd394R+bKcIxhXBZe6lXnoYtkfyv8H dq3g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@infradead.org header.s=casper.20170209 header.b=GH5JrXCe; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id p1-20020a170902bd0100b001ac6e1fd203si5198688pls.180.2023.06.26.11.14.18; Mon, 26 Jun 2023 11:14:44 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@infradead.org header.s=casper.20170209 header.b=GH5JrXCe; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231540AbjFZRhy (ORCPT + 99 others); Mon, 26 Jun 2023 13:37:54 -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: 8bit X-Spam-Status: No, score=-4.4 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_MED,SPF_HELO_NONE, SPF_NONE,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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); } +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) + 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 space 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 = 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); if (unlikely(error)) { /* -- 2.39.2