[<prev] [next>] [thread-next>] [day] [month] [year] [list]
Message-ID: <CAH6RvXgctKWU0rdByDZgUNJ9k=6Wf6c=Tw_9ZzH7Un2mZbi-uQ@mail.gmail.com>
Date: Mon, 24 Jun 2024 03:58:04 -0400
From: Chris Gregory <czipperz@...il.com>
To: netdev@...r.kernel.org
Subject: [PATCH] net: core: alloc_netdev_mqs reduce alignment overhead
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)
Powered by blists - more mailing lists