From patchwork Thu Nov 30 20:15:03 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Pasha Tatashin X-Patchwork-Id: 13475021 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 DC659C07CA9 for ; Thu, 30 Nov 2023 20:15:31 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 75CE36B04A2; Thu, 30 Nov 2023 15:15:19 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 6E22A6B04A3; Thu, 30 Nov 2023 15:15:19 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 50DF76B04A5; Thu, 30 Nov 2023 15:15:19 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0013.hostedemail.com [216.40.44.13]) by kanga.kvack.org (Postfix) with ESMTP id 3E2596B04A2 for ; Thu, 30 Nov 2023 15:15:19 -0500 (EST) Received: from smtpin26.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay01.hostedemail.com (Postfix) with ESMTP id 0F0C81C0324 for ; Thu, 30 Nov 2023 20:15:19 +0000 (UTC) X-FDA: 81515725158.26.104D69E Received: from mail-ot1-f54.google.com (mail-ot1-f54.google.com [209.85.210.54]) by imf19.hostedemail.com (Postfix) with ESMTP id 0FCCD1A0003 for ; Thu, 30 Nov 2023 20:15:16 +0000 (UTC) Authentication-Results: imf19.hostedemail.com; dkim=pass header.d=soleen.com header.s=google header.b="P/N/UTlA"; dmarc=none; spf=pass (imf19.hostedemail.com: domain of pasha.tatashin@soleen.com designates 209.85.210.54 as permitted sender) smtp.mailfrom=pasha.tatashin@soleen.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1701375317; 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=B42Ompk/0S+0FHWlF0c0WCUF97rKJOKtrfjrMLAbFqA=; b=hFoR6o4fYtD4CfDrTCb93DHFHauhhtAoLMZFOmyut1d+7JIa30Xax0HSfsJ14/MBag+ZUa xBFWHpMpOHcOAokn3PWYPSAEUd6o5ubYCz+3lYAM3v5hNavUItm13Q+oFIMJGUGp/jycfi 4wr2qWno5mbFNmU7z5ofCelWPZfUC8A= ARC-Authentication-Results: i=1; imf19.hostedemail.com; dkim=pass header.d=soleen.com header.s=google header.b="P/N/UTlA"; dmarc=none; spf=pass (imf19.hostedemail.com: domain of pasha.tatashin@soleen.com designates 209.85.210.54 as permitted sender) smtp.mailfrom=pasha.tatashin@soleen.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1701375317; a=rsa-sha256; cv=none; b=K9/VS/CrL3YA+z9fCmSfSLv3pQQl58mX2MZA/mq1jxkIx8edDbAqQ9xfWno2djCe+NKst4 hiU/FnZMaKnqSQ57cc9swGQTYT6gubtw9FKj1E9iNcRaMfmNM4IZmmZMBmg91B59RpnmTg 6ITXsnaezZqG2/EzXnPDABKBGsRHOgY= Received: by mail-ot1-f54.google.com with SMTP id 46e09a7af769-6d856210057so803655a34.1 for ; Thu, 30 Nov 2023 12:15:16 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=soleen.com; s=google; t=1701375316; x=1701980116; 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=B42Ompk/0S+0FHWlF0c0WCUF97rKJOKtrfjrMLAbFqA=; b=P/N/UTlAY4uSfQfqjHlMQNjeHgkeSVgQpovJxJLsclCW/yWyHQCvphF4KwAXjyXIjq MVQsCsHxHuNeOLgL6aSqaZTpNA3mki4NpMhUTkbrRL0sPY1yiUBIQjzZJ47GASj7UM1o A5gPRRtG+/Kb6LJ0mDBCNhCENUtED3TXrs0G3ejR+dfySRc4zpFNSgzpdXiLbeAsxnXj Hc4CaIWN+/f4ay5vA36aY7/2Kme0O8nQIyIkgk+syPAAcpMJzOTc8kVkYuVVkqnONjz2 QN/xJDmVO2Nz8KadIyTcwWKCXTPzRCrRJqX1dJQXnaoiD8daDtA7pJFRoScDVErote0X EMEA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1701375316; x=1701980116; 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=NAOK0FI+AnpMZtXMBakP5ChcSILI9PizamwhzIyikCWe3R82gNPDQJw6IIMZ2gzeNJ Jpyy+lBBUXQJzQ25Zec/OaoE2BT1sHP099TtXatv033mSMl0DXdDmhL3VHaBYScxCYJ4 CtdX6SOm7/WlJXse82PCb2JUPyYERHnD4qgALnAkHdGo+HAOl1MFOKXu06xiq+biqtl6 X62ICwEW3FpfBxS6GmrCWxEe2Jo5eBQjkhZuHQ1+tsohMhNShukDnWgEeCiGeFBAbIvT P89oYU7akENrhkOzpBRSZCYCByMVGVJtBesk83TEVfMSCwt2y2gdQTO8apSCogSNR7vQ RBzw== X-Gm-Message-State: AOJu0YwaIMQvXuNse0iTnsjrtrB5AIxWT2+BmUy2QPUhxV6Ikx8khUi7 4cJc3+o2Gyb/t23Ri7YUV4xT7Q== X-Google-Smtp-Source: AGHT+IFm2VZamMYGPMsf9vCHQb4stofA9P0lnINgFWclhv2SjMIVDU5Q4H8UbP8D1DLG6NZm/4QG2w== X-Received: by 2002:a9d:7dd2:0:b0:6d7:f02f:dcc3 with SMTP id k18-20020a9d7dd2000000b006d7f02fdcc3mr809535otn.28.1701375316245; Thu, 30 Nov 2023 12:15: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 e1-20020a0cb441000000b0067a35608186sm795252qvf.28.2023.11.30.12.15.15 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 30 Nov 2023 12:15:15 -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 Subject: [PATCH v2 09/10] iommu: observability of the IOMMU allocations Date: Thu, 30 Nov 2023 20:15:03 +0000 Message-ID: <20231130201504.2322355-10-pasha.tatashin@soleen.com> X-Mailer: git-send-email 2.43.0.rc2.451.g8631bc7472-goog In-Reply-To: <20231130201504.2322355-1-pasha.tatashin@soleen.com> References: <20231130201504.2322355-1-pasha.tatashin@soleen.com> MIME-Version: 1.0 X-Rspam-User: X-Rspamd-Server: rspam12 X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 22Q7Z4Ae I060Z4jCSddzB0Frv/7Z8hr6KKURHG1zLlej8WFjkiBhUoFn1RgkKE6Xn7idiKUQTTKalNSehR/2aSgWi5+uxiwsQZzoEnnKWvHX4++sHiMayLUaACeYSZdQLg1bkRVSqv7Ufn1yiNpDN5atuD+Ad5pybIK8yUuF7ZNkuwamjnD/D2YhdLa4wnnBwOOWbplKgEPZb3Zw11Wfj8LcyidTpjKQX2LWlmx/jRGuwro0Y+vVc1PnFsJCNMe9ZNL8Mpbhw0kI+xGevsEI6kANCxsgCWHPujweloj35k8fJATPW/2ihdhuQpd0AHYAjGCypUs7d4+dyGNEU2WV44xrHt5pQqZNJgLbHQYCSO01gxwP0C5YttuB7SQRt2PGzLqJbZcmETlvggnRZdu0STtNiRGrL7XJskj9aikaYDPtVLHvxgbHoGkOGYLBHelHk0faXR2WUghaBlYkaBIo4NuDTOLHKuzlw67GHk7RH+i8KRv0vj1ndf0d3aFni8cZF9izUyUKtK2Z+DxdN9fj80TmbOsVJCs7WGw== 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 --- 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