Received: by 2002:a05:7412:8d06:b0:f9:332d:97f1 with SMTP id bj6csp12580rdb; Mon, 18 Dec 2023 07:40:40 -0800 (PST) X-Google-Smtp-Source: AGHT+IE8QQK0/SJapeTIGPw6BYglP4OBz9Fi/SHZGoXnimJEAcuqCkmUlsr0UgZ0zG6SgkoTIdsS X-Received: by 2002:a05:6808:3998:b0:3b9:f017:288 with SMTP id gq24-20020a056808399800b003b9f0170288mr27078320oib.21.1702914040197; Mon, 18 Dec 2023 07:40:40 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1702914040; cv=none; d=google.com; s=arc-20160816; b=bG90Lbznxq8besO9/0ICjzmTXpANOtmxXMwWXozZqa0qfLFwYf45ZDUBHOlYT3I7r0 mZN+hDqFhfE/0uxOV1kCdX2Ix4gYvmgnTyEPzrTYYugQFlEi8fCzO5dH46VQck7b7iXw r6mYiDvPHLikaw5iqqX89rplBnHcNnlps2SaQnaUepFt4dgEXhy/dVbVUAZYnxIzHeHu rHxZLp1x8NeAvthajT51WEMdotF6uO+UV0BeE7sTEANjJS+kOXVnce31WQw1ppviPNKC 27STlvHvkvcZ5Rix95OOp2EFEjtGjFLz57mFnqySkiiJzjhqoW76WQRItcXG235GDpuL qOGg== 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=Ps3gOgcx63gp+vASNuJqnAAKIBRQ41EfNIZIAmlnf24=; fh=m0HBXuwgOCKat7wyuY7vstPypqMqxNmINnjBv5+EUjU=; b=VOZV6Q/vvcd7+M3dP1im0EcoqVz2Ele4HOO2NnZBFZHWCaK2tG+4jsSAgrCnRQ3bWU EIkbg9Ky3xFYw8MssjDSd2J+lI4rvIik9iNbL899szljGnV5DPFyetZkUt9p/LqIGAFM Emtj8/Y42BaM6GtPsijVz8VL4h6k3B9B/5Kucilzn/Z4Wf1DRz82Neu+JDiD9OJfdvBW 0SvQNBDeWCb+zH/Tzn0GKJ2Nt+iDUWQoWwmVD8RmqorZyailMH4F1OcqBJ6qEpdd8E3x x/9Tu0B3LARygvCucdE3muim3rTImuPevIM3qLXUiVkgaWm6c+2xXty7ZFO1ZD+oISNr EQag== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@infradead.org header.s=bombadil.20210309 header.b=PzUxxt+v; spf=pass (google.com: domain of linux-kernel+bounces-3954-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-3954-linux.lists.archive=gmail.com@vger.kernel.org" Return-Path: Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [2604:1380:45d1:ec00::1]) by mx.google.com with ESMTPS id g21-20020a0caad5000000b0067a92d7c4b7si7060628qvb.319.2023.12.18.07.40.40 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 18 Dec 2023 07:40:40 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-3954-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) client-ip=2604:1380:45d1:ec00::1; Authentication-Results: mx.google.com; dkim=pass header.i=@infradead.org header.s=bombadil.20210309 header.b=PzUxxt+v; spf=pass (google.com: domain of linux-kernel+bounces-3954-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-3954-linux.lists.archive=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 ny.mirrors.kernel.org (Postfix) with ESMTPS id 6664A1C233FE for ; Mon, 18 Dec 2023 15:40:16 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 250297206D; Mon, 18 Dec 2023 15:36:34 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=infradead.org header.i=@infradead.org header.b="PzUxxt+v" 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 1DB997147B; Mon, 18 Dec 2023 15:36:31 +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=Ps3gOgcx63gp+vASNuJqnAAKIBRQ41EfNIZIAmlnf24=; b=PzUxxt+v50nPSxDTPZ8egGBWfd MMy4h3eKPEI9Su6ip1RebkN45yXzbC6KCzepkmpLe85GHZoJSqZbASEKMt9yNN8UH7UVTwf/eT0mi w9A6TjmvLXfd7SrnEsmK4cDdhwPQtRcurwRBpW7JUAxqQ0pXquJQsT0pftxGJfvXfp9gLgSqtSymO 4/UBPeQrmuWwzuXGJ8706l8U3n7gsEUdkBmUvwt0JXXH/HXdu0JWfMQKqayYaFepmfeDAbF/DqZG9 2h+m5joplkFF1pbTk9EjlIz1dPpj0mTXzvWh2NGDfy9hKFS71M1WR9jorHRxb7VMrv3F0gkxqG33t ZovPYW6g==; 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 1rFFfL-00BESJ-1j; Mon, 18 Dec 2023 15:36:23 +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 10/17] pagevec: Add ability to iterate a queue Date: Mon, 18 Dec 2023 16:35:46 +0100 Message-Id: <20231218153553.807799-11-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 Content-Transfer-Encoding: 8bit X-SRS-Rewrite: SMTP reverse-path rewritten from by bombadil.infradead.org. See http://www.infradead.org/rpr.html From: "Matthew Wilcox (Oracle)" Add a loop counter inside the folio_batch to let us iterate from 0-nr instead of decrementing nr and treating the batch as a stack. It would generate some very weird and suboptimal I/O patterns for page writeback to iterate over the batch as a stack. Signed-off-by: Matthew Wilcox (Oracle) Signed-off-by: Christoph Hellwig --- include/linux/pagevec.h | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/include/linux/pagevec.h b/include/linux/pagevec.h index 87cc678adc850b..fcc06c300a72c3 100644 --- a/include/linux/pagevec.h +++ b/include/linux/pagevec.h @@ -27,6 +27,7 @@ struct folio; */ struct folio_batch { unsigned char nr; + unsigned char i; bool percpu_pvec_drained; struct folio *folios[PAGEVEC_SIZE]; }; @@ -40,12 +41,14 @@ struct folio_batch { static inline void folio_batch_init(struct folio_batch *fbatch) { fbatch->nr = 0; + fbatch->i = 0; fbatch->percpu_pvec_drained = false; } static inline void folio_batch_reinit(struct folio_batch *fbatch) { fbatch->nr = 0; + fbatch->i = 0; } static inline unsigned int folio_batch_count(struct folio_batch *fbatch) @@ -75,6 +78,21 @@ static inline unsigned folio_batch_add(struct folio_batch *fbatch, return folio_batch_space(fbatch); } +/** + * folio_batch_next - Return the next folio to process. + * @fbatch: The folio batch being processed. + * + * Use this function to implement a queue of folios. + * + * Return: The next folio in the queue, or NULL if the queue is empty. + */ +static inline struct folio *folio_batch_next(struct folio_batch *fbatch) +{ + if (fbatch->i == fbatch->nr) + return NULL; + return fbatch->folios[fbatch->i++]; +} + void __folio_batch_release(struct folio_batch *pvec); static inline void folio_batch_release(struct folio_batch *fbatch) -- 2.39.2