Received: by 2002:a05:7412:798b:b0:fc:a2b0:25d7 with SMTP id fb11csp495269rdb; Thu, 22 Feb 2024 09:52:04 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCVVvw5f61V8m3+22umd0eVMXjRO+8R7JbeEtli6sQImcjiumf0SVqM8VY/aUz/thMZdNKPt4kgACbz/6W9ES65zVOpCJyssBoIdo6U3ug== X-Google-Smtp-Source: AGHT+IEJZ7udOYWrHTP9y/YO5xDXSOMbiwLwd1Nm/gwbD9DAXLFFSqWJBrErjK09/uVhSLWFbFVS X-Received: by 2002:aa7:d78d:0:b0:565:4bcf:d89f with SMTP id s13-20020aa7d78d000000b005654bcfd89fmr1050706edq.8.1708624324598; Thu, 22 Feb 2024 09:52:04 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1708624324; cv=pass; d=google.com; s=arc-20160816; b=hwmky52Dxg+YyZNgoQzKWUI2tEtFBLrjYEP6Xbbs4UBH+fg8Vres/dBzhoCLJwI9Bx OHMEnvEfbl1VtF2Eg5IVSd/TWfdBM1ttS/k7oV0vRhNxNFFgln4+SRVjf8hEAaSDI7hU HUQ3oKHZUYAyG7Rffveq31b2PezPQk3txWiYMwb7jA8ny/ITM5r6l2A2Lh7D5f8Vd++L RWiQmng0M/ymvTWCF+oiyphlCHuhtbaQj8nDr7xauBhXh1VHXdiLwhg4b6xDx4o/uesS Wh5xxn5dpfdf3oYlal/xbM8wKeBlOQhQva2NLPjvdIUiIWwq5YVR8dWic/xC6v+Efd+d 7o2w== ARC-Message-Signature: i=2; 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=V0ReaiTECyup4iu8c9tFSBLtkPVhLn8yFZIGfl9p6vs=; fh=48kBuojplYPgtcq9vLbuJ9BnoOHCwOjgq6AISKXb7qs=; b=yw10XR2oaMoOUKXD+emAm28OJtZw0QnKp30yXDQAsgBYx4ylrq6MnOyqKBEV8LL1SL NDX5D2KMTdFd5SL29qN94h2VxACqGmH63UM+pqlhrPpooUmNoAVOdBExp7kMX7ne9y7n UpyR4a1eQ3S+ecSV7ksmNoUPYlgE3itomIvhB4O62I1qIwuXYyl+g9CrpE12EcURItxb /2T20F3vML64P8gYmwOTFDeJ/f209I3dD3vwNW1iKjEPMwJjNv+x26QqoC+Q3nR1cS0q fPWklS2xdBL1go3LiTLiEprYQzWlYNM5CCnUgOC7253NtmV1ZNh89EiXAkTtLg4M0GVU eBgg==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@soleen-com.20230601.gappssmtp.com header.s=20230601 header.b=USzYIUF1; arc=pass (i=1 spf=pass spfdomain=soleen.com dkim=pass dkdomain=soleen-com.20230601.gappssmtp.com dmarc=pass fromdomain=soleen.com); spf=pass (google.com: domain of linux-kernel+bounces-76998-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-76998-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=soleen.com Return-Path: Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [2604:1380:4601:e00::3]) by mx.google.com with ESMTPS id q1-20020a056402032100b005653a367ab6si685206edw.271.2024.02.22.09.52.04 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 22 Feb 2024 09:52:04 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-76998-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) client-ip=2604:1380:4601:e00::3; Authentication-Results: mx.google.com; dkim=pass header.i=@soleen-com.20230601.gappssmtp.com header.s=20230601 header.b=USzYIUF1; arc=pass (i=1 spf=pass spfdomain=soleen.com dkim=pass dkdomain=soleen-com.20230601.gappssmtp.com dmarc=pass fromdomain=soleen.com); spf=pass (google.com: domain of linux-kernel+bounces-76998-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-76998-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=soleen.com 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 am.mirrors.kernel.org (Postfix) with ESMTPS id 11EEB1F27496 for ; Thu, 22 Feb 2024 17:42:42 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 0938C15B119; Thu, 22 Feb 2024 17:40:10 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=soleen-com.20230601.gappssmtp.com header.i=@soleen-com.20230601.gappssmtp.com header.b="USzYIUF1" Received: from mail-qt1-f174.google.com (mail-qt1-f174.google.com [209.85.160.174]) (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 CE99815699E for ; Thu, 22 Feb 2024 17:39:59 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.160.174 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708623605; cv=none; b=BK9YfU1sWhI+QizkmdJWobq2qNOoMh9vXAgDab2JTo7EZmJYAoirpIWEXm1HFnhg9L0nPVzV40Sbn0sQZBF7acbcUEIOefpExJcdXPyhKdlmDgw8UfWLgxzLEGWq8fUxrjNSj0LVPLBimdkZBrsooFlM2n/UuSA5DAyiz86xEsw= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708623605; c=relaxed/simple; bh=1YoYeatwE0jJRPo4fjMAz9I4YBLnIqISqkXjJpSRXIY=; h=From:To:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=MQTmAE3xdEac27N0N30ZcsbHwJhLvhSI7ChEdvqMi0fqow6Q3UlXXXgJxJNn5NI9DxLbWc8XNZXBe3RSHtyUAd9MulcFNCmKKRFKQNnq8dDPTTtgmMoUVb/OBtgyOg4ZLwhNFABynUWgWZCvHfYzR2PBQwckWtI8VtsQ3jDGv+s= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=soleen.com; spf=pass smtp.mailfrom=soleen.com; dkim=pass (2048-bit key) header.d=soleen-com.20230601.gappssmtp.com header.i=@soleen-com.20230601.gappssmtp.com header.b=USzYIUF1; arc=none smtp.client-ip=209.85.160.174 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=soleen.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=soleen.com Received: by mail-qt1-f174.google.com with SMTP id d75a77b69052e-42a4516ec46so470151cf.0 for ; Thu, 22 Feb 2024 09:39:58 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=soleen-com.20230601.gappssmtp.com; s=20230601; t=1708623595; x=1709228395; 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=V0ReaiTECyup4iu8c9tFSBLtkPVhLn8yFZIGfl9p6vs=; b=USzYIUF1WlhhKnEc6WdPED0RYcmsgwzPw0wfUuhKoekrOpqSEjVCChrWf39hbobYRZ BPClX781LHG3hOG+VSM8F/Qb6d/77N3A0xmCAB3l+aKgFnwsYtWvZfpx4JdUzSZ1vEBx 4HnZwNC/nrtPFf64EcNDKnxBg1p8KBfmzwAksOM1VrAfDjJdQCrz8Y6tcNLiaPVZ+xsj PYHhYKxxfFDsxmDBJSOQDvlXgsx5iJzV623J9T+Kjk4AUPM/heBt9K8Co4MfEntv0+QD U+SSnFPumEHAhqXI+MUucWVzOnaQTzftQ7YeWcmHCKeklNOecifb2Hp7E9NDu34skGuj ScjA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1708623595; x=1709228395; 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=V0ReaiTECyup4iu8c9tFSBLtkPVhLn8yFZIGfl9p6vs=; b=C0svOwYwZ07MsEpyzVtsQ8iiqS4u5dzTpsFAJtT0IMdDWAHtBNRxp8omeByLxcUx6i lKp+wkojSIXtQDkYYvzZfhlemxNsLN3R9Tc+lqTPOgUIth+Xng24JB0TA32COVkYP4JD Z450eaG7Er7zStHk2UjzYnMCNwTy/ZRKdAmvY/rL5InrZdBQH3wqdm54zzJbsoKGp5Id Vpz6NFHV5GyI+VivQihS43+nN7E/7h+Vl3CzIzYMbAkzjZJhcE23jZ5lYXEOsiSh5H+9 lKXxjuljnaPlzcdvWly06oTPVJhXnbp4BwyvwjggOmh1NvIYa05B/XHfw97h0ZMvQCGF YLIg== X-Forwarded-Encrypted: i=1; AJvYcCUv1n9OEIDJ9x/cx9KJfKTBAAkIPQqNG9T648U0LXljlucck57h5dQVma2r/Cn4Fu46QXeXXPlyzRtnJBU1e2/4K9AoCzvlr4BZ2mQT X-Gm-Message-State: AOJu0Yykl/H15SAsusNKBIYIBYfk8kcFKpbNoervcC6xY6pVjY8aaBWA FPk2xCyx4rUQKp/Hl2DkwXi9idzZ3krOfovczf0/oH9WTAzeLsz751AEXCkaa8w= X-Received: by 2002:ac8:6c2:0:b0:42d:f128:eccf with SMTP id j2-20020ac806c2000000b0042df128eccfmr3903788qth.33.1708623595045; Thu, 22 Feb 2024 09:39:55 -0800 (PST) Received: from soleen.c.googlers.com.com (249.240.85.34.bc.googleusercontent.com. [34.85.240.249]) by smtp.gmail.com with ESMTPSA id f17-20020ac86ed1000000b0042e5ab6f24fsm259682qtv.7.2024.02.22.09.39.54 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 22 Feb 2024 09:39:54 -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, bagasdotme@gmail.com, mkoutny@suse.com Subject: [PATCH v5 10/11] iommu: observability of the IOMMU allocations Date: Thu, 22 Feb 2024 17:39:36 +0000 Message-ID: <20240222173942.1481394-11-pasha.tatashin@soleen.com> X-Mailer: git-send-email 2.44.0.rc0.258.g7320e95886-goog In-Reply-To: <20240222173942.1481394-1-pasha.tatashin@soleen.com> References: <20240222173942.1481394-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 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 35bfa369b134..daac2da00e40 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 a497f189d988..bb6bc504915a 100644 --- a/include/linux/mmzone.h +++ b/include/linux/mmzone.h @@ -203,6 +203,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 -- 2.44.0.rc0.258.g7320e95886-goog