Received: by 2002:a05:7412:8d10:b0:f3:1519:9f41 with SMTP id bj16csp5981035rdb; Thu, 14 Dec 2023 05:26:49 -0800 (PST) X-Google-Smtp-Source: AGHT+IEwtzIGfKzChSFqaqne4oiP9DdHYwFD/YX15SHneGLC1Tqv2A33GyB/UF7eif2rKqQDJejn X-Received: by 2002:a05:6a20:a483:b0:18f:9c4:d33e with SMTP id y3-20020a056a20a48300b0018f09c4d33emr9479898pzk.46.1702560409461; Thu, 14 Dec 2023 05:26:49 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1702560409; cv=none; d=google.com; s=arc-20160816; b=VAAubDsaKqtxF7vv30v8HFmAKdDJoGrMIO4ZLluLzQnlC6QMyXd7TN92krW07jaAN2 3ba0T41hNw9PEGsORvSklXhNaG8Z6CsTLy4fTkQvAMyKhViUBL4J+CQApcGYLgrxRJEo VePIIs3s/Kc8OxLAtKPeJtdS2LnPoPBu9Ot0BkLRdE9Seo5dAbDQhg4obzi82mkVXR+q 4vhAJvRWPQysDzsO+1mmoG72D9vigumvAULrAdwbNVHnQzY81HnOzJUTJNYeywSB6V5g PL9c0t4Rj2nawEoH0D2uAFoJv6GDDXdbxwQUnL6z78CgWv40O8/esvMs4iGLBDbXnrPB e40Q== 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=Rss8E0TEJ5ZWP+w65Q90ToBr5MzQatBIEX9ecM3F1aY=; fh=s6qbYcpKmY0AEsK/gKDpT3qiaGyyaU+hQ5h16uVwDEk=; b=id+NiSyLgIi5qsZeQI8dldqtqYP1MG/A9kmpN8rmrFNFwUVYkz3QJ7tOQupuE9HvvG 7p83rkkd2bRC86h1/d/oC/jDD/r1EayScYoizLuAQlPk3QUbYXm6TmLmI0nfT3bZALgg 6GKiW8PWT16SytMioi/07CScotfUjKvmHheERdcNuoe310dHmKB0FrTW7IvQDeWgexPk o46yGrKjl6r/CUXOW9w1yUp57Jq9N02yrRb/wSohC9iPUQ0k4rIU8zPhxjFdJyeX+yoi 1uuZJkWj+arr11U1UZEprtaemoZjb8a95zG5fp0kWCRIHrxqbrxDmayBAd8/0nn+g+wl xAtg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@infradead.org header.s=bombadil.20210309 header.b="SFp/hA0f"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.36 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from pete.vger.email (pete.vger.email. [23.128.96.36]) by mx.google.com with ESMTPS id q4-20020a655244000000b005c6667e3ce3si10943918pgp.299.2023.12.14.05.26.49 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 14 Dec 2023 05:26:49 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.36 as permitted sender) client-ip=23.128.96.36; Authentication-Results: mx.google.com; dkim=pass header.i=@infradead.org header.s=bombadil.20210309 header.b="SFp/hA0f"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.36 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 pete.vger.email (Postfix) with ESMTP id 019AF823B3E3; Thu, 14 Dec 2023 05:26:45 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at pete.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1573321AbjLNN0Y (ORCPT + 99 others); Thu, 14 Dec 2023 08:26:24 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57680 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229930AbjLNN0O (ORCPT ); Thu, 14 Dec 2023 08:26:14 -0500 Received: from bombadil.infradead.org (bombadil.infradead.org [IPv6:2607:7c80:54:3::133]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 5B46F136; Thu, 14 Dec 2023 05:26:18 -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=Rss8E0TEJ5ZWP+w65Q90ToBr5MzQatBIEX9ecM3F1aY=; b=SFp/hA0fghmYHxPZK8RDs0mSUs 2dvs2+f6lfbzUR4ZepQ8+lOvHkqOAptEtwte/LyANyBKUX+HZd6mcog/IExGHXKJfcdRoQzhSEDVK 9gl9L8NnOfFLsnDEvkTsvZZbvnfcHT60084SRlecI7C6UAQf90dwmCWmioA0g1syVyRezuHE2J+eF 21bWWbXPoewfgvDtZgt262UOaoMZWqrFo31EMV17CZ/D0kysdzJ+M4j1lDjO8XJ42vlch6Vq549hE 9UltZjPeJfE+jhxELs1O90Wb3pPSZRv3o+5Fg2ZUJ9i5WA/JSVcNZOnJTj+4nH5Fs+BxSmPDf0wae I2w0fc9g==; Received: from [88.128.88.27] (helo=localhost) by bombadil.infradead.org with esmtpsa (Exim 4.96 #2 (Red Hat Linux)) id 1rDljF-000N9J-2g; Thu, 14 Dec 2023 13:26:18 +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 07/11] writeback: Factor writeback_iter_init() out of write_cache_pages() Date: Thu, 14 Dec 2023 14:25:40 +0100 Message-Id: <20231214132544.376574-8-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=-0.8 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,SPF_HELO_NONE, SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on pete.vger.email 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 (pete.vger.email [0.0.0.0]); Thu, 14 Dec 2023 05:26:45 -0800 (PST) From: "Matthew Wilcox (Oracle)" Make it return the first folio in the batch so that we can use it in a typical for() pattern. Signed-off-by: Matthew Wilcox (Oracle) Signed-off-by: Christoph Hellwig --- mm/page-writeback.c | 47 +++++++++++++++++++++++++-------------------- 1 file changed, 26 insertions(+), 21 deletions(-) diff --git a/mm/page-writeback.c b/mm/page-writeback.c index 2243a0d1b2d3c7..8c220c6a7f824d 100644 --- a/mm/page-writeback.c +++ b/mm/page-writeback.c @@ -2429,6 +2429,28 @@ static bool should_writeback_folio(struct address_space *mapping, return true; } +static struct folio *writeback_iter_init(struct address_space *mapping, + struct writeback_control *wbc) +{ + if (wbc->range_cyclic) { + wbc->index = mapping->writeback_index; /* prev offset */ + wbc->end = -1; + } else { + wbc->index = wbc->range_start >> PAGE_SHIFT; + wbc->end = wbc->range_end >> PAGE_SHIFT; + if (wbc->range_start == 0 && wbc->range_end == LLONG_MAX) + wbc->range_whole = 1; + } + if (wbc->sync_mode == WB_SYNC_ALL || wbc->tagged_writepages) + tag_pages_for_writeback(mapping, wbc->index, wbc->end); + + wbc->done_index = wbc->index; + folio_batch_init(&wbc->fbatch); + wbc->err = 0; + + return writeback_get_next(mapping, wbc); +} + /** * 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 @@ -2464,31 +2486,14 @@ int write_cache_pages(struct address_space *mapping, struct writeback_control *wbc, writepage_t writepage, void *data) { + struct folio *folio; int error; - if (wbc->range_cyclic) { - wbc->index = mapping->writeback_index; /* prev offset */ - wbc->end = -1; - } else { - wbc->index = wbc->range_start >> PAGE_SHIFT; - wbc->end = wbc->range_end >> PAGE_SHIFT; - if (wbc->range_start == 0 && wbc->range_end == LLONG_MAX) - wbc->range_whole = 1; - } - if (wbc->sync_mode == WB_SYNC_ALL || wbc->tagged_writepages) - tag_pages_for_writeback(mapping, wbc->index, wbc->end); - - wbc->done_index = wbc->index; - folio_batch_init(&wbc->fbatch); - wbc->err = 0; - - for (;;) { - struct folio *folio = writeback_get_next(mapping, wbc); + for (folio = writeback_iter_init(mapping, wbc); + folio; + folio = writeback_get_next(mapping, wbc)) { unsigned long nr; - if (!folio) - break; - wbc->done_index = folio->index; folio_lock(folio); -- 2.39.2