netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] net: core: alloc_netdev_mqs reduce alignment overhead
@ 2024-06-24  7:58 Chris Gregory
  2024-06-25 15:29 ` Jakub Kicinski
  0 siblings, 1 reply; 2+ messages in thread
From: Chris Gregory @ 2024-06-24  7:58 UTC (permalink / raw)
  To: netdev

I was reading over alloc_netdev_mqs and noticed that it's trying to
align the allocation by adding on 31 bytes (NETDEV_ALIGN-1).  I'm not
an expert on kmalloc, but AFAICT it will always give back a pointer
aligned to ARCH_KMALLOC_MINALIGN.  On my x86_64,
ARCH_KMALLOC_MINALIGN=8 so this saves 7 bytes which could mean an
8-byte allocation is freed up.

I think there's some additional potential optimization for the case
where ARCH_KMALLOC_MINALIGN >= NETDEV_ALIGN.  In this case we can
delete the padding member completely.  I don't know if this ever
happens in practice though.

If this patch looks good, we should probably do the same thing at
linux/drivers/net/ethernet/wiznet/w5100.c:1091.

Chris
----

diff --git a/net/core/dev.c b/net/core/dev.c
index e1bb6d7856d9..73daa1573554 100644
--- a/net/core/dev.c
+++ b/net/core/dev.c
@@ -10943,7 +10943,7 @@ struct net_device *alloc_netdev_mqs(int
sizeof_priv, const char *name,
         alloc_size += sizeof_priv;
     }
     /* ensure 32-byte alignment of whole construct */
-    alloc_size += NETDEV_ALIGN - 1;
+    alloc_size += NETDEV_ALIGN - min(NETDEV_ALIGN, ARCH_KMALLOC_MINALIGN);

     p = kvzalloc(alloc_size, GFP_KERNEL_ACCOUNT | __GFP_RETRY_MAYFAIL);
     if (!p)

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

end of thread, other threads:[~2024-06-25 15:29 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-06-24  7:58 [PATCH] net: core: alloc_netdev_mqs reduce alignment overhead Chris Gregory
2024-06-25 15:29 ` Jakub Kicinski

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).