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: 13567707 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 79805C54791 for ; Thu, 22 Feb 2024 17:40:12 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id E513E6B0096; Thu, 22 Feb 2024 12:39:57 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id DFF446B0098; Thu, 22 Feb 2024 12:39:57 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id C29406B0099; Thu, 22 Feb 2024 12:39:57 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0010.hostedemail.com [216.40.44.10]) by kanga.kvack.org (Postfix) with ESMTP id AE7C46B0096 for ; Thu, 22 Feb 2024 12:39:57 -0500 (EST) Received: from smtpin01.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay08.hostedemail.com (Postfix) with ESMTP id 829B6140EEA for ; Thu, 22 Feb 2024 17:39:57 +0000 (UTC) X-FDA: 81820152834.01.C665797 Received: from mail-qt1-f176.google.com (mail-qt1-f176.google.com [209.85.160.176]) by imf19.hostedemail.com (Postfix) with ESMTP id E89D51A0020 for ; Thu, 22 Feb 2024 17:39:55 +0000 (UTC) Authentication-Results: imf19.hostedemail.com; dkim=pass header.d=soleen-com.20230601.gappssmtp.com header.s=20230601 header.b=gekjj0Qo; dmarc=pass (policy=none) header.from=soleen.com; spf=pass (imf19.hostedemail.com: domain of pasha.tatashin@soleen.com designates 209.85.160.176 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=1708623595; 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=V0ReaiTECyup4iu8c9tFSBLtkPVhLn8yFZIGfl9p6vs=; b=BJ0x0o01rdgOPHmnLOFvByZKf/veNDzKw07eEKsWCqqKAckH/DURbLd4dQK0WpF9HK9zxJ Hia0dejMMoNLTWsjLUP7j9A8R1FLPK8O3+eUq/KMDHi3C+5N3fIx9ytX6Y75PjBEqsMREs pYpRt3U4rituHvs/3tklt/qhNCbWL9w= ARC-Authentication-Results: i=1; imf19.hostedemail.com; dkim=pass header.d=soleen-com.20230601.gappssmtp.com header.s=20230601 header.b=gekjj0Qo; dmarc=pass (policy=none) header.from=soleen.com; spf=pass (imf19.hostedemail.com: domain of pasha.tatashin@soleen.com designates 209.85.160.176 as permitted sender) smtp.mailfrom=pasha.tatashin@soleen.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1708623595; a=rsa-sha256; cv=none; b=ahhayU7PuDu0AUj9ek1q90hRucbHhs8t4LZv5rxs0j/dp2EqAGO+6axb+/XcwUae9Sja6n AJBa5vssevvPye7t6qcRsEn0IMsDNUTNwB0hWQSRUviGPYacaspRlLAQecuSj8uXsCcMId 3KIlDRaZFYtutNvWkjkr60c4scX0yW8= Received: by mail-qt1-f176.google.com with SMTP id d75a77b69052e-42a9f4935a6so7789111cf.1 for ; Thu, 22 Feb 2024 09:39:55 -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=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=V0ReaiTECyup4iu8c9tFSBLtkPVhLn8yFZIGfl9p6vs=; b=gekjj0QoKjnsz1d1Uk+7fjHF/9JAXwUngjUs/IR50BzUP6ViFcTAK5rfC9PDtXYFhF rHgHnwGtGaraBrxRhd4T7SLQBnV2YYh9W66cZIUtTv4YtnKCL76hEjUCtu7Q0C2v/Zl7 Y+5p4/yKBV53WMXznWL7JOr9Kq7EuRW3fhpI5j6mPAvXUd0piPQv2jJerFDvwuPlAFpO ZskqzQImaLAflPFG8iLqpqjZWI1vKpSghcgAI9Tm9Vb59Jf5yuifEKybIBDimcRnIpZP 5SW8Vqk3RUxmSwvMpRUo4ebToxBhtFzq2dV1LLZu3Svjdu5zw2Ih09S2An+7dgAiPsGp V2Kg== 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=iXO09uQFL6aFFdSwIxrIByZfwRUFMssPUWEVLsOCMVXKNys+uS4RlWvd2VXnbVTeMk yD+uzFSDMPJrZ7KtJ++LPE2VD57O2kgIhn8So/OXAGRuAF43R67avj6BOq0xCDMmwH8Y 8x76yyxWpLY2wBrCVvn34yu5JFPNiy1uzcX8yqOkAf+rHBzUdO+z/4K/Rjf+wc+L29H7 Bg3l7qrOYUGlu4cn3TQ/klaCzoJs6I9HF30CATyOirNG1k7GHo6+yGVcIWIhGp6ts8Ao 0mikvGGai8ncg2fQZs/UklT4xIaxdKGgredOvUpskffncN+1zhLJoAgcrb4GinCllCEV yipg== X-Forwarded-Encrypted: i=1; AJvYcCUO60uJsArv9d4Fepx7lgD91x/ygMGjjSY97Jac8AP04xU0a0by/HpI/s55KolymCuNPOUVGMRMQumgx5jtZM72r8o= X-Gm-Message-State: AOJu0YxA/hccM4Jrb0MFnzzR0yRxkC7ObTmiNQiPab9mn9dOL7PjQSPc hXqkDvpaT6s8HtsCEKgptOLddf1a/2VF4IUOj0ywUbenPyfGY28REdJtFKqAGYA= X-Google-Smtp-Source: AGHT+IEfgzE/uC4xDSwqJvxbjnpMCM7aGgkDw9ad0MN7VOXeeW4kWverRuOWKwGaZsiVILRRW0AILg== 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> MIME-Version: 1.0 X-Rspamd-Queue-Id: E89D51A0020 X-Rspam-User: X-Rspamd-Server: rspam02 X-Stat-Signature: xmpis9w5tiqmubwreu519q9c1b4x4cwr X-HE-Tag: 1708623595-381510 X-HE-Meta: U2FsdGVkX19GrNJx11HyZgnkb8oZxSm93Qb3wESrXIs9tvp5MFZyCkgNeV/ksa4gpdi8h4eXgbPQuxKgydbj1otcUFbR93JAPGj6MDCztwYjyDN+oueT47kfpC4TTWhatjq/pEyQA81LZUh3o5e4wbEIfAxuASzDpK/Hoae1V/ns87HGsHiLkfW/+rU9HfE0UpKXy9Qh40oz22rY5jQp/iBTZfAWB/Iu3yuFz4xGqy3x1zzi+4TpnQ5ahKM6cNa2hePZLKCiL5ILYkqFcib69yKjWxnOTEZZt6uVUWvYP0SwOpgNroZej2Q3r+RJkvrK9WjZB05IMaatRYLycJC/LmD0OhcQZ+mwwOrJG5/MEklLLDR2+U20vI4hA79iJWSVrPPEPknZO0iubc3tmwW/SWRY2JNZFOo4U5v8hz9KaV/Rx0xoRowdAIcUszv9dXukXvUgctkbcuRJ0Fl0GYAQOrEzitwuUmQMFH5Lw1kC+BPN5lonUGWZPcceIoW2REts9phGYYnWucExGWALwBi0AlHGcCTqbkHeO4x5TpzqkeXtHwg3EmE88TC/+wjiXOFAfSuQytUEohnItawg0glorN/qGuKcWHLM9sSFKE1H7qio794S5/yrVFcC9RrzQd5+FNOr2+OG95rZAsWhiivbNGtWOd1bAUWogLgrmXOaBOrp0jApoIsNK9ZP0MQi6uFfnDbHQjavOf9TKt53OSqNSwAC31IALMwXMOYRySmgV0x2AjcEftflPpSjRiA3e0hnjpMGgq1bLHvb0dywVk1KngyIEeJfxVSgAr72VzyP+R2SrRgYpFsml60nXLZqPbphEhCiXIeWIVopx9UjHqMLuyHOqErfXiqa1lLF2z8+2RWlzPv58/inLXSP0pIZSShIO9bVRTco2KMZNA5gx9GheRYwGpqQjawPTV8t+m7RnmsfWThp8ZQUtS/kSKFjBr2Y7OscBIX9OVQg5Q44XOi ApSmVWyi O5mLPpUPu/nkQYC0y4yc1CuUWU0sG3OCQsKCPfs9bzVQPiaE/It65HZLxnBhjFGMPFKQ7/C2W6zxouRBTXDGGRwTsmhJSd+15humcz+elZsqNIvZ8GsEoYjEYkn2jgunqEBqgEkgk8XEk8LwVj7Z5qt+zr3vGEI28gz33ZGB9ZuyV7XGdH/DoVQvoaERKo3Tv2cSsjojQcFcZz77zJ3/YrpjfBe9iL1ozT7ezlHg6vN+8g0qZXaG3FcwNlw== 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 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