Skip to contentSkip to conversation

iommu/iova: Optimize iova_magazine_alloc()

PATCH Superseded Zhen Lei 3 participants 4 messages Apr 18, 2023 – May 22, 2023

Subsystems (2)

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore

Zhen Lei

author
#0 lore raw

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
index fe452ce466429a7..c970b9a2819d7bb 100644
@@ -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
maintainer Acked-by on v1 1/1
#1 lore raw
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
---
  drivers/iommu/iova.c | 8 +++++++-
  1 file changed, 7 insertions(+), 1 deletion(-)
drivers/iommu/iova.c +0 -0
index fe452ce466429a7..c970b9a2819d7bb 100644

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)
#2 lore raw
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.

Quoted 5 lines

---
  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
index fe452ce466429a7..c970b9a2819d7bb 100644
@@ -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
maintainer
#3 lore raw
Quoted 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