From patchwork Wed Feb 7 17:41:01 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Pasha Tatashin X-Patchwork-Id: 13548809 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 74A3FC4829C for ; Wed, 7 Feb 2024 17:41:30 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id BE6B96B0087; Wed, 7 Feb 2024 12:41:21 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id B98436B0088; Wed, 7 Feb 2024 12:41:21 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id A5E596B008A; Wed, 7 Feb 2024 12:41:21 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0016.hostedemail.com [216.40.44.16]) by kanga.kvack.org (Postfix) with ESMTP id 9749C6B0087 for ; Wed, 7 Feb 2024 12:41:21 -0500 (EST) Received: from smtpin21.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay03.hostedemail.com (Postfix) with ESMTP id 6CAF5A059C for ; Wed, 7 Feb 2024 17:41:21 +0000 (UTC) X-FDA: 81765724362.21.83A4465 Received: from mail-qk1-f170.google.com (mail-qk1-f170.google.com [209.85.222.170]) by imf28.hostedemail.com (Postfix) with ESMTP id A5B56C0017 for ; Wed, 7 Feb 2024 17:41:19 +0000 (UTC) Authentication-Results: imf28.hostedemail.com; dkim=none ("invalid DKIM record") header.d=soleen.com header.s=google header.b=hr964bqj; dmarc=none; spf=none (imf28.hostedemail.com: domain of pasha.tatashin@soleen.com has no SPF policy when checking 209.85.222.170) smtp.mailfrom=pasha.tatashin@soleen.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1707327679; 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=aOJ5ut398ow/2WlP29EDaCAozkqg/KeyQvQPT/mKdCU=; b=ySsYR0ZT3+LB5nMa+IC6V2tfjlq4FsyP70sCmdO/lK+/DUAh9cJ3JtPn5jSZfSvSTD0PMV 0WQ8d0rOow5lXSlmDJw2LHzSkSvJEe6zK3iefWJAIqDdm4P18DIjInl5Cos2eWUqQCZCfC C8Ol/VvpkPOGDViRGIFzU8u5Sx+u2Mc= ARC-Authentication-Results: i=1; imf28.hostedemail.com; dkim=none ("invalid DKIM record") header.d=soleen.com header.s=google header.b=hr964bqj; dmarc=none; spf=none (imf28.hostedemail.com: domain of pasha.tatashin@soleen.com has no SPF policy when checking 209.85.222.170) smtp.mailfrom=pasha.tatashin@soleen.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1707327679; a=rsa-sha256; cv=none; b=8pzjcjHV9vk8Xjs7xD1nXxbu62nWubDtOI0P9W1EJcLOwvoRj9WkAohZMK6Tz07mvcmiWD 2juvma+i0Hn+d8jNz+tkSOoBR4ByfNf0gOFTCv9i539XCvrF0DyjwMJ3CaOTdhpZzaiPRU JbvTE5T958sK2pcvp691hbAtynznznQ= Received: by mail-qk1-f170.google.com with SMTP id af79cd13be357-78405c9a152so56943985a.1 for ; Wed, 07 Feb 2024 09:41:19 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=soleen.com; s=google; t=1707327679; x=1707932479; 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=aOJ5ut398ow/2WlP29EDaCAozkqg/KeyQvQPT/mKdCU=; b=hr964bqj30gg58icmHfp/dcnahR83UBkQj0/sukFq3u3o4exBhr+OMya8tbmuhfOoI YBR69ccK5ZAfkD1Lp+Gi+iK6whwW697SAHPJufWwSYJaTMqnse1+2k4IKyu553XgGLC0 l9E3XyeL5f9ixuRrbrm2rBigrGZ+YdU+LsrvE2H/O4gVlt6c0tOa+1K0sIqM82MIFLdC dJ9l6yXRIBLwyHffqN1f5tpbrrqezNa4+dhIA973HqeNclGj8LK2zSZ3QPGXhEh0VlD9 0eATAoArlOuSBHynb+rDi42RC/JW906lgXeh4XDTx08tduh3aazXSxHDOZXYgaf46lmU QdWg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1707327679; x=1707932479; 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=aOJ5ut398ow/2WlP29EDaCAozkqg/KeyQvQPT/mKdCU=; b=u3Y531ryBv3iCaQOAT/fFH0I423D5rp+aGlTyFRsKXkNjejGqFR1iUVFq8CE6nnQiQ i6B/rq1MuIwmrCBlbZPUffhb6rKBj30TSN/HoO8jXMurwOTwM05f+Q7hTyQ3QkPZxRjI OhEr0/PUilSGcAw1fICT075+FcJGKq9LI98qtcvMF9wTkEpJpEFsf7++lxJK7/vAHKob yt9yuLagbsPWKsUmye5kyob7VSo3UOzmDQABCdGwU02sH1+Vvy5KVVl/gG3J9OXaYdGm La8dkBLF03HcGZgR+vChfkhm+lrMADrZX24L3LRJCOIVygjQ4wkeEk5e/R5WvXsFzIm6 SmZQ== X-Gm-Message-State: AOJu0YwgXmGSgjKTV8sAmImfu7ynG/9eWA5I5FLVm3k+HzmDQOSr25H2 XdKtnYQtWQsIy+nXBydtc2Hbq5hY+8SzloJlsb5214TRmJf5gHbPXWVLCVHuPsA= X-Google-Smtp-Source: AGHT+IGzHmYfHKKzBsKfi2sS1p/R7NZ/BV205sSyGSsoTpCiCT38UMcgyp+aJmcRhxrEuO8FJ5t6XA== X-Received: by 2002:a05:620a:190e:b0:783:549a:aa3f with SMTP id bj14-20020a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D8gwig/TVFwXduy2fJIryQb6xREtFO2kvs7rR0ze1qIhdPdoAdHpRi5zLY2FAaEzpNEe2mCr/hobwhz309FnEBGy3p4duYtaZy1zL2a4zFrNv5tiNnNcl0oJQIymIZEpA0gTG5Efh7EhezVq+BSrf/HYiigfcwHL2Kk0NSzTpZ1MdpdyJIqYVNw8qE0NZs/+w1hYGvTx09SD5Nyi9xL3/BRW2rCQxgyeyXpqGjk4oyXoKnR3l8WNiJ1iJD0nmckKOAXNplAPi/pNtSQ2aFjtC+ApLt075lhvFnm6wSPA8FBaPLrsV4jV48R7yNVf4gpZmuobPWdbcSx3DBmdJTRV3njPssZ/V2j2NiSDHtOBbh1aUz+Ua+gQUiepqzMS1Bw7UsDY3XjEzkvcpINTtsFGpTHvY3dZcb6W0ggjjMkZ309cd/5G3Qjk/+SEAoMU1Z40QF5/SV8NcemsKNKcbEDW6SFstkb0TygjllY 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 e10-20020a37db0a000000b007854018044bsm696310qki.134.2024.02.07.09.41.17 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 07 Feb 2024 09:41:18 -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 v4 09/10] iommu: observability of the IOMMU allocations Date: Wed, 7 Feb 2024 17:41:01 +0000 Message-ID: <20240207174102.1486130-10-pasha.tatashin@soleen.com> X-Mailer: git-send-email 2.43.0.594.gd9cf4e227d-goog In-Reply-To: <20240207174102.1486130-1-pasha.tatashin@soleen.com> References: <20240207174102.1486130-1-pasha.tatashin@soleen.com> MIME-Version: 1.0 X-Rspamd-Queue-Id: A5B56C0017 X-Rspam-User: X-Rspamd-Server: rspam02 X-Stat-Signature: 6j3juceyxgna1d9ud5d4kzc3s3daioau X-HE-Tag: 1707327679-916237 X-HE-Meta: U2FsdGVkX19Co3Dr98yTTU9NNkasIz0aq8wmNd1yvh1OSHOYLtGCqPxizq5TlJCJiVBXFwGx6zzfjfCFTtRv+6dNUdDDP7ylD1IlRXcmZ1AKarl2TLOkMTb2trkgPWUOMtaGDWBI2kBaDj4pvTWQFgUEmttovWqyGfdRJK8+QxADpMhWoljMNXHrrOcg0GRJdHB+ONPoP5QNrxBFG4bykmIBZx+MVfOWXmT0Wh1r7J42f4PoN2+OUiFV98504a3d2d0CsuAw1jDfOoHsl2427yolc+RaDSBz+LvxyrYCvu9a4aAM33krUW9KscUu4RBmQOl8k9LN7HuMBUDXX4XiInApjqYFWX2mnWZ2F/xCybEF+uiNwYILNokRWiaOScLd7OQTdy0gzgCnhVEuCWkfBSKlkVKRl9ApSHqh/4SBehdrOHVnfd7N1AzIgkDEQ2pW6oCLWb7HjkwPOs9O/hqpP0+m74JgU+tH4M8LYNtBaamVLitW0AxXH9eso8REqemDnRsspCGz/57rkQ4HsCVgbGDvjFYc+5kHjTyNKkwkYA1DXnDsDhKqSHpSG6yg18vNL7uPSFRgDhrKpCAqTVhiO2qAjkgCGFeq8J+XuNIPAWXRr8c9QsXo34P1U7ls/c1Sm7/FZrwhoyzOW5xxZpE78zIUPSAQz2Oinpc87ahNq9+ui+ccSEzKyPC7OxmTKqBx3si3zAlGpJaktf+qwzspr21NJXHDJHaEsXlrkG1v4EQ8ghs6RWh8fR+3pR3bt81QpSRLmIzm5SHanCSWCoaV4v1dGprzsAJwf+4a8aAG9mfPWvIUC3xYIfio7O/GXe1U16nMr153JTZWTYhWJ2kiVXv1UgCFxnYSdoK4Z3qg5iUrlKkcQdbPBYACjcl+2MQS+mGhDMPs2thk3PXmxP9hJYRNqFPFe0lLTYTzztcTwJh+eucDa3bvm5YATJmSUwVXvVgdENLInhUF2kIkbKn 9f9RQ5aX 9epNqkhu+NFOoFB85wvbB1RtHA3VJxzP97rG7isLE2JEi/hzheBrxRfoIIzMfaKX5wpaBdCt1icJ7DTaMK53QFe2giTW7s4ddwVcVRtwDTTAfa1+aSOqVRLo21cjiieNRNizjzpFtl+xtj2Y6NZV6IFTfv4n7zcYXLG5qf21oICZaAJ7FijZcDC/7/veb60xPA8V9B+AQN9bbnSN1OJh7HngBx/x/11C2LWcil1/w5+vU9Q0Xwegp+iWamo1L7NEydWRdKYPlhIMThjRNHUw8GwGgV6FW8JAHcyMwpGprvTg9sLfKholLlcrWkKL/2m6tEGP2bPIMW4CyZg6dTgC6LpQMClrax4s8gklHk3UPri13l1+XNNXg94PbfVopTqgaQV2Sac6Bk6zjK7TRg7VXiEdYOrrbu/4mlDyKFNXanpVAVyRV1ByiLdliWv2FyMDGJcGA 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 c412d0aaa399..7336f976b641 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. + * @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_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 (unlikely(!page)) return NULL; + __iommu_alloc_account(page, order); + return page; } @@ -53,6 +79,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; } @@ -89,6 +117,7 @@ static inline void __iommu_free_pages(struct page *page, int order) if (!page) return; + __iommu_free_account(page, order); __free_pages(page, order); } @@ -197,6 +226,7 @@ static inline void iommu_free_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