From patchwork Thu Feb 22 17:39:36 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Pasha Tatashin X-Patchwork-Id: 204914 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7300:a81b:b0:108:e6aa:91d0 with SMTP id bq27csp105741dyb; Thu, 22 Feb 2024 09:53:34 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCXRgzl8RsTH6lQfM9EAGOzuTo+ElddZsHPKhgNnhu11itIPcn404ZrCE3NmmamHI5xjpHeqpWntFwypE4Aiybo0OJL9pw== X-Google-Smtp-Source: AGHT+IGxRvBLuZg+IZcwytOEqLhOwOvzgllqAl4b0tSZCNetWVdovoSFCD/MrQKS31PqFgDrRSvI X-Received: by 2002:a17:90b:3447:b0:298:c104:1eb8 with SMTP id lj7-20020a17090b344700b00298c1041eb8mr5057393pjb.19.1708624414794; Thu, 22 Feb 2024 09:53:34 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1708624414; cv=pass; d=google.com; s=arc-20160816; b=RFG30O7wtsNcETQLcvEvz4Cq4LpzqitLh6gKgOW4NoluUkV5zMzeMjBNHwgTAxtHud 2LHHKwA/wd2bIQKAZeozq3mdpZ8WooBHvVLQ7rD7e7Qhumtx4kHtJSP38Jszgmsqn8Er u/SxW1So98aEpCFN6z//r79/c8q8WAbiz8oerKelGhQY4HpF+TgI5ePuzraYZZ9HJuaZ SVo5egLiRbmuHynaF4lijAebInmEKprMuFhSUNHAVaiBnj/dDwiMP8hYAcsku9DExuvO mspC2AEHnith+RagluGRzKHmr+UcH/01FlOzlmmK7YPt+kc/kcBuLF8xUKg3qWPXJ93z Nv/g== 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-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-76998-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=soleen.com Received: from sy.mirrors.kernel.org (sy.mirrors.kernel.org. [2604:1380:40f1:3f00::1]) by mx.google.com with ESMTPS id pj6-20020a17090b4f4600b00297160ba34csi10653502pjb.104.2024.02.22.09.53.34 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 22 Feb 2024 09:53:34 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-76998-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) client-ip=2604:1380:40f1:3f00::1; 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-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-76998-ouuuleilei=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 sy.mirrors.kernel.org (Postfix) with ESMTPS id DD574B22205 for ; Thu, 22 Feb 2024 17:43:30 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id E734815CD6B; Thu, 22 Feb 2024 17:40:14 +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 X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1791622554383933863 X-GMAIL-MSGID: 1791622554383933863 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