net: replace mc_dev with a flag in netdev_hw_addr_list
Subsystems (2)
PATCH 1/1 net: replace mc_dev with a flag in netdev_hw_addr_list
Commit 646cb8868bd2 ("net: add a generation counter for dev->mc changes") added an mc_dev back pointer to struct netdev_hw_addr_list, so the list helpers can find the netns of a dev->mc list. Only dev->mc sets it, but the pointer makes every list 8 bytes larger: 32 to 40 bytes on 64-bit. struct net_device holds four of these lists, and some drivers keep arrays of them.
Use an is_dev_mc flag in the hole after _count instead, and get the device with container_of(). The struct is 32 bytes again.
--- include/linux/netdevice.h | 6 +++--- net/core/dev_addr_lists.c | 12 ++++++++---- 2 files changed, 11 insertions(+), 7 deletions(-)
include/linux/netdevice.h +3 -3
@@ -257,11 +257,11 @@ struct netdev_hw_addr_list {*/ int _count; +/* Set for dev->mc only */ +bool is_dev_mc; +/* Auxiliary tree for faster lookup on addition and deletion */ struct rb_root tree; - -/* Set for dev->mc only, the device the list belongs to */ -struct net_device *mc_dev; };#define netdev_hw_addr_list_count (l) ((l)->_count)
net/core/dev_addr_lists.c +8 -4
@@ -25,8 +25,12 @@*/ static void __hw_addr_changed (struct netdev_hw_addr_list *list) { -if (list->mc_dev) -atomic_inc (&dev_net (list->mc_dev)->dev_mc_genid); +struct net_device *dev; + +if (!list->is_dev_mc) +return ; + dev = container_of(list, struct net_device, mc); +atomic_inc (&dev_net (dev)->dev_mc_genid); }static void __hw_addr_count_add (struct netdev_hw_addr_list *list,int value)
@@ -538,7 +542,7 @@ void __hw_addr_init(struct netdev_hw_addr_list *list)INIT_LIST_HEAD (&list->list); list->_count =0 ; list->tree =RB_ROOT ; - list->mc_dev =NULL ; + list->is_dev_mc = false; }EXPORT_SYMBOL (__hw_addr_init);
@@ -1215,7 +1219,7 @@ EXPORT_SYMBOL(dev_mc_flush);void dev_mc_init (struct net_device *dev) {__hw_addr_init (&dev->mc); - dev->mc.mc_dev = dev; + dev->mc.is_dev_mc = true; }EXPORT_SYMBOL (dev_mc_init);
Signature · 1 line
2.56.0.542.g3ef89b7020-goog
This patch was applied to netdev/net-next.git (main) by Jakub Kicinski <[email protected]>:
Hello:
This patch was applied to netdev/net-next.git (main) by Jakub Kicinski <[email protected]>:
Quoted 8 lines · On Wed, 11 Nov 2026 11:31:21 +0900 you wrote:
Commit
646cb8868bd2("net: add a generation counter fordev->mcchanges") added anmc_devback pointer to structnetdev_hw_addr_list, so the list helpers can find the netns of adev->mclist. Onlydev->mcsets it, but the pointer makes every list 8 bytes larger: 32 to 40 bytes on 64-bit. structnet_deviceholds four of these lists, and some drivers keep arrays of them.[...]
Here is the summary with links:
- [net-next] net: replace mc_dev with a flag in netdev_hw_addr_list
https://git.kernel.org/netdev/net-next/c/980d54ce8b29
You are awesome, thank you!
Signature · 2 lines
Deet-doot-dot, I am a bot. https://korg.docs.kernel.org/patchwork/pwbot.html