diff mbox series

[net-next] sock: add sndbuff full perf trace event

Message ID 1642716150-100589-1-git-send-email-jdamato@fastly.com (mailing list archive)
State Changes Requested
Delegated to: Netdev Maintainers
Headers show
Series [net-next] sock: add sndbuff full perf trace event | expand

Checks

Context Check Description
netdev/tree_selection success Clearly marked for net-next
netdev/fixes_present success Fixes tag not required for -next series
netdev/subject_prefix success Link
netdev/cover_letter success Single patches do not need cover letters
netdev/patch_count success Link
netdev/header_inline success No static functions without inline keyword in header files
netdev/build_32bit success Errors and warnings before: 7 this patch: 7
netdev/cc_maintainers warning 4 maintainers not CCed: aahringo@redhat.com rostedt@goodmis.org mingo@redhat.com edumazet@google.com
netdev/build_clang success Errors and warnings before: 22 this patch: 22
netdev/module_param success Was 0 now: 0
netdev/verify_signedoff success Signed-off-by tag matches author and committer
netdev/verify_fixes success No Fixes tag
netdev/build_allmodconfig_warn success Errors and warnings before: 12 this patch: 12
netdev/checkpatch warning CHECK: Alignment should match open parenthesis CHECK: Lines should not end with a '('
netdev/kdoc success Errors and warnings before: 0 this patch: 0
netdev/source_inline success Was 0 now: 0

Commit Message

Joe Damato Jan. 20, 2022, 10:02 p.m. UTC
Calls to sock_alloc_send_pskb can fail or trigger a wait if there is no
sndbuf space available.

Add a perf trace event to help users monitor when and how this occurs so
appropriate application level changes can be made, if necessary.

Signed-off-by: Joe Damato <jdamato@fastly.com>
---
 include/trace/events/sock.h | 21 +++++++++++++++++++++
 net/core/sock.c             |  1 +
 2 files changed, 22 insertions(+)

Comments

Cong Wang Jan. 23, 2022, 8:17 p.m. UTC | #1
On Thu, Jan 20, 2022 at 02:02:30PM -0800, Joe Damato wrote:
> Calls to sock_alloc_send_pskb can fail or trigger a wait if there is no
> sndbuf space available.
> 
> Add a perf trace event to help users monitor when and how this occurs so
> appropriate application level changes can be made, if necessary.
> 
> Signed-off-by: Joe Damato <jdamato@fastly.com>
> ---
>  include/trace/events/sock.h | 21 +++++++++++++++++++++
>  net/core/sock.c             |  1 +
>  2 files changed, 22 insertions(+)

There are more places where we set the SOCKWQ_ASYNC_NOSPACE bit, so
it looks like your patch is incomplete.

Thanks.
Joe Damato Jan. 25, 2022, 7:51 p.m. UTC | #2
On Sun, Jan 23, 2022 at 12:17 PM Cong Wang <xiyou.wangcong@gmail.com> wrote:
>
> On Thu, Jan 20, 2022 at 02:02:30PM -0800, Joe Damato wrote:
> > Calls to sock_alloc_send_pskb can fail or trigger a wait if there is no
> > sndbuf space available.
> >
> > Add a perf trace event to help users monitor when and how this occurs so
> > appropriate application level changes can be made, if necessary.
> >
> > Signed-off-by: Joe Damato <jdamato@fastly.com>
> > ---
> >  include/trace/events/sock.h | 21 +++++++++++++++++++++
> >  net/core/sock.c             |  1 +
> >  2 files changed, 22 insertions(+)
>
> There are more places where we set the SOCKWQ_ASYNC_NOSPACE bit, so
> it looks like your patch is incomplete.

Thanks for taking a look.

I had originally taken your comment to suggest that the generic stream
code should trigger the same tracepoint; I agree and am happy to
generate a v2 with that case covered.

Are you suggesting that all places where SOCKWQ_ASYNC_NOSPACE is set
(e.g. the poll functions for various protocols) should trigger this
tracepoint, as well? Some of these may not have a user configurable
sndbuf, but I suppose knowing that this event is happening could be
helpful.

Thanks.
diff mbox series

Patch

diff --git a/include/trace/events/sock.h b/include/trace/events/sock.h
index 12c3157..de6f6a7 100644
--- a/include/trace/events/sock.h
+++ b/include/trace/events/sock.h
@@ -68,6 +68,27 @@  skmem_kind_names
 #define show_skmem_kind_names(val)	\
 	__print_symbolic(val, skmem_kind_names)
 
+TRACE_EVENT(sock_sndbuf_full,
+	TP_PROTO(struct sock *sk, long timeo),
+
+	TP_ARGS(sk, timeo),
+
+	TP_STRUCT__entry(
+		__field(int, wmem_alloc)
+		__field(int, sk_sndbuf)
+		__field(long, timeo)
+	),
+
+	TP_fast_assign(
+		__entry->wmem_alloc = refcount_read(&sk->sk_wmem_alloc);
+		__entry->sk_sndbuf = READ_ONCE(sk->sk_sndbuf);
+		__entry->timeo = timeo;
+	),
+
+	TP_printk("wmem_alloc=%d sk_sndbf=%d timeo=%ld",
+		__entry->wmem_alloc, __entry->sk_sndbuf, __entry->timeo)
+);
+
 TRACE_EVENT(sock_rcvqueue_full,
 
 	TP_PROTO(struct sock *sk, struct sk_buff *skb),
diff --git a/net/core/sock.c b/net/core/sock.c
index e21485a..674627c 100644
--- a/net/core/sock.c
+++ b/net/core/sock.c
@@ -2571,6 +2571,7 @@  struct sk_buff *sock_alloc_send_pskb(struct sock *sk, unsigned long header_len,
 
 		sk_set_bit(SOCKWQ_ASYNC_NOSPACE, sk);
 		set_bit(SOCK_NOSPACE, &sk->sk_socket->flags);
+		trace_sock_sndbuf_full(sk, timeo);
 		err = -EAGAIN;
 		if (!timeo)
 			goto failure;