From patchwork Thu Dec 14 13:25:38 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christoph Hellwig X-Patchwork-Id: 13493058 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 21121C4332F for ; Thu, 14 Dec 2023 13:26:14 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id A9DC88D00B7; Thu, 14 Dec 2023 08:26:13 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id A4DE68D00B1; Thu, 14 Dec 2023 08:26:13 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 93E2C8D00B7; Thu, 14 Dec 2023 08:26:13 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0011.hostedemail.com [216.40.44.11]) by kanga.kvack.org (Postfix) with ESMTP id 84E838D00B1 for ; Thu, 14 Dec 2023 08:26:13 -0500 (EST) Received: from smtpin16.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay08.hostedemail.com (Postfix) with ESMTP id 59A13140CC1 for ; Thu, 14 Dec 2023 13:26:13 +0000 (UTC) X-FDA: 81565497426.16.F2CC833 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) by imf20.hostedemail.com (Postfix) with ESMTP id B39851C0025 for ; Thu, 14 Dec 2023 13:26:11 +0000 (UTC) Authentication-Results: imf20.hostedemail.com; dkim=pass header.d=infradead.org header.s=bombadil.20210309 header.b=uggU3y4f; spf=none (imf20.hostedemail.com: domain of BATV+55581d165dda9d0af87b+7417+infradead.org+hch@bombadil.srs.infradead.org has no SPF policy when checking 198.137.202.133) smtp.mailfrom=BATV+55581d165dda9d0af87b+7417+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=1702560371; 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=kjTxLCTcdYADmdVsT9Z0i4M7ZWEUsHvFpLFt/dTctuK09i+8VoQfEqEfHiEjoWZi9tHKMI TAOk7hexaH/5G2uoqKGy4C/TveMpVr4H1q+ITETi+W+7o+TVjTo9YjI7lPvFz1ijP+JY6L mYsO7sm7fgQ06OfIMPUJY1CGt+3AGY4= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1702560371; a=rsa-sha256; cv=none; b=VygepA5XerntXNioJAG0FHhLo2DZzs3ufmmodGLBAoZWSRmrU+rv52/6hzdaDDFKYrZSrw +kSMUCXSVGDTXDBy+dc1h95FIYSrzvtAOAQh6C4wmmy+ef9yLp5OeHHI4GO960FQKj4Uh9 CSItwfA/8/r+SH3UwHH3LQ6CfuVRncg= ARC-Authentication-Results: i=1; imf20.hostedemail.com; dkim=pass header.d=infradead.org header.s=bombadil.20210309 header.b=uggU3y4f; spf=none (imf20.hostedemail.com: domain of BATV+55581d165dda9d0af87b+7417+infradead.org+hch@bombadil.srs.infradead.org has no SPF policy when checking 198.137.202.133) smtp.mailfrom=BATV+55581d165dda9d0af87b+7417+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=uggU3y4fBWiCXTBEHx5MIrT6DE Rwcj/DmIWwKIJXJZeOj39Hyc3qKt59USXtl8gWutaJpmCNidyxQ6JdbypyM9+FdN5lrPD9KwEZBjC FtlmcDdPIF4tVCDzP5y7JZ2LDk7rSLCrikKAfcIYfGXtjjLDftVNDMAMYh3wVTSjui6YmnhR415rt DzXEuEmW7sWLCoskIiHHKwvEUXd/QnwxMxyfWuy0tLZ1Hs4+colIeuHyZBgighO8cIT+xOofAKBIy 3tz2gpPqZj0UbrFi7QCaaokGySo+SS+UDtxSseeUkYK0kUbMCXmiB2B8xFQ4KNF3jiZQp7HGwTomc xPV8yLiA==; Received: from [88.128.88.27] (helo=localhost) by bombadil.infradead.org with esmtpsa (Exim 4.96 #2 (Red Hat Linux)) id 1rDlj8-000N5b-1T; Thu, 14 Dec 2023 13:26:10 +0000 From: Christoph Hellwig 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/11] pagevec: Add ability to iterate a queue Date: Thu, 14 Dec 2023 14:25:38 +0100 Message-Id: <20231214132544.376574-6-hch@lst.de> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20231214132544.376574-1-hch@lst.de> References: <20231214132544.376574-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: B39851C0025 X-Rspam-User: X-Rspamd-Server: rspam11 X-Stat-Signature: wabzcezcht3etbgh3mstdzsjpzfq1cq7 X-HE-Tag: 1702560371-277722 X-HE-Meta: U2FsdGVkX19JDAxOYtTE5fjVP/sjJLmognI+dFKU7fzF5UJWqkK5g97e0chti2WY76NsHWT0GsvWDSLGRb8eAKtu9jHMx8bfSTgHuaivLjnoxa1YeFx4wZYdYCnxBVDYH/TJnuPujhZZerQLYca9Sn9th6gpuXT/733PR3bZ5zOiorMimA9NxtndzGcW+vWpY387yh9VBHk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aU78o4bPEwSuBCAFkHGDXFOdgh9YWf1SgeiBcwXvHPMLLsikqva8AzYo2EBVavHTO0Y+NW62//mBVeBfmvAWrdtHkH7VqLWkaZRCxw65dSu6xbS6jjoWauDC7tnd9SDcrXENRzh55sSPuGuyGdIG1VK 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 --- 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)