From patchwork Thu Dec 14 13:25:37 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christoph Hellwig X-Patchwork-Id: 13493089 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 ECA46C4332F for ; Thu, 14 Dec 2023 13:43:41 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 861608D00BC; Thu, 14 Dec 2023 08:43:41 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 811378D00B1; Thu, 14 Dec 2023 08:43:41 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 6D87F8D00BC; Thu, 14 Dec 2023 08:43:41 -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 5A20E8D00B1 for ; Thu, 14 Dec 2023 08:43:41 -0500 (EST) Received: from smtpin22.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay03.hostedemail.com (Postfix) with ESMTP id 23FBDA0C8A for ; Thu, 14 Dec 2023 13:43:41 +0000 (UTC) X-FDA: 81565541442.22.3555CAE Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) by imf06.hostedemail.com (Postfix) with ESMTP id 21994180002 for ; Thu, 14 Dec 2023 13:43:38 +0000 (UTC) Authentication-Results: imf06.hostedemail.com; dkim=pass header.d=infradead.org header.s=bombadil.20210309 header.b=JZ6CWZpv; spf=none (imf06.hostedemail.com: domain of BATV+55581d165dda9d0af87b+7417+infradead.org+hch@bombadil.srs.infradead.org has no SPF policy when checking 198.137.202.133) smtp.mailfrom=BATV+55581d165dda9d0af87b+7417+infradead.org+hch@bombadil.srs.infradead.org; dmarc=none ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1702561419; 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=zsw+wTmwL88dMqXlPcddKLu64UsXn5iiu6gG3sd2+gI=; b=LuNz5y3DGKwFsEVf++um2iPkzfPdeJjG4k3y6zNxF4d62v3Cocmhp1sGkBDH6c8qUq5OdR /Y2Wg8y38BPjq0ffcbIjig/U17I/f7A+asRMEDOyVluIZ7Bj0MsEnZiE+nLEElKU3JKkLd 7C4T/I3qH3UPvKkWAiCUog4pXg3vFPE= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1702561419; a=rsa-sha256; cv=none; b=pg2N6p2qxZYdGQ0sJ0ViD5Y7YHRW4meVmMpaTim/lcBBBhsPBaIuyF/vyustpMFeunHIt7 7hhzG0Jpd+Sko/LWO9rZANULz7uWFhHWyv15D1Nqrbl2KP9PyAJliGskIa83+bEp/2ghZL xVX0/J3ZhxUyiCihBAk4a31eCDIMsM8= ARC-Authentication-Results: i=1; imf06.hostedemail.com; dkim=pass header.d=infradead.org header.s=bombadil.20210309 header.b=JZ6CWZpv; spf=none (imf06.hostedemail.com: domain of BATV+55581d165dda9d0af87b+7417+infradead.org+hch@bombadil.srs.infradead.org has no SPF policy when checking 198.137.202.133) smtp.mailfrom=BATV+55581d165dda9d0af87b+7417+infradead.org+hch@bombadil.srs.infradead.org; dmarc=none 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=zsw+wTmwL88dMqXlPcddKLu64UsXn5iiu6gG3sd2+gI=; b=JZ6CWZpvcy4fuseqmY16OrM6T8 DbXX6t3lj9ucqim23WY1gzee/6CX0nKn2g1UGzhIl2Vjl8NqcFnlOjHFx+i9aShIaD+KleTN+MN9q X7T1cilqrP7e/fXlwM0bTTUjg9Iv4bOJiYqBzd7mvGl+LE8Uj5gfWVsCOyfKrYaFUuET31z4jAV7Y fm6r1Lcfc7Id7k+6JZ3terQhgtjm9suIj9kXItRzdauXLUZH0Z9wPJzul1PHW8hhpPBD0uiF9t3Cr hAI+CngOjGT9f/ip71qJ76kPXnqmTz2ydFkRfCHN+Umo8Ilu5I9VdRD4Zgntp4KrbwgzBzWBGx5uL kjRLq/yQ==; Received: from [88.128.88.27] (helo=localhost) by bombadil.infradead.org with esmtpsa (Exim 4.96 #2 (Red Hat Linux)) id 1rDlj5-000N3y-0Z; Thu, 14 Dec 2023 13:26:07 +0000 From: Christoph Hellwig 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 04/11] writeback: Simplify the loops in write_cache_pages() Date: Thu, 14 Dec 2023 14:25:37 +0100 Message-Id: <20231214132544.376574-5-hch@lst.de> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20231214132544.376574-1-hch@lst.de> References: <20231214132544.376574-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: 21994180002 X-Rspam-User: X-Rspamd-Server: rspam11 X-Stat-Signature: 1k1p78nerhbp1b7y5h91tujzsfx9bxtb X-HE-Tag: 1702561418-343109 X-HE-Meta: U2FsdGVkX1/vxaZ1G1eMS/cW2bxKlEbQeHrbCONIR/I7/i8d8lLRYXJZ3UQ6ocAOzcsr2HPfpPqRNSzzU+2vidViVsMGD9fk0ZIn+GIGcZhtF/94sfuB9SOrVrHUXYrYgmfM6T6AX7/uHaA3IqPc3FT61Yg7I9JgQBLafCOzwsZz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8G/cR53Or9jzjcdio6+z5BXiM7yyc730uW4zZIMWf5aQ5dnGdQPHBq+RuSZrKwcSOe4HDgTCW/7PNEox0tHtrc/WHwDddAMsEtOS6YQf9mFvJ412A0X64iUs8cScrZQCKac7LaSCg1oEMKMs+oZmeqCYT7LgsRvm1GvuhRSX10o4acxFgbzOOIbzLF8Y8/Onw+gkVBUGoGUHxtUp7VxGg5adPwEQCXP1W8lUCfrP1loiw3vWBciQ== 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)" Collapse the two nested loops into one. This is needed as a step towards turning this into an iterator. Signed-off-by: Christoph Hellwig Signed-off-by: Matthew Wilcox (Oracle) --- mm/page-writeback.c | 98 ++++++++++++++++++++++----------------------- 1 file changed, 49 insertions(+), 49 deletions(-) diff --git a/mm/page-writeback.c b/mm/page-writeback.c index 5a3df8665ff4f9..2087d16115710e 100644 --- a/mm/page-writeback.c +++ b/mm/page-writeback.c @@ -2460,6 +2460,7 @@ int write_cache_pages(struct address_space *mapping, void *data) { int error; + int i = 0; if (wbc->range_cyclic) { wbc->index = mapping->writeback_index; /* prev offset */ @@ -2477,67 +2478,66 @@ int write_cache_pages(struct address_space *mapping, folio_batch_init(&wbc->fbatch); wbc->err = 0; - while (wbc->index <= wbc->end) { - int i; - - writeback_get_batch(mapping, wbc); + for (;;) { + struct folio *folio; + unsigned long nr; + if (i == wbc->fbatch.nr) { + writeback_get_batch(mapping, wbc); + i = 0; + } if (wbc->fbatch.nr == 0) break; - for (i = 0; i < wbc->fbatch.nr; i++) { - struct folio *folio = wbc->fbatch.folios[i]; - unsigned long nr; + folio = wbc->fbatch.folios[i++]; - wbc->done_index = folio->index; + wbc->done_index = folio->index; - folio_lock(folio); - if (!should_writeback_folio(mapping, wbc, folio)) { - folio_unlock(folio); - continue; - } + folio_lock(folio); + if (!should_writeback_folio(mapping, wbc, folio)) { + folio_unlock(folio); + continue; + } - trace_wbc_writepage(wbc, inode_to_bdi(mapping->host)); - - error = writepage(folio, wbc, data); - nr = folio_nr_pages(folio); - 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 + nr; - return writeback_finish(mapping, - wbc, true); - } - if (!wbc->err) - wbc->err = error; - } + trace_wbc_writepage(wbc, inode_to_bdi(mapping->host)); + error = writepage(folio, wbc, data); + nr = folio_nr_pages(folio); + if (unlikely(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. + * 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. */ - wbc->nr_to_write -= nr; - if (wbc->nr_to_write <= 0 && - wbc->sync_mode == WB_SYNC_NONE) + 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 + nr; 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. + */ + wbc->nr_to_write -= nr; + if (wbc->nr_to_write <= 0 && + wbc->sync_mode == WB_SYNC_NONE) + return writeback_finish(mapping, wbc, true); } return writeback_finish(mapping, wbc, false);