From patchwork Sat Feb 3 07:11:43 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christoph Hellwig X-Patchwork-Id: 13543904 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 06C8CC4828D for ; Sat, 3 Feb 2024 07:12:44 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 8E4C16B006E; Sat, 3 Feb 2024 02:12:43 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 86DA26B0082; Sat, 3 Feb 2024 02:12:43 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 6C08E6B0083; Sat, 3 Feb 2024 02:12:43 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0016.hostedemail.com [216.40.44.16]) by kanga.kvack.org (Postfix) with ESMTP id 54FB86B006E for ; Sat, 3 Feb 2024 02:12:43 -0500 (EST) Received: from smtpin04.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay02.hostedemail.com (Postfix) with ESMTP id E754A120332 for ; Sat, 3 Feb 2024 07:12:42 +0000 (UTC) X-FDA: 81749624964.04.D8EB3CF Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) by imf05.hostedemail.com (Postfix) with ESMTP id 41E2A100005 for ; Sat, 3 Feb 2024 07:12:41 +0000 (UTC) Authentication-Results: imf05.hostedemail.com; dkim=pass header.d=infradead.org header.s=bombadil.20210309 header.b="0/r+7dmm"; dmarc=none; spf=none (imf05.hostedemail.com: domain of BATV+a0ed29cff9639d748e7e+7468+infradead.org+hch@bombadil.srs.infradead.org has no SPF policy when checking 198.137.202.133) smtp.mailfrom=BATV+a0ed29cff9639d748e7e+7468+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=1706944361; 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=M5Qvp5zNKGHXjXReg58hQjrWh/GgxzXP5maEkxrO/YI=; b=zlWvshgk/KOYVW7wyhRP96jn/OI/viTAD8kHhWtavmb7fzLCi8uRLYPg6T/BLA18t+MgI1 mOjIwj3rja1RwW1xXt5FjbI+E/ad4sdYzGFZaX4MyLc+CxvT3eM5jRlluiIe+whGNP1Wxm zKZwC4VsE4hDEmGbE8p/dNqX+bURcIA= ARC-Authentication-Results: i=1; imf05.hostedemail.com; dkim=pass header.d=infradead.org header.s=bombadil.20210309 header.b="0/r+7dmm"; dmarc=none; spf=none (imf05.hostedemail.com: domain of BATV+a0ed29cff9639d748e7e+7468+infradead.org+hch@bombadil.srs.infradead.org has no SPF policy when checking 198.137.202.133) smtp.mailfrom=BATV+a0ed29cff9639d748e7e+7468+infradead.org+hch@bombadil.srs.infradead.org ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1706944361; a=rsa-sha256; cv=none; b=WsNcc0bQdXYDpc6g5qVteU00c6xIem6y09eWiYp/3l71y1n36pUx95PQR4tGtlDmJvfUZY CDyvPFYfrv/iXCD/lI0uknODK3T1vs6Xr6XY/Pl/pRK6g6C6WoJQsg44eldoBsCBdlr1VZ 2pwhTavc65Aa0XEqF9+FtZZaDUPNs8k= 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=M5Qvp5zNKGHXjXReg58hQjrWh/GgxzXP5maEkxrO/YI=; b=0/r+7dmm43M5Dn9pI478JvAC/4 oMa4a8isH3iYu7/DiNuxK8ticsjuP9iB3tDFkuLLDpkg6dtFVtGZrup7ew7Rnn5OM2HIv9tS6RfwK LqawRXjuztB1xFtFVyxTQO1HlsxCukxD2MXQPsnIdK7arkvSvDEEZFNyL7beFqM3neAWYFUFJ2s1C rXejoAV9Dgdly36z5qeDNo2SknFWyn45vn2vzB7BwJXJaJ2MzKYi37Fk32ni74PE30b7+Rqi/uaDS AvC5hBjkd/pVjcP1eTjIgMojnI0ey9H2nma+pU9cepPu814Hc9/zTDPLloxTU4xB4yUYmcDRrLuB4 C+xJMSdQ==; Received: from [89.144.222.32] (helo=localhost) by bombadil.infradead.org with esmtpsa (Exim 4.97.1 #2 (Red Hat Linux)) id 1rWACd-0000000FkDE-0QIe; Sat, 03 Feb 2024 07:12:40 +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 09/13] pagevec: Add ability to iterate a queue Date: Sat, 3 Feb 2024 08:11:43 +0100 Message-Id: <20240203071147.862076-10-hch@lst.de> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20240203071147.862076-1-hch@lst.de> References: <20240203071147.862076-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: 41E2A100005 X-Rspam-User: X-Rspamd-Server: rspam02 X-Stat-Signature: us4a5i56ugcuzxxgkbkgmzty7m6zrigs X-HE-Tag: 1706944361-930588 X-HE-Meta: U2FsdGVkX1/wm1A4G/UHybX0oNSAyLFObAhN62e7Xcm7ngiSVHM86WiPsJyc0s1kDhyngSX/6phANytSl2f1L+qeka6ARMhAn7pelY12e3t7qBJfy978xzP5nyZFDS254xeX5/2B1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guRfc41ZSObFC/gY3VyNFBxRIXwu61247CsKvx/YhnUkO+NJPqdNPCB3a2uFBjWcgomJw7gy0Ze/IiCcdzIuSdA8CvpkwQvyzysX+36RYFxLGkAdqOaL+q3uMaJh/+BzTAbLJyF1eUnpyrQuK0KndsM1IkAMwrjbT2dj5dOZ0/BVWcVDbn3C+sfnaRAvXrYZuVtQZ51WqtYm4qZF5mNx746CL4g7QdHHtr74lnOFzGeL7IE2TrvjZoqGa0QAPXt+rf 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)" 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 Reviewed-by: Brian Foster Reviewed-by: Jan Kara Acked-by: Dave Chinner --- 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)