Skip to contentSkip to conversation

iommu/iova: change IOVA_MAG_SIZE to 127 to save memory

PATCH Applied Feng Tang 2 participants 2 messages Jul 3, 2022 – Jul 6, 2022

Subsystems (3)
lore
Share & tools
lore

Feng Tang

author
#0 lore raw

PATCH v2 1/1 iommu/iova: change IOVA_MAG_SIZE to 127 to save memory

kmalloc will round up the request size to power of 2, and current iova_magazine's size is 1032 (1024+8) bytes, so each instance allocated will get 2048 bytes from kmalloc, causing around 1KB waste.

Change IOVA_MAG_SIZE from 128 to 127 to make size of 'iova_magazine' 1024 bytes so that no memory will be wasted.

---
Changelog:

since v1:
* update commit log per the comments from Robin and John

 drivers/iommu/iova.c | 7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)
drivers/iommu/iova.c +6 -1
index db77aa675145b..27634ddd9b904 100644
@@ -614,7 +614,12 @@ EXPORT_SYMBOL_GPL(reserve_iova);
  * dynamic size tuning described in the paper.
  */
 
-#define IOVA_MAG_SIZE 128
+/*
+ * As kmalloc's buffer size is fixed to power of 2, 127 is chosen to
+ * assure size of 'iova_magazine' to be 1024 bytes, so that no memory
+ * will be wasted.
+ */
+#define IOVA_MAG_SIZE 127
 #define MAX_GLOBAL_MAGS 32	/* magazines per bin */
 
 struct iova_magazine {
Signature · 1 line
2.27.0
maintainer Applied
#1 lore raw
Quoted 10 lines · Feng Tang

kmalloc will round up the request size to power of 2, and current iova_magazine's size is 1032 (1024+8) bytes, so each instance allocated will get 2048 bytes from kmalloc, causing around 1KB waste.

Change IOVA_MAG_SIZE from 128 to 127 to make size of 'iova_magazine' 1024 bytes so that no memory will be wasted.

Applied, thanks.