Skip to contentSkip to conversation

app/proc-info: add memory heap dump

PATCH Superseded Gagandeep Singh 5 participants 15 messages Jul 2, 2024 – Oct 11, 2024

lore
Share & tools
lore
#0 lore raw

PATCH v2 1/2 app/proc-info: add memory heap dump

This patch add the heap dump support in proc-info
memory dump option.

---
 app/proc-info/main.c | 5 +++++
 1 file changed, 5 insertions(+)
app/proc-info/main.c +5 -0
index b672aaefbe..7137891c14 100644
@@ -20,6 +20,7 @@
 #include <rte_debug.h>
 #include <rte_ethdev.h>
 #include <rte_memory.h>
+#include <rte_malloc.h>
 #include <rte_memzone.h>
 #include <rte_launch.h>
 #include <rte_tailq.h>
@@ -637,6 +638,10 @@ meminfo_display(void)
 	rte_memzone_dump(stdout);
 	printf("---------- END_MEMORY_ZONES -----------\n");
 
+	printf("------------ HEAP DUMP -------------\n");
+	rte_malloc_dump_heaps(stdout);
+	printf("---------- END_HEAP_DUMP -----------\n");
+
 	printf("------------- TAIL_QUEUES -------------\n");
 	rte_dump_tailq(stdout);
 	printf("---------- END_TAIL_QUEUES ------------\n");
Signature · 1 line
2.25.1
#1 lore raw

PATCH v2 2/2 eal: add total memory size in memory dump APIs

This patch add total memory size dump in memzone and memsegments dump APIs.

---
 lib/eal/common/eal_common_memory.c  |  2 ++
 lib/eal/common/eal_common_memzone.c | 18 ++++++++++++++++--
 2 files changed, 18 insertions(+), 2 deletions(-)
lib/eal/common/eal_common_memory.c +2 -0
index 60ddc30580..c6b9c16617 100644
@@ -531,6 +531,8 @@ void
 rte_dump_physmem_layout(FILE *f)
 {
 	rte_memseg_walk(dump_memseg, f);
+	fprintf(f, "Total Memory Segments size = %uM\n",
+			(unsigned int) rte_eal_get_physmem_size() / (1024 * 1024));
 }
 
 static int
lib/eal/common/eal_common_memzone.c +16 -2
index 32e6b78f87..1d12ccc443 100644
@@ -58,6 +58,11 @@ rte_memzone_max_get(void)
 	return mcfg->max_memzone;
 }
 
+struct memzone_info {
+	FILE *f;
+	uint64_t t_size;
+};
+
 static inline const struct rte_memzone *
 memzone_lookup_thread_unsafe(const char *name)
 {
@@ -369,7 +374,8 @@ dump_memzone(const struct rte_memzone *mz, void *arg)
 	struct rte_memseg *ms;
 	int mz_idx, ms_idx;
 	size_t page_sz;
-	FILE *f = arg;
+	struct memzone_info *info = arg;
+	FILE *f = info->f;
 
 	mz_idx = rte_fbarray_find_idx(&mcfg->memzones, mz);
 
@@ -382,6 +388,7 @@ dump_memzone(const struct rte_memzone *mz, void *arg)
 			mz->socket_id,
 			mz->flags);
 
+	info->t_size += mz->len;
 	/* go through each page occupied by this memzone */
 	msl = rte_mem_virt2memseg_list(mz->addr);
 	if (!msl) {
@@ -414,7 +421,14 @@ dump_memzone(const struct rte_memzone *mz, void *arg)
 void
 rte_memzone_dump(FILE *f)
 {
-	rte_memzone_walk(dump_memzone, f);
+	struct memzone_info info;
+
+	memset(&info, 0, sizeof(info));
+	info.f = f;
+
+	rte_memzone_walk(dump_memzone, &info);
+	fprintf(f, "Total Memory Zones size = %uM\n", (unsigned int)info.t_size
+			/ (1024 * 1024));
 }
 
 /*
Signature · 1 line
2.25.1
#3 lore raw
In reply to Gagandeep Singh

02/07/2024 15:14, Gagandeep Singh:

app/proc-info/main.c meminfo_display(void) · line 641

Quoted 7 lines
app/proc-info/main.c +1 -0
@@ -637,6 +638,10 @@ meminfo_display(void)
 	rte_memzone_dump(stdout);
 	printf("---------- END_MEMORY_ZONES -----------\n");
 
+	printf("------------ HEAP DUMP -------------\n");

Should we add "MALLOC"?
With underscores for consistency?

Quoted 7 lines
app/proc-info/main.c +3 -0
+	rte_malloc_dump_heaps(stdout);
+	printf("---------- END_HEAP_DUMP -----------\n");
+
 	printf("------------- TAIL_QUEUES -------------\n");
 	rte_dump_tailq(stdout);
 	printf("---------- END_TAIL_QUEUES ------------\n");
#4 lore raw

Hi,

Quoted 15 lines

-----Original Message-----
From: Thomas Monjalon <[email protected]>
Sent: Monday, July 29, 2024 10:48 PM
To: Gagandeep Singh <[email protected]>
Cc: [email protected]; Reshma Pattan <[email protected]>; Hemant Agrawal <[email protected]>
Subject: Re: [PATCH 1/2] app/proc-info: add memory heap dump

02/07/2024 15:14, Gagandeep Singh:

Quoted 6 lines
app/proc-info/main.c +0 -0
@@ -637,6 +638,10 @@ meminfo_display(void)
 	rte_memzone_dump(stdout);
 	printf("---------- END_MEMORY_ZONES -----------\n");
 
Quoted 4 lines

app/proc-info/main.c meminfo_display(void) · line 641

Quoted 1 line
app/proc-info/main.c +1 -0
+	printf("------------ HEAP DUMP -------------\n");

Should we add "MALLOC"?
With underscores for consistency?

Ok, submitted the V2.

Quoted 12 lines
Quoted 8 lines
app/proc-info/main.c +3 -0
+	rte_malloc_dump_heaps(stdout);
+	printf("---------- END_HEAP_DUMP -----------\n");
+
 	printf("------------- TAIL_QUEUES -------------\n");
 	rte_dump_tailq(stdout);
 	printf("---------- END_TAIL_QUEUES ------------\n");
#5 lore raw

v2 cover proc-info memory dump enhancement

In reply to Gagandeep Singh

v2 change:
* Handled a comment to add "MALLOC" while dumping
malloc heaps.

Gagandeep Singh (2):
app/proc-info: add memory heap dump
eal: add total memory size in memory dump APIs

 app/proc-info/main.c                |  5 +++++
 lib/eal/common/eal_common_memory.c  |  2 ++
 lib/eal/common/eal_common_memzone.c | 18 ++++++++++++++++--
 3 files changed, 23 insertions(+), 2 deletions(-)
Signature · 1 line
2.25.1
#6 lore raw

PATCH v2 1/2 app/proc-info: add memory heap dump

This patch add the malloc heap dump support in proc-info memory dump option.

---
 app/proc-info/main.c | 5 +++++
 1 file changed, 5 insertions(+)
app/proc-info/main.c +5 -0
index b672aaefbe..9e26b5cf3b 100644
@@ -20,6 +20,7 @@
 #include <rte_debug.h>
 #include <rte_ethdev.h>
 #include <rte_memory.h>
+#include <rte_malloc.h>
 #include <rte_memzone.h>
 #include <rte_launch.h>
 #include <rte_tailq.h>
@@ -637,6 +638,10 @@ meminfo_display(void)
 	rte_memzone_dump(stdout);
 	printf("---------- END_MEMORY_ZONES -----------\n");
 
+	printf("---------- MALLOC_HEAP_DUMP -----------\n");
+	rte_malloc_dump_heaps(stdout);
+	printf("-------- END_MALLOC_HEAP_DUMP ---------\n");
+
 	printf("------------- TAIL_QUEUES -------------\n");
 	rte_dump_tailq(stdout);
 	printf("---------- END_TAIL_QUEUES ------------\n");
Signature · 1 line
2.25.1
#7 lore raw

PATCH v3 1/2 app/proc-info: add memory heap dump

This patch add the malloc heap dump support in proc-info memory dump option.

---
 app/proc-info/main.c | 5 +++++
 1 file changed, 5 insertions(+)
app/proc-info/main.c +5 -0
index b672aaefbe..9e26b5cf3b 100644
@@ -20,6 +20,7 @@
 #include <rte_debug.h>
 #include <rte_ethdev.h>
 #include <rte_memory.h>
+#include <rte_malloc.h>
 #include <rte_memzone.h>
 #include <rte_launch.h>
 #include <rte_tailq.h>
@@ -637,6 +638,10 @@ meminfo_display(void)
 	rte_memzone_dump(stdout);
 	printf("---------- END_MEMORY_ZONES -----------\n");
 
+	printf("---------- MALLOC_HEAP_DUMP -----------\n");
+	rte_malloc_dump_heaps(stdout);
+	printf("-------- END_MALLOC_HEAP_DUMP ---------\n");
+
 	printf("------------- TAIL_QUEUES -------------\n");
 	rte_dump_tailq(stdout);
 	printf("---------- END_TAIL_QUEUES ------------\n");
Signature · 1 line
2.25.1
#8 lore raw

PATCH v3 2/2 eal: add total memory size in memory dump APIs

This patch add total memory size dump in memzone and memsegments dump APIs.

---
 lib/eal/common/eal_common_memory.c  |  2 ++
 lib/eal/common/eal_common_memzone.c | 18 ++++++++++++++++--
 2 files changed, 18 insertions(+), 2 deletions(-)
lib/eal/common/eal_common_memory.c +2 -0
index 60ddc30580..7b4fb4c60d 100644
@@ -531,6 +531,8 @@ void
 rte_dump_physmem_layout(FILE *f)
 {
 	rte_memseg_walk(dump_memseg, f);
+	fprintf(f, "Total Memory Segments size = %"PRIu64"M\n",
+			rte_eal_get_physmem_size() / (1024 * 1024));
 }
 
 static int
lib/eal/common/eal_common_memzone.c +16 -2
index 2d9b6aa3e3..5427cbd0cb 100644
@@ -58,6 +58,11 @@ rte_memzone_max_get(void)
 	return mcfg->max_memzone;
 }
 
+struct memzone_info {
+	FILE *f;
+	uint64_t t_size;
+};
+
 static inline const struct rte_memzone *
 memzone_lookup_thread_unsafe(const char *name)
 {
@@ -367,7 +372,8 @@ dump_memzone(const struct rte_memzone *mz, void *arg)
 	struct rte_memseg *ms;
 	int mz_idx, ms_idx;
 	size_t page_sz;
-	FILE *f = arg;
+	struct memzone_info *info = arg;
+	FILE *f = info->f;
 
 	mz_idx = rte_fbarray_find_idx(&mcfg->memzones, mz);
 
@@ -380,6 +386,7 @@ dump_memzone(const struct rte_memzone *mz, void *arg)
 			mz->socket_id,
 			mz->flags);
 
+	info->t_size += mz->len;
 	/* go through each page occupied by this memzone */
 	msl = rte_mem_virt2memseg_list(mz->addr);
 	if (!msl) {
@@ -412,7 +419,14 @@ dump_memzone(const struct rte_memzone *mz, void *arg)
 void
 rte_memzone_dump(FILE *f)
 {
-	rte_memzone_walk(dump_memzone, f);
+	struct memzone_info info;
+
+	memset(&info, 0, sizeof(info));
+	info.f = f;
+
+	rte_memzone_walk(dump_memzone, &info);
+	fprintf(f, "Total Memory Zones size = %"PRIu64"M\n", info.t_size
+			/ (1024 * 1024));
 }
 
 /*
Signature · 1 line
2.25.1
#9 lore raw

Re: [v3 2/2] eal: add total memory size in memory dump APIs

Quoted 4 lines · On Thu, 10 Oct 2024 12:46:21 +0530 Gagandeep Singh <[email protected]> wrote:

This patch add total memory size dump in memzone and memsegments dump APIs.

Looks good, and acking it as is.

But you could simplify this:
+ struct memzone_info info;
+
+ memset(&info, 0, sizeof(info));
+ info.f = f;

As:

	struct memzone_info info = { .f = f };
#12 lore raw

PATCH v2 2/2 eal: add total memory size in memory dump APIs

In reply to Gagandeep Singh

This patch add total memory size dump in memzone and memsegments dump APIs.

---
 lib/eal/common/eal_common_memory.c  |  2 ++
 lib/eal/common/eal_common_memzone.c | 18 ++++++++++++++++--
 2 files changed, 18 insertions(+), 2 deletions(-)
lib/eal/common/eal_common_memory.c +2 -0
index 60ddc30580..c6b9c16617 100644
@@ -531,6 +531,8 @@ void
 rte_dump_physmem_layout(FILE *f)
 {
 	rte_memseg_walk(dump_memseg, f);
+	fprintf(f, "Total Memory Segments size = %uM\n",
+			(unsigned int) rte_eal_get_physmem_size() / (1024 * 1024));
 }
 
 static int
lib/eal/common/eal_common_memzone.c +16 -2
index 2d9b6aa3e3..4cd077d8d8 100644
@@ -58,6 +58,11 @@ rte_memzone_max_get(void)
 	return mcfg->max_memzone;
 }
 
+struct memzone_info {
+	FILE *f;
+	uint64_t t_size;
+};
+
 static inline const struct rte_memzone *
 memzone_lookup_thread_unsafe(const char *name)
 {
@@ -367,7 +372,8 @@ dump_memzone(const struct rte_memzone *mz, void *arg)
 	struct rte_memseg *ms;
 	int mz_idx, ms_idx;
 	size_t page_sz;
-	FILE *f = arg;
+	struct memzone_info *info = arg;
+	FILE *f = info->f;
 
 	mz_idx = rte_fbarray_find_idx(&mcfg->memzones, mz);
 
@@ -380,6 +386,7 @@ dump_memzone(const struct rte_memzone *mz, void *arg)
 			mz->socket_id,
 			mz->flags);
 
+	info->t_size += mz->len;
 	/* go through each page occupied by this memzone */
 	msl = rte_mem_virt2memseg_list(mz->addr);
 	if (!msl) {
@@ -412,7 +419,14 @@ dump_memzone(const struct rte_memzone *mz, void *arg)
 void
 rte_memzone_dump(FILE *f)
 {
-	rte_memzone_walk(dump_memzone, f);
+	struct memzone_info info;
+
+	memset(&info, 0, sizeof(info));
+	info.f = f;
+
+	rte_memzone_walk(dump_memzone, &info);
+	fprintf(f, "Total Memory Zones size = %uM\n", (unsigned int)info.t_size
+			/ (1024 * 1024));
 }
 
 /*
Signature · 1 line
2.25.1
#13 lore raw

Re: [v2 2/2] eal: add total memory size in memory dump APIs

Quoted 14 lines · On Tue, 30 Jul 2024 16:33:13 +0530 Gagandeep Singh <[email protected]> wrote:

This patch add total memory size dump in memzone and memsegments dump APIs.

---
 lib/eal/common/eal_common_memory.c  |  2 ++
 lib/eal/common/eal_common_memzone.c | 18 ++++++++++++++++--
 2 files changed, 18 insertions(+), 2 deletions(-)
lib/eal/common/eal_common_memory.c +0 -0
index 60ddc30580..c6b9c16617 100644

lib/eal/common/eal_common_memory.c void · line 536

Quoted 6 lines
lib/eal/common/eal_common_memory.c +2 -0
@@ -531,6 +531,8 @@ void
 rte_dump_physmem_layout(FILE *f)
 {
 	rte_memseg_walk(dump_memseg, f);
+	fprintf(f, "Total Memory Segments size = %uM\n",
+			(unsigned int) rte_eal_get_physmem_size() / (1024 * 1024));
 }

You are going to get truncated result here because rte_eal_get_physmem_size() is uint64_t and unsigned int is 32 bit. The cast happens before the division which leads to truncation with 4G. Simplest fix would be

	fprintf(f, "Total Memory Segments size = %"PRIu64"M\n",
		rte_eal_get_physmem_size() / (1024 * 1024));
#14 lore raw

Re: [v2 0/2] proc-info memory dump enhancement

In reply to Gagandeep Singh
Quoted 8 lines · Gagandeep Singh

v2 change:
* Handled a comment to add "MALLOC" while dumping
malloc heaps.

Gagandeep Singh (2):
app/proc-info: add memory heap dump
eal: add total memory size in memory dump APIs

Series applied, thanks.

Signature · 1 line
David Marchand