From patchwork Thu Dec 14 13:25:40 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christoph Hellwig X-Patchwork-Id: 178731 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7300:3b04:b0:fb:cd0c:d3e with SMTP id c4csp8541678dys; Thu, 14 Dec 2023 05:26:42 -0800 (PST) X-Google-Smtp-Source: AGHT+IH9DHi7HYwMatGnH9ceMdW3n97RQy+cRck7KDwQqbSJjRPSMocI43sUw1DAtUcnfwghupUx X-Received: by 2002:a05:6a21:a5a4:b0:187:a9b0:434b with SMTP id gd36-20020a056a21a5a400b00187a9b0434bmr13377581pzc.4.1702560401934; Thu, 14 Dec 2023 05:26:41 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1702560401; cv=none; d=google.com; s=arc-20160816; b=xb8eNj485SwKnT4lwhfZOA3S7PJWG4DzXOQiByCFwZDiTZvSWyaYZPzYiW6faJMVFt xC7T3YcLx5JVMZ4DcOzQE4k6IwsbclQjAR8uXhwSSoZLtzVjfz7XvMuXuGqqFPw0qN60 7BMcTBr52k5E9+u4HXym9rgU8XhmDH5Ch9iKzgLx2FN/wDe+nugm+iMPDJ2m6l3AqyI6 qQneJMDIL9B33aQ8m861BNg+l7MoyYIGT7m0X9vAhWwF47+HfyYGWnzEadlRXKFGmcpV Dp0jT9pIVAwMDszI+Q11+bjKgiYc3IKMm4teaXhNTHbphFhUoB3EHa9JOAxOqFqXfeR7 8XaA== 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 2620:137:e000::3:6 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: from pete.vger.email (pete.vger.email. [2620:137:e000::3:6]) by mx.google.com with ESMTPS id h6-20020a056a00170600b006cb686c08f4si11453805pfc.211.2023.12.14.05.26.41 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 14 Dec 2023 05:26:41 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:6 as permitted sender) client-ip=2620:137:e000::3:6; 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 2620:137:e000::3:6 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 865EA823B3C2; Thu, 14 Dec 2023 05:26:34 -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 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=ham 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:34 -0800 (PST) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1785263975671655863 X-GMAIL-MSGID: 1785263975671655863 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);