From patchwork Mon Jun 26 17:35:14 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Matthew Wilcox X-Patchwork-Id: 113074 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:994d:0:b0:3d9:f83d:47d9 with SMTP id k13csp7653606vqr; Mon, 26 Jun 2023 10:54:14 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ4t73je8qI3KyHzY9S1yPeRsNcqbsYjdX1JAkmy8nPy+jbJEjbyOj8zN8ysIflczTkGBnmu X-Received: by 2002:aa7:db4f:0:b0:51a:5ac3:4df8 with SMTP id n15-20020aa7db4f000000b0051a5ac34df8mr14648361edt.5.1687802054588; Mon, 26 Jun 2023 10:54:14 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1687802054; cv=none; d=google.com; s=arc-20160816; b=oggCHQwHZ4s94FK0hn+jxYdQ9ro/e9vVSSHQRzBqglKY+Vs8TT9OorppQUW1F0vS4I t/8ur5KMSgcr2d2kD2dXQLRvHNW/TO1Niau3PXe67g60M9oD7/n9nNmu8Dj9KUS1PPHu 8WhpAmRT9xuR7Ea2trw5GXbSyp407JOpU14pWbkt+a1AfhigLQbwQyBE+OzH3/icIoEs WIl8y8ptFZLkTySxxH3Sr258xZS/ePLiKTi/SGPQ/ssEUGrr70x97yzhxC4hfsdrGiTD 8u1Nr/hUltRNRbCMRBsvJp11CSt+x++ZQlqfkv2RVry1aA1TQdlPMivdkU0h02eXaHur x7ug== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=E+4oLVAPfstR5U6aMi6Troa+YNi9gddz/xau+Gpg+rc=; fh=s6qbYcpKmY0AEsK/gKDpT3qiaGyyaU+hQ5h16uVwDEk=; b=i6Hj1+oTUIPd1aJO57A3kC5V6GvYdndkh2Xyx7f4FaDtrrJczlmfNTdeR90iJD3qBR NVZNh1iH8gaq4XNbhOlhoW64EU/r8cSWjNaCYZgbABRRwOamFKMEsfQXVQzMvlDtn4Ia h3fmlQqGCbOlwaYx18Y8XF/++qw2HIhrHOOpCLFffrTUBRp8uqmWq9kxpmPEESbCatvR 1/CcPLHhgjfKpDTGxEM6kxec6DiMHZ/jZj1CrX1orHPVi+Ih4luYSsvLElp2xtoBID3j s9zwejOOz/VOVPu+EsYyq164ebMPaKO0WWI6xUR4ZRzXmwt34grqexr4WgJCwX+N9YB9 klLg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@infradead.org header.s=casper.20170209 header.b=UixsKVyP; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id y21-20020a50e615000000b0051a52a48ed4si3143288edm.156.2023.06.26.10.53.50; Mon, 26 Jun 2023 10:54:14 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@infradead.org header.s=casper.20170209 header.b=UixsKVyP; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231433AbjFZRgr (ORCPT + 99 others); Mon, 26 Jun 2023 13:36:47 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36712 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229501AbjFZRgB (ORCPT ); Mon, 26 Jun 2023 13:36:01 -0400 Received: from casper.infradead.org (casper.infradead.org [IPv6:2001:8b0:10b:1236::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 302162952; Mon, 26 Jun 2023 10:35:32 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=casper.20170209; 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=E+4oLVAPfstR5U6aMi6Troa+YNi9gddz/xau+Gpg+rc=; b=UixsKVyP80nb0Gf7F4Lg+jN462 veiCIiZ5m1gznewobjOw1LIlCVl+NQ9bzKtGc1cy/FIFA2ZFOyC31yskGu3ZRnQRQ486TqTOhj/gr MYy4BGRtCU3MWPXCVKFnpYRI0SO+7rxcxT4MHuv18Sude5qsPpa5V0wVCVDJPMg+CxWSEWOj5iYYW AJDD8UCC+LOhQrktHVtCdUQ+V85q2O0pIp+RIDy4myAwlxwJ/KnWBqgsQgybdKyrahLZIt/KPAliX Z7BL5LWIbRipCNRi/kU84/66Ojv2G0K94IDEtnbMk2QxnYFxyp6hwCZ51e4XG35VOJT7z4XE1c+22 +qrDsMow==; Received: from willy by casper.infradead.org with local (Exim 4.94.2 #2 (Red Hat Linux)) id 1qDq7X-001vV7-Jz; Mon, 26 Jun 2023 17:35:23 +0000 From: "Matthew Wilcox (Oracle)" To: linux-mm@kvack.org Cc: "Matthew Wilcox (Oracle)" , linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org, Jan Kara , David Howells Subject: [PATCH 05/12] pagevec: Add ability to iterate a queue Date: Mon, 26 Jun 2023 18:35:14 +0100 Message-Id: <20230626173521.459345-6-willy@infradead.org> X-Mailer: git-send-email 2.37.1 In-Reply-To: <20230626173521.459345-1-willy@infradead.org> References: <20230626173521.459345-1-willy@infradead.org> MIME-Version: 1.0 X-Spam-Status: No, score=-4.4 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_MED,SPF_HELO_NONE, SPF_NONE,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1769788727111366303?= X-GMAIL-MSGID: =?utf-8?q?1769788727111366303?= 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) --- include/linux/pagevec.h | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/include/linux/pagevec.h b/include/linux/pagevec.h index 87cc678adc85..fcc06c300a72 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)