From nobody Tue Feb 10 01:19:37 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