From patchwork Mon Feb 12 07:13:44 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christoph Hellwig X-Patchwork-Id: 13552751 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 426F0C4829B for ; Mon, 12 Feb 2024 07:14:30 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id CE0196B0085; Mon, 12 Feb 2024 02:14:29 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id C91086B0087; Mon, 12 Feb 2024 02:14:29 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id AE3C98D0001; Mon, 12 Feb 2024 02:14:29 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0011.hostedemail.com [216.40.44.11]) by kanga.kvack.org (Postfix) with ESMTP id 9A76C6B0085 for ; Mon, 12 Feb 2024 02:14:29 -0500 (EST) Received: from smtpin11.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay01.hostedemail.com (Postfix) with ESMTP id 75B2D1C118E for ; Mon, 12 Feb 2024 07:14:29 +0000 (UTC) X-FDA: 81782288658.11.BB2686C Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) by imf24.hostedemail.com (Postfix) with ESMTP id CB2FB180023 for ; Mon, 12 Feb 2024 07:14:27 +0000 (UTC) Authentication-Results: imf24.hostedemail.com; dkim=pass header.d=infradead.org header.s=bombadil.20210309 header.b=KSEDHvnP; dmarc=none; spf=none (imf24.hostedemail.com: domain of BATV+56c964bc8172c8a9ee6e+7477+infradead.org+hch@bombadil.srs.infradead.org has no SPF policy when checking 198.137.202.133) smtp.mailfrom=BATV+56c964bc8172c8a9ee6e+7477+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=1707722067; 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=z4ixvvDMaABgeR7GnBOm28eb2qdgQ6xM9LNDivmgN8d4oQipFf7TU0baF/qQ52MChaqta1 TvyhJmmZ1TdnyGIFMzhSqE2wfnPabw9q7cGJb00nr589aFx/tPCCg45RUs9s50XstQJ5/U W4UNWJiy0R3W8l7Em0RFSSQVpuJpoTg= ARC-Authentication-Results: i=1; imf24.hostedemail.com; dkim=pass header.d=infradead.org header.s=bombadil.20210309 header.b=KSEDHvnP; dmarc=none; spf=none (imf24.hostedemail.com: domain of BATV+56c964bc8172c8a9ee6e+7477+infradead.org+hch@bombadil.srs.infradead.org has no SPF policy when checking 198.137.202.133) smtp.mailfrom=BATV+56c964bc8172c8a9ee6e+7477+infradead.org+hch@bombadil.srs.infradead.org ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1707722067; a=rsa-sha256; cv=none; b=UhISIgS7gR68HT9UgQ96izK5P3g8+PUtU72tQsUOeHAxsuu9H05yh1wVRb0xZAdOzIeCD/ Bi2mirovCCx74C155gJadZDsnBrToGL9Mw4m19f/dyysUL5r93qfzriWOxi6IjaBXy9n1P 4GfpGvYRnKfuIoU0EwF0mwjfTpk/6NI= 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=KSEDHvnPO53cQSe7AW5PkM179C 0DYoyalxcn+DwuyW53dr955k4BfksGs0A/fvdpCrNU2v6RfJcoVVHZgjOJDRQSk6SLZW/h09KIfpl zmaOnPgCKkPSDxEUIpzJ5N6UpKlyouOnZ7yV02DDBXSQT4lDJFXjCuR22l7N5IlG95PluhMT+qC/E uMHRsQ+YRZRTuyzoAzCxKP4glZ3VsabLC+VtyKBS2vW4d6FWVD4CNp1cJ42IhVaHxcR3TMwfZ8W55 oRAplzCHTEm8E2EJI6uaS6wt3snHiqfPsgSmTI4PE/NgzauQVCyCcIuyvEnFJmHKKBXtr8ffw1NUB z92qXtog==; Received: from [2001:4bb8:190:6eab:75e9:7295:a6e3:c35d] (helo=localhost) by bombadil.infradead.org with esmtpsa (Exim 4.97.1 #2 (Red Hat Linux)) id 1rZQWI-00000004T1W-297p; Mon, 12 Feb 2024 07:14:26 +0000 From: Christoph Hellwig To: linux-mm@kvack.org Cc: Matthew Wilcox , Jan Kara , David Howells , Brian Foster , Christian Brauner , linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org, Jan Kara , Dave Chinner Subject: [PATCH 10/14] pagevec: Add ability to iterate a queue Date: Mon, 12 Feb 2024 08:13:44 +0100 Message-Id: <20240212071348.1369918-11-hch@lst.de> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20240212071348.1369918-1-hch@lst.de> References: <20240212071348.1369918-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: CB2FB180023 X-Rspam-User: X-Rspamd-Server: rspam04 X-Stat-Signature: t4r5qt4xj6ehujd3nw3nrjsn1xiqpq7j X-HE-Tag: 1707722067-610381 X-HE-Meta: U2FsdGVkX18zJYLhAahTTZEiZJ0vZ3sQD5D9JN8DEcQhcdiz7VxVA65jYR34leIrF1iFb2T/0MlHf969E7FqSd2ACcyos64DeXUnlmDS4tm7y2GJnZEoOyGHvh3knshpSZUk7a325cB8kUI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JZJ/M6Iq5W5iDhuHFDoOToz9anmmE0f7EoRPevxKkNtp9cg8JlglQbxGULcsBxAtVwWC1fIwGMUcyKZA7c4IWrtubr3eoYu8A84fKQNLiy3J0zAAo5j8SxLnUYrY24HxD/8mJ0Y3uOBK9l203cTogRYhUP9Cv/lTUKntTzbCNNgpvWR532iW+jcrrZGYD195ln+dVNtGz3CaUANqgCgn6e7vHbSHrHtEo/YL9YPAQd+uR7GRjIXz82WlWi3gIyqK9X+oXw== 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)