Received: by 2002:ac0:a581:0:0:0:0:0 with SMTP id m1-v6csp2928073imm; Sun, 1 Jul 2018 08:32:45 -0700 (PDT) X-Google-Smtp-Source: ADUXVKJaf3ZUTJTAHWGKTehb73+laZTiyxUBkBryPLadqHMKibxIiT8gPe/pukEpRvxidLPxpMns X-Received: by 2002:a65:6031:: with SMTP id p17-v6mr18661362pgu.140.1530459165799; Sun, 01 Jul 2018 08:32:45 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1530459165; cv=none; d=google.com; s=arc-20160816; b=h2UyAs9sXSmlGl3fom4rlBeJzk2GFgW6DHZoF269and6TuyYBPAIHcn1I27lKxDYv6 h4wDmuSuHhSzFwmlzl1M7lEQhC2God1dsYJSXgY/lt/anmeEAv6uCzRfviXmMFl8QEQp n7a8MtDLtP4OhHjQH00b4bHowTgaaJObxQQDppRjexnWKdYmwLYZnmlOagjwU68gAMj9 FUDx8cwKSW2xErIFuRvN6/x2jk10IePsg5h3VW5LSxlGldfGVzDQ9O4F9ERNhJ6mq0d1 0cXQIPLluJGnbAvnMKK4UsQs80ZyiW/tvoNni4WxiDEkBq0cwJCYOXjk+Ovj4g79m23o vMRg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:message-id:date:subject:cc:to:from :dkim-signature:arc-authentication-results; bh=TLJEHSMc0Ro9D+m+kk9Idvn2jncwryz9UfVUtdBu2PM=; b=PUxlcETCI4944NKFAKkzDkOTIwAPhErUsVBqWU1ykU7JH93TpOJac19Ve7M/+NlUh2 aFc9VJfSlbaOK+2K849IeseEyPG5Q4j8vSi7vT28ptszduj14nvD1mAsfMyfkHEdRXU5 RN/70oCjhUYuHbS9zhZ/I3l9BL1KuYWM/TvJQzZwW7zjZxv1NoRjJ17lApkSZRCXQNJp 73P0BupBxI79fy+C4WqHY2afdQbi9Ev/R6BZ0RAXeDNrotfB3mP50vMpEzzCA6KYjnU/ bvPa3i7hiluafdkOVE8IbYkhfDWlvm0xOtRo1dLFhjKAYsANJuIPx8vAIWlL4AtDNs+h 0kxQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=jxEEUufP; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id s9-v6si13958173plp.182.2018.07.01.08.32.30; Sun, 01 Jul 2018 08:32:45 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=jxEEUufP; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752375AbeGAPbw (ORCPT + 99 others); Sun, 1 Jul 2018 11:31:52 -0400 Received: from mail-pg0-f67.google.com ([74.125.83.67]:45153 "EHLO mail-pg0-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752217AbeGAPbv (ORCPT ); Sun, 1 Jul 2018 11:31:51 -0400 Received: by mail-pg0-f67.google.com with SMTP id z1-v6so6008416pgv.12; Sun, 01 Jul 2018 08:31:51 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id; bh=TLJEHSMc0Ro9D+m+kk9Idvn2jncwryz9UfVUtdBu2PM=; b=jxEEUufP+0V5ykg+QX+pVQpYGJijdnufAgSozaUF17jhlzV/9bWERWpBX4czahyDja Lpj2m1cv8YmM0jQ7T2Cb8gyN0fqBt8JswZW+7UdOiebsDpP0aGEsC0tpyAC7stdlTsck P+ieVqJiVAUz8Gj5+OWYyF3D/S3My++G1VKOTSpkA97bXmRpM31JqVVf9+s8FNRI6+8l 2hVrPs6G4Ts7Dv5LfmwVFG5e/cIkK0xA8MYXBriUUrW5hIjW7kT3GwHhnVfApV0U192G 0BAlbM27wb9CjrkXT87Jo0bJ8g1cTj3mSaDkgxpj2Gnk5KA4W0KJ77Dro6XMxfdL5rVn 2R3g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id; bh=TLJEHSMc0Ro9D+m+kk9Idvn2jncwryz9UfVUtdBu2PM=; b=APgIZHEKuWfyGt3Hb0R3x+QD6LAMxfJ8sQBT3LOzialIoAw4nChhVKNmrWzawb5iPz XiO2AxvafUDYsnqpOG1i8rDNXR/2aGqIHLW1h3WDpxonLlZ9/tUJTPToB5mp56HuT2ii dlLQrAyhW9ww/XALKu1wGQGrc7ZxnevlVOp6VNBgCiG8ZaJOfIB55LqQ7/aC7gcw+L8J NCjowrEOQYsFlOLzt76xc/AQwpa0T3iaxJVsccCQcKARIAZa9CsIGdEmSoOfVZh64HSP 2AxzN+FKRThSJs3TamyVbNLWBJK3UAwq6vO7WLaHJkumCbp5SIKijnNgmwPwXgguQWrJ q+bQ== X-Gm-Message-State: APt69E2CYz2SCFLnELrF4FIHsGGR6b32DBBc9gadZ72JwL72/1XrhA8y WeD9rnIzA9Ul3OvwBcw4Uag= X-Received: by 2002:a62:dd8:: with SMTP id 85-v6mr22118526pfn.202.1530459110752; Sun, 01 Jul 2018 08:31:50 -0700 (PDT) Received: from li1588-6.members.linode.com (li1588-6.members.linode.com. [139.162.104.6]) by smtp.gmail.com with ESMTPSA id y3-v6sm28014433pge.29.2018.07.01.08.31.48 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sun, 01 Jul 2018 08:31:50 -0700 (PDT) From: Yafang Shao To: davem@davemloft.net, satoru.moriya@hds.com Cc: netdev@vger.kernel.org, linux-kernel@vger.kernel.org, Yafang Shao Subject: [PATCH] net: expose sk wmem in sock_exceed_buf_limit tracepoint Date: Sun, 1 Jul 2018 23:31:30 +0800 Message-Id: <1530459090-11037-1-git-send-email-laoar.shao@gmail.com> X-Mailer: git-send-email 1.8.3.1 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Currently trace_sock_exceed_buf_limit() only show rmem info, but wmem limit may also be hit. So expose wmem info in this tracepoint as well. Regarding memcg, I think it is better to introduce a new tracepoint(if that is needed), i.e. trace_memcg_limit_hit other than show memcg info in trace_sock_exceed_buf_limit. Signed-off-by: Yafang Shao --- include/trace/events/sock.h | 30 +++++++++++++++++++++++++----- net/core/sock.c | 6 ++++-- 2 files changed, 29 insertions(+), 7 deletions(-) diff --git a/include/trace/events/sock.h b/include/trace/events/sock.h index 3176a39..a0c4b8a 100644 --- a/include/trace/events/sock.h +++ b/include/trace/events/sock.h @@ -35,6 +35,10 @@ EM(TCP_CLOSING) \ EMe(TCP_NEW_SYN_RECV) +#define skmem_kind_names \ + EM(SK_MEM_SEND) \ + EMe(SK_MEM_RECV) + /* enums need to be exported to user space */ #undef EM #undef EMe @@ -44,6 +48,7 @@ family_names inet_protocol_names tcp_state_names +skmem_kind_names #undef EM #undef EMe @@ -59,6 +64,9 @@ #define show_tcp_state_name(val) \ __print_symbolic(val, tcp_state_names) +#define show_skmem_kind_names(val) \ + __print_symbolic(val, skmem_kind_names) + TRACE_EVENT(sock_rcvqueue_full, TP_PROTO(struct sock *sk, struct sk_buff *skb), @@ -83,9 +91,9 @@ TRACE_EVENT(sock_exceed_buf_limit, - TP_PROTO(struct sock *sk, struct proto *prot, long allocated), + TP_PROTO(struct sock *sk, struct proto *prot, long allocated, int kind), - TP_ARGS(sk, prot, allocated), + TP_ARGS(sk, prot, allocated, kind), TP_STRUCT__entry( __array(char, name, 32) @@ -93,6 +101,10 @@ __field(long, allocated) __field(int, sysctl_rmem) __field(int, rmem_alloc) + __field(int, sysctl_wmem) + __field(int, wmem_alloc) + __field(int, wmem_queued) + __field(int, kind) ), TP_fast_assign( @@ -101,17 +113,25 @@ __entry->allocated = allocated; __entry->sysctl_rmem = sk_get_rmem0(sk, prot); __entry->rmem_alloc = atomic_read(&sk->sk_rmem_alloc); + __entry->sysctl_wmem = sk_get_wmem0(sk, prot); + __entry->wmem_alloc = refcount_read(&sk->sk_wmem_alloc); + __entry->wmem_queued = sk->sk_wmem_queued; + __entry->kind = kind; ), - TP_printk("proto:%s sysctl_mem=%ld,%ld,%ld allocated=%ld " - "sysctl_rmem=%d rmem_alloc=%d", + TP_printk("proto:%s sysctl_mem=%ld,%ld,%ld allocated=%ld sysctl_rmem=%d rmem_alloc=%d sysctl_wmem=%d wmem_alloc=%d wmem_queued=%d kind=%s", __entry->name, __entry->sysctl_mem[0], __entry->sysctl_mem[1], __entry->sysctl_mem[2], __entry->allocated, __entry->sysctl_rmem, - __entry->rmem_alloc) + __entry->rmem_alloc, + __entry->sysctl_wmem, + __entry->wmem_alloc, + __entry->wmem_queued, + show_skmem_kind_names(__entry->kind) + ) ); TRACE_EVENT(inet_sock_set_state, diff --git a/net/core/sock.c b/net/core/sock.c index bcc4182..65350ed 100644 --- a/net/core/sock.c +++ b/net/core/sock.c @@ -2401,9 +2401,10 @@ int __sk_mem_raise_allocated(struct sock *sk, int size, int amt, int kind) { struct proto *prot = sk->sk_prot; long allocated = sk_memory_allocated_add(sk, amt); + bool charged = true; if (mem_cgroup_sockets_enabled && sk->sk_memcg && - !mem_cgroup_charge_skmem(sk->sk_memcg, amt)) + !(charged = mem_cgroup_charge_skmem(sk->sk_memcg, amt))) goto suppress_allocation; /* Under limit. */ @@ -2461,7 +2462,8 @@ int __sk_mem_raise_allocated(struct sock *sk, int size, int amt, int kind) return 1; } - trace_sock_exceed_buf_limit(sk, prot, allocated); + if (kind == SK_MEM_SEND || (kind == SK_MEM_RECV && charged)) + trace_sock_exceed_buf_limit(sk, prot, allocated, kind); sk_memory_allocated_sub(sk, amt); -- 1.8.3.1