summaryrefslogtreecommitdiff
path: root/drivers/iommu
diff options
context:
space:
mode:
authorPasha Tatashin <pasha.tatashin@soleen.com>2024-04-13 03:25:21 +0300
committerJoerg Roedel <jroedel@suse.de>2024-04-15 15:31:47 +0300
commitbd3520a93a84cd8c3897283e5891a9106fcf5acc (patch)
tree664e71aad879fc1e588f25f29982a1bad2ef45ad /drivers/iommu
parent8e8b4ac5b0ab759fffcd4d802ab3e084e3609191 (diff)
downloadlinux-bd3520a93a84cd8c3897283e5891a9106fcf5acc.tar.xz
iommu: observability of the IOMMU allocations
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 <pasha.tatashin@soleen.com> Acked-by: David Rientjes <rientjes@google.com> Tested-by: Bagas Sanjaya <bagasdotme@gmail.com> Link: https://lore.kernel.org/r/20240413002522.1101315-11-pasha.tatashin@soleen.com Signed-off-by: Joerg Roedel <jroedel@suse.de>
Diffstat (limited to 'drivers/iommu')
-rw-r--r--drivers/iommu/iommu-pages.h30
1 files changed, 30 insertions, 0 deletions
diff --git a/drivers/iommu/iommu-pages.h b/drivers/iommu/iommu-pages.h
index 5a222d0ad25c..1264b0f6b6c3 100644
--- a/drivers/iommu/iommu-pages.h
+++ b/drivers/iommu/iommu-pages.h
@@ -21,6 +21,30 @@
*/
/**
+ * __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
* @order: page order
@@ -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);
}
}