From patchwork Sat Apr 13 00:25:21 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Pasha Tatashin X-Patchwork-Id: 13628412 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 71D66C46467 for ; Sat, 13 Apr 2024 00:25:50 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id E08E56B009E; Fri, 12 Apr 2024 20:25:37 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id D68B56B009F; Fri, 12 Apr 2024 20:25:37 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id B939C6B00A0; Fri, 12 Apr 2024 20:25:37 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0017.hostedemail.com [216.40.44.17]) by kanga.kvack.org (Postfix) with ESMTP id 99F886B009E for ; Fri, 12 Apr 2024 20:25:37 -0400 (EDT) Received: from smtpin26.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay04.hostedemail.com (Postfix) with ESMTP id 66FCF1A1059 for ; Sat, 13 Apr 2024 00:25:37 +0000 (UTC) X-FDA: 82002615114.26.3978474 Received: from mail-qk1-f177.google.com (mail-qk1-f177.google.com [209.85.222.177]) by imf16.hostedemail.com (Postfix) with ESMTP id B293618000D for ; Sat, 13 Apr 2024 00:25:35 +0000 (UTC) Authentication-Results: imf16.hostedemail.com; dkim=pass header.d=soleen-com.20230601.gappssmtp.com header.s=20230601 header.b=uj+ZOi2p; spf=pass (imf16.hostedemail.com: domain of pasha.tatashin@soleen.com designates 209.85.222.177 as permitted sender) smtp.mailfrom=pasha.tatashin@soleen.com; dmarc=pass (policy=none) header.from=soleen.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1712967935; a=rsa-sha256; cv=none; b=yCyVM/YFmlkNLdRp90F9veBu4q5JM7fFb9+MtWSlKAmh8cLpbO4pLqW1Sa90ZNBowbErBp wr1fTExpVeDY2B6MzfFsiS90UIXbDY0QCFcGfR/fyQZsMsEj7hsb2w3Ukt1IjCQnRP6haV Q71w0saP5K5yv15HCy+X+gw85B5C1+g= ARC-Authentication-Results: i=1; imf16.hostedemail.com; dkim=pass header.d=soleen-com.20230601.gappssmtp.com header.s=20230601 header.b=uj+ZOi2p; spf=pass (imf16.hostedemail.com: domain of pasha.tatashin@soleen.com designates 209.85.222.177 as permitted sender) smtp.mailfrom=pasha.tatashin@soleen.com; dmarc=pass (policy=none) header.from=soleen.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1712967935; 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=lsGN5WIIRNrc7OxFwMhPRXWLlVhvYQL3ZDijKX4hJeQ=; b=Q/3aVp8xqb6Y14CGfsafmqlJ40+M1vaFKNzWRPiz7uACP1BqrBtWUZlrQWKnmB9gDFdXHw 1QkM4oBIJS70It1xeGKmfTF1W7PJVzf81eSvetrfsmB3JobsPKrj06duMRAjUdBiSqeMO1 Gsh0RuyR2P1PDnVYnNGaVFkoSQEsOIM= Received: by mail-qk1-f177.google.com with SMTP id af79cd13be357-78ecacab93bso84638885a.3 for ; Fri, 12 Apr 2024 17:25:35 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=soleen-com.20230601.gappssmtp.com; s=20230601; t=1712967935; x=1713572735; 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=lsGN5WIIRNrc7OxFwMhPRXWLlVhvYQL3ZDijKX4hJeQ=; b=uj+ZOi2pg8QDjhM4wlmUkuWMZvYdlsOT/qaQqJshZNSQx4X3U+qASbX3HdQI2NYtVt onnKDsuHXS/7OF6269r0TqztVhNNwXzZIdneUje+SVZgB8Eatyetom55JD6PcxsTLWBG h3/yW90ncVG4OCnzE569DnC04z8k4Wiwx5DW29h1B4aSbj6PI2KqfaG8JCtE7QcLmvPZ pzmnLZTOyqqafSJEgQiVS7OEDg6Rn26SQnnUf/Vj+qo7jnkeyB+yqjfTqYPyn3/OT6Qy sYDNaMnfMUWMirWSUNjWSKditHb7ykryYeqrAURkO9O+yUMT9pdNxwT+Zq6Eo7AUhN8O aW7w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1712967935; x=1713572735; 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=lsGN5WIIRNrc7OxFwMhPRXWLlVhvYQL3ZDijKX4hJeQ=; b=h3zuIUTfTK3oJQr4NAgGUUYKSfVpG4B1cJ5BjxcdpwlYC+eODu0uR4OBeIgd35yXlr xj6hjdHeBd4qPotErQSY4BPoHmnJb47HBYezic2chBM6hiKtbEgoo/83F6k3BOW3Z0zN sXQ92YEID2x468mq7wVKlTZ3bjoLabbLmV+x576TnSFb/kegSYy60OKbIEX6qAknAhgA uFJiKPaNSz5ybCYFjY04SfFp5AtysjQrkbV1XRYvwnMcTQ2xhB+jj3PeekfOcQe3d9fH 4JIOVDjKhGpEpq9MhixGD7uLiT11XDO6KN0SMFLqHsnVt0VuVJSeURzWfuFRR0MoWB/J SuBQ== X-Forwarded-Encrypted: i=1; AJvYcCXuhGGvcF7gFKVythfgI0rYdefBz6pDT5v3sqVa+v7lvJw2+iT8Fx+Cj3tAOGasIgWC9a5aELQtV5ZXYxEgv+cPzCU= X-Gm-Message-State: AOJu0YxVaeWM/ZwHHX/fsJb1375HU965fUOJN98lkM7AT9PCjQo/vv2L stWcyA+uuDZatzFtUDJd4U9rAWt9/2Wz4QdC/r7VjV6foVZyoQmgf8iXZ9Nn+2A= X-Google-Smtp-Source: AGHT+IFlAsPoHG2FDkZGPGOgYKbc0L/VN/uoaQSjmKoP15ZCmJynTAbwXmhrnqPB3wz5ZBdnnVJffA== X-Received: by 2002:a05:620a:b41:b0:78d:53eb:c256 with SMTP id x1-20020a05620a0b4100b0078d53ebc256mr4232583qkg.72.1712967934863; Fri, 12 Apr 2024 17:25:34 -0700 (PDT) Received: from soleen.c.googlers.com.com (128.174.85.34.bc.googleusercontent.com. [34.85.174.128]) by smtp.gmail.com with ESMTPSA id wl25-20020a05620a57d900b0078d5fece9a6sm3053490qkn.101.2024.04.12.17.25.34 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 12 Apr 2024 17:25:34 -0700 (PDT) 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, bagasdotme@gmail.com, mkoutny@suse.com Subject: [PATCH v6 10/11] iommu: observability of the IOMMU allocations Date: Sat, 13 Apr 2024 00:25:21 +0000 Message-ID: <20240413002522.1101315-11-pasha.tatashin@soleen.com> X-Mailer: git-send-email 2.44.0.683.g7961c838ac-goog In-Reply-To: <20240413002522.1101315-1-pasha.tatashin@soleen.com> References: <20240413002522.1101315-1-pasha.tatashin@soleen.com> MIME-Version: 1.0 X-Rspamd-Server: rspam08 X-Rspamd-Queue-Id: B293618000D X-Stat-Signature: 56rtqyamsm3cx441suk3wzrfkxu94e1t X-Rspam-User: X-HE-Tag: 1712967935-956980 X-HE-Meta: U2FsdGVkX1/qcAgV9ddTWEdEET8JwTt51AR6kwKx4BVIx+WaoaiGR3k8/X2JLk+h9LPlxC6EHK0+dItxNfoN87BxPZ4nfN+O2bO6xZi5oip9oTgeDb0EuS0t6enU9HeBXeZVH03JIJQqUdAbEgvcxsVSLH+ofFrJpa4OmUf9Qm91HV3tv0tJJoC5RcEmJhwTgO4J2CEjOnKFKexgctkhcyEmlRDzaCWKlaR2uWKb1PUAh0QzR+iT259knXgE7S+TChmmpgjsM0S4poQY7/Kpw1cHEuqIfWV1HpKTJJU9TOWtVLI4RXwJuGZaEvx4O9hYxmvXU4rPvFjPL8RxQK4uQqb8MglcdkV3qC8si9B0UuEzqdr+kSIVopA/FOVPNsGRf57UOa0V9NTT1PoVJjbpoqkLz5Dz9Yfmb90oFEMjlEsVm5DWu9tm246BP9WVl1+DoIrgVPT402s+YcGWTSnuU+B+YAimwueo/KxuXG/11San3l4+PC9S/BDgB3Y90WlJUM6npU7sz80A7KSBd+JNDwd37keoFOlVve3tz1u9i3rY2DKloJiKil4zu3NuUUMXEVHf1M5GJJsCYHQwb2291i4OSZ+BEol1xT3Zeg7fjPKxU4Ioaw9OGeTOnUQZiXIOdV8ILt936ZI/cDnQO1ownBBgWnoi++G6PyxrHDfXz89pLSm/d9xgYJazCgVKR6d7D9EirYYYwSKINVjyNQm0RAEMvumq/Ewc4EFGpUf0qrHGVa7EX3D0I1jU9Zfe3mU4+qdjn4L4Krbnz56qskRIdmsBouLPWOH0O3oBAZIVtJshByTBAK0IYdFvO/oKGnBvHSq3b7iZbSxtmdzH0KlXtQfHYNhmi3d1ch9WGJIfm06VzTyz44XYkXTi/wDMGLcBKSsjQ+3OpPtXqBdYMQw6zDhuVeuZeWkqzCmnoNgqebUxnN6yYdwwr2o5fYC9bGsCwrTvY3vv0qATJDIJxI1 4GCYfTfU kA/BfzoURt8phKyoRTfbpNRj2cPZXqzvQfGz/trATZUmkI2s9QWoAqBVynKr56KK8B0Pw7rlGuH36eW1R8YCWcNM7kd+dwBS2bCDGV9jY63xW/XqC0k3KjExUoc0ByIDgcjfWVJR9A6L4YwLw09DOFb2KyHG0ijcRUfvFrfPfPAIM6CUyEF3gOV1ecV1h/AUTRRDdOvSIi81pPvaqeRu35QRzPbDx+OW89egSQKwdUtxQQLvjN7c1dcu1xgODNNPeg4/37nu29MAiHcCn7GX6WO9G4hd40+lm57aa2Uxg/EdI0z1hScpI0i92IgOHOY5AmGjUJpv2MRmqRek4tcgq6gUX1BkZNmxw74mRu9GDD4w8MESVed6U1fUJ4bOFsKVI6g1eD1Q3WYJ1cK1Bv3a033hR3FgiP0eBfa2WHqFeR4znT8W+X/GVQNR8pHwaR4czByFRpnv1rFl0AUFIlC69u7tgt2jqrp6+R023JteajIMDV2/ApzAORy0FPZjludSCerspepFD6l/FU0HTf7UbleiEzszGGtEQbNHFcoYCsrisT2jhkNz2h9pajEf7GN5tOlkJ0dR2phyRwjc= 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 Tested-by: Bagas Sanjaya --- 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 5a222d0ad25c..1264b0f6b6c3 100644 --- a/drivers/iommu/iommu-pages.h +++ b/drivers/iommu/iommu-pages.h @@ -20,6 +20,30 @@ * 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 - allocate a zeroed page of a given order. * @gfp: buddy allocator flags @@ -35,6 +59,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; } @@ -48,6 +74,7 @@ static inline void __iommu_free_pages(struct page *page, int order) if (!page) return; + __iommu_free_account(page, order); __free_pages(page, order); } @@ -67,6 +94,8 @@ static inline void *iommu_alloc_pages_node(int nid, gfp_t gfp, int order) if (unlikely(!page)) return NULL; + __iommu_alloc_account(page, order); + return page_address(page); } @@ -147,6 +176,7 @@ static inline void iommu_put_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 c11b7cde81ef..be17195f6f86 100644 --- a/include/linux/mmzone.h +++ b/include/linux/mmzone.h @@ -206,6 +206,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 db79935e4a54..8507c497218b 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