From nobody Mon Feb 9 16:33:25 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 F12C7EB64DC for ; Mon, 26 Jun 2023 17:37:38 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231522AbjFZRhh (ORCPT ); Mon, 26 Jun 2023 13:37:37 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36628 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230363AbjFZRgO (ORCPT ); Mon, 26 Jun 2023 13:36:14 -0400 Received: from casper.infradead.org (casper.infradead.org [IPv6:2001:8b0:10b:1236::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 22D2C170D; Mon, 26 Jun 2023 10:35:44 -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=Eb8+i22W56HZAod8nWQSK472UiI/gYMP48K8do/ME/8=; b=I8BvqJCHhBej30amkNnVaHN6rH u9uO/sVt2f+jz7JcGOSx+zl/f70NIeziA/OlCB4o62GnbbwwGLVv/hBjABtamZ47YbH1j4ZOO4hoc QRtJcd7ZjBN83uepkFoGD0dLghMKRhe+wpJC6dFdWan3E0U1OHu3sqtiCt8ZD7+zxqDSwb0Vbi5uq nOyJHt2ANqAHJbdn5QtHLs8S1Ecyurt3g/m+y5pugk3uH39x/eU2jWFeYf7aR2cgIn9Y2zwwl/ozy mNgR7J1eV9HCBuDFaS061IwieX96E0vWyEzjHBhaHEzX9wLQ2iAiERfPCLB4uIn1bhmMDv7lULBmZ j2uURkZQ==; Received: from willy by casper.infradead.org with local (Exim 4.94.2 #2 (Red Hat Linux)) id 1qDq7X-001vV1-CW; 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 02/12] writeback: Factor writeback_get_batch() out of write_cache_pages() Date: Mon, 26 Jun 2023 18:35:11 +0100 Message-Id: <20230626173521.459345-3-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" This simple helper will be the basis of the writeback iterator. To make this work, we need to remember the current index and end positions in writeback_control. Signed-off-by: Matthew Wilcox (Oracle) --- include/linux/writeback.h | 2 ++ mm/page-writeback.c | 49 +++++++++++++++++++++------------------ 2 files changed, 29 insertions(+), 22 deletions(-) diff --git a/include/linux/writeback.h b/include/linux/writeback.h index 5b7d11f54013..7dd050b40e4b 100644 --- a/include/linux/writeback.h +++ b/include/linux/writeback.h @@ -54,6 +54,8 @@ struct writeback_control { loff_t range_end; =20 struct folio_batch fbatch; + pgoff_t index; + pgoff_t end; /* Inclusive */ pgoff_t done_index; int err; =20 diff --git a/mm/page-writeback.c b/mm/page-writeback.c index abd7c0eebc72..67c7f1564727 100644 --- a/mm/page-writeback.c +++ b/mm/page-writeback.c @@ -2378,6 +2378,22 @@ static int writeback_finish(struct address_space *ma= pping, return wbc->err; } =20 +static void writeback_get_batch(struct address_space *mapping, + struct writeback_control *wbc) +{ + xa_mark_t tag; + + if (wbc->sync_mode =3D=3D WB_SYNC_ALL || wbc->tagged_writepages) + tag =3D PAGECACHE_TAG_TOWRITE; + else + tag =3D PAGECACHE_TAG_DIRTY; + + folio_batch_release(&wbc->fbatch); + cond_resched(); + filemap_get_folios_tag(mapping, &wbc->index, wbc->end, tag, + &wbc->fbatch); +} + /** * 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 @@ -2414,41 +2430,32 @@ int write_cache_pages(struct address_space *mapping, void *data) { int error; - int nr_folios; - pgoff_t index; - pgoff_t end; /* Inclusive */ - xa_mark_t tag; =20 if (wbc->range_cyclic) { - index =3D mapping->writeback_index; /* prev offset */ - end =3D -1; + wbc->index =3D mapping->writeback_index; /* prev offset */ + wbc->end =3D -1; } else { - index =3D wbc->range_start >> PAGE_SHIFT; - end =3D wbc->range_end >> PAGE_SHIFT; + 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, index, end); - tag =3D PAGECACHE_TAG_TOWRITE; - } else { - tag =3D PAGECACHE_TAG_DIRTY; - } + if (wbc->sync_mode =3D=3D WB_SYNC_ALL || wbc->tagged_writepages) + tag_pages_for_writeback(mapping, wbc->index, wbc->end); =20 - wbc->done_index =3D index; + wbc->done_index =3D wbc->index; folio_batch_init(&wbc->fbatch); wbc->err =3D 0; =20 - while (index <=3D end) { + while (wbc->index <=3D wbc->end) { int i; =20 - nr_folios =3D filemap_get_folios_tag(mapping, &index, end, - tag, &wbc->fbatch); + writeback_get_batch(mapping, wbc); =20 - if (nr_folios =3D=3D 0) + if (wbc->fbatch.nr =3D=3D 0) break; =20 - for (i =3D 0; i < nr_folios; i++) { + for (i =3D 0; i < wbc->fbatch.nr; i++) { struct folio *folio =3D wbc->fbatch.folios[i]; =20 wbc->done_index =3D folio->index; @@ -2524,8 +2531,6 @@ int write_cache_pages(struct address_space *mapping, wbc->sync_mode =3D=3D WB_SYNC_NONE) return writeback_finish(mapping, wbc, true); } - folio_batch_release(&wbc->fbatch); - cond_resched(); } =20 return writeback_finish(mapping, wbc, false); --=20 2.39.2