Received: by 2002:a05:7412:419a:b0:f3:1519:9f41 with SMTP id i26csp4139528rdh; Tue, 28 Nov 2023 13:00:21 -0800 (PST) X-Google-Smtp-Source: AGHT+IGSKs1epK52Labj89ddKEOZhrTX2GfGsWXl7tEHvlgG/GR/FS3Qsaa8iX3pnjjqLbyAeL1S X-Received: by 2002:a05:6a21:3293:b0:18b:3c54:e6d8 with SMTP id yt19-20020a056a21329300b0018b3c54e6d8mr16517416pzb.39.1701205221309; Tue, 28 Nov 2023 13:00:21 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1701205221; cv=none; d=google.com; s=arc-20160816; b=mh7G3qiCvYL0Qk8MSVoJx6dWQVoxoDJeq0M7mKLwzYGvh5KnEpBjVwOmEAXIACTF/P hV2Gs/+IOZimyuISWK0XqOXIiWjINMslfh8sTY+HmLJZfjI9FgtqDdpRWKZ2GYyo+Na/ EPWveIKoV+lxaXwp+62e6mOIlsbSbcNVtGZr0s775TMWz6unOKBZ/lKcunwvhaxdKavp 3mcwsc9ur4EtJdwSYJvuoMq+0OzW9G0oyDGUUwf3MC2FagrYkHbNvvsqp3+exyxhNmd8 Mrtww60FF00EcuH7hveBx6lAIzFNqjktPBruNELRmkxWbPbS3jO4lmv6vb1A7B5WmmSb rAGA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:to:from :dkim-signature; bh=B42Ompk/0S+0FHWlF0c0WCUF97rKJOKtrfjrMLAbFqA=; fh=z7CihAYYs+frw4g3uL4utEDJXxOOJDcFFsLsywo+fzs=; b=ubqVpdopXwtSAzaE4WqGh74u2bLHC8nYn2QeiIgz/KiSRJkCm4lG+jR58OsQ8tyQe0 iPXz7GBFqSKfOs9lK+8Z/76OTRqv286gTus5dZrfYXXPxYsR1F7V6PFlp64AhJqheIzW UNzzsvVDaaX2HXbXa/MQtHIL9ZOcclgctvvuC1LImOw2Cn8ly3XjscyJht6orjiTerbS 9IpzAhbn3t1DjFL6qN+EgJ3oeKSIfs3RnD/iGT9839AWnvKIcsVR481n+csTBX3b5pvs jZ4TNPHanaFddydyc62LkFBNNcR0q7HfeEs4OnEjctiHUpUBacoM8CwykSKOiKUtqHMu wqpQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@soleen.com header.s=google header.b="o/IjtgFT"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:1 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from morse.vger.email (morse.vger.email. [2620:137:e000::3:1]) by mx.google.com with ESMTPS id f20-20020a056a001ad400b006baae7ecfacsi13166352pfv.308.2023.11.28.13.00.20 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 28 Nov 2023 13:00:21 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:1 as permitted sender) client-ip=2620:137:e000::3:1; Authentication-Results: mx.google.com; dkim=pass header.i=@soleen.com header.s=google header.b="o/IjtgFT"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:1 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by morse.vger.email (Postfix) with ESMTP id 8BB4A8082CE3; Tue, 28 Nov 2023 12:50:39 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at morse.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1346589AbjK1UuT (ORCPT + 99 others); Tue, 28 Nov 2023 15:50:19 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57096 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1346327AbjK1Utx (ORCPT ); Tue, 28 Nov 2023 15:49:53 -0500 Received: from mail-qk1-x733.google.com (mail-qk1-x733.google.com [IPv6:2607:f8b0:4864:20::733]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A41F51FE3 for ; Tue, 28 Nov 2023 12:49:54 -0800 (PST) Received: by mail-qk1-x733.google.com with SMTP id af79cd13be357-77dc733b25cso32577385a.1 for ; Tue, 28 Nov 2023 12:49:54 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=soleen.com; s=google; t=1701204593; x=1701809393; 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=B42Ompk/0S+0FHWlF0c0WCUF97rKJOKtrfjrMLAbFqA=; b=o/IjtgFTQohEBhw0MZJjxpDFsK8WY+R+3BTtTpGQII2P13f/+ALn1Hy1IXvWVdR/nD Lyiof2gy8t2RhxKCEUsyu+xMdiXK9kYoEk+4v/CzcoYIytWDzr1xFcYGEzHNgNcaBdW9 tAiqsBj6qw9GXtEYKNQ3ooHJ55Nu1ClGh5bpzyliIBIGe95+K6f79uK9JvgU43Zf242q YUzxqt31PfSpVlffh94ObQZfG9yu2J2ns0gk6IUz4N8Hc3yMSYkUSuadexgr0Wxx3uG4 KbnpHLUoQoop5xVrJz/cc1zQDMyzBUmrrcZvilPxHWSaUgC8vcdRE67dlaDeWTafMnNd QAlQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1701204593; x=1701809393; 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=B42Ompk/0S+0FHWlF0c0WCUF97rKJOKtrfjrMLAbFqA=; b=I2GrVQeHzRGO3rZ8vKXIasVMgcPBzG8n3ZVRm13ZlmT03/WAqFJAK2utps2NIM2k1X uE5kQKFydItIAiyR3JOxrCYoutk3D+/jHWZUKBR17SjMilGUHy2+JgtbOD8rpjcYGWYv rx7rlRcemD9lmcYPnVnblzRj48Y62GSjvLPrPMTIaVED55kOIDO+0J7mLIzgtLjQBnSW tOy4KK8qSIvBqisOjebTQDArY/oww4mO4oNsBI0I+OvYJytw/SOOvcIO7n/g8LQtunYl lSMuHWXxN+I0tIEz8Nw/hsapR4n7WN5tp0qlEOwAwjQZ4bZhhgAuiN6ncvHeULDZWoQn u3dw== X-Gm-Message-State: AOJu0Ywto5sstbpBtjLiMZIhAocFtfczP/teEh5NfpuWxE2jzl6OrgYv YG3h/qds+/fu2V3JzEdkBdgbIg== X-Received: by 2002:ad4:4a6f:0:b0:67a:5ae8:d346 with SMTP id cn15-20020ad44a6f000000b0067a5ae8d346mr3075756qvb.62.1701204593484; Tue, 28 Nov 2023 12:49:53 -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 d11-20020a0cfe8b000000b0067a56b6adfesm1056863qvs.71.2023.11.28.12.49.52 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 28 Nov 2023 12:49:53 -0800 (PST) From: Pasha Tatashin To: akpm@linux-foundation.org, alex.williamson@redhat.com, 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, jasowang@redhat.com, jernej.skrabec@gmail.com, jgg@ziepe.ca, jonathanh@nvidia.com, joro@8bytes.org, kevin.tian@intel.com, krzysztof.kozlowski@linaro.org, kvm@vger.kernel.org, linux-arm-kernel@lists.infradead.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, mst@redhat.com, m.szyprowski@samsung.com, netdev@vger.kernel.org, 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, virtualization@lists.linux.dev, wens@csie.org, will@kernel.org, yu-cheng.yu@intel.com Subject: [PATCH 13/16] iommu: observability of the IOMMU allocations Date: Tue, 28 Nov 2023 20:49:35 +0000 Message-ID: <20231128204938.1453583-14-pasha.tatashin@soleen.com> X-Mailer: git-send-email 2.43.0.rc2.451.g8631bc7472-goog In-Reply-To: <20231128204938.1453583-1-pasha.tatashin@soleen.com> References: <20231128204938.1453583-1-pasha.tatashin@soleen.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-0.9 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on morse.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (morse.vger.email [0.0.0.0]); Tue, 28 Nov 2023 12:50:39 -0800 (PST) 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 --- 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 2332f807d514..69895a355c0c 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. + * @pages: head struct page of the page. + * @order: order of the page + */ +static inline void __iommu_alloc_account(struct page *pages, int order) +{ + const long pgcnt = 1l << order; + + mod_node_page_state(page_pgdat(pages), NR_IOMMU_PAGES, pgcnt); +} + +/** + * __iommu_free_account - account a page that is about to be freed. + * @pages: head struct page of the page. + * @order: order of the page + */ +static inline void __iommu_free_account(struct page *pages, int order) +{ + const long pgcnt = 1l << order; + + mod_node_page_state(page_pgdat(pages), 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 (!pages) return NULL; + __iommu_alloc_account(pages, order); + return pages; } @@ -53,6 +79,8 @@ static inline struct page *__iommu_alloc_pages(gfp_t gfp, int order) if (!pages) return NULL; + __iommu_alloc_account(pages, order); + return pages; } @@ -89,6 +117,7 @@ static inline void __iommu_free_pages(struct page *pages, int order) if (!pages) return; + __iommu_free_account(pages, order); __free_pages(pages, order); } @@ -192,6 +221,7 @@ static inline void iommu_free_pages_list(struct list_head *pages) struct page *p = list_entry(pages->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 3c25226beeed..1a4d0bba3e8b 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.rc2.451.g8631bc7472-goog