From patchwork Mon Dec 18 15:35:39 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christoph Hellwig X-Patchwork-Id: 13497157 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 D5D23C35274 for ; Mon, 18 Dec 2023 15:36:09 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 658828D000A; Mon, 18 Dec 2023 10:36:07 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 6053C8D0009; Mon, 18 Dec 2023 10:36:07 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 45A448D000A; Mon, 18 Dec 2023 10:36:07 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0013.hostedemail.com [216.40.44.13]) by kanga.kvack.org (Postfix) with ESMTP id 2BA5F8D0009 for ; Mon, 18 Dec 2023 10:36:07 -0500 (EST) Received: from smtpin14.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay04.hostedemail.com (Postfix) with ESMTP id 0BCF61A0139 for ; Mon, 18 Dec 2023 15:36:07 +0000 (UTC) X-FDA: 81580339974.14.F21C0B2 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) by imf01.hostedemail.com (Postfix) with ESMTP id B26AC40019 for ; Mon, 18 Dec 2023 15:36:04 +0000 (UTC) Authentication-Results: imf01.hostedemail.com; dkim=pass header.d=infradead.org header.s=bombadil.20210309 header.b=wv7lyBIR; dmarc=none; spf=none (imf01.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=1702913764; a=rsa-sha256; cv=none; b=thmSkkjexpxnYu7rsicit2sE0rsPQthEGu/OvPYeZ22Mz5NwC94/zFBLr9hfca0fseHec7 Sn0Jnwe0IR8PKtYZ0BC92UXEPjKxNTSUsp+6SqgDAd1RZj2cNFudB4LJxkNC9UxIRIYkFc pnUo876iZB+ICKQUqGXKjpcd6+gW5Bg= ARC-Authentication-Results: i=1; imf01.hostedemail.com; dkim=pass header.d=infradead.org header.s=bombadil.20210309 header.b=wv7lyBIR; dmarc=none; spf=none (imf01.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=1702913764; 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=SkcRys0g0eAUf8/FxArC7DdEKspx8sFQujh+FCrTtN4=; b=aZcwNs239qIXwJrbua1JgdcPAEkOHyMIPH5yPVq1OHREOoNqYw8XPhcscNL09xq70Pv1Q2 I7YqGotnBhw3XQcSb8vVrSDVrtHiU03UoQN0N2pzB+teb1s0/YvErMfQp2ixMeAHHpGOg8 P1JFMwUC4vmatkcjc5UEVJc9KEqBdec= 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=SkcRys0g0eAUf8/FxArC7DdEKspx8sFQujh+FCrTtN4=; b=wv7lyBIRNIQLwC91K/1xIPUpmW 14UXm/U10zKWL8yi3CuNad4Wvj16dy3mlQm0OVgg9NbwoDwc9qHaPbHXu2UjDhtjk2lWCXoBQfv5y YEpJvvDmZco1oWzVjD3D1Bgi4x8XaNM+D43GKOOpJzTHkDmAlPg/KuQswq8wrsi4bfjwuTjO/hdvm dUdZUwx4kWJO8dxO3K/HNOHsO1nztgCOjXKRGJ3UzIgnl6x1j4KIzYPFncrhFFqH64N2gYSfK/F7I wirO6bPgiOsKjEkwmyDnPYkuODr8U12dz5uP43SplWoRAOxukXhfL16C6CpPgTpzEr6QuMYcez9D6 2LhabeBQ==; 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 1rFFf1-00BEIj-0m; Mon, 18 Dec 2023 15:36:03 +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 03/17] writeback: rework the loop termination condition in write_cache_pages Date: Mon, 18 Dec 2023 16:35:39 +0100 Message-Id: <20231218153553.807799-4-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-Rspam-User: X-Rspamd-Server: rspam06 X-Rspamd-Queue-Id: B26AC40019 X-Stat-Signature: sft9x66sq6mrcm39ruumsx7kmamhzqag X-HE-Tag: 1702913764-294854 X-HE-Meta: U2FsdGVkX1/CbNusdsNh5LB05go+MjQzU/qgm8wtZDZQZABX7/Au77kEfyPo+C9CqVuR1eWIftA4h9aY95LLa6s5uIVuAwP+bBV9Qv7N9S/oXdSbRW3CYBcF7r6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ZM+rLbWiC2HvLaC/XSluYeaWR83CFI22blCcvTXYJRetsFYyoy6O9PH4L5CT++jpaxAWja5GooB2/l7CKJx4kdU2uru9/e9Cwvv/iDgLWH2QR4f/Rh4/Uyou7YQxSAjDNLsGZ2N+SrJGgrXfzlfx3zPA5mENwL4v1lxEWG+G+2K83eVi90DYRs39sI9ZJlp4CU222M35/7YZv6JMYULOQBYmvDPGPSEvpLTDnyZ9eG/8kmXGP4WEQM= 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: Rework we deal with the cleanup after the writepage call. First handle the magic AOP_WRITEPAGE_ACTIVATE separately from real error returns to get it out of the way of the actual error handling. Then merge the code to set ret for integrity vs non-integrity writeback. For non-integrity writeback the loop is terminated on the first error, so ret will never be non-zero. Then use a single block to check for non-integrity writewack to consolidate the cases where it returns for either an error or running off the end of nr_to_write. Signed-off-by: Christoph Hellwig Reviewed-by: Jan Kara --- mm/page-writeback.c | 62 +++++++++++++++++++++------------------------ 1 file changed, 29 insertions(+), 33 deletions(-) diff --git a/mm/page-writeback.c b/mm/page-writeback.c index 8e312d73475646..7ed6c2bc8dd51c 100644 --- a/mm/page-writeback.c +++ b/mm/page-writeback.c @@ -2474,43 +2474,39 @@ int write_cache_pages(struct address_space *mapping, error = writepage(folio, wbc, data); nr = folio_nr_pages(folio); wbc->nr_to_write -= nr; - 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) { - ret = error; - done_index = folio->index + nr; - done = 1; - break; - } - if (!ret) - ret = error; + + /* + * 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; } /* - * 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. + * 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. */ - done_index = folio->index + nr; - if (wbc->nr_to_write <= 0 && - wbc->sync_mode == WB_SYNC_NONE) { - done = 1; - break; + if (error && !ret) + ret = error; + if (wbc->sync_mode == WB_SYNC_NONE) { + if (ret || wbc->nr_to_write <= 0) { + done_index = folio->index + nr; + done = 1; + break; + } } } folio_batch_release(&fbatch);