From mboxrd@z Thu Jan 1 00:00:00 1970 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 ED87EEB64D7 for ; Mon, 26 Jun 2023 17:35:49 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 9FE4C8D000E; Mon, 26 Jun 2023 13:35:43 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 988948D000C; Mon, 26 Jun 2023 13:35:43 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 765198D000E; Mon, 26 Jun 2023 13:35:43 -0400 (EDT) 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 63EDB8D000C for ; Mon, 26 Jun 2023 13:35:43 -0400 (EDT) Received: from smtpin06.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay04.hostedemail.com (Postfix) with ESMTP id 3364B1A0526 for ; Mon, 26 Jun 2023 17:35:43 +0000 (UTC) X-FDA: 80945601366.06.D88BD1F Received: from casper.infradead.org (casper.infradead.org [90.155.50.34]) by imf02.hostedemail.com (Postfix) with ESMTP id 0F6F680020 for ; Mon, 26 Jun 2023 17:35:40 +0000 (UTC) Authentication-Results: imf02.hostedemail.com; dkim=pass header.d=infradead.org header.s=casper.20170209 header.b=jW+KKslS; dmarc=none; spf=none (imf02.hostedemail.com: domain of willy@infradead.org has no SPF policy when checking 90.155.50.34) smtp.mailfrom=willy@infradead.org ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1687800941; 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=Hry/pakf3XrjxtX3FxEBHlEHaVaCFV/OlgXU52VAJV8=; b=qGISzn0gzWbrFLRjfZPPF6Lnl/RnoeWLmZ8YJYKnhXVsuqzxJCeHbxf+hGom8qFZc9gPJ3 zowTMSt/fEqsYxIu+eJS/PTSqLD4PHOKWGeocHY0atGzAAN9cZ3cVbyJbozk2gt/o+AEYC /e8QbiZNMfrOIARbh2KAUaat72bcqPg= ARC-Authentication-Results: i=1; imf02.hostedemail.com; dkim=pass header.d=infradead.org header.s=casper.20170209 header.b=jW+KKslS; dmarc=none; spf=none (imf02.hostedemail.com: domain of willy@infradead.org has no SPF policy when checking 90.155.50.34) smtp.mailfrom=willy@infradead.org ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1687800941; a=rsa-sha256; cv=none; b=b35X5egmdIP/eG7P2sc9bCRaWiKjAbkIppuVesiUWb+ad5W1MlGtPRXWUKcPLDR96g+6Vz PJtcjBaxevDcPQVrskYsxCuVxcFWh8K0UdtoxwxcjWXYa71V4FA4A1y+va1rtPiU+wdTHo CB+JctxCyCDGXCttYem+iNXmbJXVnLA= DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=casper.20170209; 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=Hry/pakf3XrjxtX3FxEBHlEHaVaCFV/OlgXU52VAJV8=; b=jW+KKslSaTipXxmpNDSSeOnylL hzbQCyN3wKzjlszSqjc4HEgvviOgGGjspRJs0Vjv5zO3/R9XMbjtxpTsmS+9Gcwuw/ZcmCCyUnNeN H4tbBHnB66YtrhxCVg35T1Z99VBOHuc93t96BguJpmXgSVovFmRpL3E4/mslcgF20oYguKO1t+f7E aUfCqCMqXZB9pkY6yvUPK4VnHdbnXMwfDHnVDWMQUOAefkCf44Iu/CmD4lgC7Vnrxqd1w5+fQwu8z //QbapaLS3fMPaq6e7Ev6OQIihxf6gBxNalmqp3q/qnWQWabKWAZg/iTq63WdoLJnsWBSSCUnMJEx OM6BZUcg==; Received: from willy by casper.infradead.org with local (Exim 4.94.2 #2 (Red Hat Linux)) id 1qDq7X-001vV5-HI; Mon, 26 Jun 2023 17:35:23 +0000 From: "Matthew Wilcox (Oracle)" 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/12] writeback: Simplify the loops in write_cache_pages() Date: Mon, 26 Jun 2023 18:35:13 +0100 Message-Id: <20230626173521.459345-5-willy@infradead.org> X-Mailer: git-send-email 2.37.1 In-Reply-To: <20230626173521.459345-1-willy@infradead.org> References: <20230626173521.459345-1-willy@infradead.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Rspam-User: X-Rspamd-Server: rspam12 X-Rspamd-Queue-Id: 0F6F680020 X-Stat-Signature: 9xyy4crrfrsb1diuj1du4cu93eexnf4a X-HE-Tag: 1687800940-362994 X-HE-Meta: U2FsdGVkX18uFgpRyEn6YJimkO9bmac71oo6+ngOpMWIxMpTxncSme+tueyr+qNeUYjKfDHwbTOmDFx0+Lou+/B+VBSEzAlbcDoSfJIZkCGGMmWedPv4OuXD4ODDVqHY9pGd+PWe15g6LwHKkXuMHrydjRzBFI5n1l+9k2gkq9eB6EMFsGF+Zgm4cmtoThXz/MeQIaR2vUnk24n4XKuwj0wRwVbLXH+V9zTrZaulWk+wP+kSgFo62wWU5j8b0G3rgqVTAThDRLs9f/cukHxGpQzfhRxeAMuoQVY3B5WgYAFx/1Mk5sy9iiy3jQXmyPDkS59Ai3hjOQiCF4ZQ9Yubm+ilH3Tlmybt/t367uNZYPk3Urc7RAjAm5wsMT77/NFK5k8Ddhu2+UBA3F5r0Jt10udD1FDKYRzLxqi9eMWMx32Ki+lWOv2nX4zmzeofCl2a5FkqxPl4aowNVS+H1e9/carS121GRRX8ZeJZ1gplbFDrg6iFyrphDZLXASYtCeq93xmB+H/qZr1uJ67hvJ6YYxlxIP7N3Cxwh+6wKZWkfQLRV/VmEJtL7lUSvuxbBJL/OGoWizIKT2+UbJiw1p14Ja3pdu0Setl9MVrjuPMU6q7Qe5cNbbXP3eXKCPB24DuD8UrnvxmGpXnlVe8nSWo7NO8cADpBos9Ue5I/b7MWSsp1b2q6JczD1jc69NF40gCfzMYzeka+XOIGm2hyILG3PVb12H6x9huW3/CzVUbEX6HZvTgUPZct2DQXdZqjIMuHpmqwNx54B8h4FKp/gqRDpl/NWJZxX/+vO51OmOp3WGMW9ABPve39aQmAUXIZhC6J7otJcmIou2tM4ZWZ3Rqr7SUrnzb/G/WKKtK3IGFTX2Htx1VWYHY0gR0pWS3WXBfdefeX35k5tiA1BwPEug5QstRd3eM4qA2emr83LbxXsZneR5SGli9VC8I3lxg/wMoHExOUY6x3SfWbzDSTYHF AC95j3+8 HxGSJ2TOYwEdv0mTcqdpN0eVaiVsGzPfPOry4Ipd7wylIgE2TYXdp3rt44w7EWiCNNEhiNucymlivX1WC5nJ/bchFAns+ta6Wr24ShDUxlRpNTYxYj18O8Pw4AuTOPRSNh2GAau6s4o0K85RfLDlrk/8BDB1JbMM1HLIp 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: Collapse the two nested loops into one. This is needed as a step towards turning this into an iterator. --- mm/page-writeback.c | 94 ++++++++++++++++++++++----------------------- 1 file changed, 47 insertions(+), 47 deletions(-) diff --git a/mm/page-writeback.c b/mm/page-writeback.c index 54f2972dab45..68f28eeb15ed 100644 --- a/mm/page-writeback.c +++ b/mm/page-writeback.c @@ -2461,6 +2461,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 */ @@ -2478,65 +2479,64 @@ 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; + 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]; + 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); - 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 + - folio_nr_pages(folio); - 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); + 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. */ - 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 + + folio_nr_pages(folio); 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. + */ + if (--wbc->nr_to_write <= 0 && + wbc->sync_mode == WB_SYNC_NONE) + return writeback_finish(mapping, wbc, true); } return writeback_finish(mapping, wbc, false); -- 2.39.2