From nobody Sun Feb 8 12:14:01 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 DCF1BEB64DC for ; Mon, 26 Jun 2023 17:36:26 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231298AbjFZRgZ (ORCPT ); Mon, 26 Jun 2023 13:36:25 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36682 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231214AbjFZRf5 (ORCPT ); Mon, 26 Jun 2023 13:35:57 -0400 Received: from casper.infradead.org (casper.infradead.org [IPv6:2001:8b0:10b:1236::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 1B02B2943; Mon, 26 Jun 2023 10:35:29 -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=X5nRO0yDxZXWnd7LdLo4tOM7JIHXSxr3v1Ba4laEERQ=; b=dHEryiCMCiT4PhowBmljTazeb4 RfsGun/8AwiFhnxjHPY2gvtCCziQPaTgjIcWGU73SOzA0fIcWSc+KbOLrgdYC4Zw96YeQhBZRALK/ NSBPdxwMWaRAijWdgrt+j34hxyho6y0P1lr64rSX2UkSY1tDGNfQdbrrGFebrtmHVEhAv0KlkYeFU ujdjqmyJB88r6R4mfBfQoxY25rsKXKRMoVEo5+adJIWvQ62By9WrCtZs+R2PDfdlY39s3mGEwpvNk KHhl2zlWg2zGwPsq6yaIwOvK4o9yUved9e1DKnPqix1EiRAggAwzHGMIQkutgfy3RkGGM5orcLDHJ 6asH01mQ==; Received: from willy by casper.infradead.org with local (Exim 4.94.2 #2 (Red Hat Linux)) id 1qDq7X-001vUz-9V; 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 01/12] writeback: Factor out writeback_finish() Date: Mon, 26 Jun 2023 18:35:10 +0100 Message-Id: <20230626173521.459345-2-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" Instead of having a 'done' variable that controls the nested loops, have a writeback_finish() that can be returned directly. This involves keeping more things in writeback_control, but it's just moving stuff allocated on the stack to being allocated slightly earlier on the stack. Signed-off-by: Matthew Wilcox (Oracle) --- include/linux/writeback.h | 6 ++++ mm/page-writeback.c | 74 +++++++++++++++++++++------------------ 2 files changed, 45 insertions(+), 35 deletions(-) diff --git a/include/linux/writeback.h b/include/linux/writeback.h index fba937999fbf..5b7d11f54013 100644 --- a/include/linux/writeback.h +++ b/include/linux/writeback.h @@ -11,6 +11,7 @@ #include #include #include +#include =20 struct bio; =20 @@ -52,6 +53,10 @@ struct writeback_control { loff_t range_start; loff_t range_end; =20 + struct folio_batch fbatch; + pgoff_t done_index; + int err; + enum writeback_sync_modes sync_mode; =20 unsigned for_kupdate:1; /* A kupdate writeback */ @@ -59,6 +64,7 @@ struct writeback_control { unsigned tagged_writepages:1; /* tag-and-write to avoid livelock */ unsigned for_reclaim:1; /* Invoked from the page allocator */ unsigned range_cyclic:1; /* range_start is cyclic */ + unsigned range_whole:1; /* entire file */ unsigned for_sync:1; /* sync(2) WB_SYNC_ALL writeback */ unsigned unpinned_fscache_wb:1; /* Cleared I_PINNING_FSCACHE_WB */ =20 diff --git a/mm/page-writeback.c b/mm/page-writeback.c index 1d17fb1ec863..abd7c0eebc72 100644 --- a/mm/page-writeback.c +++ b/mm/page-writeback.c @@ -2360,6 +2360,24 @@ void tag_pages_for_writeback(struct address_space *m= apping, } EXPORT_SYMBOL(tag_pages_for_writeback); =20 +static int writeback_finish(struct address_space *mapping, + struct writeback_control *wbc, bool done) +{ + folio_batch_release(&wbc->fbatch); + + /* + * If we hit the last page and there is more work to be done: + * wrap the index back to the start of the file for the next + * time we are called. + */ + if (wbc->range_cyclic && !done) + wbc->done_index =3D 0; + if (wbc->range_cyclic || (wbc->range_whole && wbc->nr_to_write > 0)) + mapping->writeback_index =3D wbc->done_index; + + return wbc->err; +} + /** * 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 @@ -2395,18 +2413,12 @@ int write_cache_pages(struct address_space *mapping, struct writeback_control *wbc, writepage_t writepage, void *data) { - int ret =3D 0; - int done =3D 0; int error; - struct folio_batch fbatch; int nr_folios; pgoff_t index; pgoff_t end; /* Inclusive */ - pgoff_t done_index; - int range_whole =3D 0; xa_mark_t tag; =20 - folio_batch_init(&fbatch); if (wbc->range_cyclic) { index =3D mapping->writeback_index; /* prev offset */ end =3D -1; @@ -2414,7 +2426,7 @@ int write_cache_pages(struct address_space *mapping, index =3D wbc->range_start >> PAGE_SHIFT; end =3D wbc->range_end >> PAGE_SHIFT; if (wbc->range_start =3D=3D 0 && wbc->range_end =3D=3D LLONG_MAX) - range_whole =3D 1; + wbc->range_whole =3D 1; } if (wbc->sync_mode =3D=3D WB_SYNC_ALL || wbc->tagged_writepages) { tag_pages_for_writeback(mapping, index, end); @@ -2422,20 +2434,24 @@ int write_cache_pages(struct address_space *mapping, } else { tag =3D PAGECACHE_TAG_DIRTY; } - done_index =3D index; - while (!done && (index <=3D end)) { + + wbc->done_index =3D index; + folio_batch_init(&wbc->fbatch); + wbc->err =3D 0; + + while (index <=3D end) { int i; =20 nr_folios =3D filemap_get_folios_tag(mapping, &index, end, - tag, &fbatch); + tag, &wbc->fbatch); =20 if (nr_folios =3D=3D 0) break; =20 for (i =3D 0; i < nr_folios; i++) { - struct folio *folio =3D fbatch.folios[i]; + struct folio *folio =3D wbc->fbatch.folios[i]; =20 - done_index =3D folio->index; + wbc->done_index =3D folio->index; =20 folio_lock(folio); =20 @@ -2488,14 +2504,14 @@ int write_cache_pages(struct address_space *mapping, folio_unlock(folio); error =3D 0; } else if (wbc->sync_mode !=3D WB_SYNC_ALL) { - ret =3D error; - done_index =3D folio->index + - folio_nr_pages(folio); - done =3D 1; - break; + wbc->err =3D error; + wbc->done_index =3D folio->index + + folio_nr_pages(folio); + return writeback_finish(mapping, + wbc, true); } - if (!ret) - ret =3D error; + if (!wbc->err) + wbc->err =3D error; } =20 /* @@ -2505,26 +2521,14 @@ int write_cache_pages(struct address_space *mapping, * we tagged for writeback prior to entering this loop. */ if (--wbc->nr_to_write <=3D 0 && - wbc->sync_mode =3D=3D WB_SYNC_NONE) { - done =3D 1; - break; - } + wbc->sync_mode =3D=3D WB_SYNC_NONE) + return writeback_finish(mapping, wbc, true); } - folio_batch_release(&fbatch); + folio_batch_release(&wbc->fbatch); cond_resched(); } =20 - /* - * If we hit the last page and there is more work to be done: wrap - * back the index back to the start of the file for the next - * time we are called. - */ - if (wbc->range_cyclic && !done) - done_index =3D 0; - if (wbc->range_cyclic || (range_whole && wbc->nr_to_write > 0)) - mapping->writeback_index =3D done_index; - - return ret; + return writeback_finish(mapping, wbc, false); } EXPORT_SYMBOL(write_cache_pages); =20 --=20 2.39.2 From nobody Sun Feb 8 12:14:01 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 From nobody Sun Feb 8 12:14:01 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 062DFEB64D7 for ; Mon, 26 Jun 2023 17:37:57 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231561AbjFZRhz (ORCPT ); Mon, 26 Jun 2023 13:37:55 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35964 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231175AbjFZRgS (ORCPT ); Mon, 26 Jun 2023 13:36:18 -0400 Received: from casper.infradead.org (casper.infradead.org [IPv6:2001:8b0:10b:1236::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 71AA32D4F; Mon, 26 Jun 2023 10:35:47 -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=v6PqW+r7ocyNrYaEadNjC9yXbOPBKSknhOaHoHVmJpk=; b=GH5JrXCeoj/GgOPu3iWjttA4pE R9WD1MiCBTid7jEiZMHLeGsbpndBGL7pWST3FhxBWC5vruJtb8/vXrvH0+f62gbXnsXZRlsky8pJq 9+M9D8g1czSuBHKCI6CMEd9w5TLyOR/pLQ95L/J/rI+M7DmyKqKs1a6+MLyLQd2/ds8H1fO846FuZ n8cEC0dArDnoP6JGY1ECb59L60b5jQv8FpFk5u65nzfMXMt5F7+6Z/YkjT4frnabjEqYJXLozDGS7 3U7dQlvwCi5sQU/ji6nNPG8IbAEl5U5k7LHM+ju+XzD5CgDWD6fjTcbsn7X1Y6zVcs+D6Xlzu9mZ+ XAvaJBew==; Received: from willy by casper.infradead.org with local (Exim 4.94.2 #2 (Red Hat Linux)) id 1qDq7X-001vV3-FD; 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 03/12] writeback: Factor should_writeback_folio() out of write_cache_pages() Date: Mon, 26 Jun 2023 18:35:12 +0100 Message-Id: <20230626173521.459345-4-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" Reduce write_cache_pages() by about 30 lines; much of it is commentary, but it all bundles nicely into an obvious function. Signed-off-by: Matthew Wilcox (Oracle) --- mm/page-writeback.c | 60 +++++++++++++++++++++++++-------------------- 1 file changed, 33 insertions(+), 27 deletions(-) diff --git a/mm/page-writeback.c b/mm/page-writeback.c index 67c7f1564727..54f2972dab45 100644 --- a/mm/page-writeback.c +++ b/mm/page-writeback.c @@ -2394,6 +2394,37 @@ static void writeback_get_batch(struct address_space= *mapping, &wbc->fbatch); } =20 +static bool should_writeback_folio(struct address_space *mapping, + struct writeback_control *wbc, struct folio *folio) +{ + /* + * Folio truncated or invalidated. We can freely skip it then, + * even for data integrity operations: the folio has disappeared + * concurrently, so there could be no real expectation of this + * data integrity operation even if there is now a new, dirty + * folio at the same pagecache index. + */ + if (unlikely(folio->mapping !=3D mapping)) + return false; + + /* Did somebody write it for us? */ + if (!folio_test_dirty(folio)) + return false; + + if (folio_test_writeback(folio)) { + if (wbc->sync_mode !=3D WB_SYNC_NONE) + folio_wait_writeback(folio); + else + return false; + } + + BUG_ON(folio_test_writeback(folio)); + if (!folio_clear_dirty_for_io(folio)) + return false; + + return true; +} + /** * 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 @@ -2461,38 +2492,13 @@ int write_cache_pages(struct address_space *mapping, wbc->done_index =3D folio->index; =20 folio_lock(folio); - - /* - * Page truncated or invalidated. We can freely skip it - * then, even for data integrity operations: the page - * has disappeared concurrently, so there could be no - * real expectation of this data integrity operation - * even if there is now a new, dirty page at the same - * pagecache address. - */ - if (unlikely(folio->mapping !=3D mapping)) { -continue_unlock: + if (!should_writeback_folio(mapping, wbc, folio)) { folio_unlock(folio); continue; } =20 - if (!folio_test_dirty(folio)) { - /* someone wrote it for us */ - goto continue_unlock; - } - - if (folio_test_writeback(folio)) { - if (wbc->sync_mode !=3D WB_SYNC_NONE) - folio_wait_writeback(folio); - else - goto continue_unlock; - } - - BUG_ON(folio_test_writeback(folio)); - if (!folio_clear_dirty_for_io(folio)) - goto continue_unlock; - trace_wbc_writepage(wbc, inode_to_bdi(mapping->host)); + error =3D writepage(folio, wbc, data); if (unlikely(error)) { /* --=20 2.39.2 From nobody Sun Feb 8 12:14:01 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 AB1C8EB64D7 for ; Mon, 26 Jun 2023 17:37:21 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230114AbjFZRhT (ORCPT ); Mon, 26 Jun 2023 13:37:19 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35720 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230047AbjFZRgH (ORCPT ); Mon, 26 Jun 2023 13:36:07 -0400 Received: from casper.infradead.org (casper.infradead.org [IPv6:2001:8b0:10b:1236::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 246EC10D7; Mon, 26 Jun 2023 10:35:41 -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=Hry/pakf3XrjxtX3FxEBHlEHaVaCFV/OlgXU52VAJV8=; b=jW+KKslSaTipXxmpNDSSeOnylL hzbQCyN3wKzjlszSqjc4HEgvviOgGGjspRJs0Vjv5zO3/R9XMbjtxpTsmS+9Gcwuw/ZcmCCyUnNeN H4tbBHnB66YtrhxCVg35T1Z99VBOHuc93t96BguJpmXgSVovFmRpL3E4/mslcgF20oYguKO1t+f7E aUfCqCMqXZB9pkY6yvUPK4VnHdbnXMwfDHnVDWMQUOAefkCf44Iu/CmD4lgC7Vnrxqd1w5+fQwu8z //QbapaLS3fMPaq6e7Ev6OQIihxf6gBxNalmqp3q/qnWQWabKWAZg/iTq63WdoLJnsWBSSCUnMJEx OM6BZUcg==; Received: from willy by casper.infradead.org with local (Exim 4.94.2 #2 (Red Hat Linux)) id 1qDq7X-001vV5-HI; 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 04/12] writeback: Simplify the loops in write_cache_pages() Date: Mon, 26 Jun 2023 18:35:13 +0100 Message-Id: <20230626173521.459345-5-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" Collapse the two nested loops into one. This is needed as a step towards turning this into an iterator. --- mm/page-writeback.c | 94 ++++++++++++++++++++++----------------------- 1 file changed, 47 insertions(+), 47 deletions(-) diff --git a/mm/page-writeback.c b/mm/page-writeback.c index 54f2972dab45..68f28eeb15ed 100644 --- a/mm/page-writeback.c +++ b/mm/page-writeback.c @@ -2461,6 +2461,7 @@ int write_cache_pages(struct address_space *mapping, void *data) { int error; + int i =3D 0; =20 if (wbc->range_cyclic) { wbc->index =3D mapping->writeback_index; /* prev offset */ @@ -2478,65 +2479,64 @@ int write_cache_pages(struct address_space *mapping, folio_batch_init(&wbc->fbatch); wbc->err =3D 0; =20 - while (wbc->index <=3D wbc->end) { - int i; - - writeback_get_batch(mapping, wbc); + for (;;) { + struct folio *folio; =20 + if (i =3D=3D wbc->fbatch.nr) { + writeback_get_batch(mapping, wbc); + i =3D 0; + } if (wbc->fbatch.nr =3D=3D 0) break; =20 - for (i =3D 0; i < wbc->fbatch.nr; i++) { - struct folio *folio =3D wbc->fbatch.folios[i]; + folio =3D wbc->fbatch.folios[i++]; =20 - wbc->done_index =3D folio->index; + wbc->done_index =3D folio->index; =20 - folio_lock(folio); - if (!should_writeback_folio(mapping, wbc, folio)) { - folio_unlock(folio); - continue; - } + folio_lock(folio); + if (!should_writeback_folio(mapping, wbc, folio)) { + folio_unlock(folio); + continue; + } =20 - trace_wbc_writepage(wbc, inode_to_bdi(mapping->host)); - - error =3D writepage(folio, wbc, data); - if (unlikely(error)) { - /* - * Handle errors according to the type of - * writeback. There's no need to continue for - * background writeback. Just push done_index - * past this page so media errors won't choke - * writeout for the entire file. For integrity - * writeback, we must process the entire dirty - * set regardless of errors because the fs may - * still have state to clear for each page. In - * that case we continue processing and return - * the first error. - */ - if (error =3D=3D AOP_WRITEPAGE_ACTIVATE) { - folio_unlock(folio); - error =3D 0; - } else if (wbc->sync_mode !=3D WB_SYNC_ALL) { - wbc->err =3D error; - wbc->done_index =3D folio->index + - folio_nr_pages(folio); - return writeback_finish(mapping, - wbc, true); - } - if (!wbc->err) - wbc->err =3D error; - } + trace_wbc_writepage(wbc, inode_to_bdi(mapping->host)); =20 + error =3D writepage(folio, wbc, data); + if (unlikely(error)) { /* - * We stop writing back only if we are not doing - * integrity sync. In case of integrity sync we have to - * keep going until we have written all the pages - * we tagged for writeback prior to entering this loop. + * Handle errors according to the type of + * writeback. There's no need to continue for + * background writeback. Just push done_index + * past this page so media errors won't choke + * writeout for the entire file. For integrity + * writeback, we must process the entire dirty + * set regardless of errors because the fs may + * still have state to clear for each page. In + * that case we continue processing and return + * the first error. */ - if (--wbc->nr_to_write <=3D 0 && - wbc->sync_mode =3D=3D WB_SYNC_NONE) + if (error =3D=3D AOP_WRITEPAGE_ACTIVATE) { + folio_unlock(folio); + error =3D 0; + } else if (wbc->sync_mode !=3D WB_SYNC_ALL) { + wbc->err =3D error; + wbc->done_index =3D folio->index + + folio_nr_pages(folio); return writeback_finish(mapping, wbc, true); + } + if (!wbc->err) + wbc->err =3D error; } + + /* + * We stop writing back only if we are not doing + * integrity sync. In case of integrity sync we have to + * keep going until we have written all the pages + * we tagged for writeback prior to entering this loop. + */ + if (--wbc->nr_to_write <=3D 0 && + wbc->sync_mode =3D=3D WB_SYNC_NONE) + return writeback_finish(mapping, wbc, true); } =20 return writeback_finish(mapping, wbc, false); --=20 2.39.2 From nobody Sun Feb 8 12:14:01 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 B6948EB64D9 for ; Mon, 26 Jun 2023 17:36:50 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230154AbjFZRgs (ORCPT ); Mon, 26 Jun 2023 13:36:48 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36712 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229501AbjFZRgB (ORCPT ); Mon, 26 Jun 2023 13:36:01 -0400 Received: from casper.infradead.org (casper.infradead.org [IPv6:2001:8b0:10b:1236::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 302162952; Mon, 26 Jun 2023 10:35:32 -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=E+4oLVAPfstR5U6aMi6Troa+YNi9gddz/xau+Gpg+rc=; b=UixsKVyP80nb0Gf7F4Lg+jN462 veiCIiZ5m1gznewobjOw1LIlCVl+NQ9bzKtGc1cy/FIFA2ZFOyC31yskGu3ZRnQRQ486TqTOhj/gr MYy4BGRtCU3MWPXCVKFnpYRI0SO+7rxcxT4MHuv18Sude5qsPpa5V0wVCVDJPMg+CxWSEWOj5iYYW AJDD8UCC+LOhQrktHVtCdUQ+V85q2O0pIp+RIDy4myAwlxwJ/KnWBqgsQgybdKyrahLZIt/KPAliX Z7BL5LWIbRipCNRi/kU84/66Ojv2G0K94IDEtnbMk2QxnYFxyp6hwCZ51e4XG35VOJT7z4XE1c+22 +qrDsMow==; Received: from willy by casper.infradead.org with local (Exim 4.94.2 #2 (Red Hat Linux)) id 1qDq7X-001vV7-Jz; 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 05/12] pagevec: Add ability to iterate a queue Date: Mon, 26 Jun 2023 18:35:14 +0100 Message-Id: <20230626173521.459345-6-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" Add a loop counter inside the folio_batch to let us iterate from 0-nr instead of decrementing nr and treating the batch as a stack. It would generate some very weird and suboptimal I/O patterns for page writeback to iterate over the batch as a stack. Signed-off-by: Matthew Wilcox (Oracle) --- include/linux/pagevec.h | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/include/linux/pagevec.h b/include/linux/pagevec.h index 87cc678adc85..fcc06c300a72 100644 --- a/include/linux/pagevec.h +++ b/include/linux/pagevec.h @@ -27,6 +27,7 @@ struct folio; */ struct folio_batch { unsigned char nr; + unsigned char i; bool percpu_pvec_drained; struct folio *folios[PAGEVEC_SIZE]; }; @@ -40,12 +41,14 @@ struct folio_batch { static inline void folio_batch_init(struct folio_batch *fbatch) { fbatch->nr =3D 0; + fbatch->i =3D 0; fbatch->percpu_pvec_drained =3D false; } =20 static inline void folio_batch_reinit(struct folio_batch *fbatch) { fbatch->nr =3D 0; + fbatch->i =3D 0; } =20 static inline unsigned int folio_batch_count(struct folio_batch *fbatch) @@ -75,6 +78,21 @@ static inline unsigned folio_batch_add(struct folio_batc= h *fbatch, return folio_batch_space(fbatch); } =20 +/** + * folio_batch_next - Return the next folio to process. + * @fbatch: The folio batch being processed. + * + * Use this function to implement a queue of folios. + * + * Return: The next folio in the queue, or NULL if the queue is empty. + */ +static inline struct folio *folio_batch_next(struct folio_batch *fbatch) +{ + if (fbatch->i =3D=3D fbatch->nr) + return NULL; + return fbatch->folios[fbatch->i++]; +} + void __folio_batch_release(struct folio_batch *pvec); =20 static inline void folio_batch_release(struct folio_batch *fbatch) --=20 2.39.2 From nobody Sun Feb 8 12:14:01 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 A514AEB64D7 for ; Mon, 26 Jun 2023 17:36:52 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231462AbjFZRgu (ORCPT ); Mon, 26 Jun 2023 13:36:50 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36718 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229584AbjFZRgB (ORCPT ); Mon, 26 Jun 2023 13:36:01 -0400 Received: from casper.infradead.org (casper.infradead.org [IPv6:2001:8b0:10b:1236::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 21687295B; Mon, 26 Jun 2023 10:35:35 -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=9GHSvlYBgCYCqD7sma1ZZnKYfGDXP4peUgN6BejXrU0=; b=H2DjqGYqS0ifPU6GyJXK8/BxHu vFVfQGhUx+x0NN019oG/9u6ta/c935isFdskogz6Zi5wk9YpfV1rQeHd3yOr16sdWHX3Sm1wYo4Tl q8Fc6gm3j5a09vRX3D7oa0aXQ+iDxgDnkfjvdQIGdTEVvqcbxfdqAXQOe5yO1SaLR+j0jt7+c+sW9 Pf8KrI7ur+AjXLjxw7Oxzr9qKsXddBrG4X2eYIqgC9KINNGsUfczjLXew+6IH5c7gUiUOekAEY/4T S1ZXhpeY87W/eVlS6lP9H5r3hIaN6in+5mIpOPY/vuuee0LlE5XFsUlbax1JnG8mOLDe9HZw6BXwb 4sjyyKCg==; Received: from willy by casper.infradead.org with local (Exim 4.94.2 #2 (Red Hat Linux)) id 1qDq7X-001vV9-Mf; 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 06/12] writeback: Use the folio_batch queue iterator Date: Mon, 26 Jun 2023 18:35:15 +0100 Message-Id: <20230626173521.459345-7-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" Instead of keeping our own local iterator variable, use the one just added to folio_batch. Signed-off-by: Matthew Wilcox (Oracle) --- mm/page-writeback.c | 18 ++++++++---------- 1 file changed, 8 insertions(+), 10 deletions(-) diff --git a/mm/page-writeback.c b/mm/page-writeback.c index 68f28eeb15ed..f782b48c5b0c 100644 --- a/mm/page-writeback.c +++ b/mm/page-writeback.c @@ -2378,11 +2378,15 @@ static int writeback_finish(struct address_space *m= apping, return wbc->err; } =20 -static void writeback_get_batch(struct address_space *mapping, +static struct folio *writeback_get_next(struct address_space *mapping, struct writeback_control *wbc) { + struct folio *folio =3D folio_batch_next(&wbc->fbatch); xa_mark_t tag; =20 + if (folio) + return folio; + if (wbc->sync_mode =3D=3D WB_SYNC_ALL || wbc->tagged_writepages) tag =3D PAGECACHE_TAG_TOWRITE; else @@ -2392,6 +2396,7 @@ static void writeback_get_batch(struct address_space = *mapping, cond_resched(); filemap_get_folios_tag(mapping, &wbc->index, wbc->end, tag, &wbc->fbatch); + return folio_batch_next(&wbc->fbatch); } =20 static bool should_writeback_folio(struct address_space *mapping, @@ -2461,7 +2466,6 @@ int write_cache_pages(struct address_space *mapping, void *data) { int error; - int i =3D 0; =20 if (wbc->range_cyclic) { wbc->index =3D mapping->writeback_index; /* prev offset */ @@ -2480,17 +2484,11 @@ int write_cache_pages(struct address_space *mapping, wbc->err =3D 0; =20 for (;;) { - struct folio *folio; + struct folio *folio =3D writeback_get_next(mapping, wbc); =20 - if (i =3D=3D wbc->fbatch.nr) { - writeback_get_batch(mapping, wbc); - i =3D 0; - } - if (wbc->fbatch.nr =3D=3D 0) + if (!folio) break; =20 - folio =3D wbc->fbatch.folios[i++]; - wbc->done_index =3D folio->index; =20 folio_lock(folio); --=20 2.39.2 From nobody Sun Feb 8 12:14:01 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 From nobody Sun Feb 8 12:14:01 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 1F56DEB64D9 for ; Mon, 26 Jun 2023 17:36:24 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230513AbjFZRgW (ORCPT ); Mon, 26 Jun 2023 13:36:22 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36332 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231666AbjFZRf4 (ORCPT ); Mon, 26 Jun 2023 13:35:56 -0400 Received: from casper.infradead.org (casper.infradead.org [IPv6:2001:8b0:10b:1236::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 1FC05272C; Mon, 26 Jun 2023 10:35:27 -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=4j8qD1VIDkeu8FuhbX23YTq3SVJUsBomytwghqZoPiA=; b=jO+IuqRONCDpfM0ToVlDzBovD9 NnIpFqCSVbzcdzA354Ai8J4uwvQXN3vjxzaPqsdl/xu+9TkLDzcRKCal7PcOkbcF4dV4DToUbguua DhQc5GIdojQ+898Vu6UjYABB/NZtHhCqnv6dR6n3B4zANWT8SgicSzfUO8KQHTKbqL3iiVruTyBBi TgOxqzuFcqc3rCbML9MBL2LZcXwzT5+YcSAaJsyE93G9W7FkKk1k0a6BL0e2AQngll3EYEidWhOx1 MbKdipsmpf8sBpR98d+bhM2uO0wX76Fuou4HTdMTNuQoYS1f6L3Oed9cA/g5bqwApTqNnCdDFN0wS UGzEVQmg==; Received: from willy by casper.infradead.org with local (Exim 4.94.2 #2 (Red Hat Linux)) id 1qDq7X-001vVD-S2; 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 08/12] writeback: Factor writeback_get_folio() out of write_cache_pages() Date: Mon, 26 Jun 2023 18:35:17 +0100 Message-Id: <20230626173521.459345-9-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" Move the loop for should-we-write-this-folio to its own function. Signed-off-by: Matthew Wilcox (Oracle) --- mm/page-writeback.c | 35 +++++++++++++++++++++++------------ 1 file changed, 23 insertions(+), 12 deletions(-) diff --git a/mm/page-writeback.c b/mm/page-writeback.c index 18f332611a52..659df2b5c7c0 100644 --- a/mm/page-writeback.c +++ b/mm/page-writeback.c @@ -2430,6 +2430,27 @@ static bool should_writeback_folio(struct address_sp= ace *mapping, return true; } =20 +static struct folio *writeback_get_folio(struct address_space *mapping, + struct writeback_control *wbc) +{ + struct folio *folio; + + for (;;) { + folio =3D writeback_get_next(mapping, wbc); + if (!folio) + return NULL; + wbc->done_index =3D folio->index; + + folio_lock(folio); + if (likely(should_writeback_folio(mapping, wbc, folio))) + break; + folio_unlock(folio); + } + + trace_wbc_writepage(wbc, inode_to_bdi(mapping->host)); + return folio; +} + static struct folio *writeback_iter_init(struct address_space *mapping, struct writeback_control *wbc) { @@ -2449,7 +2470,7 @@ static struct folio *writeback_iter_init(struct addre= ss_space *mapping, folio_batch_init(&wbc->fbatch); wbc->err =3D 0; =20 - return writeback_get_next(mapping, wbc); + return writeback_get_folio(mapping, wbc); } =20 /** @@ -2492,17 +2513,7 @@ int write_cache_pages(struct address_space *mapping, =20 for (folio =3D writeback_iter_init(mapping, wbc); folio; - folio =3D writeback_get_next(mapping, wbc)) { - wbc->done_index =3D folio->index; - - folio_lock(folio); - if (!should_writeback_folio(mapping, wbc, folio)) { - folio_unlock(folio); - continue; - } - - trace_wbc_writepage(wbc, inode_to_bdi(mapping->host)); - + folio =3D writeback_get_folio(mapping, wbc)) { error =3D writepage(folio, wbc, data); if (unlikely(error)) { /* --=20 2.39.2 From nobody Sun Feb 8 12:14:01 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 51F31EB64D7 for ; Mon, 26 Jun 2023 17:36:31 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231377AbjFZRg3 (ORCPT ); Mon, 26 Jun 2023 13:36:29 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36686 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230189AbjFZRf6 (ORCPT ); Mon, 26 Jun 2023 13:35:58 -0400 Received: from casper.infradead.org (casper.infradead.org [IPv6:2001:8b0:10b:1236::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 7458E2947; Mon, 26 Jun 2023 10:35:29 -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=E3aum7WU0bI7IZ184SOLo7ZVUjIFr4d1vA4qDi5sBMk=; b=rbgGQajzMWS1Zvm8l8B087MlBY fs44oUGNMU1wvCmN1CEVg8sLCwUHuiJlE08WOgKcUUJtDr9vSnXdpzQu4hlEVqGAcXaOveiLHWRJ1 1u6GHkry9xBdQ+r/N6cioIMqR/K0lH0Jf8YA7KNQuh3yKOHri1HNfo7aRakN0NWaL9VTHfI+TFQux TOzoFNpy0Ud+oGkcZUrTaqQ9Vujxhrvbn5RT2aQviJhsaKZjlRED4Zewl45kh+nmk/MNYILFiyZO1 5iKDAXUGwGzrxMmiWKexkmO63AcO7cu39YjbMncfmuaVnM7mc9wjySOtqZrDnAo8xwQ4xeVmtsNpf ddtVl8Nw==; Received: from willy by casper.infradead.org with local (Exim 4.94.2 #2 (Red Hat Linux)) id 1qDq7X-001vVG-VE; Mon, 26 Jun 2023 17:35:24 +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 09/12] writeback: Factor writeback_iter_next() out of write_cache_pages() Date: Mon, 26 Jun 2023 18:35:18 +0100 Message-Id: <20230626173521.459345-10-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" Pull the post-processing of the writepage_t callback into a separate function. That means changing writeback_finish() to return NULL, and writeback_get_next() to call writeback_finish() when we naturally run out of folios. Signed-off-by: Matthew Wilcox (Oracle) --- mm/page-writeback.c | 84 ++++++++++++++++++++++++--------------------- 1 file changed, 44 insertions(+), 40 deletions(-) diff --git a/mm/page-writeback.c b/mm/page-writeback.c index 659df2b5c7c0..ef61d7006c5e 100644 --- a/mm/page-writeback.c +++ b/mm/page-writeback.c @@ -2360,7 +2360,7 @@ void tag_pages_for_writeback(struct address_space *ma= pping, } EXPORT_SYMBOL(tag_pages_for_writeback); =20 -static int writeback_finish(struct address_space *mapping, +static struct folio *writeback_finish(struct address_space *mapping, struct writeback_control *wbc, bool done) { folio_batch_release(&wbc->fbatch); @@ -2375,7 +2375,7 @@ static int writeback_finish(struct address_space *map= ping, if (wbc->range_cyclic || (wbc->range_whole && wbc->nr_to_write > 0)) mapping->writeback_index =3D wbc->done_index; =20 - return wbc->err; + return NULL; } =20 static struct folio *writeback_get_next(struct address_space *mapping, @@ -2438,7 +2438,7 @@ static struct folio *writeback_get_folio(struct addre= ss_space *mapping, for (;;) { folio =3D writeback_get_next(mapping, wbc); if (!folio) - return NULL; + return writeback_finish(mapping, wbc, false); wbc->done_index =3D folio->index; =20 folio_lock(folio); @@ -2473,6 +2473,45 @@ static struct folio *writeback_iter_init(struct addr= ess_space *mapping, return writeback_get_folio(mapping, wbc); } =20 +static struct folio *writeback_iter_next(struct address_space *mapping, + struct writeback_control *wbc, struct folio *folio, int error) +{ + if (unlikely(error)) { + /* + * Handle errors according to the type of writeback. + * There's no need to continue for background writeback. + * Just push done_index past this folio so media + * errors won't choke writeout for the entire file. + * For integrity writeback, we must process the entire + * dirty set regardless of errors because the fs may + * still have state to clear for each folio. In that + * case we continue processing and return the first error. + */ + if (error =3D=3D AOP_WRITEPAGE_ACTIVATE) { + folio_unlock(folio); + error =3D 0; + } else if (wbc->sync_mode !=3D WB_SYNC_ALL) { + wbc->err =3D error; + wbc->done_index =3D folio->index + + folio_nr_pages(folio); + return writeback_finish(mapping, wbc, true); + } + if (!wbc->err) + wbc->err =3D error; + } + + /* + * We stop writing back only if we are not doing integrity + * sync. In case of integrity sync we have to keep going until + * we have written all the folios we tagged for writeback prior + * to entering this loop. + */ + if (--wbc->nr_to_write <=3D 0 && wbc->sync_mode =3D=3D WB_SYNC_NONE) + return writeback_finish(mapping, wbc, true); + + return writeback_get_folio(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 @@ -2513,46 +2552,11 @@ int write_cache_pages(struct address_space *mapping, =20 for (folio =3D writeback_iter_init(mapping, wbc); folio; - folio =3D writeback_get_folio(mapping, wbc)) { + folio =3D writeback_iter_next(mapping, wbc, folio, error)) { error =3D writepage(folio, wbc, data); - if (unlikely(error)) { - /* - * Handle errors according to the type of - * writeback. There's no need to continue for - * background writeback. Just push done_index - * past this page so media errors won't choke - * writeout for the entire file. For integrity - * writeback, we must process the entire dirty - * set regardless of errors because the fs may - * still have state to clear for each page. In - * that case we continue processing and return - * the first error. - */ - if (error =3D=3D AOP_WRITEPAGE_ACTIVATE) { - folio_unlock(folio); - error =3D 0; - } else if (wbc->sync_mode !=3D WB_SYNC_ALL) { - wbc->err =3D error; - wbc->done_index =3D folio->index + - folio_nr_pages(folio); - return writeback_finish(mapping, wbc, true); - } - if (!wbc->err) - wbc->err =3D error; - } - - /* - * We stop writing back only if we are not doing - * integrity sync. In case of integrity sync we have to - * keep going until we have written all the pages - * we tagged for writeback prior to entering this loop. - */ - if (--wbc->nr_to_write <=3D 0 && - wbc->sync_mode =3D=3D WB_SYNC_NONE) - return writeback_finish(mapping, wbc, true); } =20 - return writeback_finish(mapping, wbc, false); + return wbc->err; } EXPORT_SYMBOL(write_cache_pages); =20 --=20 2.39.2 From nobody Sun Feb 8 12:14:01 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 46054EB64D9 for ; Mon, 26 Jun 2023 17:36:47 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231429AbjFZRgp (ORCPT ); Mon, 26 Jun 2023 13:36:45 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35964 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231682AbjFZRgB (ORCPT ); Mon, 26 Jun 2023 13:36:01 -0400 Received: from casper.infradead.org (casper.infradead.org [IPv6:2001:8b0:10b:1236::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 75E542955; Mon, 26 Jun 2023 10:35:32 -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=DbRDOwy4aGYzGm5HeqIsIhOnoGhV3uqwtbzHnV71lmw=; b=W1PA+/Bi8v1fqLdsB7yl772V0f RgwlNsF3bvGRmX6GeWkooNi1wYpT1f3iUIzX4l7MUM38mQ9Zw5s7SQOuMEMB53KdS5tSL+OHJSisS K87JMB2fNoyImDp7TG+shhEPLoq4/BISTARhOn43kcMebEMFO3G44dQ5TWC3FZLmULKJjwLPoTUNq WUIpgwde5+sWTO8N2dyN3HIV4wxNNuQ+5Pvpm5cCn3mV9Sxw1bvQhXNl0ETOjQa+6UJarTN7j2N2A ahz+Xz2UCRm0wunSNn5GNma/A151vXBBaymuvJ4fLZ0+HcnPGNDiVY6mFsk/ZzC0yxz2xPztK9RUp bM2BXbXg==; Received: from willy by casper.infradead.org with local (Exim 4.94.2 #2 (Red Hat Linux)) id 1qDq7Y-001vVI-28; Mon, 26 Jun 2023 17:35:24 +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 10/12] writeback: Add for_each_writeback_folio() Date: Mon, 26 Jun 2023 18:35:19 +0100 Message-Id: <20230626173521.459345-11-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" Wrap up the iterator with a nice bit of syntactic sugar. Now the caller doesn't need to know about wbc->err and can just return error, not knowing that the iterator took care of storing errors correctly. Signed-off-by: Matthew Wilcox (Oracle) --- include/linux/writeback.h | 14 +++++++++++--- mm/page-writeback.c | 11 ++++------- 2 files changed, 15 insertions(+), 10 deletions(-) diff --git a/include/linux/writeback.h b/include/linux/writeback.h index 7dd050b40e4b..84d5306ef045 100644 --- a/include/linux/writeback.h +++ b/include/linux/writeback.h @@ -369,14 +369,22 @@ int balance_dirty_pages_ratelimited_flags(struct addr= ess_space *mapping, =20 bool wb_over_bg_thresh(struct bdi_writeback *wb); =20 +struct folio *writeback_iter_init(struct address_space *mapping, + struct writeback_control *wbc); +struct folio *writeback_iter_next(struct address_space *mapping, + struct writeback_control *wbc, struct folio *folio, int error); + +#define for_each_writeback_folio(mapping, wbc, folio, error) \ + for (folio =3D writeback_iter_init(mapping, wbc); \ + folio || ((error =3D wbc->err), false); \ + folio =3D writeback_iter_next(mapping, wbc, folio, error)) + typedef int (*writepage_t)(struct folio *folio, struct writeback_control *= wbc, void *data); - -void tag_pages_for_writeback(struct address_space *mapping, - pgoff_t start, pgoff_t end); int write_cache_pages(struct address_space *mapping, struct writeback_control *wbc, writepage_t writepage, void *data); + int do_writepages(struct address_space *mapping, struct writeback_control = *wbc); void writeback_set_ratelimit(void); void tag_pages_for_writeback(struct address_space *mapping, diff --git a/mm/page-writeback.c b/mm/page-writeback.c index ef61d7006c5e..245d6318dfb2 100644 --- a/mm/page-writeback.c +++ b/mm/page-writeback.c @@ -2451,7 +2451,7 @@ static struct folio *writeback_get_folio(struct addre= ss_space *mapping, return folio; } =20 -static struct folio *writeback_iter_init(struct address_space *mapping, +struct folio *writeback_iter_init(struct address_space *mapping, struct writeback_control *wbc) { if (wbc->range_cyclic) { @@ -2473,7 +2473,7 @@ static struct folio *writeback_iter_init(struct addre= ss_space *mapping, return writeback_get_folio(mapping, wbc); } =20 -static struct folio *writeback_iter_next(struct address_space *mapping, +struct folio *writeback_iter_next(struct address_space *mapping, struct writeback_control *wbc, struct folio *folio, int error) { if (unlikely(error)) { @@ -2550,13 +2550,10 @@ int write_cache_pages(struct address_space *mapping, struct folio *folio; int error; =20 - for (folio =3D writeback_iter_init(mapping, wbc); - folio; - folio =3D writeback_iter_next(mapping, wbc, folio, error)) { + for_each_writeback_folio(mapping, wbc, folio, error) error =3D writepage(folio, wbc, data); - } =20 - return wbc->err; + return error; } EXPORT_SYMBOL(write_cache_pages); =20 --=20 2.39.2 From nobody Sun Feb 8 12:14:01 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 BA8E7EB64DC for ; Mon, 26 Jun 2023 17:36:20 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230308AbjFZRgS (ORCPT ); Mon, 26 Jun 2023 13:36:18 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36554 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231670AbjFZRf4 (ORCPT ); Mon, 26 Jun 2023 13:35:56 -0400 Received: from casper.infradead.org (casper.infradead.org [IPv6:2001:8b0:10b:1236::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C6A562738; Mon, 26 Jun 2023 10:35:27 -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=sd4UR031RbDntAg7Q2TtCsIA81STdESVBYZOrBi6xDM=; b=qIKh3LKNsyIKL6wn9vPVDEzZ+D eEqSPJa/7CQUC5xinii35WBEGVSuPYk98nQd3Rk665j4winBw8s0gcTwod5j//SI78kDfO8LiKpb2 QxPbWsAW0AuHq/5s0VxBqJ9MT/wDfN/+rlOdpY2Fk2YtsFFIPIG9BsONHh4138hmsct/3ELFT9roh e0+vNhPUTa71jfAWtaK5OPKL2MmIEixL3WqzjOmsa18TETHpzf2dOygWdHq4KBAPddiWMAqpgRmR3 ydq70lu0ywMlmKyHpMvrSv53DWf8nfN6Ya3A+O2Bn3zHyOeojHJDOD+gOEsd739ZMiyDu/U2u0Yl8 Ak2tJitA==; Received: from willy by casper.infradead.org with local (Exim 4.94.2 #2 (Red Hat Linux)) id 1qDq7Y-001vVK-58; Mon, 26 Jun 2023 17:35:24 +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 11/12] iomap: Convert iomap_writepages() to use for_each_writeback_folio() Date: Mon, 26 Jun 2023 18:35:20 +0100 Message-Id: <20230626173521.459345-12-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 removes one indirect function call per folio, and adds typesafety by not casting through a void pointer. Signed-off-by: Matthew Wilcox (Oracle) --- fs/iomap/buffered-io.c | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/fs/iomap/buffered-io.c b/fs/iomap/buffered-io.c index a4fa81af60d9..a4dd17abe244 100644 --- a/fs/iomap/buffered-io.c +++ b/fs/iomap/buffered-io.c @@ -1711,9 +1711,8 @@ iomap_writepage_map(struct iomap_writepage_ctx *wpc, * regular allocated space. */ static int iomap_do_writepage(struct folio *folio, - struct writeback_control *wbc, void *data) + struct writeback_control *wbc, struct iomap_writepage_ctx *wpc) { - struct iomap_writepage_ctx *wpc =3D data; struct inode *inode =3D folio->mapping->host; u64 end_pos, isize; =20 @@ -1810,13 +1809,16 @@ iomap_writepages(struct address_space *mapping, str= uct writeback_control *wbc, struct iomap_writepage_ctx *wpc, const struct iomap_writeback_ops *ops) { - int ret; + struct folio *folio; + int err; =20 wpc->ops =3D ops; - ret =3D write_cache_pages(mapping, wbc, iomap_do_writepage, wpc); + for_each_writeback_folio(mapping, wbc, folio, err) + err =3D iomap_do_writepage(folio, wbc, wpc); + if (!wpc->ioend) - return ret; - return iomap_submit_ioend(wpc, wpc->ioend, ret); + return err; + return iomap_submit_ioend(wpc, wpc->ioend, err); } EXPORT_SYMBOL_GPL(iomap_writepages); =20 --=20 2.39.2 From nobody Sun Feb 8 12:14:01 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 861DEEB64D7 for ; Mon, 26 Jun 2023 17:36:55 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230173AbjFZRgy (ORCPT ); Mon, 26 Jun 2023 13:36:54 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36724 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229621AbjFZRgC (ORCPT ); Mon, 26 Jun 2023 13:36:02 -0400 Received: from casper.infradead.org (casper.infradead.org [IPv6:2001:8b0:10b:1236::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 6B418295C; Mon, 26 Jun 2023 10:35:35 -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=ImqynQi+azeOKkPbJPWnsB36hvgJ5MojMLeTL2XpTIs=; b=EnXvWYXx+3E+jBbF7Z3B+1Gi/T yYgl8ytz+fZoD1bsHwC8cXajllUXh279ulAn62xGFuLds1WNXkGTXCQQEyIO2oWdLPtMZma2d/AMg 5Su9uB7fPivq5SeGFfjxhRCguvBEtuQ+YT74zwhANJ5gvelakTfU9l8U8T0yUP1L00nf5upXTXCP+ Tl1v60WsSro8t+8iDng1kThDvglAI8CetB6z50p5gO6KiKgThZkNJZBBkCDUuV1iH9gr8bU4TyNAL wyAv9pc62eib4kBG2gca6eQc6JVqDCIx0YaYqXUQ3JQrqmBSOGcIkls/+Yr7M2SL3Upaqt+O1iEA3 6Vw5OxJw==; Received: from willy by casper.infradead.org with local (Exim 4.94.2 #2 (Red Hat Linux)) id 1qDq7Y-001vVM-AH; Mon, 26 Jun 2023 17:35:24 +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 12/12] writeback: Remove a use of write_cache_pages() from do_writepages() Date: Mon, 26 Jun 2023 18:35:21 +0100 Message-Id: <20230626173521.459345-13-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" Use the new for_each_writeback_folio() directly instead of indirecting through a callback. Signed-off-by: Matthew Wilcox (Oracle) --- mm/page-writeback.c | 27 +++++++++++++++------------ 1 file changed, 15 insertions(+), 12 deletions(-) diff --git a/mm/page-writeback.c b/mm/page-writeback.c index 245d6318dfb2..55832679af21 100644 --- a/mm/page-writeback.c +++ b/mm/page-writeback.c @@ -2557,13 +2557,21 @@ int write_cache_pages(struct address_space *mapping, } EXPORT_SYMBOL(write_cache_pages); =20 -static int writepage_cb(struct folio *folio, struct writeback_control *wbc, - void *data) +static int writeback_use_writepage(struct address_space *mapping, + struct writeback_control *wbc) { - struct address_space *mapping =3D data; - int ret =3D mapping->a_ops->writepage(&folio->page, wbc); - mapping_set_error(mapping, ret); - return ret; + struct blk_plug plug; + struct folio *folio; + int err; + + blk_start_plug(&plug); + for_each_writeback_folio(mapping, wbc, folio, err) { + err =3D mapping->a_ops->writepage(&folio->page, wbc); + mapping_set_error(mapping, err); + } + blk_finish_plug(&plug); + + return err; } =20 int do_writepages(struct address_space *mapping, struct writeback_control = *wbc) @@ -2579,12 +2587,7 @@ int do_writepages(struct address_space *mapping, str= uct writeback_control *wbc) if (mapping->a_ops->writepages) { ret =3D mapping->a_ops->writepages(mapping, wbc); } else if (mapping->a_ops->writepage) { - struct blk_plug plug; - - blk_start_plug(&plug); - ret =3D write_cache_pages(mapping, wbc, writepage_cb, - mapping); - blk_finish_plug(&plug); + ret =3D writeback_use_writepage(mapping, wbc); } else { /* deal with chardevs and other special files */ ret =3D 0; --=20 2.39.2