netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH net-next v2] rtnetlink: honor RTEXT_FILTER_SKIP_STATS in IFLA_STATS
@ 2025-10-29  8:01 Adrian Moreno
  2025-10-29  9:01 ` Toke Høiland-Jørgensen
                   ` (2 more replies)
  0 siblings, 3 replies; 5+ messages in thread
From: Adrian Moreno @ 2025-10-29  8:01 UTC (permalink / raw)
  To: netdev
  Cc: kuba, nicolas.dichtel, toke, Adrian Moreno, David S. Miller,
	Eric Dumazet, Paolo Abeni, Simon Horman, Kuniyuki Iwashima,
	Stanislav Fomichev, Xiao Liang, Cong Wang, linux-kernel

Gathering interface statistics can be a relatively expensive operation
on certain systems as it requires iterating over all the cpus.

RTEXT_FILTER_SKIP_STATS was first introduced [1] to skip AF_INET6
statistics from interface dumps and it was then extended [2] to
also exclude IFLA_VF_INFO.

The semantics of the flag does not seem to be limited to AF_INET
or VF statistics and having a way to query the interface status
(e.g: carrier, address) without retrieving its statistics seems
reasonable. So this patch extends the use RTEXT_FILTER_SKIP_STATS
to also affect IFLA_STATS.

[1] https://lore.kernel.org/all/20150911204848.GC9687@oracle.com/
[2] https://lore.kernel.org/all/20230611105108.122586-1-gal@nvidia.com/

Signed-off-by: Adrian Moreno <amorenoz@redhat.com>
---
 net/core/rtnetlink.c | 8 +++++---
 1 file changed, 5 insertions(+), 3 deletions(-)

diff --git a/net/core/rtnetlink.c b/net/core/rtnetlink.c
index 8040ff7c356e..aa09d026817b 100644
--- a/net/core/rtnetlink.c
+++ b/net/core/rtnetlink.c
@@ -1275,8 +1275,9 @@ static noinline size_t if_nlmsg_size(const struct net_device *dev,
 	       + nla_total_size(IFALIASZ) /* IFLA_IFALIAS */
 	       + nla_total_size(IFNAMSIZ) /* IFLA_QDISC */
 	       + nla_total_size_64bit(sizeof(struct rtnl_link_ifmap))
-	       + nla_total_size(sizeof(struct rtnl_link_stats))
-	       + nla_total_size_64bit(sizeof(struct rtnl_link_stats64))
+	       + ((ext_filter_mask & RTEXT_FILTER_SKIP_STATS) ? 0 :
+		  (nla_total_size(sizeof(struct rtnl_link_stats)) +
+		   nla_total_size_64bit(sizeof(struct rtnl_link_stats64))))
 	       + nla_total_size(MAX_ADDR_LEN) /* IFLA_ADDRESS */
 	       + nla_total_size(MAX_ADDR_LEN) /* IFLA_BROADCAST */
 	       + nla_total_size(4) /* IFLA_TXQLEN */
@@ -2123,7 +2124,8 @@ static int rtnl_fill_ifinfo(struct sk_buff *skb,
 	if (rtnl_phys_switch_id_fill(skb, dev))
 		goto nla_put_failure;
 
-	if (rtnl_fill_stats(skb, dev))
+	if (!(ext_filter_mask & RTEXT_FILTER_SKIP_STATS) &&
+	    rtnl_fill_stats(skb, dev))
 		goto nla_put_failure;
 
 	if (rtnl_fill_vf(skb, dev, ext_filter_mask))
-- 
2.51.0


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

* Re: [PATCH net-next v2] rtnetlink: honor RTEXT_FILTER_SKIP_STATS in IFLA_STATS
  2025-10-29  8:01 [PATCH net-next v2] rtnetlink: honor RTEXT_FILTER_SKIP_STATS in IFLA_STATS Adrian Moreno
@ 2025-10-29  9:01 ` Toke Høiland-Jørgensen
  2025-10-29  9:10 ` Nicolas Dichtel
  2025-10-31  1:20 ` Jakub Kicinski
  2 siblings, 0 replies; 5+ messages in thread
From: Toke Høiland-Jørgensen @ 2025-10-29  9:01 UTC (permalink / raw)
  To: Adrian Moreno, netdev
  Cc: kuba, nicolas.dichtel, Adrian Moreno, David S. Miller,
	Eric Dumazet, Paolo Abeni, Simon Horman, Kuniyuki Iwashima,
	Stanislav Fomichev, Xiao Liang, Cong Wang, linux-kernel

Adrian Moreno <amorenoz@redhat.com> writes:

> Gathering interface statistics can be a relatively expensive operation
> on certain systems as it requires iterating over all the cpus.
>
> RTEXT_FILTER_SKIP_STATS was first introduced [1] to skip AF_INET6
> statistics from interface dumps and it was then extended [2] to
> also exclude IFLA_VF_INFO.
>
> The semantics of the flag does not seem to be limited to AF_INET
> or VF statistics and having a way to query the interface status
> (e.g: carrier, address) without retrieving its statistics seems
> reasonable. So this patch extends the use RTEXT_FILTER_SKIP_STATS
> to also affect IFLA_STATS.
>
> [1] https://lore.kernel.org/all/20150911204848.GC9687@oracle.com/
> [2] https://lore.kernel.org/all/20230611105108.122586-1-gal@nvidia.com/
>
> Signed-off-by: Adrian Moreno <amorenoz@redhat.com>

Reviewed-by: Toke Høiland-Jørgensen <toke@redhat.com>


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

* Re: [PATCH net-next v2] rtnetlink: honor RTEXT_FILTER_SKIP_STATS in IFLA_STATS
  2025-10-29  8:01 [PATCH net-next v2] rtnetlink: honor RTEXT_FILTER_SKIP_STATS in IFLA_STATS Adrian Moreno
  2025-10-29  9:01 ` Toke Høiland-Jørgensen
@ 2025-10-29  9:10 ` Nicolas Dichtel
  2025-10-31  1:20 ` Jakub Kicinski
  2 siblings, 0 replies; 5+ messages in thread
From: Nicolas Dichtel @ 2025-10-29  9:10 UTC (permalink / raw)
  To: Adrian Moreno, netdev
  Cc: kuba, toke, David S. Miller, Eric Dumazet, Paolo Abeni,
	Simon Horman, Kuniyuki Iwashima, Stanislav Fomichev, Xiao Liang,
	linux-kernel, Cong Wang

Le 29/10/2025 à 09:01, Adrian Moreno a écrit :
> Gathering interface statistics can be a relatively expensive operation
> on certain systems as it requires iterating over all the cpus.
> 
> RTEXT_FILTER_SKIP_STATS was first introduced [1] to skip AF_INET6
> statistics from interface dumps and it was then extended [2] to
> also exclude IFLA_VF_INFO.
> 
> The semantics of the flag does not seem to be limited to AF_INET
> or VF statistics and having a way to query the interface status
> (e.g: carrier, address) without retrieving its statistics seems
> reasonable. So this patch extends the use RTEXT_FILTER_SKIP_STATS
> to also affect IFLA_STATS.
> 
> [1] https://lore.kernel.org/all/20150911204848.GC9687@oracle.com/
> [2] https://lore.kernel.org/all/20230611105108.122586-1-gal@nvidia.com/
> 
> Signed-off-by: Adrian Moreno <amorenoz@redhat.com>

Reviewed-by: Nicolas Dichtel <nicolas.dichtel@6wind.com>

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

* Re: [PATCH net-next v2] rtnetlink: honor RTEXT_FILTER_SKIP_STATS in IFLA_STATS
  2025-10-29  8:01 [PATCH net-next v2] rtnetlink: honor RTEXT_FILTER_SKIP_STATS in IFLA_STATS Adrian Moreno
  2025-10-29  9:01 ` Toke Høiland-Jørgensen
  2025-10-29  9:10 ` Nicolas Dichtel
@ 2025-10-31  1:20 ` Jakub Kicinski
  2025-11-03 15:29   ` Adrián Moreno
  2 siblings, 1 reply; 5+ messages in thread
From: Jakub Kicinski @ 2025-10-31  1:20 UTC (permalink / raw)
  To: Adrian Moreno
  Cc: netdev, nicolas.dichtel, toke, David S. Miller, Eric Dumazet,
	Paolo Abeni, Simon Horman, Kuniyuki Iwashima, Stanislav Fomichev,
	Xiao Liang, Cong Wang, linux-kernel

On Wed, 29 Oct 2025 09:01:52 +0100 Adrian Moreno wrote:
> --- a/net/core/rtnetlink.c
> +++ b/net/core/rtnetlink.c
> @@ -1275,8 +1275,9 @@ static noinline size_t if_nlmsg_size(const struct net_device *dev,
>  	       + nla_total_size(IFALIASZ) /* IFLA_IFALIAS */
>  	       + nla_total_size(IFNAMSIZ) /* IFLA_QDISC */
>  	       + nla_total_size_64bit(sizeof(struct rtnl_link_ifmap))
> -	       + nla_total_size(sizeof(struct rtnl_link_stats))
> -	       + nla_total_size_64bit(sizeof(struct rtnl_link_stats64))
> +	       + ((ext_filter_mask & RTEXT_FILTER_SKIP_STATS) ? 0 :
> +		  (nla_total_size(sizeof(struct rtnl_link_stats)) +
> +		   nla_total_size_64bit(sizeof(struct rtnl_link_stats64))))
>  	       + nla_total_size(MAX_ADDR_LEN) /* IFLA_ADDRESS */
>  	       + nla_total_size(MAX_ADDR_LEN) /* IFLA_BROADCAST */
>  	       + nla_total_size(4) /* IFLA_TXQLEN */

Forgive me but now I'm gonna nit pick ;)
Please break this out into a proper if condition.
It's quite hard to read.

	size_t size;

	size = NLMSG_ALIGN(sizeof(struct ifinfomsg))
		+ /* .. litany .. */

	if (!(ext_filter_mask & RTEXT_FILTER_SKIP_STATS))
		size += nla_total_size(sizeof(struct rtnl_link_stats)) +
			nla_total_size_64bit(sizeof(struct rtnl_link_stats64));

	return size;
-- 
pw-bot: cr

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

* Re: [PATCH net-next v2] rtnetlink: honor RTEXT_FILTER_SKIP_STATS in IFLA_STATS
  2025-10-31  1:20 ` Jakub Kicinski
@ 2025-11-03 15:29   ` Adrián Moreno
  0 siblings, 0 replies; 5+ messages in thread
From: Adrián Moreno @ 2025-11-03 15:29 UTC (permalink / raw)
  To: Jakub Kicinski
  Cc: netdev, nicolas.dichtel, toke, David S. Miller, Eric Dumazet,
	Paolo Abeni, Simon Horman, Kuniyuki Iwashima, Stanislav Fomichev,
	Xiao Liang, Cong Wang, linux-kernel

On Thu, Oct 30, 2025 at 06:20:57PM -0700, Jakub Kicinski wrote:
> On Wed, 29 Oct 2025 09:01:52 +0100 Adrian Moreno wrote:
> > --- a/net/core/rtnetlink.c
> > +++ b/net/core/rtnetlink.c
> > @@ -1275,8 +1275,9 @@ static noinline size_t if_nlmsg_size(const struct net_device *dev,
> >  	       + nla_total_size(IFALIASZ) /* IFLA_IFALIAS */
> >  	       + nla_total_size(IFNAMSIZ) /* IFLA_QDISC */
> >  	       + nla_total_size_64bit(sizeof(struct rtnl_link_ifmap))
> > -	       + nla_total_size(sizeof(struct rtnl_link_stats))
> > -	       + nla_total_size_64bit(sizeof(struct rtnl_link_stats64))
> > +	       + ((ext_filter_mask & RTEXT_FILTER_SKIP_STATS) ? 0 :
> > +		  (nla_total_size(sizeof(struct rtnl_link_stats)) +
> > +		   nla_total_size_64bit(sizeof(struct rtnl_link_stats64))))
> >  	       + nla_total_size(MAX_ADDR_LEN) /* IFLA_ADDRESS */
> >  	       + nla_total_size(MAX_ADDR_LEN) /* IFLA_BROADCAST */
> >  	       + nla_total_size(4) /* IFLA_TXQLEN */
>
> Forgive me but now I'm gonna nit pick ;)
> Please break this out into a proper if condition.
> It's quite hard to read.
>
> 	size_t size;
>
> 	size = NLMSG_ALIGN(sizeof(struct ifinfomsg))
> 		+ /* .. litany .. */
>
> 	if (!(ext_filter_mask & RTEXT_FILTER_SKIP_STATS))
> 		size += nla_total_size(sizeof(struct rtnl_link_stats)) +
> 			nla_total_size_64bit(sizeof(struct rtnl_link_stats64));
>
> 	return size;

Sure, I'll send V3.

> --
> pw-bot: cr
>


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

end of thread, other threads:[~2025-11-03 15:29 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-10-29  8:01 [PATCH net-next v2] rtnetlink: honor RTEXT_FILTER_SKIP_STATS in IFLA_STATS Adrian Moreno
2025-10-29  9:01 ` Toke Høiland-Jørgensen
2025-10-29  9:10 ` Nicolas Dichtel
2025-10-31  1:20 ` Jakub Kicinski
2025-11-03 15:29   ` Adrián Moreno

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