Skip to contentSkip to conversation

prevent the read ahead of /proc/slabinfo in ss - take 3

PATCH In review Bryton Lee 2 participants 3 messages Feb 10, 2015 – Feb 12, 2015

Subsystems (2)
lore
Share & tools
lore

Bryton Lee

author
#0 lore raw

PATCH 1/1 prevent the read ahead of /proc/slabinfo in ss - take 3

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

---
 misc/ss.c | 13 ++++++++++---
 1 file changed, 10 insertions(+), 3 deletions(-)
misc/ss.c +10 -3
index 7fc0a99..74721b5 100644
@@ -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)
Signature · 1 line
2.0.5
#1 lore raw
Quoted 11 lines · Bryton Lee

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

---
  misc/ss.c | 13 ++++++++++---
  1 file changed, 10 insertions(+), 3 deletions(-)
misc/ss.c +0 -0
index 7fc0a99..74721b5 100644

[...]

misc/ss.c static int get_slabstat(struct slabstat *s) · line 659

Quoted 5 lines
misc/ss.c +1 -0
@@ -655,6 +656,8 @@ static int get_slabstat(struct slabstat *s)
  			break;
  	}
 
+    slabstat_valid = 1;

This is indented incorrectly. Use one TAB please.

Quoted 15 lines
misc/ss.c +4 -0
+
  	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;

misc/ss.c static int print_summary(void) · line 3207

Quoted 6 lines
misc/ss.c +3 -0
@@ -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

author
#2 lore raw
Quoted 45 lines · Sergei Shtylyov
Quoted 13 lines · Bryton Lee

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

---
  misc/ss.c | 13 ++++++++++---
  1 file changed, 10 insertions(+), 3 deletions(-)
misc/ss.c +0 -0
index 7fc0a99..74721b5 100644

[...]

misc/ss.c static int get_slabstat(struct slabstat *s) · line 659

Quoted 6 lines
misc/ss.c +1 -0
@@ -655,6 +656,8 @@ static int get_slabstat(struct slabstat *s)
                        break;
        }
 
+    slabstat_valid = 1;

This is indented incorrectly. Use one TAB please.

Quoted 18 lines
misc/ss.c +4 -0
+
        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");
 
Quoted 7 lines

misc/ss.c static int tcp_show(struct filter *f, int socktype) · line 2238

Quoted 3 lines
misc/ss.c +3 -0
+       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.

Quoted 4 lines

[...]

WBR, Sergei

Signature · 3 lines
Best Regards

Bryton.Lee