
From: Xiang Chen <chenxiang66@hisilicon.com> Add a print in iova_rcache to trace how many iovas are in use. Signed-off-by: Xiang Chen <chenxiang66@hisilicon.com> --- drivers/iommu/iommu-debugfs.c | 2 ++ drivers/iommu/iova.c | 3 +++ include/linux/iova.h | 1 + 3 files changed, 6 insertions(+) diff --git a/drivers/iommu/iommu-debugfs.c b/drivers/iommu/iommu-debugfs.c index 6489430..1904fe9 100644 --- a/drivers/iommu/iommu-debugfs.c +++ b/drivers/iommu/iommu-debugfs.c @@ -118,6 +118,8 @@ static int debugfs_iova_rcache_show(struct seq_file *s, void *p) sprintf(string + strlen(string), "[%d]=%d ", i, size); } pr_err("%s\n", string); + pr_err("rb_total: %lld\n", iovad->rb_total); + return 0; } DEFINE_SHOW_ATTRIBUTE(debugfs_iova_rcache); diff --git a/drivers/iommu/iova.c b/drivers/iommu/iova.c index ecdebcd..f09755a 100644 --- a/drivers/iommu/iova.c +++ b/drivers/iommu/iova.c @@ -66,6 +66,7 @@ init_iova_domain(struct iova_domain *iovad, unsigned long granule, iovad->flush_cb = NULL; iovad->fq = NULL; iovad->anchor.pfn_lo = iovad->anchor.pfn_hi = IOVA_ANCHOR; + iovad->rb_total = 0; rb_link_node(&iovad->anchor.node, NULL, &iovad->rbroot.rb_node); rb_insert_color(&iovad->anchor.node, &iovad->rbroot); cpuhp_state_add_instance_nocalls(CPUHP_IOMMU_IOVA_DEAD, &iovad->cpuhp_dead); @@ -284,6 +285,7 @@ static int __alloc_and_insert_iova_range(struct iova_domain *iovad, /* If we have 'prev', it's a valid place to start the insertion. */ iova_insert_rbtree(&iovad->rbroot, new, prev); __cached_rbnode_insert_update(iovad, new); + iovad->rb_total++; spin_unlock_irqrestore(&iovad->iova_rbtree_lock, flags); return 0; @@ -419,6 +421,7 @@ static void private_free_iova(struct iova_domain *iovad, struct iova *iova) assert_spin_locked(&iovad->iova_rbtree_lock); __cached_rbnode_delete_update(iovad, iova); rb_erase(&iova->node, &iovad->rbroot); + iovad->rb_total--; free_iova_mem(iova); } diff --git a/include/linux/iova.h b/include/linux/iova.h index 8d935e3..1eb4628 100644 --- a/include/linux/iova.h +++ b/include/linux/iova.h @@ -115,6 +115,7 @@ struct iova_domain { atomic_t fq_timer_on; /* 1 when timer is active, 0 when not */ struct hlist_node cpuhp_dead; + u64 rb_total; }; static inline unsigned long iova_size(struct iova *iova) -- 2.8.1