From patchwork Thu Jan 25 08:57:42 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christoph Hellwig X-Patchwork-Id: 13530236 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 7C248C47422 for ; Thu, 25 Jan 2024 08:58:18 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 1783E280007; Thu, 25 Jan 2024 03:58:18 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 12B86280001; Thu, 25 Jan 2024 03:58:18 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id EBBFD280007; Thu, 25 Jan 2024 03:58:17 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0014.hostedemail.com [216.40.44.14]) by kanga.kvack.org (Postfix) with ESMTP id DA5BF280001 for ; Thu, 25 Jan 2024 03:58:17 -0500 (EST) Received: from smtpin24.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay06.hostedemail.com (Postfix) with ESMTP id A7D6BA23A0 for ; Thu, 25 Jan 2024 08:58:17 +0000 (UTC) X-FDA: 81717231834.24.1FD8B13 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) by imf24.hostedemail.com (Postfix) with ESMTP id 353DD180009 for ; Thu, 25 Jan 2024 08:58:16 +0000 (UTC) Authentication-Results: imf24.hostedemail.com; dkim=pass header.d=infradead.org header.s=bombadil.20210309 header.b=eLUk9fi9; dmarc=none; spf=none (imf24.hostedemail.com: domain of BATV+b97a0fc658bf3e588113+7459+infradead.org+hch@bombadil.srs.infradead.org has no SPF policy when checking 198.137.202.133) smtp.mailfrom=BATV+b97a0fc658bf3e588113+7459+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=1706173096; 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=/IByKLVlZu2F9wnx0I/UOWkm2jwSLHoNKmPo511TdLQ=; b=jp8+/BAQLADAxd4yxNnNRQ4zpS3ELPgKKp0xJpiA7Nv3ecRcMOqXo2TH6Q9d5MKfhKNaIH GbX41OdoDj+GgO3sbl6GpyG6+zX/SUPzThHcB+BW76pTonEi7Cye6OTNLYAz5zKf/ZjERR X0kjSnBSAA0AsQst+Q4KtMiTZM3A/eQ= ARC-Authentication-Results: i=1; imf24.hostedemail.com; dkim=pass header.d=infradead.org header.s=bombadil.20210309 header.b=eLUk9fi9; dmarc=none; spf=none (imf24.hostedemail.com: domain of BATV+b97a0fc658bf3e588113+7459+infradead.org+hch@bombadil.srs.infradead.org has no SPF policy when checking 198.137.202.133) smtp.mailfrom=BATV+b97a0fc658bf3e588113+7459+infradead.org+hch@bombadil.srs.infradead.org ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1706173096; a=rsa-sha256; cv=none; b=nOvFJ+OoHP5445gsCOue1rzXbU9M6vU6YB/tpX+AxhyvXK5P0mzxplGQs1F71CXmJblFnR n8enctbA+FKBb384ku+sYHCSM5hvKYLejfLrK2RvLTDbSWwXuVogLD/uWzUSz86ZmAACuI fakRXhKrCPS/WJWA6n0yTw4iJ0szHO8= 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=/IByKLVlZu2F9wnx0I/UOWkm2jwSLHoNKmPo511TdLQ=; b=eLUk9fi9CgDuij9FcAeuvwTARz 8KJIalgD3lOvEQm62ev1whPRxGCnYvwgCXnYzGxY1Z6XK6kDAd0yo6bkm/gDeVk4+WaNIWOruRjDR +PJz06AgPTbEXqLs6VfmjRGGKBwIEbksUcd/Ru6/Y/JbLCVPoWmLWB0G2xnFny5y3sNQS9CbxmziL vBeQXKMKuN80WJXNn3pF4wB7Sq7vQUp6A4jX8BqdR2HVFnfnseHhUI+shRy1FgbiGcOHEaPeKL7Ol 8NQzQW3x+PqYfF4RYL4DqXwQnSf3SROFvkZuWlvr4ns6fBtbtLuO793R5ioUD12tlhVWFya9qiyKG rFxgu+YQ==; 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 1rSvYs-007QBY-2m; Thu, 25 Jan 2024 08:58:15 +0000 From: Christoph Hellwig To: linux-mm@kvack.org Cc: Matthew Wilcox , Jan Kara , David Howells , Brian Foster , Christian Brauner , "Darrick J. Wong" , linux-xfs@vger.kernel.org, linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org, Jan Kara , Dave Chinner Subject: [PATCH 03/19] writeback: rework the loop termination condition in write_cache_pages Date: Thu, 25 Jan 2024 09:57:42 +0100 Message-Id: <20240125085758.2393327-4-hch@lst.de> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20240125085758.2393327-1-hch@lst.de> References: <20240125085758.2393327-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-Server: rspam09 X-Rspamd-Queue-Id: 353DD180009 X-Stat-Signature: ygqmq74ehd6wgyhp1mecasbuqtyjniw5 X-Rspam-User: X-HE-Tag: 1706173096-903277 X-HE-Meta: U2FsdGVkX1+6+MKBR+eEhJxNU4jY/1KDBm2VyHi1leL3d44pmDTyngKYuqF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QmXSmc1kSbHvFusiup8HV4HjA/pwiQ8GQUEsNKdQ+YA0ekEkNRWgKt9/MnP68UMteiZ+H2e2TQ+g== 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 0c1e9c016bc48f..259c37bc34d2a7 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);