From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-pf0-f196.google.com ([209.85.192.196]:38190 "EHLO mail-pf0-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1032742AbeCARJD (ORCPT ); Thu, 1 Mar 2018 12:09:03 -0500 Received: by mail-pf0-f196.google.com with SMTP id d26so2712247pfn.5 for ; Thu, 01 Mar 2018 09:09:03 -0800 (PST) Message-ID: <1519924140.11375.1.camel@gmail.com> Subject: Re: [PATCH] inet: add bound ports statistic From: Eric Dumazet To: Stephen Hemminger Cc: David Miller , netdev@vger.kernel.org, sthemmin@microsoft.com Date: Thu, 01 Mar 2018 09:09:00 -0800 In-Reply-To: <20180301081613.3b52cd83@xeon-e3> References: <20180301020101.3975-1-sthemmin@microsoft.com> <1519871282.11536.2.camel@gmail.com> <20180228.223217.1178910703084049513.davem@davemloft.net> <1519878495.11536.4.camel@gmail.com> <20180301081613.3b52cd83@xeon-e3> Content-Type: text/plain; charset="UTF-8" Mime-Version: 1.0 Content-Transfer-Encoding: 7bit Sender: netdev-owner@vger.kernel.org List-ID: On Thu, 2018-03-01 at 08:16 -0800, Stephen Hemminger wrote: > > I went through a several possible alternatives. > 1. Add a counter in the hash bucket head (like listen already has). > But not namespace aware > 2. Add a percpu counter in network namespace (new struct tcp_netns) > Logical and adds place to move tcp open sockets as well. > But more expensive and several places in code don't have easy > access to namespace. __this_cpu_inc() should not be very expensive. We always have access to socket namespace when inserting/deleting a bind entry. Since we take the spinlock at that times, inserting __this_cpu_inc(sock_net(sk)->ipv4.bind_counter) would add few instructions. > 3. Counting entries in userspace; defeats the purpose of -s flag. > > Agree it is not an urgent statistic, it is just it got broken; willing to > just drop it. Not counting the fact that it has really no purpose. > > What about adding cond_resched between buckets like other places do? This still is dirtying at least 1MB of memory and performs ~64K atomic operations. Waste of cpu caches and memory bus. If we consider converting the whole /proc/net/socketstat to provide a netns view only, we might use a percpu structure holding all TCP socket counters, to make sure no more than one cache line per cpu is used while folding all the cpus counters.