iommu/iova: Optimize iova_magazine_alloc()
Subsystems (2)
PATCH 1/1 iommu/iova: Optimize iova_magazine_alloc()
Only the member 'size' needs to be initialized to 0. Clearing the array pfns[], which is about 1 KiB in size, not only wastes time, but also causes cache pollution.
--- drivers/iommu/iova.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-)
drivers/iommu/iova.c +7 -1
@@ -647,7 +647,13 @@ struct iova_rcache {static struct iova_magazine *iova_magazine_alloc (gfp_t flags) { -return kzalloc (sizeof (struct iova_magazine ), flags); +struct iova_magazine *mag; + + mag =kmalloc (sizeof (struct iova_magazine ), flags); +if (mag) + mag->size =0 ; + +return mag; }static void iova_magazine_free (struct iova_magazine *mag)
Signature · 1 line
2.25.1
Quoted 3 lines · Zhen Lei
Only the member 'size' needs to be initialized to 0. Clearing the array pfns[], which is about 1 KiB in size, not only wastes time, but also causes cache pollution.
Makes sense to me.
Quoted 10 lines
Signed-off-by Zhen Lei <[email protected]>--- drivers/iommu/iova.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-)drivers/iommu/iova.c +0
-0
drivers/iommu/iova.c struct iova_rcache { · line 652
Quoted 7 lines
drivers/iommu/iova.c +3
-1@@ -647,7 +647,13 @@ struct iova_rcache {static struct iova_magazine *iova_magazine_alloc (gfp_t flags) { -return kzalloc (sizeof (struct iova_magazine ), flags); +struct iova_magazine *mag; + + mag =kmalloc (sizeof (struct iova_magazine ), flags);
Nit: maybe sizeof(*mag) is preferable?
Quoted 7 lines
drivers/iommu/iova.c +4
-0+if (mag) + mag->size =0 ; + +return mag; }static void iova_magazine_free (struct iova_magazine *mag)
Quoted 14 lines · Robin Murphy
Quoted 3 lines · Zhen Lei
Only the member 'size' needs to be initialized to 0. Clearing the array pfns[], which is about 1 KiB in size, not only wastes time, but also causes cache pollution.
Makes sense to me.
Acked-by Robin Murphy <[email protected]>Quoted 5 lines
Signed-off-by Zhen Lei <[email protected]>---
drivers/iommu/iova.c| 8 +++++++-1 file changed, 7 insertions(+), 1 deletion(-)
Quoted 13 lines
drivers/iommu/iova.c struct iova_rcache { · line 651
Quoted 11 lines
drivers/iommu/iova.c +3
-1@@ -647,7 +647,13 @@ struct iova_rcache { static struct iova_magazine *iova_magazine_alloc(gfp_t flags) { - return kzalloc(sizeof(struct iova_magazine), flags); + struct iova_magazine *mag; + + mag = kmalloc(sizeof(struct iova_magazine), flags);Nit: maybe
sizeof(*mag)is preferable?
Yes, sizeof(*mag) is the more recommended usage, I will post v2 tomorrow.
Quoted 10 lines
drivers/iommu/iova.c struct iova_rcache { · line 659
Quoted 7 lines
drivers/iommu/iova.c +4
-0+ if (mag) + mag->size = 0; + + return mag; } static void iova_magazine_free(struct iova_magazine *mag).
Signature · 2 lines
Regards, Zhen Lei
Joerg Roedel
maintainerQuoted 1 line · Leizhen (ThunderTown)
Yes,
sizeof(*mag)is the more recommended usage, I will post v2 tomorrow.
Somehow v2 didn't make it to my inbox, but I found it on lore. This is applied now, thanks.
Regards,
Joerg