All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH 2/2] ss: implement -M option to get all memory information
@ 2012-04-25  7:15 Shan Wei
  2012-04-25 17:41 ` Stephen Hemminger
  0 siblings, 1 reply; 9+ messages in thread
From: Shan Wei @ 2012-04-25  7:15 UTC (permalink / raw)
  To: Stephen Hemminger, xemul, NetDev

From: Shan Wei <davidshan@tencent.com>

INET_DIAG_SKMEMINFO is used to monitor socket memory information
which contains more information than INET_DIAG_MEMINFO.

-m option is retained for old kernel that don't surpport INET_DIAG_SKMEMINFO.


Signed-off-by: Shan Wei <davidshan@tencent.com>
---
 misc/ss.c |   27 +++++++++++++++++++++++++--
 1 files changed, 25 insertions(+), 2 deletions(-)

diff --git a/misc/ss.c b/misc/ss.c
index 5f70a26..3c8befd 100644
--- a/misc/ss.c
+++ b/misc/ss.c
@@ -45,6 +45,7 @@ int show_options = 0;
 int show_details = 0;
 int show_users = 0;
 int show_mem = 0;
+int show_skmem = 0;
 int show_tcpinfo = 0;
 
 int netid_width;
@@ -1410,6 +1411,19 @@ static void tcp_show_info(const struct nlmsghdr *nlh, struct inet_diag_msg *r)
 			printf(" rcv_space:%d", info->tcpi_rcv_space);
 
 	}
+
+	if (tb[INET_DIAG_SKMEMINFO]) {
+		const unsigned int *skmeminfo =  RTA_DATA(tb[INET_DIAG_SKMEMINFO]);
+		printf(" skmem:(r%u,rb%u,t%u,tb%u,f%u,w%u,o%u)",
+			skmeminfo[SK_MEMINFO_RMEM_ALLOC],
+			skmeminfo[SK_MEMINFO_RCVBUF],
+			skmeminfo[SK_MEMINFO_WMEM_ALLOC],
+			skmeminfo[SK_MEMINFO_SNDBUF],
+			skmeminfo[SK_MEMINFO_FWD_ALLOC],
+			skmeminfo[SK_MEMINFO_WMEM_QUEUED],
+			skmeminfo[SK_MEMINFO_OPTMEM]);
+	}
+
 }
 
 static int tcp_show_sock(struct nlmsghdr *nlh, struct filter *f)
@@ -1466,7 +1480,7 @@ static int tcp_show_sock(struct nlmsghdr *nlh, struct filter *f)
 			printf("%08x", r->id.idiag_cookie[1]);
  		printf("%08x", r->id.idiag_cookie[0]);
 	}
-	if (show_mem || show_tcpinfo) {
+	if (show_mem || show_tcpinfo || show_skmem) {
 		printf("\n\t");
 		tcp_show_info(nlh, r);
 	}
@@ -1508,6 +1522,9 @@ static int tcp_show_netlink(struct filter *f, FILE *dump_fp, int socktype)
 	if (show_mem)
 		req.r.idiag_ext |= (1<<(INET_DIAG_MEMINFO-1));
 
+	if (show_skmem)
+		req.r.idiag_ext |= (1<<(INET_DIAG_SKMEMINFO-1));
+
 	if (show_tcpinfo) {
 		req.r.idiag_ext |= (1<<(INET_DIAG_INFO-1));
 		req.r.idiag_ext |= (1<<(INET_DIAG_VEGASINFO-1));
@@ -2581,6 +2598,8 @@ static void _usage(FILE *dest)
 "   -o, --options       show timer information\n"
 "   -e, --extended      show detailed socket information\n"
 "   -m, --memory        show socket memory usage\n"
+"   -M, --skmem         show socket memory information.\n"
+"                       this option which will replace -m, is valid since Linux 3.3.\n"
 "   -p, --processes	show process using socket\n"
 "   -i, --info		show internal TCP information\n"
 "   -s, --summary	show socket usage summary\n"
@@ -2652,6 +2671,7 @@ static const struct option long_opts[] = {
 	{ "options", 0, 0, 'o' },
 	{ "extended", 0, 0, 'e' },
 	{ "memory", 0, 0, 'm' },
+	{ "skmem", 0, 0, 'M'}
 	{ "info", 0, 0, 'i' },
 	{ "processes", 0, 0, 'p' },
 	{ "dccp", 0, 0, 'd' },
@@ -2690,7 +2710,7 @@ int main(int argc, char *argv[])
 
 	current_filter.states = default_filter.states;
 
-	while ((ch = getopt_long(argc, argv, "dhaletuwxnro460spf:miA:D:F:vV",
+	while ((ch = getopt_long(argc, argv, "dhaletuwxnro460spf:mMiA:D:F:vV",
 				 long_opts, NULL)) != EOF) {
 		switch(ch) {
 		case 'n':
@@ -2709,6 +2729,9 @@ int main(int argc, char *argv[])
 		case 'm':
 			show_mem = 1;
 			break;
+		case 'M':
+			show_skmem = 1;
+			break;
 		case 'i':
 			show_tcpinfo = 1;
 			break;
-- 
1.7.1

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

* Re: [PATCH 2/2] ss: implement -M option to get all memory information
  2012-04-25  7:15 [PATCH 2/2] ss: implement -M option to get all memory information Shan Wei
@ 2012-04-25 17:41 ` Stephen Hemminger
  2012-04-27  2:04   ` Shan Wei
  0 siblings, 1 reply; 9+ messages in thread
From: Stephen Hemminger @ 2012-04-25 17:41 UTC (permalink / raw)
  To: Shan Wei; +Cc: xemul, NetDev

On Wed, 25 Apr 2012 15:15:27 +0800
Shan Wei <shanwei88@gmail.com> wrote:

> From: Shan Wei <davidshan@tencent.com>
> 
> INET_DIAG_SKMEMINFO is used to monitor socket memory information
> which contains more information than INET_DIAG_MEMINFO.
> 
> -m option is retained for old kernel that don't surpport INET_DIAG_SKMEMINFO.
> 
> 
> Signed-off-by: Shan Wei <davidshan@tencent.com>
> ---
>  misc/ss.c |   27 +++++++++++++++++++++++++--
>  1 files changed, 25 insertions(+), 2 deletions(-)
> 
> diff --git a/misc/ss.c b/misc/ss.c
> index 5f70a26..3c8befd 100644
> --- a/misc/ss.c
> +++ b/misc/ss.c
> @@ -45,6 +45,7 @@ int show_options = 0;
>  int show_details = 0;
>  int show_users = 0;
>  int show_mem = 0;
> +int show_skmem = 0;
>  int show_tcpinfo = 0;
>  
>  int netid_width;
> @@ -1410,6 +1411,19 @@ static void tcp_show_info(const struct nlmsghdr *nlh, struct inet_diag_msg *r)
>  			printf(" rcv_space:%d", info->tcpi_rcv_space);
>  
>  	}
> +
> +	if (tb[INET_DIAG_SKMEMINFO]) {
> +		const unsigned int *skmeminfo =  RTA_DATA(tb[INET_DIAG_SKMEMINFO]);
> +		printf(" skmem:(r%u,rb%u,t%u,tb%u,f%u,w%u,o%u)",
> +			skmeminfo[SK_MEMINFO_RMEM_ALLOC],
> +			skmeminfo[SK_MEMINFO_RCVBUF],
> +			skmeminfo[SK_MEMINFO_WMEM_ALLOC],
> +			skmeminfo[SK_MEMINFO_SNDBUF],
> +			skmeminfo[SK_MEMINFO_FWD_ALLOC],
> +			skmeminfo[SK_MEMINFO_WMEM_QUEUED],
> +			skmeminfo[SK_MEMINFO_OPTMEM]);
> +	}
> +
>  }
>  
>  static int tcp_show_sock(struct nlmsghdr *nlh, struct filter *f)
> @@ -1466,7 +1480,7 @@ static int tcp_show_sock(struct nlmsghdr *nlh, struct filter *f)
>  			printf("%08x", r->id.idiag_cookie[1]);
>   		printf("%08x", r->id.idiag_cookie[0]);
>  	}
> -	if (show_mem || show_tcpinfo) {
> +	if (show_mem || show_tcpinfo || show_skmem) {
>  		printf("\n\t");
>  		tcp_show_info(nlh, r);
>  	}
> @@ -1508,6 +1522,9 @@ static int tcp_show_netlink(struct filter *f, FILE *dump_fp, int socktype)
>  	if (show_mem)
>  		req.r.idiag_ext |= (1<<(INET_DIAG_MEMINFO-1));
>  
> +	if (show_skmem)
> +		req.r.idiag_ext |= (1<<(INET_DIAG_SKMEMINFO-1));
> +
>  	if (show_tcpinfo) {
>  		req.r.idiag_ext |= (1<<(INET_DIAG_INFO-1));
>  		req.r.idiag_ext |= (1<<(INET_DIAG_VEGASINFO-1));
> @@ -2581,6 +2598,8 @@ static void _usage(FILE *dest)
>  "   -o, --options       show timer information\n"
>  "   -e, --extended      show detailed socket information\n"
>  "   -m, --memory        show socket memory usage\n"
> +"   -M, --skmem         show socket memory information.\n"
> +"                       this option which will replace -m, is valid since Linux 3.3.\n"

Please don't add reference to kernel version.
Why does this need to be a new option? Maybe just do the right thing
if present in the netlink response?

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

* Re: [PATCH 2/2] ss: implement -M option to get all memory information
  2012-04-25 17:41 ` Stephen Hemminger
@ 2012-04-27  2:04   ` Shan Wei
  2012-04-27 17:21     ` Stephen Hemminger
  0 siblings, 1 reply; 9+ messages in thread
From: Shan Wei @ 2012-04-27  2:04 UTC (permalink / raw)
  To: Stephen Hemminger; +Cc: xemul, NetDev

Stephen Hemminger said, at 2012/4/26 1:41:

>>  "   -m, --memory        show socket memory usage\n"
>> +"   -M, --skmem         show socket memory information.\n"
>> +"                       this option which will replace -m, is valid since Linux 3.3.\n"
> 
> Please don't add reference to kernel version.
> Why does this need to be a new option? Maybe just do the right thing
> if present in the netlink response?


Actually, I'm ok for your suggestion that using a existing option(-m) to
export all memory information. But with a new option is better for us.

Maybe some people use latest iproute source with under kernel 3.3.0, some don't.
-m option will take different user experience, specially for UDP socket.
Currently -m option has no effect on UDP socket which i will submit another patch
to export memory information for. new option, fresh experience.

(Exporting out memory information will help us to analysis dropped packets 
which recorded in RcvbufErrors and SndbufErrors.)
 

 

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

* Re: [PATCH 2/2] ss: implement -M option to get all memory information
  2012-04-27  2:04   ` Shan Wei
@ 2012-04-27 17:21     ` Stephen Hemminger
  2012-05-02  9:45       ` Shan Wei
  0 siblings, 1 reply; 9+ messages in thread
From: Stephen Hemminger @ 2012-04-27 17:21 UTC (permalink / raw)
  To: Shan Wei; +Cc: xemul, NetDev

On Fri, 27 Apr 2012 10:04:17 +0800
Shan Wei <shanwei88@gmail.com> wrote:

> Stephen Hemminger said, at 2012/4/26 1:41:
> 
> >>  "   -m, --memory        show socket memory usage\n"
> >> +"   -M, --skmem         show socket memory information.\n"
> >> +"                       this option which will replace -m, is valid since Linux 3.3.\n"
> > 
> > Please don't add reference to kernel version.
> > Why does this need to be a new option? Maybe just do the right thing
> > if present in the netlink response?
> 
> 
> Actually, I'm ok for your suggestion that using a existing option(-m) to
> export all memory information. But with a new option is better for us.

Why? if you are arguing to replace the option anyway.

> Maybe some people use latest iproute source with under kernel 3.3.0, some don't.
> -m option will take different user experience, specially for UDP socket.
> Currently -m option has no effect on UDP socket which i will submit another patch
> to export memory information for. new option, fresh experience.

Lots of options return more or different information based on kernel
version, probably the biggest example is how stats are processed.

> (Exporting out memory information will help us to analysis dropped packets 
> which recorded in RcvbufErrors and SndbufErrors.)
>  
> 
>  
> 

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

* Re: [PATCH 2/2] ss: implement -M option to get all memory information
  2012-04-27 17:21     ` Stephen Hemminger
@ 2012-05-02  9:45       ` Shan Wei
  2012-05-02 19:00         ` Stephen Hemminger
  0 siblings, 1 reply; 9+ messages in thread
From: Shan Wei @ 2012-05-02  9:45 UTC (permalink / raw)
  To: Stephen Hemminger; +Cc: xemul, NetDev

Hi stephen:

Stephen Hemminger said, at 2012/4/28 1:21:

> Lots of options return more or different information based on kernel
> version, probably the biggest example is how stats are processed.


how about the following patch?

----
[PATCH] ss: use new INET_DIAG_SKMEMINFO option to get memory information for tcp socket


Signed-off-by: Shan Wei <davidshan@tencent.com>
---
 misc/ss.c |   16 ++++++++++++++--
 1 files changed, 14 insertions(+), 2 deletions(-)

diff --git a/misc/ss.c b/misc/ss.c
index 5f70a26..3cfc9e8 100644
--- a/misc/ss.c
+++ b/misc/ss.c
@@ -1336,7 +1336,17 @@ static void tcp_show_info(const struct nlmsghdr *nlh, struct inet_diag_msg *r)
 	parse_rtattr(tb, INET_DIAG_MAX, (struct rtattr*)(r+1),
 		     nlh->nlmsg_len - NLMSG_LENGTH(sizeof(*r)));
 
-	if (tb[INET_DIAG_MEMINFO]) {
+	if (tb[INET_DIAG_SKMEMINFO]) {
+		const unsigned int *skmeminfo =  RTA_DATA(tb[INET_DIAG_SKMEMINFO]);
+		printf(" skmem:(r%u,rb%u,t%u,tb%u,f%u,w%u,o%u)",
+			skmeminfo[SK_MEMINFO_RMEM_ALLOC],
+			skmeminfo[SK_MEMINFO_RCVBUF],
+			skmeminfo[SK_MEMINFO_WMEM_ALLOC],
+			skmeminfo[SK_MEMINFO_SNDBUF],
+			skmeminfo[SK_MEMINFO_FWD_ALLOC],
+			skmeminfo[SK_MEMINFO_WMEM_QUEUED],
+			skmeminfo[SK_MEMINFO_OPTMEM]);
+	}else if (tb[INET_DIAG_MEMINFO]) {
 		const struct inet_diag_meminfo *minfo
 			= RTA_DATA(tb[INET_DIAG_MEMINFO]);
 		printf(" mem:(r%u,w%u,f%u,t%u)",
@@ -1505,8 +1515,10 @@ static int tcp_show_netlink(struct filter *f, FILE *dump_fp, int socktype)
 	memset(&req.r, 0, sizeof(req.r));
 	req.r.idiag_family = AF_INET;
 	req.r.idiag_states = f->states;
-	if (show_mem)
+	if (show_mem) {
 		req.r.idiag_ext |= (1<<(INET_DIAG_MEMINFO-1));
+		req.r.idiag_ext |= (1<<(INET_DIAG_SKMEMINFO-1));
+	}
 
 	if (show_tcpinfo) {
 		req.r.idiag_ext |= (1<<(INET_DIAG_INFO-1));
-- 
1.7.1


 

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

* Re: [PATCH 2/2] ss: implement -M option to get all memory information
  2012-05-02  9:45       ` Shan Wei
@ 2012-05-02 19:00         ` Stephen Hemminger
  2012-05-03  8:37           ` Pavel Emelyanov
  2012-05-03  8:39           ` Shan Wei
  0 siblings, 2 replies; 9+ messages in thread
From: Stephen Hemminger @ 2012-05-02 19:00 UTC (permalink / raw)
  To: Shan Wei; +Cc: xemul, NetDev

On Wed, 02 May 2012 17:45:02 +0800
Shan Wei <shanwei88@gmail.com> wrote:

> Hi stephen:
> 
> Stephen Hemminger said, at 2012/4/28 1:21:
> 
> > Lots of options return more or different information based on kernel
> > version, probably the biggest example is how stats are processed.
> 
> 
> how about the following patch?
> 
> ----
> [PATCH] ss: use new INET_DIAG_SKMEMINFO option to get memory information for tcp socket
> 
> 
> Signed-off-by: Shan Wei <davidshan@tencent.com>
> ---
>  misc/ss.c |   16 ++++++++++++++--
>  1 files changed, 14 insertions(+), 2 deletions(-)
> 
> diff --git a/misc/ss.c b/misc/ss.c
> index 5f70a26..3cfc9e8 100644
> --- a/misc/ss.c
> +++ b/misc/ss.c
> @@ -1336,7 +1336,17 @@ static void tcp_show_info(const struct nlmsghdr *nlh, struct inet_diag_msg *r)
>  	parse_rtattr(tb, INET_DIAG_MAX, (struct rtattr*)(r+1),
>  		     nlh->nlmsg_len - NLMSG_LENGTH(sizeof(*r)));
>  
> -	if (tb[INET_DIAG_MEMINFO]) {
> +	if (tb[INET_DIAG_SKMEMINFO]) {
> +		const unsigned int *skmeminfo =  RTA_DATA(tb[INET_DIAG_SKMEMINFO]);
> +		printf(" skmem:(r%u,rb%u,t%u,tb%u,f%u,w%u,o%u)",
> +			skmeminfo[SK_MEMINFO_RMEM_ALLOC],
> +			skmeminfo[SK_MEMINFO_RCVBUF],
> +			skmeminfo[SK_MEMINFO_WMEM_ALLOC],
> +			skmeminfo[SK_MEMINFO_SNDBUF],
> +			skmeminfo[SK_MEMINFO_FWD_ALLOC],
> +			skmeminfo[SK_MEMINFO_WMEM_QUEUED],
> +			skmeminfo[SK_MEMINFO_OPTMEM]);
> +	}else if (tb[INET_DIAG_MEMINFO]) {
>  		const struct inet_diag_meminfo *minfo
>  			= RTA_DATA(tb[INET_DIAG_MEMINFO]);
>  		printf(" mem:(r%u,w%u,f%u,t%u)",
> @@ -1505,8 +1515,10 @@ static int tcp_show_netlink(struct filter *f, FILE *dump_fp, int socktype)
>  	memset(&req.r, 0, sizeof(req.r));
>  	req.r.idiag_family = AF_INET;
>  	req.r.idiag_states = f->states;
> -	if (show_mem)
> +	if (show_mem) {
>  		req.r.idiag_ext |= (1<<(INET_DIAG_MEMINFO-1));
> +		req.r.idiag_ext |= (1<<(INET_DIAG_SKMEMINFO-1));
> +	}
>  
>  	if (show_tcpinfo) {
>  		req.r.idiag_ext |= (1<<(INET_DIAG_INFO-1));

This looks good, is the skmeminfo a superset of the old meminfo?
But your code is broken on 64 bit. skmeminfo in kernel is an array of __u32!

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

* Re: [PATCH 2/2] ss: implement -M option to get all memory information
  2012-05-02 19:00         ` Stephen Hemminger
@ 2012-05-03  8:37           ` Pavel Emelyanov
  2012-05-03  8:39           ` Shan Wei
  1 sibling, 0 replies; 9+ messages in thread
From: Pavel Emelyanov @ 2012-05-03  8:37 UTC (permalink / raw)
  To: Stephen Hemminger; +Cc: Shan Wei, NetDev

On 05/02/2012 11:00 PM, Stephen Hemminger wrote:
> On Wed, 02 May 2012 17:45:02 +0800
> Shan Wei <shanwei88@gmail.com> wrote:
> 
>> Hi stephen:
>>
>> Stephen Hemminger said, at 2012/4/28 1:21:
>>
>>> Lots of options return more or different information based on kernel
>>> version, probably the biggest example is how stats are processed.
>>
>>
>> how about the following patch?
>>
>> ----
>> [PATCH] ss: use new INET_DIAG_SKMEMINFO option to get memory information for tcp socket
>>
>>
>> Signed-off-by: Shan Wei <davidshan@tencent.com>
>> ---
>>  misc/ss.c |   16 ++++++++++++++--
>>  1 files changed, 14 insertions(+), 2 deletions(-)
>>
>> diff --git a/misc/ss.c b/misc/ss.c
>> index 5f70a26..3cfc9e8 100644
>> --- a/misc/ss.c
>> +++ b/misc/ss.c
>> @@ -1336,7 +1336,17 @@ static void tcp_show_info(const struct nlmsghdr *nlh, struct inet_diag_msg *r)
>>  	parse_rtattr(tb, INET_DIAG_MAX, (struct rtattr*)(r+1),
>>  		     nlh->nlmsg_len - NLMSG_LENGTH(sizeof(*r)));
>>  
>> -	if (tb[INET_DIAG_MEMINFO]) {
>> +	if (tb[INET_DIAG_SKMEMINFO]) {
>> +		const unsigned int *skmeminfo =  RTA_DATA(tb[INET_DIAG_SKMEMINFO]);
>> +		printf(" skmem:(r%u,rb%u,t%u,tb%u,f%u,w%u,o%u)",
>> +			skmeminfo[SK_MEMINFO_RMEM_ALLOC],
>> +			skmeminfo[SK_MEMINFO_RCVBUF],
>> +			skmeminfo[SK_MEMINFO_WMEM_ALLOC],
>> +			skmeminfo[SK_MEMINFO_SNDBUF],
>> +			skmeminfo[SK_MEMINFO_FWD_ALLOC],
>> +			skmeminfo[SK_MEMINFO_WMEM_QUEUED],
>> +			skmeminfo[SK_MEMINFO_OPTMEM]);
>> +	}else if (tb[INET_DIAG_MEMINFO]) {
>>  		const struct inet_diag_meminfo *minfo
>>  			= RTA_DATA(tb[INET_DIAG_MEMINFO]);
>>  		printf(" mem:(r%u,w%u,f%u,t%u)",
>> @@ -1505,8 +1515,10 @@ static int tcp_show_netlink(struct filter *f, FILE *dump_fp, int socktype)
>>  	memset(&req.r, 0, sizeof(req.r));
>>  	req.r.idiag_family = AF_INET;
>>  	req.r.idiag_states = f->states;
>> -	if (show_mem)
>> +	if (show_mem) {
>>  		req.r.idiag_ext |= (1<<(INET_DIAG_MEMINFO-1));
>> +		req.r.idiag_ext |= (1<<(INET_DIAG_SKMEMINFO-1));
>> +	}
>>  
>>  	if (show_tcpinfo) {
>>  		req.r.idiag_ext |= (1<<(INET_DIAG_INFO-1));
> 
> This looks good, is the skmeminfo a superset of the old meminfo?

In terms of the values it returns -- yes, but these two structures are not
binary compatible to each other.

> But your code is broken on 64 bit. skmeminfo in kernel is an array of __u32!

Hmm :( So is the inet_diag_meminfo, which was the prototype for the skmeminfo...
Should we introduce the SKMEMINFO64?

> .
> 

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

* Re: [PATCH 2/2] ss: implement -M option to get all memory information
  2012-05-02 19:00         ` Stephen Hemminger
  2012-05-03  8:37           ` Pavel Emelyanov
@ 2012-05-03  8:39           ` Shan Wei
  2012-05-03 15:25             ` Stephen Hemminger
  1 sibling, 1 reply; 9+ messages in thread
From: Shan Wei @ 2012-05-03  8:39 UTC (permalink / raw)
  To: Stephen Hemminger; +Cc: xemul, NetDev

Stephen Hemminger said, at 2012/5/3 3:00:

> 
> This looks good, is the skmeminfo a superset of the old meminfo?


Yes, skmeminfo is a superset of old meminfo.
Using this can get more socket memory information. 

> But your code is broken on 64 bit. skmeminfo in kernel is an array of __u32!


OK. here is a new version.

----
[PATCH] ss: use new INET_DIAG_SKMEMINFO option to get more memory information for tcp socket


Signed-off-by: Shan Wei <davidshan@tencent.com>
---
 misc/ss.c |   16 ++++++++++++++--
 1 files changed, 14 insertions(+), 2 deletions(-)

diff --git a/misc/ss.c b/misc/ss.c
index 5f70a26..bd60548 100644
--- a/misc/ss.c
+++ b/misc/ss.c
@@ -1336,7 +1336,17 @@ static void tcp_show_info(const struct nlmsghdr *nlh, struct inet_diag_msg *r)
 	parse_rtattr(tb, INET_DIAG_MAX, (struct rtattr*)(r+1),
 		     nlh->nlmsg_len - NLMSG_LENGTH(sizeof(*r)));
 
-	if (tb[INET_DIAG_MEMINFO]) {
+	if (tb[INET_DIAG_SKMEMINFO]) {
+		const __u32 *skmeminfo =  RTA_DATA(tb[INET_DIAG_SKMEMINFO]);
+		printf(" skmem:(r%u,rb%u,t%u,tb%u,f%u,w%u,o%u)",
+			skmeminfo[SK_MEMINFO_RMEM_ALLOC],
+			skmeminfo[SK_MEMINFO_RCVBUF],
+			skmeminfo[SK_MEMINFO_WMEM_ALLOC],
+			skmeminfo[SK_MEMINFO_SNDBUF],
+			skmeminfo[SK_MEMINFO_FWD_ALLOC],
+			skmeminfo[SK_MEMINFO_WMEM_QUEUED],
+			skmeminfo[SK_MEMINFO_OPTMEM]);
+	}else if (tb[INET_DIAG_MEMINFO]) {
 		const struct inet_diag_meminfo *minfo
 			= RTA_DATA(tb[INET_DIAG_MEMINFO]);
 		printf(" mem:(r%u,w%u,f%u,t%u)",
@@ -1505,8 +1515,10 @@ static int tcp_show_netlink(struct filter *f, FILE *dump_fp, int socktype)
 	memset(&req.r, 0, sizeof(req.r));
 	req.r.idiag_family = AF_INET;
 	req.r.idiag_states = f->states;
-	if (show_mem)
+	if (show_mem) {
 		req.r.idiag_ext |= (1<<(INET_DIAG_MEMINFO-1));
+		req.r.idiag_ext |= (1<<(INET_DIAG_SKMEMINFO-1));
+	}
 
 	if (show_tcpinfo) {
 		req.r.idiag_ext |= (1<<(INET_DIAG_INFO-1));
-- 
1.7.1

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

* Re: [PATCH 2/2] ss: implement -M option to get all memory information
  2012-05-03  8:39           ` Shan Wei
@ 2012-05-03 15:25             ` Stephen Hemminger
  0 siblings, 0 replies; 9+ messages in thread
From: Stephen Hemminger @ 2012-05-03 15:25 UTC (permalink / raw)
  To: Shan Wei; +Cc: xemul, NetDev

On Thu, 03 May 2012 16:39:52 +0800
Shan Wei <shanwei88@gmail.com> wrote:

> Stephen Hemminger said, at 2012/5/3 3:00:
> 
> > 
> > This looks good, is the skmeminfo a superset of the old meminfo?
> 
> 
> Yes, skmeminfo is a superset of old meminfo.
> Using this can get more socket memory information. 
> 
> > But your code is broken on 64 bit. skmeminfo in kernel is an array of __u32!
> 
> 
> OK. here is a new version.
> 
> ----
> [PATCH] ss: use new INET_DIAG_SKMEMINFO option to get more memory information for tcp socket
> 
> 
> Signed-off-by: Shan Wei <davidshan@tencent.com>
> ---
>  misc/ss.c |   16 ++++++++++++++--
>  1 files changed, 14 insertions(+), 2 deletions(-)
> 
> diff --git a/misc/ss.c b/misc/ss.c
> index 5f70a26..bd60548 100644
> --- a/misc/ss.c
> +++ b/misc/ss.c
> @@ -1336,7 +1336,17 @@ static void tcp_show_info(const struct nlmsghdr *nlh, struct inet_diag_msg *r)
>  	parse_rtattr(tb, INET_DIAG_MAX, (struct rtattr*)(r+1),
>  		     nlh->nlmsg_len - NLMSG_LENGTH(sizeof(*r)));
>  
> -	if (tb[INET_DIAG_MEMINFO]) {
> +	if (tb[INET_DIAG_SKMEMINFO]) {
> +		const __u32 *skmeminfo =  RTA_DATA(tb[INET_DIAG_SKMEMINFO]);
> +		printf(" skmem:(r%u,rb%u,t%u,tb%u,f%u,w%u,o%u)",
> +			skmeminfo[SK_MEMINFO_RMEM_ALLOC],
> +			skmeminfo[SK_MEMINFO_RCVBUF],
> +			skmeminfo[SK_MEMINFO_WMEM_ALLOC],
> +			skmeminfo[SK_MEMINFO_SNDBUF],
> +			skmeminfo[SK_MEMINFO_FWD_ALLOC],
> +			skmeminfo[SK_MEMINFO_WMEM_QUEUED],
> +			skmeminfo[SK_MEMINFO_OPTMEM]);
> +	}else if (tb[INET_DIAG_MEMINFO]) {
>  		const struct inet_diag_meminfo *minfo
>  			= RTA_DATA(tb[INET_DIAG_MEMINFO]);
>  		printf(" mem:(r%u,w%u,f%u,t%u)",
> @@ -1505,8 +1515,10 @@ static int tcp_show_netlink(struct filter *f, FILE *dump_fp, int socktype)
>  	memset(&req.r, 0, sizeof(req.r));
>  	req.r.idiag_family = AF_INET;
>  	req.r.idiag_states = f->states;
> -	if (show_mem)
> +	if (show_mem) {
>  		req.r.idiag_ext |= (1<<(INET_DIAG_MEMINFO-1));
> +		req.r.idiag_ext |= (1<<(INET_DIAG_SKMEMINFO-1));
> +	}
>  
>  	if (show_tcpinfo) {
>  		req.r.idiag_ext |= (1<<(INET_DIAG_INFO-1));

This looks good, I will apply it

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

end of thread, other threads:[~2012-05-03 15:25 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2012-04-25  7:15 [PATCH 2/2] ss: implement -M option to get all memory information Shan Wei
2012-04-25 17:41 ` Stephen Hemminger
2012-04-27  2:04   ` Shan Wei
2012-04-27 17:21     ` Stephen Hemminger
2012-05-02  9:45       ` Shan Wei
2012-05-02 19:00         ` Stephen Hemminger
2012-05-03  8:37           ` Pavel Emelyanov
2012-05-03  8:39           ` Shan Wei
2012-05-03 15:25             ` Stephen Hemminger

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.