Received: by 2002:a05:7412:8d10:b0:f3:1519:9f41 with SMTP id bj16csp5980907rdb; Thu, 14 Dec 2023 05:26:36 -0800 (PST) X-Google-Smtp-Source: AGHT+IFIgQX0pN8zDZ9Tex6ZIKAvUUofrjwy37+kaikKs1w3zXCN5qt5DENsTFaYJ20H52oMHKOw X-Received: by 2002:a17:90a:9318:b0:28b:70b:1939 with SMTP id p24-20020a17090a931800b0028b070b1939mr1458509pjo.6.1702560396141; Thu, 14 Dec 2023 05:26:36 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1702560396; cv=none; d=google.com; s=arc-20160816; b=WRya3cXpiYrv9vC12ryY0HtZYM3iXUyANGnzTeQSFUX4F6dx5/8dX14RP/rDEi49/Y sJYuT7nhKFBbBq/dS+cRWn/YxkTDa81qdilBcIcHxV5qkTEhov9qk99sCERAV74m8Niq 2G71aUYozG9ClG7GZEwUE7MbExwZcPvQwKgFybRrHCaU42UZP+rzELMYddN6sDTB3sBP +4uU8PoGWCtBMT7aZ6S783SFDLT4FpRuNNX2uZcx5Zgi2kaL6ort+y/ec3sP7xvE7e75 YVemRs1Rl5QOVrmHAvLkIxhlXqv0FHro/iIFIR0+jWU7hiZMFIH2P0Dtwfo3NMJvWwkh NKTg== 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=kAPP6X55X6rvLdfMOtbLbsXeMDzuMOl2croRJo78UX4=; fh=s6qbYcpKmY0AEsK/gKDpT3qiaGyyaU+hQ5h16uVwDEk=; b=dMeSsMv/fgBVDhqI9kM2K0KBz6gGvCTdr7dWS8S4yzLsJUSyT2IA82yNrKy2HFk9zp Lk7IRpzK8e24cUEoPD8AFl7/b8AC/pmKG9w8uYqYtYWphLOOHsFesrDN4JyEqtuHMbQd 02j411ode7vckLHZgwv1/bE+f1UKfm4WffchlgShydpVr4mXzYBp2S8S3rLw0WPrj45b VJiuFm5oQUZLSNlvHDh0f8OKOfRbOPY5b1gJ/tq2HDvGgGkcwb8iyQ4rKvg8zp/gxlbO j+cd2KgMq9C7gWx378wq4FRitD+U7J6jnQVwgi2J732rxGc09uaUASFUkiwRdmSlNAKd L3mg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@infradead.org header.s=bombadil.20210309 header.b=fYKo14Qx; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:7 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from snail.vger.email (snail.vger.email. [2620:137:e000::3:7]) by mx.google.com with ESMTPS id bb8-20020a17090b008800b0028b14154724si512124pjb.121.2023.12.14.05.26.35 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 14 Dec 2023 05:26:36 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:7 as permitted sender) client-ip=2620:137:e000::3:7; Authentication-Results: mx.google.com; dkim=pass header.i=@infradead.org header.s=bombadil.20210309 header.b=fYKo14Qx; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:7 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by snail.vger.email (Postfix) with ESMTP id 94E3D802572A; Thu, 14 Dec 2023 05:26:34 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at snail.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1573313AbjLNN0W (ORCPT + 99 others); Thu, 14 Dec 2023 08:26:22 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46268 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229834AbjLNN0P (ORCPT ); Thu, 14 Dec 2023 08:26:15 -0500 Received: from bombadil.infradead.org (bombadil.infradead.org [IPv6:2607:7c80:54:3::133]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B131412E; Thu, 14 Dec 2023 05:26:21 -0800 (PST) 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=kAPP6X55X6rvLdfMOtbLbsXeMDzuMOl2croRJo78UX4=; b=fYKo14QxQKLG96JxNh2gKkqwXa wsvp3uUwGV/Pnm6RVQ/FkMXvsez7eoeecA/pnOwd1vlL/3q7t/raPaZZEcb8RfyZEmpowiZMPLews ppeYWW2XD2womPwLiqiyZobEmdUTrc9J1baAEJ+PnEaO9wafX1ux6yu8ZSaE3ttElyNcNu5l7JyZ6 aE1PvkMIS0bXSJEWwBte6poJSIKKE0+N5v2kwDU42DTmDcVmeNJCjolZuPnbW6cySjI5L2MIe9N7t 820nBKAWHp+TfTTmFYqUoodssCijbcLm2oCZalIcEf11h3nd3Ltie7vsrHAttdJKjAc5duP5q0ioq LbAP1U3Q==; Received: from [88.128.88.27] (helo=localhost) by bombadil.infradead.org with esmtpsa (Exim 4.96 #2 (Red Hat Linux)) id 1rDljI-000NBD-36; Thu, 14 Dec 2023 13:26:21 +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 08/11] writeback: Factor writeback_get_folio() out of write_cache_pages() Date: Thu, 14 Dec 2023 14:25:41 +0100 Message-Id: <20231214132544.376574-9-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 Content-Transfer-Encoding: 8bit X-SRS-Rewrite: SMTP reverse-path rewritten from by bombadil.infradead.org. See http://www.infradead.org/rpr.html X-Spam-Status: No, score=-1.8 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_EF,HEADER_FROM_DIFFERENT_DOMAINS, RCVD_IN_DNSWL_BLOCKED,SPF_HELO_NONE,SPF_NONE,T_SCC_BODY_TEXT_LINE autolearn=no 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-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (snail.vger.email [0.0.0.0]); Thu, 14 Dec 2023 05:26:34 -0800 (PST) From: "Matthew Wilcox (Oracle)" Move the loop for should-we-write-this-folio to its own function. Signed-off-by: Matthew Wilcox (Oracle) Signed-off-by: Christoph Hellwig --- 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 8c220c6a7f824d..b0accca1f4bfa7 100644 --- a/mm/page-writeback.c +++ b/mm/page-writeback.c @@ -2429,6 +2429,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) { @@ -2448,7 +2469,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); } /** @@ -2491,19 +2512,9 @@ int write_cache_pages(struct address_space *mapping, for (folio = writeback_iter_init(mapping, wbc); folio; - folio = writeback_get_next(mapping, wbc)) { + folio = writeback_get_folio(mapping, wbc)) { unsigned long nr; - 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)); - error = writepage(folio, wbc, data); nr = folio_nr_pages(folio); if (unlikely(error)) { -- 2.39.2