From patchwork Thu Jan 25 08:57:49 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christoph Hellwig X-Patchwork-Id: 13530265 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 61D1CC47258 for ; Thu, 25 Jan 2024 08:58:45 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id E4C066B0096; Thu, 25 Jan 2024 03:58:44 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id DD2BB6B0099; Thu, 25 Jan 2024 03:58:44 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id C72956B009B; Thu, 25 Jan 2024 03:58:44 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0014.hostedemail.com [216.40.44.14]) by kanga.kvack.org (Postfix) with ESMTP id B2E486B0096 for ; Thu, 25 Jan 2024 03:58:44 -0500 (EST) Received: from smtpin16.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay01.hostedemail.com (Postfix) with ESMTP id 9640D1C04ED for ; Thu, 25 Jan 2024 08:58:44 +0000 (UTC) X-FDA: 81717232968.16.6012589 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) by imf16.hostedemail.com (Postfix) with ESMTP id ECD3218000B for ; Thu, 25 Jan 2024 08:58:42 +0000 (UTC) Authentication-Results: imf16.hostedemail.com; dkim=pass header.d=infradead.org header.s=bombadil.20210309 header.b=fJTltGtB; spf=none (imf16.hostedemail.com: domain of BATV+b97a0fc658bf3e588113+7459+infradead.org+hch@bombadil.srs.infradead.org has no SPF policy when checking 198.137.202.133) smtp.mailfrom=BATV+b97a0fc658bf3e588113+7459+infradead.org+hch@bombadil.srs.infradead.org; dmarc=none ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1706173123; a=rsa-sha256; cv=none; b=hc4lpm+XruM7LrN7mL7aRNmu4BYLEIAG81qLRcN37JkEYbkMk4NYlfGX+NjT7neH9Dtn0t a7xoSg1/mQbdbcFI11v6YAk7Kat7zLHv/QD1djL+g3w07Svwjhk/k9OtdiVsnb406EwC+a bIWjE9Ij1GkFxrwAqoTWuPR4fxr4Mak= ARC-Authentication-Results: i=1; imf16.hostedemail.com; dkim=pass header.d=infradead.org header.s=bombadil.20210309 header.b=fJTltGtB; spf=none (imf16.hostedemail.com: domain of BATV+b97a0fc658bf3e588113+7459+infradead.org+hch@bombadil.srs.infradead.org has no SPF policy when checking 198.137.202.133) smtp.mailfrom=BATV+b97a0fc658bf3e588113+7459+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=1706173123; 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=dVreMySeIHkVOAtpz+bbvTB1WjeCUE+T6e0OUt9+4gE=; b=LuUAsrNUeRmykdOpyIWBdNeABu5a6nEEqj8xJk3D+xb05KAEdBULhXYdrUy0NqIAfEl7J6 M/65dOnKF1zNpuaNEHWsBgFGQPHqSzki8OUCgMPSCCiCGz4N3eAqOlFfzW74vtQhnJ8dAY WPG+I+oQsHEUVDHbvAzur7RWTY9ixPo= 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=dVreMySeIHkVOAtpz+bbvTB1WjeCUE+T6e0OUt9+4gE=; b=fJTltGtBkzo7VMXaXfEGU0S2qs Y3TXmX4Qw3Kb87AMBLFpKxAN9cRUSTRyhiiLisdvt3e15LemYDbHh8CX9oVaTrWkT5WcI5gqltSre gtXc3Rz3jEWxdX3UHPaeOS3Hb7hZHyiBx9CArSuas0VLj+Ee0BTXrEiRRZLHn1rJ0hvNfPCacQIwi 4w22mSTaXwIpKlSsPKZRSg8yGpeIFN3eeGaHzY2sIVQdKILOhUE8l7UQQW7gIheMp4DibuLjTg2lA lkMK3uinulqtVqUk1ihMf4BxEx5sAZjWCGzuhRZUixA07JrSrTkRKRTb4na0D7Pg3JVqopLmucgfQ J05KCISQ==; 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 1rSvZJ-007QNR-2E; Thu, 25 Jan 2024 08:58:42 +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 10/19] pagevec: Add ability to iterate a queue Date: Thu, 25 Jan 2024 09:57:49 +0100 Message-Id: <20240125085758.2393327-11-hch@lst.de> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20240125085758.2393327-1-hch@lst.de> References: <20240125085758.2393327-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-Server: rspam08 X-Rspamd-Queue-Id: ECD3218000B X-Stat-Signature: 8paadqnmckm8kqd63bii6rtixxw6xhqt X-Rspam-User: X-HE-Tag: 1706173122-404225 X-HE-Meta: U2FsdGVkX1/3eceohhCGzfRD7KkT/Ki6RNSEkpLJCUoVszvYNJn5iQ7dYprYk2pZ2B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whmQdBI/BDPh1k3rSFCylsR/dz205k84cZmBLzoGAsejy4y7akkVtN8/JogZ9qbTAaUmQc11t1oqLfiELYfXW6vb7TSwT68Rwwqd2SguTLHfvhNLmz3WBM99YAkFh1cC76RLlN+DpdKcWndHbU6bG/Dz7n6TEP8e9PywzgObObWr7/3pPAuM+CNBaMb5JUYh/D4xu1HL9Y2ZW7MGbAfgC570condyYonHicZoY/98bTgbp+yyz69PKYPWPtuQjZ5K/fOcmyDcefTQx2g+kitQCkFvRdvFORIZxa9besmao5vIEttjtvT7P/6UtgfeCJJdoUoKatrd4D1FHWvf5ck6kanKqEY8TKo8sFIw== 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 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)