Skip to content

Commit bd3520a

Browse files
soleenjoergroedel
authored andcommitted
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>
1 parent 8e8b4ac commit bd3520a

File tree

3 files changed

+36
-0
lines changed

3 files changed

+36
-0
lines changed

drivers/iommu/iommu-pages.h

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,30 @@
2020
* large, i.e. multiple gigabytes in size.
2121
*/
2222

23+
/**
24+
* __iommu_alloc_account - account for newly allocated page.
25+
* @page: head struct page of the page.
26+
* @order: order of the page
27+
*/
28+
static inline void __iommu_alloc_account(struct page *page, int order)
29+
{
30+
const long pgcnt = 1l << order;
31+
32+
mod_node_page_state(page_pgdat(page), NR_IOMMU_PAGES, pgcnt);
33+
}
34+
35+
/**
36+
* __iommu_free_account - account a page that is about to be freed.
37+
* @page: head struct page of the page.
38+
* @order: order of the page
39+
*/
40+
static inline void __iommu_free_account(struct page *page, int order)
41+
{
42+
const long pgcnt = 1l << order;
43+
44+
mod_node_page_state(page_pgdat(page), NR_IOMMU_PAGES, -pgcnt);
45+
}
46+
2347
/**
2448
* __iommu_alloc_pages - allocate a zeroed page of a given order.
2549
* @gfp: buddy allocator flags
@@ -35,6 +59,8 @@ static inline struct page *__iommu_alloc_pages(gfp_t gfp, int order)
3559
if (unlikely(!page))
3660
return NULL;
3761

62+
__iommu_alloc_account(page, order);
63+
3864
return page;
3965
}
4066

@@ -48,6 +74,7 @@ static inline void __iommu_free_pages(struct page *page, int order)
4874
if (!page)
4975
return;
5076

77+
__iommu_free_account(page, order);
5178
__free_pages(page, order);
5279
}
5380

@@ -67,6 +94,8 @@ static inline void *iommu_alloc_pages_node(int nid, gfp_t gfp, int order)
6794
if (unlikely(!page))
6895
return NULL;
6996

97+
__iommu_alloc_account(page, order);
98+
7099
return page_address(page);
71100
}
72101

@@ -147,6 +176,7 @@ static inline void iommu_put_pages_list(struct list_head *page)
147176
struct page *p = list_entry(page->prev, struct page, lru);
148177

149178
list_del(&p->lru);
179+
__iommu_free_account(p, 0);
150180
put_page(p);
151181
}
152182
}

include/linux/mmzone.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -206,6 +206,9 @@ enum node_stat_item {
206206
#endif
207207
NR_PAGETABLE, /* used for pagetables */
208208
NR_SECONDARY_PAGETABLE, /* secondary pagetables, e.g. KVM pagetables */
209+
#ifdef CONFIG_IOMMU_SUPPORT
210+
NR_IOMMU_PAGES, /* # of pages allocated by IOMMU */
211+
#endif
209212
#ifdef CONFIG_SWAP
210213
NR_SWAPCACHE,
211214
#endif

mm/vmstat.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1242,6 +1242,9 @@ const char * const vmstat_text[] = {
12421242
#endif
12431243
"nr_page_table_pages",
12441244
"nr_sec_page_table_pages",
1245+
#ifdef CONFIG_IOMMU_SUPPORT
1246+
"nr_iommu_pages",
1247+
#endif
12451248
#ifdef CONFIG_SWAP
12461249
"nr_swapcached",
12471250
#endif

0 commit comments

Comments
 (0)