mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Yuyang Huang <yuyanghuang@google.com>
To: Yuyang Huang <yuyanghuang@google.com>
Cc: "David S. Miller" <davem@davemloft.net>,
	 Aleksandr Loktionov <aleksandr.loktionov@intel.com>,
	Andrew Lunn <andrew+netdev@lunn.ch>,
	 Eric Dumazet <edumazet@kernel.org>,
	Jakub Kicinski <kuba@kernel.org>, Paolo Abeni <pabeni@redhat.com>,
	 Simon Horman <horms@kernel.org>,
	Stanislav Fomichev <sdf.kernel@gmail.com>,
	linux-kernel@vger.kernel.org,  netdev@vger.kernel.org
Subject: [PATCH net-next] net: replace mc_dev with a flag in netdev_hw_addr_list
Date: Wed, 11 Nov 2026 11:31:21 +0900	[thread overview]
Message-ID: <20261111023121.1511995-1-yuyanghuang@google.com> (raw)

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


                 reply	other threads:[~2026-11-11  2:31 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20261111023121.1511995-1-yuyanghuang@google.com \
    --to=yuyanghuang@google.com \
    --cc=aleksandr.loktionov@intel.com \
    --cc=andrew+netdev@lunn.ch \
    --cc=davem@davemloft.net \
    --cc=edumazet@kernel.org \
    --cc=horms@kernel.org \
    --cc=kuba@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=netdev@vger.kernel.org \
    --cc=pabeni@redhat.com \
    --cc=sdf.kernel@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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®