From patchwork Thu Feb 15 06:36:45 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christoph Hellwig X-Patchwork-Id: 13557444 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 A46C0C48BEB for ; Thu, 15 Feb 2024 06:37:39 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 4084C6B00B7; Thu, 15 Feb 2024 01:37:26 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 259CA6B00B6; Thu, 15 Feb 2024 01:37:26 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 05E0F6B00B7; Thu, 15 Feb 2024 01:37:25 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0015.hostedemail.com [216.40.44.15]) by kanga.kvack.org (Postfix) with ESMTP id DE7166B00B5 for ; Thu, 15 Feb 2024 01:37:25 -0500 (EST) Received: from smtpin18.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay08.hostedemail.com (Postfix) with ESMTP id 824A0140D65 for ; Thu, 15 Feb 2024 06:37:25 +0000 (UTC) X-FDA: 81793081650.18.380EF32 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) by imf22.hostedemail.com (Postfix) with ESMTP id D9F07C0005 for ; Thu, 15 Feb 2024 06:37:23 +0000 (UTC) Authentication-Results: imf22.hostedemail.com; dkim=pass header.d=infradead.org header.s=bombadil.20210309 header.b=oocpZKdd; dmarc=none; spf=none (imf22.hostedemail.com: domain of BATV+a252b21bd4a653ddb6e6+7480+infradead.org+hch@bombadil.srs.infradead.org has no SPF policy when checking 198.137.202.133) smtp.mailfrom=BATV+a252b21bd4a653ddb6e6+7480+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=1707979043; 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=lqsE9e9g/aV1IX8p5q9WkClTU9w4LCBRqnjTTL0vuQZNT5CYEYeh3bQJ0qES2M2ix+4Z2y hnmIzr/CEGJilEy/3tP45pS1dddrxmxe18WmkHiOUJ5eOKYPqv1e61dnxl9Ak/YdcuLGvx SKZ9ImlNmH0YfKtT3jas/uZuO/uY6b8= ARC-Authentication-Results: i=1; imf22.hostedemail.com; dkim=pass header.d=infradead.org header.s=bombadil.20210309 header.b=oocpZKdd; dmarc=none; spf=none (imf22.hostedemail.com: domain of BATV+a252b21bd4a653ddb6e6+7480+infradead.org+hch@bombadil.srs.infradead.org has no SPF policy when checking 198.137.202.133) smtp.mailfrom=BATV+a252b21bd4a653ddb6e6+7480+infradead.org+hch@bombadil.srs.infradead.org ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1707979043; a=rsa-sha256; cv=none; b=7THl9yZ6jD8YYWbSjnS0P4Xf+Un1/hGFkZoJURCy771KYRmWvMgU/Zhmb/6l10+yr9nwxF 6DBHlozwdGDiQHpzNbuWYaE2edmRA34hO3ywSxNky9HVaEtpvRGRf2pm1hb+inEt20fR22 8QboGGDc3y5a4qw4oJH3wu/LuRyp7oE= 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=oocpZKddbVY6RivLE2iFbVbswr +U/BXlpxFleRHdXUV6ZMR2h0ZR8BOy5nKcJJJ/GUEaAExDlL9pX5lAZXTSltOaS9OTTnJDvTzQcQv eL1jmtI9M2tdt2PMmW371ExOcZVdcEKOWF1jU1tTp+uIg57k2D50vxNDLOWMnvi1qZxUQArDazn3j FituwDoNFLW7LSflofvpYgyI9EICnaZCJIC8q4Z2M5xgJUStQXHSMa8GMpchZls5wuGh++UqPRyMm pRCmsqHqfq9HrJ5bKPZnZ1XJoD4MvnwuyYa2HZbnR1PaeCY3pQwDmE40RCjh6kW3u2J3T1zTDC95D nTwbtk9g==; 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.97.1 #2 (Red Hat Linux)) id 1raVN4-0000000F6yZ-2rwu; Thu, 15 Feb 2024 06:37:23 +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: Thu, 15 Feb 2024 07:36:45 +0100 Message-Id: <20240215063649.2164017-11-hch@lst.de> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20240215063649.2164017-1-hch@lst.de> References: <20240215063649.2164017-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: D9F07C0005 X-Rspam-User: X-Rspamd-Server: rspam05 X-Stat-Signature: 5nkkd9btbmwff88kesxxasnukyx7b36b X-HE-Tag: 1707979043-501707 X-HE-Meta: U2FsdGVkX18JenJDzycID3rXzwHpDCpGivO/t8T58pQ7kbDvCz7c1R+tyOrm5I1/t4rm+N15QJHX34AEU0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X6JLKQbb8pCfg0Z1Qya6si2cZC/DBLIOTckM5Pz8x/o7Oa/GZ1PiWUua+TnuV8WTO5uDKk3FhUkgiHXk06iET6082HTo8NskchXi6iyYEhER2QBSkd+NNnx5Ua8VfQ/dm4s/SzVYINVJUFAIkNVM7y2RHS6ijgY/XHOF8er6Ji1OFtlwCFd+wskrMPjWf7HkhYtkQHU1uM6LPsmOY9i+1noS4KqrfcjgCh6+lNVv0Xs3HoiE14obS+S0afp98EY2T9rQwE1a7i6QiFOarz1cjrlMBFXBI0/x3mkgmU1w08drQXZ6lS3XfEo9vkqa8r6n58gd9yBQzvY8AXpJ3jBOQ== 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)