From patchwork Mon Dec 18 15:35:47 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christoph Hellwig X-Patchwork-Id: 180501 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7300:24d3:b0:fb:cd0c:d3e with SMTP id r19csp1329142dyi; Mon, 18 Dec 2023 07:41:01 -0800 (PST) X-Google-Smtp-Source: AGHT+IEIeyOmENyyyR4FnPc0vR8xComYXuXujMSenGAeFniconm+2zFiYhbKf/5QVDI1BaVhNVET X-Received: by 2002:a17:906:6c92:b0:a23:6eb6:6b35 with SMTP id s18-20020a1709066c9200b00a236eb66b35mr20677ejr.136.1702914060930; Mon, 18 Dec 2023 07:41:00 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1702914060; cv=none; d=google.com; s=arc-20160816; b=i5RhPAS9wFJHwnQzXmmzLQPN9tW799myGZHo/TI3yY/jGEy+X5rkVImEDqc7T9HctP XYDRURQeDlPyqnU2vgEHL9fNCtxln8Itb+J5xbDlXTRWVTJOKx9lxv1QBLnU7/tUMdFF 3Kbbdu14EoW71S8qM84HgDv/UNB2XISW89OTIqB/HdPxXl2x21qpGoRAFA2gsIRSWedP 4BOaqyeFa/Q//EXsWbA3Vc3CYmxITg8wBWHq5HII1X4rAwiPqeRupV9CMGY1BdEwqZOK lK1gvyfarPb7osOpZuy7UfBgaIBJjMIPUNCGb17pTApjU/1M/NaFfruB02i83QPzv3jZ 7dww== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :date:subject:cc:to:from:dkim-signature; bh=3B9Hp+QAdQFWcqrQUPpFbTk6qvR0M5sjBup3lTEiqhs=; fh=m0HBXuwgOCKat7wyuY7vstPypqMqxNmINnjBv5+EUjU=; b=GX/wtOGSgdQFZ+mOVcRWK0WQ1tkiP98j20c8KXsZiPpTkwiboBPGXlVl/tTQRIqvgx apPRaYtYFD3ZfiCAccMu8rNZ1/K+SQ2RTu0OmwO9AYZKnpia5P0fkeeG0SROHekJ9urF UAUVRpkauwc1fK3NI9NoHCoTUNaB8EWfD5ipmbCWpONODLQK2/oL1mK+9NKfVX/8Amiu 6ui/ByAMHZNEi4CuWJ0hcrFHS2pBxhJb+1FmLL4pcmiXBrmpUIxArUTj+uSdszqQFZ7n M6/n2wrK5ngkAmdSwtwvNHrj7eP38QhAqX6Isc/rEzjQvQUJtCbqbrXmdL3AbhkwK9eV mEeg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@infradead.org header.s=bombadil.20210309 header.b=THuXRAhN; spf=pass (google.com: domain of linux-kernel+bounces-3953-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-3953-ouuuleilei=gmail.com@vger.kernel.org" Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [147.75.80.249]) by mx.google.com with ESMTPS id j25-20020a170906051900b00a2352a12fb4si1153328eja.1017.2023.12.18.07.41.00 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 18 Dec 2023 07:41:00 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-3953-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) client-ip=147.75.80.249; Authentication-Results: mx.google.com; dkim=pass header.i=@infradead.org header.s=bombadil.20210309 header.b=THuXRAhN; spf=pass (google.com: domain of linux-kernel+bounces-3953-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-3953-ouuuleilei=gmail.com@vger.kernel.org" Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by am.mirrors.kernel.org (Postfix) with ESMTPS id 02DD81F24816 for ; Mon, 18 Dec 2023 15:40:38 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 9043273473; Mon, 18 Dec 2023 15:36:35 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=infradead.org header.i=@infradead.org header.b="THuXRAhN" X-Original-To: linux-kernel@vger.kernel.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 536C34239E; Mon, 18 Dec 2023 15:36:30 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=lst.de Authentication-Results: smtp.subspace.kernel.org; spf=none smtp.mailfrom=bombadil.srs.infradead.org 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=3B9Hp+QAdQFWcqrQUPpFbTk6qvR0M5sjBup3lTEiqhs=; b=THuXRAhNeLCiO2K1fm6woSSF0o FKejSp1UwrESZMKns9PM7cdQ7F8P7vGO1leM/ItulT1ZAASbVhH3soffvn0yy2cYNQ7Db4BAOr9ku m7Aeco/LSG1tytEmmHRNB8t01Capsk3p3022lowatIGQS/92K5TIZZ50ORvE1uUbfbl5qTGihahCG t7RR7qRTsnt6rYpRX6/KmySAwqvvivwVdHHPiSnYv+ICCPdXwP4idam3OfER0xCEM1QDucjIIGYwL z3kxcpHeMwiL3Gk+EC3dtqn2BU8RvjxXmiBBSf79ujCTwihDzG75A4W/ShiFDKWGhEztFg+1o/gtd WL+ry0qg==; 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 1rFFfO-00BEUC-1y; Mon, 18 Dec 2023 15:36:27 +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 11/17] writeback: Use the folio_batch queue iterator Date: Mon, 18 Dec 2023 16:35:47 +0100 Message-Id: <20231218153553.807799-12-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> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-SRS-Rewrite: SMTP reverse-path rewritten from by bombadil.infradead.org. See http://www.infradead.org/rpr.html X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1785634814315315578 X-GMAIL-MSGID: 1785634814315315578 From: "Matthew Wilcox (Oracle)" Instead of keeping our own local iterator variable, use the one just added to folio_batch. Signed-off-by: Matthew Wilcox (Oracle) Signed-off-by: Christoph Hellwig Reviewed-by: Jan Kara --- mm/page-writeback.c | 19 +++++++++---------- 1 file changed, 9 insertions(+), 10 deletions(-) diff --git a/mm/page-writeback.c b/mm/page-writeback.c index c7983ea3040be4..70f42fd9a95b5d 100644 --- a/mm/page-writeback.c +++ b/mm/page-writeback.c @@ -2397,13 +2397,19 @@ static pgoff_t wbc_end(struct writeback_control *wbc) return wbc->range_end >> PAGE_SHIFT; } -static void writeback_get_batch(struct address_space *mapping, +static struct folio *writeback_get_next(struct address_space *mapping, struct writeback_control *wbc) { + struct folio *folio = folio_batch_next(&wbc->fbatch); + + if (folio) + return folio; + folio_batch_release(&wbc->fbatch); cond_resched(); filemap_get_folios_tag(mapping, &wbc->index, wbc_end(wbc), wbc_to_tag(wbc), &wbc->fbatch); + return folio_batch_next(&wbc->fbatch); } static bool should_writeback_folio(struct address_space *mapping, @@ -2473,7 +2479,6 @@ int write_cache_pages(struct address_space *mapping, { int error; pgoff_t end; /* Inclusive */ - int i = 0; if (wbc->range_cyclic) { wbc->index = mapping->writeback_index; /* prev offset */ @@ -2489,18 +2494,12 @@ int write_cache_pages(struct address_space *mapping, wbc->err = 0; for (;;) { - struct folio *folio; + struct folio *folio = writeback_get_next(mapping, wbc); unsigned long nr; - if (i == wbc->fbatch.nr) { - writeback_get_batch(mapping, wbc); - i = 0; - } - if (wbc->fbatch.nr == 0) + if (!folio) break; - folio = wbc->fbatch.folios[i++]; - folio_lock(folio); if (!should_writeback_folio(mapping, wbc, folio)) { folio_unlock(folio);