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: 196230 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7301:9bc1:b0:106:209c:c626 with SMTP id op1csp944658dyc; Sat, 3 Feb 2024 02:15:07 -0800 (PST) X-Google-Smtp-Source: AGHT+IEJaBVIs4cgTf3OPXEiGrWo7feQaV4HAkieCO4xlQhXcjR/DndKLttGVizv3SFZwDofrbc1 X-Received: by 2002:a05:620a:218d:b0:783:55af:9d5c with SMTP id g13-20020a05620a218d00b0078355af9d5cmr4655197qka.55.1706955307097; Sat, 03 Feb 2024 02:15:07 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1706955307; cv=pass; d=google.com; s=arc-20160816; b=MPeqoVkl0GtcqJiujlgDBNjsow8p2/+MOToffTF2tT8bIgodrJc/DSEj8Gdam4Sg8q L6phF3oSww8W8Rfjv2Z4thiFBTI+51bSlbJ5QpbyXokDHY2gf2f49cT2UXQNbF60nKUD jO7n/Olp3bDnEO5MTSUsJAybV3SsRygyNzB0Am0sa25zGWZDE1wIRIufmhFQ3JxDvYiV 96tsyYWyjbJXMq2tHhjbdKl0DbnXIdVHyVSArjjSdml0J+tUbs5ujSBfeOohJWp8WyyC SF8lsMTtjSBZcbuG3hw6E06zz//BIjjKOIganTEvVMtZMhxPYGpl6AbuNTFOtpj6K5uG +vjA== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :date:subject:cc:to:from:dkim-signature; bh=M5Qvp5zNKGHXjXReg58hQjrWh/GgxzXP5maEkxrO/YI=; fh=TY3wz6kcoptQnUGOkpmDAyOteoMooHl0LcTQW4Xc2OA=; b=wmynSf12yKztQzOuvNddQA3SlWjSz6ev+aev3t91Y2zEEJEr4H3f+FGBs3HWZWhd7o 6RLr6yOREYyGfXzppzQDUFkCMTTHt8x1sfl3dGwbHSk00O8wrzCazrCp9ac6I28Qlx/F U+oWaoEw95mYFTQAoTRUC5y0GdQ63AAO4XWOotLm0di3lboLLtr0KyW4fRAD5z0pm0Sx 5Z/QNPIvKeBpkriWe5cG0A8X1g/XXYK4SfkTlRZhO94mnOwOH2IFYMvD52fjUdntNc0S Mc++XYhyB3/oy04J80M7gnawjASrpwwzU1N2brTtm5yMhMRIul3Vb/CmnHU+WWbI2zGb 2/IQ==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@infradead.org header.s=bombadil.20210309 header.b="0/r+7dmm"; arc=pass (i=1 dkim=pass dkdomain=infradead.org); spf=pass (google.com: domain of linux-kernel+bounces-50958-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-50958-ouuuleilei=gmail.com@vger.kernel.org" X-Forwarded-Encrypted: i=1; AJvYcCUeg56SnqedbyH8OE0ZIN7gI84z21pztFMqmbbF3v4OpNZ2woKbTCRK+G644teWKwvVED0BKsvwGekkVvkdouDN194lDg== Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [2604:1380:45d1:ec00::1]) by mx.google.com with ESMTPS id l19-20020a05620a211300b0078438018b61si3925147qkl.136.2024.02.03.02.15.06 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 03 Feb 2024 02:15:07 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-50958-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) client-ip=2604:1380:45d1:ec00::1; Authentication-Results: mx.google.com; dkim=pass header.i=@infradead.org header.s=bombadil.20210309 header.b="0/r+7dmm"; arc=pass (i=1 dkim=pass dkdomain=infradead.org); spf=pass (google.com: domain of linux-kernel+bounces-50958-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-50958-ouuuleilei=gmail.com@vger.kernel.org" Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ny.mirrors.kernel.org (Postfix) with ESMTPS id 8B86C1C25B49 for ; Sat, 3 Feb 2024 07:15:18 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 41DDB54BDD; Sat, 3 Feb 2024 07:12:46 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=infradead.org header.i=@infradead.org header.b="0/r+7dmm" Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 5022853812; Sat, 3 Feb 2024 07:12:42 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=198.137.202.133 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706944363; cv=none; b=ETCvOLdhlL9VCtJUvI3xZj4JQL+17KTC3v+xM66TzcbwePUD5wFkSREACWT1O0PcmLTd36yyXvlqi+nrxuFz5EVigP6wY/I4t+dWPZYVWKodJpzklIOMQq79RDXTsS3GtXfcF+Pzbucu/pnoL7KQEMstq62duXOVV8MqIGXvzcs= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706944363; c=relaxed/simple; bh=8YXecWRICYuMcNttDcOnWW490EjFn6keh2I4C8IPcyw=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=uIvJoH33sA4D3FKDBM4CFRm0itPyg4kiw0XXUc7vTM4FoBi7TnHJWZrR/SNi7ioLCV/WV6XoObo7ss3lTahpbpBdH/AnbAI8ceA0oAALxQNbLUUrKmeyTEr15vfqr1TFo72g8Yz95uIY7mb50va/UOgAR+IfXLCu0NfZmN/qjTw= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=lst.de; spf=none smtp.mailfrom=bombadil.srs.infradead.org; dkim=pass (2048-bit key) header.d=infradead.org header.i=@infradead.org header.b=0/r+7dmm; arc=none smtp.client-ip=198.137.202.133 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=lst.de Authentication-Results: smtp.subspace.kernel.org; spf=none smtp.mailfrom=bombadil.srs.infradead.org 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> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-SRS-Rewrite: SMTP reverse-path rewritten from by bombadil.infradead.org. See http://www.infradead.org/rpr.html X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1789872368070897557 X-GMAIL-MSGID: 1789872368070897557 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)