Received: by 2002:a05:6358:3188:b0:123:57c1:9b43 with SMTP id q8csp16533857rwd; Mon, 26 Jun 2023 11:15:07 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ6YVznNW+cwOEEaWODGxd9werndgegb5dXZdADCx6kZBXjPn6DtjvJFHkJAyYlvtoHALHFW X-Received: by 2002:a17:902:690c:b0:1b8:97e:4e61 with SMTP id j12-20020a170902690c00b001b8097e4e61mr2270709plk.65.1687803307055; Mon, 26 Jun 2023 11:15:07 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1687803307; cv=none; d=google.com; s=arc-20160816; b=I4NHsvM8JPPsHW10PwFXyRzvg9+GpTeBFJg+cfJX4MkcY0BOE5GugK4XO8IPHbghXF /sp2D3KUWKlTjzY4Up/xyse7X02lZUt3T7isSVGhJrf83311itR4YQ+/mQCD3LSaupKJ QjtH1bp7otCNK24aL8kDlRyG4eG6tidpofubP6TVwgfT01xDoLOqH4lSAVfkGvNE01sR jSGHSf0SOIcxHdT3g5l+aTe3ki6e+GjN6IAddasHar2Ph8GkjruG6fr/a6BITIWebOUZ o8Mn6ciIN/kFM11niM8mUJPsg+k7PfuTF0r2Erxe6WG2a4TcEGmfyenOHhbC0j4zesg4 QtBQ== 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=Rl4mK631QVfMYqrn657sw5cU2nYiKao9j/G8hhMJYQc=; fh=s6qbYcpKmY0AEsK/gKDpT3qiaGyyaU+hQ5h16uVwDEk=; b=sKvg7Om6/RTagsJq1QES1i9EnhljfZYRc815wpvnfxO6LZQPqV+rC9qhoWakqgXqmQ i0Qsa+RPTaPRIts5TLOSXjFVzBGQeEYErfa/7KOxQXSiEHZRgDfAJgTuaRg8E58eBGRV MN1ABnlj5XKWr89/TJUax0VX7QekKL1ihsDPMdODc3QMnChuxzDfJPQUNsBq5wQ+U28U +9oPAY5CIQioghTzgpOBJcfPkWEAFLDhgECB/ihJUfTzbrxCa4JnntZ42qfUGcGnBJrZ Eogww1nzjj6ORZMZDxKjO/K8ENo4cyjaLWFdcB+yBfyc9n3GX2P9I612BJr8JPQvVvs4 rxow== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@infradead.org header.s=casper.20170209 header.b=nbsu3asm; 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 z6-20020a170903018600b001b5125f9cdcsi5679820plg.285.2023.06.26.11.14.54; Mon, 26 Jun 2023 11:15:07 -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=nbsu3asm; 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 S231566AbjFZRiC (ORCPT + 99 others); Mon, 26 Jun 2023 13:38:02 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36778 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229910AbjFZRhD (ORCPT ); Mon, 26 Jun 2023 13:37:03 -0400 Received: from casper.infradead.org (casper.infradead.org [IPv6:2001:8b0:10b:1236::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 757FB19A4; Mon, 26 Jun 2023 10:35:50 -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=Rl4mK631QVfMYqrn657sw5cU2nYiKao9j/G8hhMJYQc=; b=nbsu3asmGLUEUJkp+PGufwS657 4CnYI/PCw6l8Xww27U0CYRwuyhdw3qbIis63qGdeGzCtVLsJOFwYt3NxR09Tdc5xZeJfOY8HBxSpD ML123J3s2go0dLVKtO7JpczdsBdChbc2qdUxfvc7R/nlZz9ke8A7G0kVR8Pe3BeM8cYwULIOBI4va QsVz+e8awbc3irLZPqIwC6yclmfeLbv2Eyi3WV9YAYsgEKeC1gNGPKT8+flhqRnRCmJZMdmeKgqPH POUXY9Q1cVqApg0noTgC9DVH6ZMLKwAsYN6jYt4BOAsygoP/Us8PMzM8KNlDC/dCF+nMklunLylR/ u0gT4KlA==; Received: from willy by casper.infradead.org with local (Exim 4.94.2 #2 (Red Hat Linux)) id 1qDq7X-001vVB-PR; 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 07/12] writeback: Factor writeback_iter_init() out of write_cache_pages() Date: Mon, 26 Jun 2023 18:35:16 +0100 Message-Id: <20230626173521.459345-8-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 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) --- mm/page-writeback.c | 48 ++++++++++++++++++++++++--------------------- 1 file changed, 26 insertions(+), 22 deletions(-) diff --git a/mm/page-writeback.c b/mm/page-writeback.c index f782b48c5b0c..18f332611a52 100644 --- a/mm/page-writeback.c +++ b/mm/page-writeback.c @@ -2430,6 +2430,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 @@ -2465,30 +2487,12 @@ 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); - - if (!folio) - break; - + for (folio = writeback_iter_init(mapping, wbc); + folio; + folio = writeback_get_next(mapping, wbc)) { wbc->done_index = folio->index; folio_lock(folio); -- 2.39.2