From patchwork Mon Dec 18 15:35:46 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christoph Hellwig X-Patchwork-Id: 13497164 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 E5CEFC35274 for ; Mon, 18 Dec 2023 15:36:29 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 064C98D0009; Mon, 18 Dec 2023 10:36:27 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id F06198D0001; Mon, 18 Dec 2023 10:36:26 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id D33F28D0009; Mon, 18 Dec 2023 10:36:26 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0012.hostedemail.com [216.40.44.12]) by kanga.kvack.org (Postfix) with ESMTP id AB1018D0001 for ; Mon, 18 Dec 2023 10:36:26 -0500 (EST) Received: from smtpin25.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay05.hostedemail.com (Postfix) with ESMTP id 86016401E5 for ; Mon, 18 Dec 2023 15:36:26 +0000 (UTC) X-FDA: 81580340772.25.89908FB Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) by imf07.hostedemail.com (Postfix) with ESMTP id DC3D040023 for ; Mon, 18 Dec 2023 15:36:24 +0000 (UTC) Authentication-Results: imf07.hostedemail.com; dkim=pass header.d=infradead.org header.s=bombadil.20210309 header.b=PzUxxt+v; spf=none (imf07.hostedemail.com: domain of BATV+09f18f96a25a69770120+7421+infradead.org+hch@bombadil.srs.infradead.org has no SPF policy when checking 198.137.202.133) smtp.mailfrom=BATV+09f18f96a25a69770120+7421+infradead.org+hch@bombadil.srs.infradead.org; dmarc=none ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1702913784; 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=Ps3gOgcx63gp+vASNuJqnAAKIBRQ41EfNIZIAmlnf24=; b=QVc8TNjw72rP5qtmFeuAkKnzCtTbcdGgFnesbM1Vpn/eosLZKfAIaEklxElsQrLm39KVR0 AM8bZtHR9b233BL9rnRX378L9ge5mF7pklcsjc4VvzoaqeoU+/nX1p4Jf3rtm67JXh/8Ri BjfbkJWDvv2qclMNCF+nrkcnJkYHch8= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1702913784; a=rsa-sha256; cv=none; b=6j+BmNUJcHC9upA+8r8ONFXW+r+v14jNU4tggYo+P8Kr8UmWXS1PFLp4UFriqDyh+AC0fn DVq+G7pPy9ySzhdq3/cORJIcb8H2Ygx9hnQCP9vUTQpe9jlDOPMTZ8ozJS/1degqXE2MIZ 0HgVmtehceQHAhv/BkzBYpuvqX2ex5s= ARC-Authentication-Results: i=1; imf07.hostedemail.com; dkim=pass header.d=infradead.org header.s=bombadil.20210309 header.b=PzUxxt+v; spf=none (imf07.hostedemail.com: domain of BATV+09f18f96a25a69770120+7421+infradead.org+hch@bombadil.srs.infradead.org has no SPF policy when checking 198.137.202.133) smtp.mailfrom=BATV+09f18f96a25a69770120+7421+infradead.org+hch@bombadil.srs.infradead.org; dmarc=none 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> 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: DC3D040023 X-Rspam-User: X-Stat-Signature: pfnwqstxo8wcf66hfos6kqhxzih651fi X-Rspamd-Server: rspam03 X-HE-Tag: 1702913784-473425 X-HE-Meta: U2FsdGVkX18U9Jks0Idx52Jro+bZ0uH7iyjB00Uiqb0RqXenP6b/yf/nuOergsNU5jMnZgPMcySpIgPyzAaXkssbTiGTa40+TRfsYLuJGpFbHHlQbugXwsKFKdkhBINATncLvjLQ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Vh+0OrAXiWCb3sXrOhmOZx0h/USinifErmt9PW2FpLPJC09iZhJ0tI2aq1wZRiwYBJKVIlHTQAo/++Zh5yzQjVsRQAxP31ZvD99aGP0p7r+KoCCmTKGMtFU1vOm5e1DnFWBKpAgeq6ohJPRmawvUZu+vhZQktlA+cXEsGTezZ8/xbtu6e+qHgZ05CrCWJ/pmZ5eHhxtNbt7He/6HDUtLRrAyVKwcpEPHDvRxoExcF3A1Po7YL3/1QuocdBH 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: Jan Kara --- 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)