From patchwork Fri Dec 22 15:08:13 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christoph Hellwig X-Patchwork-Id: 13503411 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 2FDC5C41535 for ; Fri, 22 Dec 2023 15:08:41 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 28BF16B007E; Fri, 22 Dec 2023 10:08:38 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 214E06B0080; Fri, 22 Dec 2023 10:08:38 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 03ECB6B0081; Fri, 22 Dec 2023 10:08:37 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0010.hostedemail.com [216.40.44.10]) by kanga.kvack.org (Postfix) with ESMTP id E48866B007E for ; Fri, 22 Dec 2023 10:08:37 -0500 (EST) Received: from smtpin12.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay07.hostedemail.com (Postfix) with ESMTP id B285F160E76 for ; Fri, 22 Dec 2023 15:08:37 +0000 (UTC) X-FDA: 81594785874.12.1B252E5 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) by imf02.hostedemail.com (Postfix) with ESMTP id EE0788002B for ; Fri, 22 Dec 2023 15:08:35 +0000 (UTC) Authentication-Results: imf02.hostedemail.com; dkim=pass header.d=infradead.org header.s=bombadil.20210309 header.b=Z6VUXUaO; dmarc=none; spf=none (imf02.hostedemail.com: domain of BATV+af923ccb694ecd533eae+7425+infradead.org+hch@bombadil.srs.infradead.org has no SPF policy when checking 198.137.202.133) smtp.mailfrom=BATV+af923ccb694ecd533eae+7425+infradead.org+hch@bombadil.srs.infradead.org ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1703257716; a=rsa-sha256; cv=none; b=KMJyp1fPFlErvLU66E3Cs5oDQecsJJfK7BbsmrD6oLgb9IZKu6S8k0dmgqAC2x8Af42+fb tpXPCj1pysTV6OQQiASeB0RM1HE/INojHJvpY1bzP7aw+zawRdNajElUo7N5oXqRihMfqw wHFksrQzVrf8Aj+Zt+aoeRE3di6iC/w= ARC-Authentication-Results: i=1; imf02.hostedemail.com; dkim=pass header.d=infradead.org header.s=bombadil.20210309 header.b=Z6VUXUaO; dmarc=none; spf=none (imf02.hostedemail.com: domain of BATV+af923ccb694ecd533eae+7425+infradead.org+hch@bombadil.srs.infradead.org has no SPF policy when checking 198.137.202.133) smtp.mailfrom=BATV+af923ccb694ecd533eae+7425+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=1703257716; 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=aiTqCmsyGk4E7LEDYa2Lc4VptDi32CoIamzlkv7IN4k=; b=prN8jrcpjJI57EdzMF2XC3KN06Q2HtQQ575zajKYa6Hkpyy5grF5b8NtaQUWwYaDo5wzrR F4eN7dxS3rxEem0EA0D32ZD8HzcQAsbLvdn9U7YuTGMAaMoRvBu2kerEaA2Dsn6/wD8G2z HwHnjtiYkubLH74nIW+JckZcpES2P4c= 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=aiTqCmsyGk4E7LEDYa2Lc4VptDi32CoIamzlkv7IN4k=; b=Z6VUXUaOnTXFhPPhvYLJ/CI7r+ 598L/x1qssfMn/59wmI2TR1LAjz4u+kDW5Nm60tNob0N/ESCYSA2gORLrF8dLjo+CB2AUmg9iWjiU vg3Yj1XFCntRF8l5h7YKvZVe5SEmrCIeF9qXoxetiOCRs4Q1Aitg6PbJi19nea7MVIO19Kp5CYZF+ 3Nnj3WXzTHCmBacJmCICSBDReSKIntJmPrV+8G22uCHaMisfcnpBn+5MVwkkeYU9SHRM8Yq+5wxK8 RQjG0VQl7bkgPwdxOLdyOnWEQzTsJ/bRLdG9XcL5S0sXkeQNYuqZwZ3EdiMtKs0PavEur4+WPuOJm HpUGJILg==; 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 1rGh8c-006BMq-2T; Fri, 22 Dec 2023 15:08:35 +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, Jan Kara , Dave Chinner Subject: [PATCH 03/17] writeback: rework the loop termination condition in write_cache_pages Date: Fri, 22 Dec 2023 16:08:13 +0100 Message-Id: <20231222150827.1329938-4-hch@lst.de> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20231222150827.1329938-1-hch@lst.de> References: <20231222150827.1329938-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: EE0788002B X-Stat-Signature: fgq58dbcjz5yn87wa5j935makqhe3887 X-HE-Tag: 1703257715-118278 X-HE-Meta: U2FsdGVkX18pIl/dFPQ37jN3ePsl2Oswd1/tNpXrYd73ft98iYTraJXqQScRyd7CEwjZcjMR1LnrlZ7ZqeYdXfjoMy6/809wLa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ZzLVt2GPLi9DUG9pmzeV7+e5UudHW2E6zRKLSVaWyqQS9q77l4v4uXcCFTrAZBKUTFqs5fTDdxb0+HaLBdsNTKR4AifJu/I3YDoSEoBo3txsKQDVRxbJ7T3zmKr3+D21iPitDVerOVgvHUGeXD9zFz/mPrE1eUpdg52EzP/F3qRTwTutgjFTfeVqRyrFRjwvNwJa8RSNWc9jAkqTmCqUjtboT5Da4A+q/Rq1ZoYdvoMzziUV1uYt/yTCQ4yiKBsI8qQMFxi9DnyPNCdk+rLTY2atTOuf0TbT0+7P4z+8gmLZbSJeriqSE= 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 the way 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 path. 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 Acked-by: Dave Chinner --- 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);