From patchwork Mon Dec 18 15:35:50 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christoph Hellwig X-Patchwork-Id: 13497168 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 AFC3EC35274 for ; Mon, 18 Dec 2023 15:36:41 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 015986B0085; Mon, 18 Dec 2023 10:36:41 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id E91DD6B0088; Mon, 18 Dec 2023 10:36:40 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id C96D46B0089; Mon, 18 Dec 2023 10:36:40 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0011.hostedemail.com [216.40.44.11]) by kanga.kvack.org (Postfix) with ESMTP id B88656B0085 for ; Mon, 18 Dec 2023 10:36:40 -0500 (EST) Received: from smtpin22.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay06.hostedemail.com (Postfix) with ESMTP id 9524EA292A for ; Mon, 18 Dec 2023 15:36:40 +0000 (UTC) X-FDA: 81580341360.22.219BCFB Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) by imf12.hostedemail.com (Postfix) with ESMTP id C5B864001A for ; Mon, 18 Dec 2023 15:36:38 +0000 (UTC) Authentication-Results: imf12.hostedemail.com; dkim=pass header.d=infradead.org header.s=bombadil.20210309 header.b="n/KNWRHz"; dmarc=none; spf=none (imf12.hostedemail.com: domain of BATV+09f18f96a25a69770120+7421+infradead.org+hch@bombadil.srs.infradead.org has no SPF policy when checking 198.137.202.133) smtp.mailfrom=BATV+09f18f96a25a69770120+7421+infradead.org+hch@bombadil.srs.infradead.org ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1702913798; 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=lOde0PGi4Z6M7IdLHCKfLkz19eMYDieJg9XbB+ncAEo=; b=P6Z73JPwPfE2KJJ39gh2ybU9DUEtSCMpfNYqVX0mwgFbKT8Vk3E0YglM1SkzGrsZB4jQD1 zelZUZqMJcRPoo+Zz+r0XBHKzTR+CN/RDAHxAmMFYLaPJ7CaduNEFx1+qToEWfw4GPHkPX IhEKljCn0zpHEOpvf5axHMJCJuLBV9o= ARC-Authentication-Results: i=1; imf12.hostedemail.com; dkim=pass header.d=infradead.org header.s=bombadil.20210309 header.b="n/KNWRHz"; dmarc=none; spf=none (imf12.hostedemail.com: domain of BATV+09f18f96a25a69770120+7421+infradead.org+hch@bombadil.srs.infradead.org has no SPF policy when checking 198.137.202.133) smtp.mailfrom=BATV+09f18f96a25a69770120+7421+infradead.org+hch@bombadil.srs.infradead.org ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1702913798; a=rsa-sha256; cv=none; b=raksNgdSUCZFy84ujG0mAvu3TN7lcvCuFtyB0It/GtHukmnzJWiEIZ7DLwb0akpoqlEjN7 AtCnqAcCv4eeKt29mXz+2VdxX5Thhfbdp/XkxOvGAeHGX85T1pUSIKag8oitnSe+eGiL1o Gp9LaAIsvi0uUqcwQ4uPSkS/K7pAZ/k= DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=bombadil.20210309; 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=lOde0PGi4Z6M7IdLHCKfLkz19eMYDieJg9XbB+ncAEo=; b=n/KNWRHzl0Vuw7qwMs1UYzUUD+ itAzOZiMXFPZCbTYFwBvFV2uQpY3ZdylXEIWixZXWjNKLUCXFSQ57YVIbXC8wJScFm28gORoCP+Yi hZWQK8/6AkPBsNn7WjAHENXCNj+5xS1xxxEnfprZO2gzyaxOtGqdUqb9VYPWGt+1/ebCeTj52bMkV eEWxwgWKuQvWNHrgQpzFNaQqNPqCqaSsXje3yLomMY4ATq2rL67xi0bZijgTq8eTBV2zniKCTgGjs 6yp0+AJIT0zWHgTOFWE15g4u0wKKgOI7K7XRNoilnqCmsKHJwS2V/24atVv67qSQSUEtUNZH/UU0Z vEC8Dhsg==; Received: from 2a02-8389-2341-5b80-39d3-4735-9a3c-88d8.cable.dynamic.v6.surfer.at ([2a02:8389:2341:5b80:39d3:4735:9a3c:88d8] helo=localhost) by bombadil.infradead.org with esmtpsa (Exim 4.96 #2 (Red Hat Linux)) id 1rFFfZ-00BEZB-0p; Mon, 18 Dec 2023 15:36:37 +0000 From: Christoph Hellwig To: linux-mm@kvack.org Cc: "Matthew Wilcox (Oracle)" , Jan Kara , David Howells , Brian Foster , linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH 14/17] writeback: Factor writeback_iter_next() out of write_cache_pages() Date: Mon, 18 Dec 2023 16:35:50 +0100 Message-Id: <20231218153553.807799-15-hch@lst.de> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20231218153553.807799-1-hch@lst.de> References: <20231218153553.807799-1-hch@lst.de> MIME-Version: 1.0 X-SRS-Rewrite: SMTP reverse-path rewritten from by bombadil.infradead.org. See http://www.infradead.org/rpr.html X-Rspamd-Queue-Id: C5B864001A X-Rspam-User: X-Rspamd-Server: rspam04 X-Stat-Signature: 5914ap7z6o6ueisuj3ktwsnffxmreeq8 X-HE-Tag: 1702913798-839381 X-HE-Meta: U2FsdGVkX1/kPHyF2uNOR37TulBlF2XSqVWsKfd2aoxVuQnxf4Ia2lW6ZycVoOiPOomwbo/KERRUoyYl03CeYYPyAepQTC6kAkX53fIa4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HLgjdJ6SvmpcWE2mz2FSsTTuZBLiQfYUCBpsVDFRUvAQKbtFX0EOPR/IBaVz3a4fH3CwPBdGmf8glXEGfXv14NDwBMceQst4kJoQiFenU4ixSt7+EMZquUqiLRxy2YE9HLFUCb4F2ddBnSQ0FxiIGOM7rOIXIo7eSTRjtWOJYH8e/lkOybwVU4A6XolwW+bR/7scJSqv3nz5bEVLP4XUU2oOoJzB4+HLo6k1Q4/DLrCQyhXirRFyMHslaUp0/kuiOHMZzzD7jwPLNFkZdIDBzHq4gMoueYai0zq+ndf/C+7hVLHatF0pvHLwKUVcIOBNZ4E07JzjWFgoLvpAn6Jxhbv66EFyW0J2Nk9GreDWwngYJmEGfdw3mjK7fS0HGmHE+rwg== 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: List-Subscribe: List-Unsubscribe: From: "Matthew Wilcox (Oracle)" 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) Signed-off-by: Christoph Hellwig Reviewed-by: Jan Kara --- mm/page-writeback.c | 85 ++++++++++++++++++++++++--------------------- 1 file changed, 45 insertions(+), 40 deletions(-) diff --git a/mm/page-writeback.c b/mm/page-writeback.c index 9d37dd5e58ffb6..0771f19950081f 100644 --- a/mm/page-writeback.c +++ b/mm/page-writeback.c @@ -2449,8 +2449,10 @@ static struct folio *writeback_get_folio(struct address_space *mapping, for (;;) { folio = writeback_get_next(mapping, wbc); - if (!folio) + if (!folio) { + writeback_finish(mapping, wbc, 0); return NULL; + } folio_lock(folio); if (likely(should_writeback_folio(mapping, wbc, folio))) break; @@ -2477,6 +2479,46 @@ 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) +{ + unsigned long nr = folio_nr_pages(folio); + + wbc->nr_to_write -= nr; + + /* + * Handle the legacy AOP_WRITEPAGE_ACTIVATE magic return value. + * Eventually all instances should just unlock the folio themselves and + * return 0; + */ + if (error == AOP_WRITEPAGE_ACTIVATE) { + folio_unlock(folio); + error = 0; + } + + if (error && !wbc->err) + wbc->err = error; + + /* + * For integrity sync we have to keep going until we have written all + * the folios we tagged for writeback prior to entering the writeback + * loop, even if we run past wbc->nr_to_write or encounter errors. + * This is because the file system may still have state to clear for + * each folio. We'll eventually return the first error encountered. + * + * For background writeback just push done_index past this folio so that + * we can just restart where we left off and media errors won't choke + * writeout for the entire file. + */ + if (wbc->sync_mode == WB_SYNC_NONE && + (wbc->err || wbc->nr_to_write <= 0)) { + writeback_finish(mapping, wbc, folio->index + nr); + return NULL; + } + + 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 @@ -2517,47 +2559,10 @@ int write_cache_pages(struct address_space *mapping, for (folio = writeback_iter_init(mapping, wbc); folio; - folio = writeback_get_folio(mapping, wbc)) { - unsigned long nr; - + folio = writeback_iter_next(mapping, wbc, folio, error)) error = writepage(folio, wbc, data); - nr = folio_nr_pages(folio); - wbc->nr_to_write -= nr; - - /* - * Handle the legacy AOP_WRITEPAGE_ACTIVATE magic return value. - * Eventually all instances should just unlock the folio - * themselves and return 0; - */ - if (error == AOP_WRITEPAGE_ACTIVATE) { - folio_unlock(folio); - error = 0; - } - - if (error && !wbc->err) - wbc->err = error; - /* - * For integrity sync we have to keep going until we have - * written all the folios we tagged for writeback prior to - * entering this loop, even if we run past wbc->nr_to_write or - * encounter errors. This is because the file system may still - * have state to clear for each folio. We'll eventually return - * the first error encountered. - * - * For background writeback just push done_index past this folio - * so that we can just restart where we left off and media - * errors won't choke writeout for the entire file. - */ - if (wbc->sync_mode == WB_SYNC_NONE && - (wbc->err || wbc->nr_to_write <= 0)) { - writeback_finish(mapping, wbc, folio->index + nr); - return error; - } - } - - writeback_finish(mapping, wbc, 0); - return 0; + return wbc->err; } EXPORT_SYMBOL(write_cache_pages);