linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH v2] iommu/iova: change IOVA_MAG_SIZE to 127 to save memory
@ 2022-07-03 11:44 Feng Tang
  2022-07-06 11:31 ` Joerg Roedel
  0 siblings, 1 reply; 2+ messages in thread
From: Feng Tang @ 2022-07-03 11:44 UTC (permalink / raw)
  To: Joerg Roedel, Will Deacon, Robin Murphy, John Garry, iommu,
	iommu, Andrew Morton, Christoph Lameter, Vlastimil Babka
  Cc: linux-mm, linux-kernel, 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.

Signed-off-by: Feng Tang <feng.tang@intel.com>
Acked-by: Robin Murphy <robin.murphy@arm.com>
---
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(-)

diff --git a/drivers/iommu/iova.c b/drivers/iommu/iova.c
index db77aa675145b..27634ddd9b904 100644
--- a/drivers/iommu/iova.c
+++ b/drivers/iommu/iova.c
@@ -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 {
-- 
2.27.0


^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [PATCH v2] iommu/iova: change IOVA_MAG_SIZE to 127 to save memory
  2022-07-03 11:44 [PATCH v2] iommu/iova: change IOVA_MAG_SIZE to 127 to save memory Feng Tang
@ 2022-07-06 11:31 ` Joerg Roedel
  0 siblings, 0 replies; 2+ messages in thread
From: Joerg Roedel @ 2022-07-06 11:31 UTC (permalink / raw)
  To: Feng Tang
  Cc: Will Deacon, Robin Murphy, John Garry, iommu, iommu,
	Andrew Morton, Christoph Lameter, Vlastimil Babka, linux-mm,
	linux-kernel

On Sun, Jul 03, 2022 at 07:44:50PM +0800, Feng Tang wrote:
> 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.
> 
> Signed-off-by: Feng Tang <feng.tang@intel.com>
> Acked-by: Robin Murphy <robin.murphy@arm.com>

Applied, thanks.


^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2022-07-06 11:31 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-07-03 11:44 [PATCH v2] iommu/iova: change IOVA_MAG_SIZE to 127 to save memory Feng Tang
2022-07-06 11:31 ` Joerg Roedel

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).