* [PATCH net-next] net: replace mc_dev with a flag in netdev_hw_addr_list
@ 2026-11-11 2:31 Yuyang Huang
0 siblings, 0 replies; only message in thread
From: Yuyang Huang @ 2026-11-11 2:31 UTC (permalink / raw)
To: Yuyang Huang
Cc: David S. Miller, Aleksandr Loktionov, Andrew Lunn, Eric Dumazet,
Jakub Kicinski, Paolo Abeni, Simon Horman, Stanislav Fomichev,
linux-kernel, netdev
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.
Link: https://lore.kernel.org/netdev/8dcd9564-e9a3-4b00-93b8-3cb023d68047@redhat.com/
Signed-off-by: Yuyang Huang <yuyanghuang@google.com>
---
include/linux/netdevice.h | 6 +++---
net/core/dev_addr_lists.c | 12 ++++++++----
2 files changed, 11 insertions(+), 7 deletions(-)
diff --git a/include/linux/netdevice.h b/include/linux/netdevice.h
index c0ae442c4344..e00687e8e750 100644
--- a/include/linux/netdevice.h
+++ b/include/linux/netdevice.h
@@ -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)
diff --git a/net/core/dev_addr_lists.c b/net/core/dev_addr_lists.c
index d827cc21867b..b6f25e487984 100644
--- a/net/core/dev_addr_lists.c
+++ b/net/core/dev_addr_lists.c
@@ -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);
--
2.56.0.542.g3ef89b7020-goog
^ permalink raw reply [flat|nested] only message in thread
only message in thread, other threads:[~2026-11-11 2:31 UTC | newest]
Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-11-11 2:31 [PATCH net-next] net: replace mc_dev with a flag in netdev_hw_addr_list Yuyang Huang
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®