From patchwork Mon Jun 26 17:35:17 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Matthew Wilcox X-Patchwork-Id: 113073 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:994d:0:b0:3d9:f83d:47d9 with SMTP id k13csp7651824vqr; Mon, 26 Jun 2023 10:50:23 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ7joGvFzWsayS74b4wsJ61MJrwbPv/m+wkS82u1EanDZrSz+j3bbmH90Kh4lrAWm445Mo5Y X-Received: by 2002:aa7:db51:0:b0:51d:a24c:db20 with SMTP id n17-20020aa7db51000000b0051da24cdb20mr1203303edt.18.1687801822743; Mon, 26 Jun 2023 10:50:22 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1687801822; cv=none; d=google.com; s=arc-20160816; b=YU4xA72dwOt41dgi3fVex/HnXkBn9A+Uy9oHxzbhdDOsCgvX5zVt7fmIDKfM2tzvN3 8StIOOH58y+A6Zz6y53stC/SUknMB3/xqQuBLLODckoBMTkG9y8e9RwC20oiHLLYqeDR Au/yX8ZqyP63JV5GqcIqMENtMYyoXqenqJEVTaISdeEYgHBOLX2yXmHWR3Y5W74STB6a cLsll4Bh0Bdtb7BnrRuRpQ2YdVOITHQP28q9cNdpiOK2uUhkdIsQNtVd+i5/oO/R8POL RTSCMlSTEtd7VTQUhlWKo+JS7ogew9ciiNEXQ5nPTH+aG3SfuETvTOnMjjBoFYucf84K gaeQ== 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=4j8qD1VIDkeu8FuhbX23YTq3SVJUsBomytwghqZoPiA=; fh=s6qbYcpKmY0AEsK/gKDpT3qiaGyyaU+hQ5h16uVwDEk=; b=F5+3xvqrZaVEA0z8Y1zkB+Bmy6v8RV8fzy8rmlop41n1fLZ34IITB4jyGMQiuzTAiG rgKK0+KQtdbduFohWI8R78XGpSwPLFvVH7STry7q6mY7KRVrfSw8l7QFrwJd5CU55RbA i+LlCRnrDWI0CVD+cwNqmBdiYl/tFOWGfsN7UYgHnECrt5tlRQQ+dHtudQrkL8S3TkFo tt26AMdJ0dYNmnayzK62Bi1j6Ivq8G55KZe5OsKQZ0SllMrtT+gMZfNsriCAD7lP6XDo GpXOLWJG00BniEr+15F4JpldCPF6brDfHul3nQte13gUxrpL6HKuml24tsl9kfSTMVuH 95gg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@infradead.org header.s=casper.20170209 header.b=jO+IuqRO; 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: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id w18-20020aa7da52000000b0051a4886f920si2863173eds.548.2023.06.26.10.49.58; Mon, 26 Jun 2023 10:50:22 -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=jO+IuqRO; 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 S231213AbjFZRgV (ORCPT + 99 others); Mon, 26 Jun 2023 13:36:21 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36332 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231666AbjFZRf4 (ORCPT ); Mon, 26 Jun 2023 13:35:56 -0400 Received: from casper.infradead.org (casper.infradead.org [IPv6:2001:8b0:10b:1236::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 1FC05272C; Mon, 26 Jun 2023 10:35:27 -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=4j8qD1VIDkeu8FuhbX23YTq3SVJUsBomytwghqZoPiA=; b=jO+IuqRONCDpfM0ToVlDzBovD9 NnIpFqCSVbzcdzA354Ai8J4uwvQXN3vjxzaPqsdl/xu+9TkLDzcRKCal7PcOkbcF4dV4DToUbguua DhQc5GIdojQ+898Vu6UjYABB/NZtHhCqnv6dR6n3B4zANWT8SgicSzfUO8KQHTKbqL3iiVruTyBBi TgOxqzuFcqc3rCbML9MBL2LZcXwzT5+YcSAaJsyE93G9W7FkKk1k0a6BL0e2AQngll3EYEidWhOx1 MbKdipsmpf8sBpR98d+bhM2uO0wX76Fuou4HTdMTNuQoYS1f6L3Oed9cA/g5bqwApTqNnCdDFN0wS UGzEVQmg==; Received: from willy by casper.infradead.org with local (Exim 4.94.2 #2 (Red Hat Linux)) id 1qDq7X-001vVD-S2; 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 08/12] writeback: Factor writeback_get_folio() out of write_cache_pages() Date: Mon, 26 Jun 2023 18:35:17 +0100 Message-Id: <20230626173521.459345-9-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 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 X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1769788484490766846?= X-GMAIL-MSGID: =?utf-8?q?1769788484490766846?= Move the loop for should-we-write-this-folio to its own function. Signed-off-by: Matthew Wilcox (Oracle) --- 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 18f332611a52..659df2b5c7c0 100644 --- a/mm/page-writeback.c +++ b/mm/page-writeback.c @@ -2430,6 +2430,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) { @@ -2449,7 +2470,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); } /** @@ -2492,17 +2513,7 @@ int write_cache_pages(struct address_space *mapping, for (folio = writeback_iter_init(mapping, wbc); folio; - folio = writeback_get_next(mapping, wbc)) { - 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)); - + folio = writeback_get_folio(mapping, wbc)) { error = writepage(folio, wbc, data); if (unlikely(error)) { /*