public inbox for netdev@vger.kernel.org
 help / color / mirror / Atom feed
From: David Miller <davem@davemloft.net>
To: xiangxia.m.yue@gmail.com
Cc: netdev@vger.kernel.org
Subject: Re: [PATCH] tcp: Support tcp socket allocated counter in namespace.
Date: Tue, 13 Feb 2018 12:19:46 -0500 (EST)	[thread overview]
Message-ID: <20180213.121946.1379751706930638939.davem@davemloft.net> (raw)
In-Reply-To: <1518489840-27911-1-git-send-email-xiangxia.m.yue@gmail.com>

From: Tonghao Zhang <xiangxia.m.yue@gmail.com>
Date: Mon, 12 Feb 2018 18:44:00 -0800

> Sometimes, we want to know how many tcp sockets are in use
> different _net_ namespaces. It's a key resource metric. With
> this patch, we can get it via /proc/net/sockstat.
> 
> The 'alloc' show in /proc/net/sockstat is the total tcp
> sockets in the kernel. This patch moves it to namespace,
> via adding a counter because the previous counter is used
> in proto(e.g tcp, udp and sctp) memory management.
> 
> Signed-off-by: Tonghao Zhang <xiangxia.m.yue@gmail.com>
 ...
> @@ -453,6 +453,8 @@ void tcp_init_sock(struct sock *sk)
>  	sk->sk_rcvbuf = sock_net(sk)->ipv4.sysctl_tcp_rmem[1];
>  
>  	sk_sockets_allocated_inc(sk);
> +	if (likely(sk->sk_net_refcnt))
> +		tcp_sock_allocated_add(sock_net(sk), 1);
>  }
>  EXPORT_SYMBOL(tcp_init_sock);
>  
 ...
> @@ -1928,6 +1928,8 @@ void tcp_v4_destroy_sock(struct sock *sk)
>  	tcp_saved_syn_free(tp);
>  
>  	sk_sockets_allocated_dec(sk);
> +	if (likely(sk->sk_net_refcnt))
> +		tcp_sock_allocated_add(sock_net(sk), -1);
>  }
>  EXPORT_SYMBOL(tcp_v4_destroy_sock);
>  
 ...
> @@ -559,6 +559,9 @@ struct sock *tcp_create_openreq_child(const struct sock *sk,
>  		newtp->rack.reo_wnd_persist = 0;
>  		newtp->rack.dsack_seen = 0;
>  
> +		if (likely(newsk->sk_net_refcnt))
> +			tcp_sock_allocated_add(sock_net(newsk), 1);
> +
>  		__TCP_INC_STATS(sock_net(sk), TCP_MIB_PASSIVEOPENS);

The amount of new conditional tests in these fast paths are not
justified for this new counter which is of debatable usefullness.

I'm not applying this, sorry.

  reply	other threads:[~2018-02-13 17:19 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-02-13  2:44 [PATCH] tcp: Support tcp socket allocated counter in namespace Tonghao Zhang
2018-02-13 17:19 ` David Miller [this message]
2018-02-28 13:01   ` Tonghao Zhang
2018-02-28 14:41     ` David Miller
2018-02-28 14:53       ` Tonghao Zhang
2018-02-28 19:19 ` Stephen Hemminger

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=20180213.121946.1379751706930638939.davem@davemloft.net \
    --to=davem@davemloft.net \
    --cc=netdev@vger.kernel.org \
    --cc=xiangxia.m.yue@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