From nobody Mon Feb 9 16:45:38 2026 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 9F6C0EB64D9 for ; Mon, 26 Jun 2023 17:38:09 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230047AbjFZRiE (ORCPT ); Mon, 26 Jun 2023 13:38:04 -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: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" 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_sp= ace *mapping, return true; } =20 +static struct folio *writeback_iter_init(struct address_space *mapping, + struct writeback_control *wbc) +{ + if (wbc->range_cyclic) { + wbc->index =3D mapping->writeback_index; /* prev offset */ + wbc->end =3D -1; + } else { + wbc->index =3D wbc->range_start >> PAGE_SHIFT; + wbc->end =3D wbc->range_end >> PAGE_SHIFT; + if (wbc->range_start =3D=3D 0 && wbc->range_end =3D=3D LLONG_MAX) + wbc->range_whole =3D 1; + } + if (wbc->sync_mode =3D=3D WB_SYNC_ALL || wbc->tagged_writepages) + tag_pages_for_writeback(mapping, wbc->index, wbc->end); + + wbc->done_index =3D wbc->index; + folio_batch_init(&wbc->fbatch); + wbc->err =3D 0; + + return writeback_get_next(mapping, wbc); +} + /** * write_cache_pages - walk the list of dirty pages of the given address s= pace 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; =20 - if (wbc->range_cyclic) { - wbc->index =3D mapping->writeback_index; /* prev offset */ - wbc->end =3D -1; - } else { - wbc->index =3D wbc->range_start >> PAGE_SHIFT; - wbc->end =3D wbc->range_end >> PAGE_SHIFT; - if (wbc->range_start =3D=3D 0 && wbc->range_end =3D=3D LLONG_MAX) - wbc->range_whole =3D 1; - } - if (wbc->sync_mode =3D=3D WB_SYNC_ALL || wbc->tagged_writepages) - tag_pages_for_writeback(mapping, wbc->index, wbc->end); - - wbc->done_index =3D wbc->index; - folio_batch_init(&wbc->fbatch); - wbc->err =3D 0; - - for (;;) { - struct folio *folio =3D writeback_get_next(mapping, wbc); - - if (!folio) - break; - + for (folio =3D writeback_iter_init(mapping, wbc); + folio; + folio =3D writeback_get_next(mapping, wbc)) { wbc->done_index =3D folio->index; =20 folio_lock(folio); --=20 2.39.2