From patchwork Tue Dec 26 20:02:04 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Pasha Tatashin X-Patchwork-Id: 13505035 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 893E6C4707B for ; Tue, 26 Dec 2023 20:02:35 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 777206B0085; Tue, 26 Dec 2023 15:02:19 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 6AF826B0087; Tue, 26 Dec 2023 15:02:19 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 4B6AD6B0088; Tue, 26 Dec 2023 15:02:19 -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 2F3EC6B0085 for ; Tue, 26 Dec 2023 15:02:19 -0500 (EST) Received: from smtpin20.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay05.hostedemail.com (Postfix) with ESMTP id 10AD840659 for ; Tue, 26 Dec 2023 20:02:19 +0000 (UTC) X-FDA: 81610041198.20.B3B9C55 Received: from mail-oi1-f175.google.com (mail-oi1-f175.google.com [209.85.167.175]) by imf23.hostedemail.com (Postfix) with ESMTP id 62CC5140023 for ; Tue, 26 Dec 2023 20:02:17 +0000 (UTC) Authentication-Results: imf23.hostedemail.com; dkim=pass header.d=soleen.com header.s=google header.b=FKYsw2IM; dmarc=none; spf=pass (imf23.hostedemail.com: domain of pasha.tatashin@soleen.com designates 209.85.167.175 as permitted sender) smtp.mailfrom=pasha.tatashin@soleen.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1703620937; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:mime-version:mime-version:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=mxo16AeffIcUl0pfz0nlTIeaxJpBLQvEVDy59ntWJzo=; b=RT0RaLAwmN+mOnA210PNJ39avMG4NyBUZZEExmN9GkGM7iXj6+dwbtkIK+aW0wXj5FwnR5 XaZsim/ZWMbVe/EoDXwnZPCiulAwC58bhQGAdQgZui7UH2JbUnjfX5Ka5smtIzd4gu2Uqg MFFpi0AadfcUE53BgzoVHNPhNgjkKw0= ARC-Authentication-Results: i=1; imf23.hostedemail.com; dkim=pass header.d=soleen.com header.s=google header.b=FKYsw2IM; dmarc=none; spf=pass (imf23.hostedemail.com: domain of pasha.tatashin@soleen.com designates 209.85.167.175 as permitted sender) smtp.mailfrom=pasha.tatashin@soleen.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1703620937; a=rsa-sha256; cv=none; b=6EcRZ7qDdDMT8X6OSGYUxWxIJEgVsFZyvuSaswjjwHnRklhdO+6TaqQaMJJSAzIDH3/Hs2 3gNUgc09GQ01cruJ482mc1m6FLbSQ4wbnqCq3WGbmK9J+SEm7lyJbd+Kfm77ckeiNCLR3X XIbNB5xGHRVobNfZXn1KiOLcixBOb5o= Received: by mail-oi1-f175.google.com with SMTP id 5614622812f47-3bb968c02baso1737442b6e.0 for ; Tue, 26 Dec 2023 12:02:17 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=soleen.com; s=google; t=1703620936; x=1704225736; darn=kvack.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:from:to:cc:subject:date:message-id :reply-to; bh=mxo16AeffIcUl0pfz0nlTIeaxJpBLQvEVDy59ntWJzo=; b=FKYsw2IMHEm9h9xXJ+HtRUj4EZ+mjNPSbBEJkGKVEAUw2O3NVlw5a3OYg/4ONpcXb9 4yJxOmiIhjiCiNWUrrxRl84AGhtcgMGV+saYDiTtPsTmZjRRAGm0Ky1ciLc37wWKBiE6 7gKQT7LBoIUtk0kriHgPbnKh51ehNTocTz9huSROU2toyeRmWG3ncQUTgTzPa7jwZgOn 8ahMhwkjvQicLZs5+Tieb4WKq7cUt70DliOR5R/HSaRt5EPY5iy/3hFYJt/vE+zKLi5v +Fk7J8n/tofPyN2QCsPRii5+oGarYoa3liSBho68YFZWV15n4fmyxVMu1oMfMmf6x1jx 71Ow== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1703620936; x=1704225736; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=mxo16AeffIcUl0pfz0nlTIeaxJpBLQvEVDy59ntWJzo=; b=NWxd5NMAPdgqqSbEZ1J02MLp+fqYVGNCgrAaMG4SvLmg64e0hisgFRQluvLOSh9Jl+ vLbaF2MBCHMPq5Sv4t42pRkH+625DvWlnK3NdBr1hRrafFYQ3Cqo14TiZnA/A725/mAI 7G0KaUO1UJgXyr5gJjM5mhjGklX2e2lBJbZUYnxnauQszNTCdNXmVaY8tAhS55+EQJZ7 ADoslBYmDQ4o7SbraFe2tXZaidGLM4psZ8WWxZfqkpjVtKUAoH9R+en1T4ql+PyQ+j6V tmUM5CNtkPIg1QxbRGXC4m1RisM5Ja9VsnYR2Kvb6RsU7lq75o/0fID0PyRgLGEK39yl 3GjA== X-Gm-Message-State: AOJu0Yyt9kgmM+yNXet3Mxb+II2x46AbRUslq0ep2+RI2uygIXawtHv7 n+LNDizgCptkoDGKVtKMLeDRZ7pl6QVqqA== X-Google-Smtp-Source: AGHT+IHrGAGi+32a17cjz4hMVcRXIy2GjdCBrEmS3N5kwjkJAZZsim1kCd/4+YrLV4TJHLLCVok4zA== X-Received: by 2002:a05:6808:448c:b0:3ae:5bf5:4ad1 with SMTP id eq12-20020a056808448c00b003ae5bf54ad1mr9246412oib.33.1703620936477; Tue, 26 Dec 2023 12:02:16 -0800 (PST) Received: from soleen.c.googlers.com.com (55.87.194.35.bc.googleusercontent.com. [35.194.87.55]) by smtp.gmail.com with ESMTPSA id t5-20020a0cf985000000b0067f696f412esm4894539qvn.112.2023.12.26.12.02.15 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 26 Dec 2023 12:02:16 -0800 (PST) From: Pasha Tatashin To: akpm@linux-foundation.org, alim.akhtar@samsung.com, alyssa@rosenzweig.io, asahi@lists.linux.dev, baolu.lu@linux.intel.com, bhelgaas@google.com, cgroups@vger.kernel.org, corbet@lwn.net, david@redhat.com, dwmw2@infradead.org, hannes@cmpxchg.org, heiko@sntech.de, iommu@lists.linux.dev, jernej.skrabec@gmail.com, jonathanh@nvidia.com, joro@8bytes.org, krzysztof.kozlowski@linaro.org, linux-doc@vger.kernel.org, linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org, linux-mm@kvack.org, linux-rockchip@lists.infradead.org, linux-samsung-soc@vger.kernel.org, linux-sunxi@lists.linux.dev, linux-tegra@vger.kernel.org, lizefan.x@bytedance.com, marcan@marcan.st, mhiramat@kernel.org, m.szyprowski@samsung.com, pasha.tatashin@soleen.com, paulmck@kernel.org, rdunlap@infradead.org, robin.murphy@arm.com, samuel@sholland.org, suravee.suthikulpanit@amd.com, sven@svenpeter.dev, thierry.reding@gmail.com, tj@kernel.org, tomas.mudrunka@gmail.com, vdumpa@nvidia.com, wens@csie.org, will@kernel.org, yu-cheng.yu@intel.com, rientjes@google.com Subject: [PATCH v3 09/10] iommu: observability of the IOMMU allocations Date: Tue, 26 Dec 2023 20:02:04 +0000 Message-ID: <20231226200205.562565-10-pasha.tatashin@soleen.com> X-Mailer: git-send-email 2.43.0.472.g3155946c3a-goog In-Reply-To: <20231226200205.562565-1-pasha.tatashin@soleen.com> References: <20231226200205.562565-1-pasha.tatashin@soleen.com> MIME-Version: 1.0 X-Rspamd-Queue-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hYuaVMNdY1qhepcUDNF Dmtmee2O 3tLpw5yqKDSPlXVaLDzQcm1hGJaEbIbv9iiJkEiXdM2aP7zSZBpa3QtK0VhcCtsE5oJtm5l1O0shzdFGgeHfZ33wC0VW7Bzn1AyklVjsm8sganld1SXX2xm5qF6gv/IRGnDIQ6DBZrpmVDIB3RLLhqqR2ed1XddGxYg+75pgvNj09JfE= 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: Add NR_IOMMU_PAGES into node_stat_item that counts number of pages that are allocated by the IOMMU subsystem. The allocations can be view per-node via: /sys/devices/system/node/nodeN/vmstat. For example: $ grep iommu /sys/devices/system/node/node*/vmstat /sys/devices/system/node/node0/vmstat:nr_iommu_pages 106025 /sys/devices/system/node/node1/vmstat:nr_iommu_pages 3464 The value is in page-count, therefore, in the above example the iommu allocations amount to ~428M. Signed-off-by: Pasha Tatashin Acked-by: David Rientjes --- drivers/iommu/iommu-pages.h | 30 ++++++++++++++++++++++++++++++ include/linux/mmzone.h | 3 +++ mm/vmstat.c | 3 +++ 3 files changed, 36 insertions(+) diff --git a/drivers/iommu/iommu-pages.h b/drivers/iommu/iommu-pages.h index 99105503b771..4e70cdf7acac 100644 --- a/drivers/iommu/iommu-pages.h +++ b/drivers/iommu/iommu-pages.h @@ -17,6 +17,30 @@ * state can be rather large, i.e. multiple gigabytes in size. */ +/** + * __iommu_alloc_account - account for newly allocated page. + * @page: head struct page of the page. + * @order: order of the page + */ +static inline void __iommu_alloc_account(struct page *page, int order) +{ + const long pgcnt = 1l << order; + + mod_node_page_state(page_pgdat(page), NR_IOMMU_PAGES, pgcnt); +} + +/** + * __iommu_free_account - account a page that is about to be freed. + * @page: head struct page of the page. + * @order: order of the page + */ +static inline void __iommu_free_account(struct page *page, int order) +{ + const long pgcnt = 1l << order; + + mod_node_page_state(page_pgdat(page), NR_IOMMU_PAGES, -pgcnt); +} + /** * __iommu_alloc_pages_node - allocate a zeroed page of a given order from * specific NUMA node. @@ -35,6 +59,8 @@ static inline struct page *__iommu_alloc_pages_node(int nid, gfp_t gfp, if (unlikely(!page)) return NULL; + __iommu_alloc_account(page, order); + return page; } @@ -53,6 +79,8 @@ static inline struct page *__iommu_alloc_pages(gfp_t gfp, int order) if (unlikely(!page)) return NULL; + __iommu_alloc_account(page, order); + return page; } @@ -89,6 +117,7 @@ static inline void __iommu_free_pages(struct page *page, int order) if (!page) return; + __iommu_free_account(page, order); __free_pages(page, order); } @@ -197,6 +226,7 @@ static inline void iommu_free_pages_list(struct list_head *page) struct page *p = list_entry(page->prev, struct page, lru); list_del(&p->lru); + __iommu_free_account(p, 0); put_page(p); } } diff --git a/include/linux/mmzone.h b/include/linux/mmzone.h index 9db36e197712..f0b54c752e22 100644 --- a/include/linux/mmzone.h +++ b/include/linux/mmzone.h @@ -200,6 +200,9 @@ enum node_stat_item { #endif NR_PAGETABLE, /* used for pagetables */ NR_SECONDARY_PAGETABLE, /* secondary pagetables, e.g. KVM pagetables */ +#ifdef CONFIG_IOMMU_SUPPORT + NR_IOMMU_PAGES, /* # of pages allocated by IOMMU */ +#endif #ifdef CONFIG_SWAP NR_SWAPCACHE, #endif diff --git a/mm/vmstat.c b/mm/vmstat.c index 359460deb377..801b58890b6c 100644 --- a/mm/vmstat.c +++ b/mm/vmstat.c @@ -1242,6 +1242,9 @@ const char * const vmstat_text[] = { #endif "nr_page_table_pages", "nr_sec_page_table_pages", +#ifdef CONFIG_IOMMU_SUPPORT + "nr_iommu_pages", +#endif #ifdef CONFIG_SWAP "nr_swapcached", #endif