Re: [PATCH v2 2/2] net: add trace events for net_device refcnt

From: David Ahern
Date: Tue Nov 12 2019 - 10:27:37 EST


On 11/12/19 6:05 AM, Tony Lu wrote:
> diff --git a/include/trace/events/net.h b/include/trace/events/net.h
> index 3b28843652d2..3bf6dd738882 100644
> --- a/include/trace/events/net.h
> +++ b/include/trace/events/net.h
> @@ -326,6 +326,47 @@ DEFINE_EVENT(net_dev_rx_exit_template, netif_receive_skb_list_exit,
> TP_ARGS(ret)
> );
>
> +DECLARE_EVENT_CLASS(net_dev_refcnt_template,
> +
> + TP_PROTO(struct net_device *dev, void *location),
> +
> + TP_ARGS(dev, location),
> +
> + TP_STRUCT__entry(
> + __string( name, dev->name )
> + __field( int, refcnt )
> + __field( void *, location )
> + ),
> +
> + TP_fast_assign(
> + int i, refcnt = 0;
> +
> + for_each_possible_cpu(i)
> + refcnt += *per_cpu_ptr(dev->pcpu_refcnt, i);

Rather than copying the definition of netdev_refcnt_read here, so just
use it.

> +
> + __assign_str(name, dev->name);
> + __entry->refcnt = refcnt;
> + __entry->location = location;
> + ),
> +
> + TP_printk("dev=%s refcnt=%d location=%p",
> + __get_str(name), __entry->refcnt, __entry->location)
> +);
> +
> +DEFINE_EVENT(net_dev_refcnt_template, net_dev_put,
> +
> + TP_PROTO(struct net_device *dev, void *location),
> +
> + TP_ARGS(dev, location)
> +);
> +
> +DEFINE_EVENT(net_dev_refcnt_template, net_dev_hold,
> +
> + TP_PROTO(struct net_device *dev, void *location),
> +
> + TP_ARGS(dev, location)
> +);
> +
> #endif /* _TRACE_NET_H */
>

The location alone does nothing for resolving reference count leaks; you
really have to use stack traces to pair up the hold and put and to give
context for what are repetitive locations for the hold and put.