netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] prevent the read ahead of /proc/slabinfo in ss - take 3
@ 2015-02-10  5:52 Bryton Lee
  2015-02-10 12:51 ` Sergei Shtylyov
  0 siblings, 1 reply; 3+ messages in thread
From: Bryton Lee @ 2015-02-10  5:52 UTC (permalink / raw)
  To: stephen, netdev, davem; +Cc: eric.dumazet, brytonlee01

prevent the read ahead of /proc/slabinfo in ss.

Signed-off-by: Bryton Lee <brytonlee01@gmail.com>
---
 misc/ss.c | 13 ++++++++++---
 1 file changed, 10 insertions(+), 3 deletions(-)

diff --git a/misc/ss.c b/misc/ss.c
index 7fc0a99..74721b5 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[] =
 {
@@ -655,6 +656,8 @@ static int get_slabstat(struct slabstat *s)
 			break;
 	}
 
+    slabstat_valid = 1;
+
 	fclose(fp);
 	return 0;
 }
@@ -2230,6 +2233,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<<SS_TIME_WAIT))
 			guess += slabstat.tcp_tws;
@@ -3196,6 +3202,9 @@ static int print_summary(void)
 	if (get_snmp_int("Tcp:", "CurrEstab", &sn.tcp_estab) < 0)
 		perror("ss: get_snmpstat");
 
+	if (!slabstat_valid)
+		get_slabstat(&slabstat);
+
 	printf("Total: %d (kernel %d)\n", s.socks, slabstat.socks);
 
 	printf("TCP:   %d (estab %d, closed %d, orphaned %d, synrecv %d, timewait %d/%d), ports %d\n",
@@ -3543,8 +3552,6 @@ int main(int argc, char *argv[])
 	argc -= optind;
 	argv += optind;
 
-	get_slabstat(&slabstat);
-
 	if (do_summary) {
 		print_summary();
 		if (do_default && argc == 0)
-- 
2.0.5

^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH] prevent the read ahead of /proc/slabinfo in ss - take 3
  2015-02-10  5:52 [PATCH] prevent the read ahead of /proc/slabinfo in ss - take 3 Bryton Lee
@ 2015-02-10 12:51 ` Sergei Shtylyov
  2015-02-12  1:21   ` Bryton Lee
  0 siblings, 1 reply; 3+ messages in thread
From: Sergei Shtylyov @ 2015-02-10 12:51 UTC (permalink / raw)
  To: Bryton Lee, stephen, netdev, davem; +Cc: eric.dumazet

On 2/10/2015 8:52 AM, Bryton Lee wrote:

> prevent the read ahead of /proc/slabinfo in ss.

> Signed-off-by: Bryton Lee <brytonlee01@gmail.com>
> ---
>   misc/ss.c | 13 ++++++++++---
>   1 file changed, 10 insertions(+), 3 deletions(-)

> diff --git a/misc/ss.c b/misc/ss.c
> index 7fc0a99..74721b5 100644
> --- a/misc/ss.c
> +++ b/misc/ss.c
[...]
> @@ -655,6 +656,8 @@ static int get_slabstat(struct slabstat *s)
>   			break;
>   	}
>
> +    slabstat_valid = 1;

    This is indented incorrectly. Use one TAB please.

> +
>   	fclose(fp);
>   	return 0;
>   }
> @@ -2230,6 +2233,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<<SS_TIME_WAIT))
>   			guess += slabstat.tcp_tws;
> @@ -3196,6 +3202,9 @@ static int print_summary(void)
>   	if (get_snmp_int("Tcp:", "CurrEstab", &sn.tcp_estab) < 0)
>   		perror("ss: get_snmpstat");
>
> +	if (!slabstat_valid)
> +		get_slabstat(&slabstat);
> +

    Can't you perform this check inside get_slabstat()?

[...]

WBR, Sergei

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] prevent the read ahead of /proc/slabinfo in ss - take 3
  2015-02-10 12:51 ` Sergei Shtylyov
@ 2015-02-12  1:21   ` Bryton Lee
  0 siblings, 0 replies; 3+ messages in thread
From: Bryton Lee @ 2015-02-12  1:21 UTC (permalink / raw)
  To: Sergei Shtylyov; +Cc: stephen, netdev, David Miller, Eric Dumazet

On Tue, Feb 10, 2015 at 8:51 PM, Sergei Shtylyov
<sergei.shtylyov@cogentembedded.com> wrote:
> On 2/10/2015 8:52 AM, Bryton Lee wrote:
>
>> prevent the read ahead of /proc/slabinfo in ss.
>
>
>> Signed-off-by: Bryton Lee <brytonlee01@gmail.com>
>> ---
>>   misc/ss.c | 13 ++++++++++---
>>   1 file changed, 10 insertions(+), 3 deletions(-)
>
>
>> diff --git a/misc/ss.c b/misc/ss.c
>> index 7fc0a99..74721b5 100644
>> --- a/misc/ss.c
>> +++ b/misc/ss.c
>
> [...]
>>
>> @@ -655,6 +656,8 @@ static int get_slabstat(struct slabstat *s)
>>                         break;
>>         }
>>
>> +    slabstat_valid = 1;
>
>
>    This is indented incorrectly. Use one TAB please.
>
>> +
>>         fclose(fp);
>>         return 0;
>>   }
>> @@ -2230,6 +2233,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<<SS_TIME_WAIT))
>>                         guess += slabstat.tcp_tws;
>> @@ -3196,6 +3202,9 @@ static int print_summary(void)
>>         if (get_snmp_int("Tcp:", "CurrEstab", &sn.tcp_estab) < 0)
>>                 perror("ss: get_snmpstat");
>>
>> +       if (!slabstat_valid)
>> +               get_slabstat(&slabstat);
>> +
>
>
>    Can't you perform this check inside get_slabstat()?
>

OK, I can submit it in another mail, coming soon.

> [...]
>
> WBR, Sergei
>



-- 
Best Regards

Bryton.Lee

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2015-02-12  1:21 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-02-10  5:52 [PATCH] prevent the read ahead of /proc/slabinfo in ss - take 3 Bryton Lee
2015-02-10 12:51 ` Sergei Shtylyov
2015-02-12  1:21   ` Bryton Lee

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).