Received: by 2002:a05:7412:b995:b0:f9:9502:5bb8 with SMTP id it21csp2999304rdb; Tue, 26 Dec 2023 12:06:11 -0800 (PST) X-Google-Smtp-Source: AGHT+IEqh8EkfYhtu5mWL8hkut2uCWBMpT3jbK+iIaOy+Hx6VMJQkcn+rap7Sp8dkjBhp5mEUeP1 X-Received: by 2002:ad4:5587:0:b0:67f:aed4:4dd9 with SMTP id f7-20020ad45587000000b0067faed44dd9mr6269015qvx.113.1703621171281; Tue, 26 Dec 2023 12:06:11 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1703621171; cv=none; d=google.com; s=arc-20160816; b=m49SQo3NjFZheg2gwZKP2GlXk2khHIJV5a23b3joLhNgk78K4Hb+UVzWckhB8zhuwX GMAVk4oZjexNw6DlTdX3R1u/uyO3aT0bUNC8Azw5HTbZMQcLRk7axjK+8Oh4n0Pct2AK xhW7emyBDhejC9Hu0d0XPUjPZNVXejnd3Q8JqR4pHs+xrBnz48/G45h5GEV30nBQmj+O 0oGd5kFre22Alv872s8i0snYD6ofjzJuVnwYBFBLcK/ZW1oIB+X4Ng6eZ+o4WzNdivBC AkfY5ua94buNxut5gefZUnBwRiWNgFrWymex+5zJduHwPNU3Gb26mWsRVxwjZbbzv6Xo J1eg== ARC-Message-Signature: i=1; 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:to:from:dkim-signature; bh=mxo16AeffIcUl0pfz0nlTIeaxJpBLQvEVDy59ntWJzo=; fh=lUkiT048LCyG2kYH3uS9GPNyu6fkGQdYtFXGdyQ4NZk=; b=bYMBkdrC8oYcZ+EI+fUAvhsPJYqNpbg7S04WQQ4EAId2av8APB5wXxOivWzvUmQ9w/ FyeD8yhR/Eip2tTSMKI1kaivdb3g+d5RiunOjMu81hp8stFF/eRRAWXDEedsWbxvBJrC X2MAxYiV5WlBFjMrYQr2iB4j1RE8OV7cZM//K2LK/n6gX6FFRl1XDP7ZNixLlPoHl9xq mMJ+xerJEf676z5gMbg7YHM4GV68U0u9MYmHb2iVwmI/x9CRrEIQyC4DFnEu99F+Edsg gfSGQb4BrxtRyL98T0V383Ca0XNq4aeyHJlpq8BcTIU4FT5oZOl37k7WXGgMEGvTo5kV 5psg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@soleen.com header.s=google header.b=UHUAVpWt; spf=pass (google.com: domain of linux-kernel+bounces-11675-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-11675-linux.lists.archive=gmail.com@vger.kernel.org" Return-Path: Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [2604:1380:45d1:ec00::1]) by mx.google.com with ESMTPS id bs9-20020a05620a470900b0077fad1ee0fasi14254515qkb.373.2023.12.26.12.06.11 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 26 Dec 2023 12:06:11 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-11675-linux.lists.archive=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=@soleen.com header.s=google header.b=UHUAVpWt; spf=pass (google.com: domain of linux-kernel+bounces-11675-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-11675-linux.lists.archive=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 F16641C2201A for ; Tue, 26 Dec 2023 20:06:10 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 90D5418E1E; Tue, 26 Dec 2023 20:02:24 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=soleen.com header.i=@soleen.com header.b="UHUAVpWt" X-Original-To: linux-kernel@vger.kernel.org Received: from mail-oi1-f179.google.com (mail-oi1-f179.google.com [209.85.167.179]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 9A5A31118A for ; Tue, 26 Dec 2023 20:02:17 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=soleen.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=soleen.com Received: by mail-oi1-f179.google.com with SMTP id 5614622812f47-3bbbc6b4ed1so518651b6e.2 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=vger.kernel.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=UHUAVpWtpyn25vEAJZm0X9lVwVAm1yJFL5IZ/Qw7/4jQxvJmrSNLxbxEYHgmqOfR8y AM8qxtN30r7N1Xij5+3kTrvi5aXfFW3xmXfzVBIVWG/sKt9mc2tYPxsLcl/TmIj7ZrPX mZ6FyhdWhUPrHcvAnI17RNkoEv9L1C0vcP+8wsp8jRRZswVd8MSv1O6KuD4gTIWGz4K2 g0WIsNwVkmiKUIlfBIQVL2LFz+r3XSB7UdD/IF35xQoDT8xEUZwu++jpyuMdhwrz0xGZ yF9KX3ma646jnjdrNHvOMOjRkflYjsSAMu13GVd7IVlRil5t30bDkH9dHETKH7y3jNps xaIw== 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=Z6UGodhKkpc5oExw6jwOsuA/AVpK31Ek/znuBH4iXZASOp5O80XpnSfKOI3eLegt0V 7thwQ9WK+GbWgG2G3+9NGi2t+O0KQgiGiyUhMTUopMDGVZR9DO3Pa7tIsrnq0WIIf7u9 p/y6CbUCSDhN3h8fV0HWUhtQhpeo3oduGutcftnPDpl4XQtproZIlvD3OYn7Md5gnGIR 5mIrJMaVURN5ZteDsYp0Zih9zVs/9IdPGE0CEZDSEYk+4UOHjG8F7hNBT/S00XR7zRME KQWyuCV/Ri2Yp/5uyvgMWbBZi1vtl11RtsUbkpy9Sl3H+YGFmEslRC8ULgblxadS3iFk hMNQ== X-Gm-Message-State: AOJu0YyF/vmQlO04qAsZiYU7T/jH0A+ITItjQ0RQrDOUF3Axgg8V51n2 3EoeXQRbR6IdD353VrQDxPvhSPr7/fPigg== 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> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 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 -- 2.43.0.472.g3155946c3a-goog