From mboxrd@z Thu Jan 1 00:00:00 1970 From: Bryton Lee Subject: [PATCH] prevent the read ahead of /proc/slabinfo in ss take 2 Date: Tue, 10 Feb 2015 10:46:00 +0800 Message-ID: <1423536360-5298-1-git-send-email-brytonlee01@gmail.com> Cc: eric.dumazet@gmail.com, brytonlee01@gmail.com To: stephen@networkplumber.org, netdev@vger.kernel.org, davem@davemloft.net Return-path: Received: from mail-pa0-f51.google.com ([209.85.220.51]:50396 "EHLO mail-pa0-f51.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751319AbbBJCql (ORCPT ); Mon, 9 Feb 2015 21:46:41 -0500 Received: by mail-pa0-f51.google.com with SMTP id eu11so16144284pac.10 for ; Mon, 09 Feb 2015 18:46:41 -0800 (PST) Sender: netdev-owner@vger.kernel.org List-ID: ss reads ahead of /proc/slabinfo whatever slabstat will be used or not in future. this will cause huge system delay when the kernel hires SLAB allocator(SLUB allocator is ok). when program reads /proc/slabinfo, it will call s_show() in SLAB allocator level, and s_show() calls spin_lock_irq(&l3->list_lock) then iterate on whole three lists. if one slab has about 900 million objects (for example dentry), it will cause more than 1000ms delay. so this patch prevents the read ahead of /proc/slabinfo, ss runs with most parameters not using slabstat at all. and this patch also change slabstat and slabstat_valid to static. Signed-off-by: Bryton Lee --- misc/ss.c | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/misc/ss.c b/misc/ss.c index 7fc0a99..5fa6259 100644 --- a/misc/ss.c +++ b/misc/ss.c @@ -616,7 +616,8 @@ struct slabstat int skbs; }; -struct slabstat slabstat; +static struct slabstat slabstat; +static int slabstat_valid = 0; static const char *slabstat_ids[] = { @@ -2230,6 +2231,9 @@ static int tcp_show(struct filter *f, int socktype) * it is able to give us some memory for snapshot. */ if (1) { + if (!slabstat_valid) + get_slabstat(&slabstat); + int guess = slabstat.socks+slabstat.tcp_syns; if (f->states&(1<