From: Stephen Hemminger <stephen@networkplumber•org>
To: davem@davemloft•net, gerrit@erg•abdn.ac.uk, kuznet@ms2•inr.ac.ru,
yoshfuji@linux-ipv6•org
Cc: netdev@vger•kernel.org, dccp@vger•kernel.org,
Stephen Hemminger <sthemmin@microsoft•com>,
Stephen Hemminger <stephen@networkplumber•org>
Subject: [PATCH net-next v3 2/2] socket: keep track of the number of sockets allocated
Date: Mon, 7 May 2018 11:43:33 -0700 [thread overview]
Message-ID: <20180507184333.32688-3-sthemmin@microsoft.com> (raw)
In-Reply-To: <20180507184333.32688-1-sthemmin@microsoft.com>
Add a per-cpu counter to keep track of the number of inodes allocated
to sockets to fix incorrect statistics from ss command.
The ss command tries to keep track of the number of sockets
allocated but it was doing by the slabinfo statistics which are
wrong (due to merging) and not available when using slub.
Signed-off-by: Stephen Hemminger <stephen@networkplumber•org>
---
net/socket.c | 21 +++++++++++++++++++--
1 file changed, 19 insertions(+), 2 deletions(-)
diff --git a/net/socket.c b/net/socket.c
index f10f1d947c78..89ec7f41559d 100644
--- a/net/socket.c
+++ b/net/socket.c
@@ -234,6 +234,18 @@ static int move_addr_to_user(struct sockaddr_storage *kaddr, int klen,
}
static struct kmem_cache *sock_inode_cachep __ro_after_init;
+static unsigned int __percpu *sock_pcpu_allocated;
+
+static unsigned int sock_allocated(void)
+{
+ unsigned int res = 0;
+ int cpu;
+
+ for_each_possible_cpu(cpu)
+ res += *per_cpu_ptr(sock_pcpu_allocated, cpu);
+
+ return res;
+}
static struct inode *sock_alloc_inode(struct super_block *sb)
{
@@ -248,6 +260,7 @@ static struct inode *sock_alloc_inode(struct super_block *sb)
kmem_cache_free(sock_inode_cachep, ei);
return NULL;
}
+ this_cpu_inc(*sock_pcpu_allocated);
init_waitqueue_head(&wq->wait);
wq->fasync_list = NULL;
wq->flags = 0;
@@ -270,6 +283,7 @@ static void sock_destroy_inode(struct inode *inode)
ei = container_of(inode, struct socket_alloc, vfs_inode);
wq = rcu_dereference_protected(ei->socket.wq, 1);
kfree_rcu(wq, rcu);
+ this_cpu_dec(*sock_pcpu_allocated);
kmem_cache_free(sock_inode_cachep, ei);
}
@@ -290,6 +304,8 @@ static void init_inodecache(void)
SLAB_MEM_SPREAD | SLAB_ACCOUNT),
init_once);
BUG_ON(sock_inode_cachep == NULL);
+ sock_pcpu_allocated = alloc_percpu(unsigned int);
+ BUG_ON(sock_pcpu_allocated == NULL);
}
static const struct super_operations sockfs_ops = {
@@ -2738,8 +2754,9 @@ core_initcall(sock_init); /* early initcall */
#ifdef CONFIG_PROC_FS
void socket_seq_show(struct seq_file *seq)
{
- seq_printf(seq, "sockets: used %d\n",
- sock_inuse_get(seq->private));
+ seq_printf(seq, "sockets: used %d allocated %u\n",
+ sock_inuse_get(seq->private),
+ sock_allocated());
}
#endif /* CONFIG_PROC_FS */
--
2.17.0
next prev parent reply other threads:[~2018-05-07 18:43 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-05-07 18:43 [PATCH net-next v3 0/2] socket statistics for ss Stephen Hemminger
2018-05-07 18:43 ` [PATCH net-next v3 1/2] inet: add bound ports statistic Stephen Hemminger
2018-05-07 18:43 ` Stephen Hemminger [this message]
2018-05-09 15:22 ` [PATCH net-next v3 0/2] socket statistics for ss Stephen Hemminger
2018-05-09 17:18 ` Eric Dumazet
2018-05-09 17:31 ` Stephen Hemminger
2018-05-09 17:53 ` Eric Dumazet
2018-05-09 18:44 ` Stephen Hemminger
2018-05-09 18:53 ` Eric Dumazet
2018-05-09 19:34 ` 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=20180507184333.32688-3-sthemmin@microsoft.com \
--to=stephen@networkplumber$(echo .)org \
--cc=davem@davemloft$(echo .)net \
--cc=dccp@vger$(echo .)kernel.org \
--cc=gerrit@erg$(echo .)abdn.ac.uk \
--cc=kuznet@ms2$(echo .)inr.ac.ru \
--cc=netdev@vger$(echo .)kernel.org \
--cc=sthemmin@microsoft$(echo .)com \
--cc=yoshfuji@linux-ipv6$(echo .)org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
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