From mboxrd@z Thu Jan 1 00:00:00 1970 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 kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id D3F9EEB64D9 for ; Mon, 26 Jun 2023 17:35:33 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 2ADCF8D0008; Mon, 26 Jun 2023 13:35:32 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 1BC7E8D0006; Mon, 26 Jun 2023 13:35:31 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id DF5AF8D0007; Mon, 26 Jun 2023 13:35:31 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0017.hostedemail.com [216.40.44.17]) by kanga.kvack.org (Postfix) with ESMTP id C30528D0002 for ; Mon, 26 Jun 2023 13:35:31 -0400 (EDT) Received: from smtpin14.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay10.hostedemail.com (Postfix) with ESMTP id 753B9C07EE for ; Mon, 26 Jun 2023 17:35:31 +0000 (UTC) X-FDA: 80945600862.14.0B460B7 Received: from casper.infradead.org (casper.infradead.org [90.155.50.34]) by imf01.hostedemail.com (Postfix) with ESMTP id B5EA540009 for ; Mon, 26 Jun 2023 17:35:29 +0000 (UTC) Authentication-Results: imf01.hostedemail.com; dkim=pass header.d=infradead.org header.s=casper.20170209 header.b=rbgGQajz; spf=none (imf01.hostedemail.com: domain of willy@infradead.org has no SPF policy when checking 90.155.50.34) smtp.mailfrom=willy@infradead.org; dmarc=none ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1687800929; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=E3aum7WU0bI7IZ184SOLo7ZVUjIFr4d1vA4qDi5sBMk=; b=gy3/39lbQ6Px3Rz/+8/ScRnW+YGaXVzTB/517JL+ICVQBkWqjvpaHYGxRLX1u6dJVjn25L U/0Ox6CHqH5QLBD3aXnTDxmq/LbjBBphcOrWUO2FiswHjo3hDz97KUI4ePs2hrq7FLUTYh c4IkgvR71v8xVyKGpnEnynn1G8dAngI= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1687800929; a=rsa-sha256; cv=none; b=SbKaYjk3F4mrSC4Mf2w0LmfPxLH9N4a/hyvyCLb65SJcM0qASoDhQgcy4MREU3NU98L425 6aFu9PXt9r5S/UahwJPdqqQhir0/LRoA8WZzG7boc9ttF2bW4wgr4Mui8FVhLdSklLJPrI 21XH4Xaw0xPfcjL7WSBxhQ/6UB3kY1k= ARC-Authentication-Results: i=1; imf01.hostedemail.com; dkim=pass header.d=infradead.org header.s=casper.20170209 header.b=rbgGQajz; spf=none (imf01.hostedemail.com: domain of willy@infradead.org has no SPF policy when checking 90.155.50.34) smtp.mailfrom=willy@infradead.org; dmarc=none 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: 8bit X-Stat-Signature: ao4gftmuofz5yqebcw37fhoieq6r3z9q X-Rspamd-Server: rspam10 X-Rspamd-Queue-Id: B5EA540009 X-Rspam-User: X-HE-Tag: 1687800929-691446 X-HE-Meta: U2FsdGVkX1/ewxi6Pk5SAMP78l8rMYa4lczUObmzTA2B/tAhDdG2L/jBnUe2L+DhXR3Ddg6G4+0bd8QaMFHBJrzb8T1ea1kUNzrCLP3eva9RencTZLPlgJbk0m3HANunPMOWB6Nrh/uBwwGB2B5aLtCh6lsUuAguhBfhPB0QBYWbfiVqgYk8sNr44vseMvd2wmCgPi1u3W+pMV8VjuBUmZciluFyDDLG2+tXtY4xXsTQYUGMUAm9IhN/pyjAZ1ASEkWKWOQ0HsgF58Jwg4v44GoDMQrjKiblNTvgwzSZgtl0a3h/ZG3MrxGkWSOFk+X3cYO3yaFWduODG6EBTAAwSwNIO2l3k2IQ1TWk1xplEri/y84fWfG5znn9tIX351cNfvJuC7JFFcAONX53J5xpT75Hpr7FYpEGl7iy5EX4SMyMpShW2eZgOVJz+dt4JcD1ns0GAejW2TXu71jgcGa5KkzYFivsDbD2zCveVNztMSNDHr7Pv1QsAyN0eOmeOSUwLAS7KHhmNshpsevCR+X151tuHUelFxO0MUriYp8+kGP0ScMfaj525ne4n3paVWlke0KEMGhCfEdaFgtsXv4cRSxwo5A1D6Oyo3XETx/aq8bhJUX4fkS01FFr5V+Xib4hKPkas3uz5u2IOVOroOoA9faqszCjgy8E1FenmCxrEWi8D612q3MDk2iixUBU+F97y9JkNl1tw+Ry/evLcg8jILUPnZVSYRv73ih6dExZOvb6NKbD0p3h7Jr7BNoLD/0Xs0hXGVZIz84fXqKW9zpaFwGO9YqYRkbf+aqUfKmuBuYXBRv5lnvrVBy98Yge5nnT9MUyzIB/aLVhFiw3k+kHLWwcnYIrRMTA+M9Wv2geX9WNgQXM9hkB+Lc+5Yg42a9dy/diS+pJWrJGdLtORWFV/kJeKEeY1htkOZGMA4MHOCfMuteVyepXgGNKHDF2/yircopNNkF148EQbzFv1bz wTpOwcA0 ROHWHS3yM5RWPwI1rRJ1Ic32nyydekxX4BlJ6VUB/tgVsMTwDdMLhC5l0vnQM4OywCCYlMsI8V73MQ0avRuFSYNRAf5qyLxU+TMDUCJIQH5ixIpzLjjazWmFjDSCWkUB/kQ70IosngdI9zg+HRV7xdg3macVUKm5Rz2BSy01AxZRUunS7UqjC9fqpzECnF2aKyuE499SubkBiyb1RpjjPM3Uf37RuF3KBX0jh X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: 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 *mapping, } EXPORT_SYMBOL(tag_pages_for_writeback); -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 *mapping, if (wbc->range_cyclic || (wbc->range_whole && wbc->nr_to_write > 0)) mapping->writeback_index = wbc->done_index; - return wbc->err; + return NULL; } static struct folio *writeback_get_next(struct address_space *mapping, @@ -2438,7 +2438,7 @@ static struct folio *writeback_get_folio(struct address_space *mapping, for (;;) { folio = writeback_get_next(mapping, wbc); if (!folio) - return NULL; + return writeback_finish(mapping, wbc, false); wbc->done_index = folio->index; folio_lock(folio); @@ -2473,6 +2473,45 @@ static struct folio *writeback_iter_init(struct address_space *mapping, return writeback_get_folio(mapping, wbc); } +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 == AOP_WRITEPAGE_ACTIVATE) { + folio_unlock(folio); + error = 0; + } else if (wbc->sync_mode != WB_SYNC_ALL) { + wbc->err = error; + wbc->done_index = folio->index + + folio_nr_pages(folio); + return writeback_finish(mapping, wbc, true); + } + if (!wbc->err) + wbc->err = 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 <= 0 && wbc->sync_mode == 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 space and write all of them. * @mapping: address space structure to write @@ -2513,46 +2552,11 @@ int write_cache_pages(struct address_space *mapping, for (folio = writeback_iter_init(mapping, wbc); folio; - folio = writeback_get_folio(mapping, wbc)) { + folio = writeback_iter_next(mapping, wbc, folio, error)) { error = 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 == AOP_WRITEPAGE_ACTIVATE) { - folio_unlock(folio); - error = 0; - } else if (wbc->sync_mode != WB_SYNC_ALL) { - wbc->err = error; - wbc->done_index = folio->index + - folio_nr_pages(folio); - return writeback_finish(mapping, wbc, true); - } - if (!wbc->err) - wbc->err = 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 <= 0 && - wbc->sync_mode == WB_SYNC_NONE) - return writeback_finish(mapping, wbc, true); } - return writeback_finish(mapping, wbc, false); + return wbc->err; } EXPORT_SYMBOL(write_cache_pages); -- 2.39.2