app/testpmd: add memory dump command
PATCH 1/1 app/testpmd: add memory dump command
Introduce new command to dump memory statistics of each socket, summary, also show changes since last call.
Usage:
dump_socket
--- app/test-pmd/cmdline.c | 52 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 52 insertions(+)
app/test-pmd/cmdline.c +52 -0
@@ -9566,6 +9566,55 @@ struct cmd_dump_result {#undef DUMP_SIZE } + +/* Dump the socket memory statistics on console */ +static void +dump_socket_mem (FILE *f) +{ +struct rte_malloc_socket_stats socket_stats; +unsigned int i; +int64_t total =0 ; +int64_t alloc =0 ; +int64_t free =0 ; +unsigned int n_alloc =0 ; +unsigned int n_free =0 ; +static int64_t last_allocs; +static int64_t last_total; + + +for (i =0 ; i <RTE_MAX_NUMA_NODES ; i++) { +if (rte_malloc_get_socket_stats (i, &socket_stats) || + !socket_stats.heap_totalsz_bytes) +continue ; + total += socket_stats.heap_totalsz_bytes; + alloc += socket_stats.heap_allocsz_bytes; + free += socket_stats.heap_freesz_bytes; + n_alloc += socket_stats.alloc_count; + n_free += socket_stats.free_count; +fprintf (f, +"Socket %u: size(M) total: %.6lf alloc: %.6lf(%.3lf%%) free: %.6lf \tcount alloc: %-4u free: %u\n" , + i, + socket_stats.heap_totalsz_bytes /1.0e6 , + socket_stats.heap_allocsz_bytes /1.0e6 , + (double )socket_stats.heap_allocsz_bytes *100 / + (double )socket_stats.heap_totalsz_bytes, + socket_stats.heap_freesz_bytes /1.0e6 , + socket_stats.alloc_count, + socket_stats.free_count); + } +fprintf (f, +"Total : size(M) total: %.6lf alloc: %.6lf(%.3lf%%) free: %.6lf \tcount alloc: %-4u free: %u\n" , + total /1.0e6 , alloc /1.0e6 , + (double )alloc *100 / (double )total, free /1.0e6 , + n_alloc, n_free); +if (last_allocs) +fprintf (stdout,"Memory total change: %.6lf(M), allocation change: %.6lf(M)\n" , + (total - last_total) /1.0e6 , + (alloc - last_allocs) /1.0e6 ); + last_allocs = alloc; + last_total = total; +} +static void cmd_dump_parsed (void *parsed_result, __attribute__((unused))struct cmdline *cl, __attribute__((unused))void *data)
@@ -9574,6 +9623,8 @@ static void cmd_dump_parsed(void *parsed_result,if (!strcmp (res->dump,"dump_physmem" ))rte_dump_physmem_layout (stdout); +else if (!strcmp (res->dump,"dump_socket" )) +dump_socket_mem (stdout);else if (!strcmp (res->dump,"dump_memzone" ))rte_memzone_dump (stdout);else if (!strcmp (res->dump,"dump_struct_sizes" ))
@@ -9592,6 +9643,7 @@ static void cmd_dump_parsed(void *parsed_result, TOKEN_STRING_INITIALIZER(struct cmd_dump_result, dump,"dump_physmem#" "dump_memzone#" +"dump_socket#" "dump_struct_sizes#" "dump_ring#" "dump_mempool#"
Signature · 1 line
1.8.3.1
Quoted 5 lines · Xueming Li
Introduce new command to dump memory statistics of each socket, summary, also show changes since last call.
Usage:
dump_socket
Can you please update documentation for this new command?
Quoted 2 lines
Signed-off-by Xueming Li <[email protected]>
<...>
PATCH 1/1 app/testpmd: add memory dump command
In reply to Xueming Liv0: initial version
v1: update user guide
Xueming Li (1):
app/testpmd: add memory dump command
app/test-pmd/cmdline.c | 52 +++++++++++++++++++++++++++++ doc/guides/testpmd_app_ug/testpmd_funcs.rst | 6 ++++ 2 files changed, 58 insertions(+)
Signature · 1 line
1.8.3.1
PATCH 1/1 app/testpmd: add memory dump command
Introduce new command to dump memory statistics of each socket, summary, also show changes since last call.
Usage:
dump_socket
--- app/test-pmd/cmdline.c | 52 +++++++++++++++++++++++++++++ doc/guides/testpmd_app_ug/testpmd_funcs.rst | 6 ++++ 2 files changed, 58 insertions(+)
app/test-pmd/cmdline.c +52 -0
@@ -9568,6 +9568,55 @@ struct cmd_dump_result {#undef DUMP_SIZE } + +/* Dump the socket memory statistics on console */ +static void +dump_socket_mem (FILE *f) +{ +struct rte_malloc_socket_stats socket_stats; +unsigned int i; +int64_t total =0 ; +int64_t alloc =0 ; +int64_t free =0 ; +unsigned int n_alloc =0 ; +unsigned int n_free =0 ; +static int64_t last_allocs; +static int64_t last_total; + + +for (i =0 ; i <RTE_MAX_NUMA_NODES ; i++) { +if (rte_malloc_get_socket_stats (i, &socket_stats) || + !socket_stats.heap_totalsz_bytes) +continue ; + total += socket_stats.heap_totalsz_bytes; + alloc += socket_stats.heap_allocsz_bytes; + free += socket_stats.heap_freesz_bytes; + n_alloc += socket_stats.alloc_count; + n_free += socket_stats.free_count; +fprintf (f, +"Socket %u: size(M) total: %.6lf alloc: %.6lf(%.3lf%%) free: %.6lf \tcount alloc: %-4u free: %u\n" , + i, + socket_stats.heap_totalsz_bytes /1.0e6 , + socket_stats.heap_allocsz_bytes /1.0e6 , + (double )socket_stats.heap_allocsz_bytes *100 / + (double )socket_stats.heap_totalsz_bytes, + socket_stats.heap_freesz_bytes /1.0e6 , + socket_stats.alloc_count, + socket_stats.free_count); + } +fprintf (f, +"Total : size(M) total: %.6lf alloc: %.6lf(%.3lf%%) free: %.6lf \tcount alloc: %-4u free: %u\n" , + total /1.0e6 , alloc /1.0e6 , + (double )alloc *100 / (double )total, free /1.0e6 , + n_alloc, n_free); +if (last_allocs) +fprintf (stdout,"Memory total change: %.6lf(M), allocation change: %.6lf(M)\n" , + (total - last_total) /1.0e6 , + (alloc - last_allocs) /1.0e6 ); + last_allocs = alloc; + last_total = total; +} +static void cmd_dump_parsed (void *parsed_result, __attribute__((unused))struct cmdline *cl, __attribute__((unused))void *data)
@@ -9576,6 +9625,8 @@ static void cmd_dump_parsed(void *parsed_result,if (!strcmp (res->dump,"dump_physmem" ))rte_dump_physmem_layout (stdout); +else if (!strcmp (res->dump,"dump_socket" )) +dump_socket_mem (stdout);else if (!strcmp (res->dump,"dump_memzone" ))rte_memzone_dump (stdout);else if (!strcmp (res->dump,"dump_malloc" )) {
@@ -9604,6 +9655,7 @@ static void cmd_dump_parsed(void *parsed_result, TOKEN_STRING_INITIALIZER(struct cmd_dump_result, dump,"dump_physmem#" "dump_memzone#" +"dump_socket#" "dump_struct_sizes#" "dump_ring#" "dump_mempool#"
doc/guides/testpmd_app_ug/testpmd_funcs.rst +6 -0
@@ -539,6 +539,12 @@ Dumps the layout of all memory zones:: testpmd> dump_memzone +dump socket +~~~~~~~~~~~~ + +Dumps the memory usage of all sockets:: + + testpmd> dump_socket dump struct size ~~~~~~~~~~~~~~~~
Signature · 1 line
1.8.3.1
Quoted 45 lines · Xueming Li
Introduce new command to dump memory statistics of each socket, summary, also show changes since last call.
Usage:
dump_socketSigned-off-by Xueming Li <[email protected]>--- app/test-pmd/cmdline.c | 52 +++++++++++++++++++++++++++++ doc/guides/testpmd_app_ug/testpmd_funcs.rst | 6 ++++ 2 files changed, 58 insertions(+)app/test-pmd/cmdline.c +25
-0@@ -9568,6 +9568,55 @@ struct cmd_dump_result {#undef DUMP_SIZE } + +/* Dump the socket memory statistics on console */ +static void +dump_socket_mem (FILE *f) +{ +struct rte_malloc_socket_stats socket_stats; +unsigned int i; +int64_t total =0 ; +int64_t alloc =0 ; +int64_t free =0 ; +unsigned int n_alloc =0 ; +unsigned int n_free =0 ; +static int64_t last_allocs; +static int64_t last_total; + + +for (i =0 ; i <RTE_MAX_NUMA_NODES ; i++) { +if (rte_malloc_get_socket_stats (i, &socket_stats) || + !socket_stats.heap_totalsz_bytes) +continue ; + total += socket_stats.heap_totalsz_bytes; + alloc += socket_stats.heap_allocsz_bytes; + free += socket_stats.heap_freesz_bytes; + n_alloc += socket_stats.alloc_count; + n_free += socket_stats.free_count;
app/test-pmd/cmdline.c struct cmd_dump_result { · line 9605
Quoted 10 lines
app/test-pmd/cmdline.c +10
-0+fprintf (f, +"Socket %u: size(M) total: %.6lf alloc: %.6lf(%.3lf%%) free: %.6lf \tcount alloc: %-4u free: %u\n" , + i, + socket_stats.heap_totalsz_bytes /1.0e6 , + socket_stats.heap_allocsz_bytes /1.0e6 , + (double )socket_stats.heap_allocsz_bytes *100 / + (double )socket_stats.heap_totalsz_bytes, + socket_stats.heap_freesz_bytes /1.0e6 , + socket_stats.alloc_count, + socket_stats.free_count);
This gives an output like [1], can you please divide to (1024*1024) to convert byte to Mb, than it can give more clear numbers.
[1]
Socket 0: size(M) total: 2933.915648 alloc: 1871.655424(63.794%) free:
1062.260224 count alloc: 2137 free: 36
Socket 1: size(M) total: 2923.429888 alloc: 1863.400064(63.740%) free:
1060.029824 count alloc: 177 free: 1
Total : size(M) total: 5857.345536 alloc: 3735.055488(63.767%) free:
2122.290048 count alloc: 2314 free: 37
Memory total change: 0.000000(M), allocation change: 0.000000(M)
Quoted 39 lines
app/test-pmd/cmdline.c +17
-0+ } +fprintf (f, +"Total : size(M) total: %.6lf alloc: %.6lf(%.3lf%%) free: %.6lf \tcount alloc: %-4u free: %u\n" , + total /1.0e6 , alloc /1.0e6 , + (double )alloc *100 / (double )total, free /1.0e6 , + n_alloc, n_free); +if (last_allocs) +fprintf (stdout,"Memory total change: %.6lf(M), allocation change: %.6lf(M)\n" , + (total - last_total) /1.0e6 , + (alloc - last_allocs) /1.0e6 ); + last_allocs = alloc; + last_total = total; +} +static void cmd_dump_parsed (void *parsed_result, __attribute__((unused))struct cmdline *cl, __attribute__((unused))void *data)@@ -9576,6 +9625,8 @@ static void cmd_dump_parsed(void *parsed_result,if (!strcmp (res->dump,"dump_physmem" ))rte_dump_physmem_layout (stdout); +else if (!strcmp (res->dump,"dump_socket" )) +dump_socket_mem (stdout);else if (!strcmp (res->dump,"dump_memzone" ))rte_memzone_dump (stdout);else if (!strcmp (res->dump,"dump_malloc" )) {@@ -9604,6 +9655,7 @@ static void cmd_dump_parsed(void *parsed_result, TOKEN_STRING_INITIALIZER(struct cmd_dump_result, dump,"dump_physmem#" "dump_memzone#" +"dump_socket#" "dump_struct_sizes#" "dump_ring#" "dump_mempool#" doc/guides/testpmd_app_ug/testpmd_funcs.rst +0
-0
doc/guides/testpmd_app_ug/testpmd_funcs.rst Dumps the layout of all memory zones:: · line 547
Quoted 9 lines
doc/guides/testpmd_app_ug/testpmd_funcs.rst +6
-0@@ -539,6 +539,12 @@ Dumps the layout of all memory zones:: testpmd> dump_memzone +dump socket +~~~~~~~~~~~~ + +Dumps the memory usage of all sockets:: + + testpmd> dump_socket
'dump_socket' looks like it will list the socket information, what do you think changing the command name to 'dump_socket_mem' to clarify it will dump the memory information?
Quoted 4 lines
doc/guides/testpmd_app_ug/testpmd_funcs.rst +0
-0dump struct size ~~~~~~~~~~~~~~~~
Quoted 3 lines · On Fri, 3 Apr 2020 14:29:06 +0100 Ferruh Yigit <[email protected]> wrote:
app/test-pmd/cmdline.c struct cmd_dump_result { · line 9580
Quoted 3 lines
app/test-pmd/cmdline.c +3
-0+int64_t total =0 ; +int64_t alloc =0 ; +int64_t free =0 ;
Should be unsigned (ie uint64_t)
Quoted 10 lines · On Fri, 3 Apr 2020 14:29:06 +0100 Ferruh Yigit <[email protected]> wrote:
app/test-pmd/cmdline.c struct cmd_dump_result { · line 9605
Quoted 7 lines
app/test-pmd/cmdline.c +7
-0+ socket_stats.heap_totalsz_bytes /1.0e6 , + socket_stats.heap_allocsz_bytes /1.0e6 , + (double )socket_stats.heap_allocsz_bytes *100 / + (double )socket_stats.heap_totalsz_bytes, + socket_stats.heap_freesz_bytes /1.0e6 , + socket_stats.alloc_count, + socket_stats.free_count);This gives an output like [1], can you please divide to (1024*1024) to convert byte to Mb, than it can give more clear numbers.
Agree, the standard is to use 1024*1024 for memory megabytes. And 1000*1000 for bytes in networking.
Quoted 15 lines
From: dev [mailto:[email protected]] On Behalf Of Stephen Hemminger
Sent: Friday, April 3, 2020 6:09 PMQuoted 9 lines · On Fri, 3 Apr 2020 14:29:06 +0100 Ferruh Yigit <[email protected]> wrote:
app/test-pmd/cmdline.c struct cmd_dump_result { · line 9605
Quoted 7 lines
app/test-pmd/cmdline.c +7
-0+ socket_stats.heap_totalsz_bytes /1.0e6 , + socket_stats.heap_allocsz_bytes /1.0e6 , + (double )socket_stats.heap_allocsz_bytes *100 / + (double )socket_stats.heap_totalsz_bytes, + socket_stats.heap_freesz_bytes /1.0e6 , + socket_stats.alloc_count, + socket_stats.free_count);This gives an output like [1], can you please divide to (1024*1024)
Quoted 4 lines
to convert
Quoted 1 line
byte to Mb, than it can give more clear numbers.
Agree, the standard is to use 1024*1024 for memory megabytes.
That was the old standard. It has been 1000*1000 so for a decade now.
1000000 is the internationally agreed standard for the MB (megabyte) unit. It has been adopted by all major standardization organs, and is the legally binding definition.
If you want to use 1024*1024, the correct unit is MiB (mebibyte). And in this case, it probably makes sense. Just use the correct MiB unit instead of the incorrect MB unit.
For further information, please also refer to:
https://en.wikipedia.org/wiki/Megabyte
Quoted 1 line
And 1000*1000 for bytes in networking.
Yes.
PATCH v2 1/1 app/testpmd: add memory dump command
In reply to Xueming Liv0: initial version
v1: update user guide
v2: change CLI to "dump_socket_mem
change memory unit MB caculation from 1e6 to 1024*1024
Xueming Li (1):
app/testpmd: add memory dump command
app/test-pmd/cmdline.c | 53 +++++++++++++++++++++++++++++ doc/guides/testpmd_app_ug/testpmd_funcs.rst | 6 ++++ 2 files changed, 59 insertions(+)
Signature · 1 line
1.8.3.1
PATCH v2 1/1 app/testpmd: add memory dump command
Introduce new command to dump memory statistics of each socket, summary, also show changes since last call.
Usage:
dump_socket_mem
--- app/test-pmd/cmdline.c | 53 +++++++++++++++++++++++++++++ doc/guides/testpmd_app_ug/testpmd_funcs.rst | 6 ++++ 2 files changed, 59 insertions(+)
app/test-pmd/cmdline.c +53 -0
@@ -9568,6 +9568,56 @@ struct cmd_dump_result {#undef DUMP_SIZE } + +/* Dump the socket memory statistics on console */ +static void +dump_socket_mem (FILE *f) +{ +struct rte_malloc_socket_stats socket_stats; +unsigned int i; +size_t total =0 ; +size_t alloc =0 ; +size_t free =0 ; +unsigned int n_alloc =0 ; +unsigned int n_free =0 ; +static size_t last_allocs; +static size_t last_total; + + +for (i =0 ; i <RTE_MAX_NUMA_NODES ; i++) { +if (rte_malloc_get_socket_stats (i, &socket_stats) || + !socket_stats.heap_totalsz_bytes) +continue ; + total += socket_stats.heap_totalsz_bytes; + alloc += socket_stats.heap_allocsz_bytes; + free += socket_stats.heap_freesz_bytes; + n_alloc += socket_stats.alloc_count; + n_free += socket_stats.free_count; +fprintf (f, +"Socket %u: size(M) total: %.6lf alloc: %.6lf(%.3lf%%) free: %.6lf \tcount alloc: %-4u free: %u\n" , + i, + (double )socket_stats.heap_totalsz_bytes / (1024 *1024 ), + (double )socket_stats.heap_allocsz_bytes / (1024 *1024 ), + (double )socket_stats.heap_allocsz_bytes *100 / + (double )socket_stats.heap_totalsz_bytes, + (double )socket_stats.heap_freesz_bytes / (1024 *1024 ), + socket_stats.alloc_count, + socket_stats.free_count); + } +fprintf (f, +"Total : size(M) total: %.6lf alloc: %.6lf(%.3lf%%) free: %.6lf \tcount alloc: %-4u free: %u\n" , + (double )total / (1024 *1024 ), (double )alloc / (1024 *1024 ), + (double )alloc *100 / (double )total, + (double )free / (1024 *1024 ), + n_alloc, n_free); +if (last_allocs) +fprintf (stdout,"Memory total change: %.6lf(M), allocation change: %.6lf(M)\n" , + ((double )total - (double )last_total) / (1024 *1024 ), + (double )(alloc - (double )last_allocs) /1024 /1024 ); + last_allocs = alloc; + last_total = total; +} +static void cmd_dump_parsed (void *parsed_result, __attribute__((unused))struct cmdline *cl, __attribute__((unused))void *data)
@@ -9576,6 +9626,8 @@ static void cmd_dump_parsed(void *parsed_result,if (!strcmp (res->dump,"dump_physmem" ))rte_dump_physmem_layout (stdout); +else if (!strcmp (res->dump,"dump_socket_mem" )) +dump_socket_mem (stdout);else if (!strcmp (res->dump,"dump_memzone" ))rte_memzone_dump (stdout);else if (!strcmp (res->dump,"dump_malloc" )) {
@@ -9604,6 +9656,7 @@ static void cmd_dump_parsed(void *parsed_result, TOKEN_STRING_INITIALIZER(struct cmd_dump_result, dump,"dump_physmem#" "dump_memzone#" +"dump_socket_mem#" "dump_struct_sizes#" "dump_ring#" "dump_mempool#"
doc/guides/testpmd_app_ug/testpmd_funcs.rst +6 -0
@@ -539,6 +539,12 @@ Dumps the layout of all memory zones:: testpmd> dump_memzone +dump socket +~~~~~~~~~~~~ + +Dumps the memory usage of all sockets:: + + testpmd> dump_socket_mem dump struct size ~~~~~~~~~~~~~~~~
Signature · 1 line
1.8.3.1
Quoted 7 lines · Xueming Li
Introduce new command to dump memory statistics of each socket, summary, also show changes since last call.
Usage:
dump_socket_memSigned-off-by Xueming Li <[email protected]>
<...>
app/test-pmd/cmdline.c static void cmd_dump_parsed(void *parsed_result, · line 9633
Quoted 9 lines
app/test-pmd/cmdline.c +2
-0@@ -9576,6 +9626,8 @@ static void cmd_dump_parsed(void *parsed_result,if (!strcmp (res->dump,"dump_physmem" ))rte_dump_physmem_layout (stdout); +else if (!strcmp (res->dump,"dump_socket_mem" )) +dump_socket_mem (stdout);else if (!strcmp (res->dump,"dump_memzone" ))rte_memzone_dump (stdout);else if (!strcmp (res->dump,"dump_malloc" )) {
This "dump_malloc" is not in the upstream, which cause a conflict while merging the patch, which is breaking our automated tests.
It is OK for now, but for later please rebase your patches on latest master.
Quoted 13 lines
app/test-pmd/cmdline.c +1
-0@@ -9604,6 +9656,7 @@ static void cmd_dump_parsed(void *parsed_result, TOKEN_STRING_INITIALIZER(struct cmd_dump_result, dump,"dump_physmem#" "dump_memzone#" +"dump_socket_mem#" "dump_struct_sizes#" "dump_ring#" "dump_mempool#" doc/guides/testpmd_app_ug/testpmd_funcs.rst +0
-0
doc/guides/testpmd_app_ug/testpmd_funcs.rst Dumps the layout of all memory zones:: · line 543
Quoted 5 lines
doc/guides/testpmd_app_ug/testpmd_funcs.rst +2
-0@@ -539,6 +539,12 @@ Dumps the layout of all memory zones:: testpmd> dump_memzone +dump socket +~~~~~~~~~~~~
Title fixed as "dump socket memory" while merging
Applied to dpdk-next-net/master, thanks.
Hi Ferruh,
Thanks for your comments, noted.
Quoted 62 lines
-----Original Message-----
From: Ferruh Yigit <[email protected]>
Sent: Tuesday, April 7, 2020 5:22 PM
To: Xueming(Steven) Li <[email protected]>; Wenzhuo Lu <[email protected]>; Jingjing Wu <[email protected]>; Bernard Iremonger <[email protected]>; Anatoly Burakov <[email protected]>; Stephen Hemminger <[email protected]>
Cc: [email protected]; Asaf Penso <[email protected]>
Subject: Re: [dpdk-dev] [PATCH v2] app/testpmd: add memory dump commandQuoted 7 lines · Xueming Li
Introduce new command to dump memory statistics of each socket, summary, also show changes since last call.
Usage:
dump_socket_memSigned-off-by Xueming Li <[email protected]><...>
app/test-pmd/cmdline.c static void cmd_dump_parsed(void *parsed_result, · line 9633
Quoted 9 lines
app/test-pmd/cmdline.c +2
-0@@ -9576,6 +9626,8 @@ static void cmd_dump_parsed(void *parsed_result,if (!strcmp (res->dump,"dump_physmem" ))rte_dump_physmem_layout (stdout); +else if (!strcmp (res->dump,"dump_socket_mem" )) +dump_socket_mem (stdout);else if (!strcmp (res->dump,"dump_memzone" ))rte_memzone_dump (stdout);else if (!strcmp (res->dump,"dump_malloc" )) {This "
dump_malloc" is not in the upstream, which cause a conflict while merging the patch, which is breaking our automated tests.
It is OK for now, but for later please rebase your patches on latest master.Quoted 14 lines
app/test-pmd/cmdline.c +1
-0@@ -9604,6 +9656,7 @@ static void cmd_dump_parsed(void *parsed_result, TOKEN_STRING_INITIALIZER(struct cmd_dump_result, dump,"dump_physmem#" "dump_memzone#" +"dump_socket_mem#" "dump_struct_sizes#" "dump_ring#" "dump_mempool#" doc/guides/testpmd_app_ug/testpmd_funcs.rst +0
-0doc/guides/testpmd_app_ug/testpmd_funcs.rst Dumps the layout of all memory zones:: · line 543
Quoted 5 lines
doc/guides/testpmd_app_ug/testpmd_funcs.rst +2
-0@@ -539,6 +539,12 @@ Dumps the layout of all memory zones:: testpmd> dump_memzone +dump socket +~~~~~~~~~~~~Title fixed as "dump socket memory" while merging
net/master, thanks.