mem_debug add more log
RFC 1/1 mem_debug add more log
1. The debugging log in current DPDK RTE_MALLOC_DEBUG mode is insufficient, which makes it difficult to locate the issues, such as:
a) When a memeory overlflow occur in rte_free, there is a little log information. Even if abort here, we can find which API is core dumped but we still need to read the source code to find out where the requested memory is overflowed.
b) Current DPDK can NOT find that the overflow if the memory has been used and not released.
c) If there are two pieces of continuous memory, when the first block is not released and an overflow is occured and also the second block of memory is covered, a memory overflow will be detected once the second block of memory is released. However, current DPDK can not find the correct point of memory overflow. It only detect the memory overflow of the second block but should dedect the one of first block.
----------------------------------------------------------------------------------
| header cookie | data1 | trailer cookie | header cookie | data2 |trailer cookie |
----------------------------------------------------------------------------------
2. To fix above issues, we can store the requested information When DPDK request memory. Including the requested address and requested momory's file, function and numbers of rows and then put it into a list.
-------------------- ---------------------- ----------------------
| struct list_head |---->| struct malloc_info |---->| struct malloc_info |
-------------------- ---------------------- ----------------------
The above 3 problems can be solved through this implementation:
a) If there is a memory overflow in rte_free, you can traverse the
list to find the information of overflow memory and print the
overflow memory information. like this:
code:
37 char *p = rte_zmalloc(NULL, 64, 0);
38 memset(p, 0, 65);
39 rte_free(p);
40 //rte_malloc_validate_all_memory();
memory error:
EAL: Error: Invalid memory
malloc memory address 0x17ff2c340 overflow in \
file:../examples/helloworld/main.c function:main line:37 b)c) Provide a interface to check all memory overflow in function
rte_malloc_validate_all_memory, this function will check all memory on the list. Call this funcation manually at the exit point of business logic, we can find all overflow points in time.
--- lib/librte_eal/common/eal_common_mcfg.c | 30 ++ lib/librte_eal/common/eal_memcfg.h | 3 + lib/librte_eal/common/rte_malloc.c | 380 ++++++++++++++++++++- lib/librte_eal/include/rte_eal_memconfig.h | 15 + lib/librte_eal/include/rte_malloc.h | 70 ++++ lib/librte_eal/version.map | 13 + 6 files changed, 510 insertions(+), 1 deletion(-)
lib/librte_eal/common/eal_common_mcfg.c +30 -0
@@ -174,3 +174,33 @@ rte_mcfg_get_single_file_segments(void)struct rte_mem_config *mcfg =rte_eal_get_configuration ()->mem_config;return (bool )mcfg->single_file_segments; } + +#ifdef RTE_MALLOC_DEBUG +void +rte_mcfg_malloc_debug_read_lock (void ) +{ +struct rte_mem_config *mcfg =rte_eal_get_configuration ()->mem_config; +rte_rwlock_read_lock (&mcfg->malloc_debug_lock); +} + +void +rte_mcfg_malloc_debug_read_unlock (void ) +{ +struct rte_mem_config *mcfg =rte_eal_get_configuration ()->mem_config; +rte_rwlock_read_unlock (&mcfg->malloc_debug_lock); +} + +void +rte_mcfg_malloc_debug_write_lock (void ) +{ +struct rte_mem_config *mcfg =rte_eal_get_configuration ()->mem_config; +rte_rwlock_write_lock (&mcfg->malloc_debug_lock); +} + +void +rte_mcfg_malloc_debug_write_unlock (void ) +{ +struct rte_mem_config *mcfg =rte_eal_get_configuration ()->mem_config; +rte_rwlock_write_unlock (&mcfg->malloc_debug_lock); +} +#endif
lib/librte_eal/common/eal_memcfg.h +3 -0
@@ -37,6 +37,9 @@ struct rte_mem_config {rte_rwlock_t qlock;/**< used by tailqs for thread safety. */ rte_rwlock_t mplock;/**< used by mempool library for thread safety. */ rte_spinlock_t tlock;/**< used by timer library for thread safety. */ +#ifdef RTE_MALLOC_DEBUG +rte_rwlock_t malloc_debug_lock;/**< used by malloc debug. */ +#endif rte_rwlock_t memory_hotplug_lock;/**< Indicates whether memory hotplug request is in progress. */
lib/librte_eal/common/rte_malloc.c +379 -1
417 lines not on this page · raw message
lib/librte_eal/include/rte_eal_memconfig.h +15 -0
@@ -122,6 +122,21 @@ __rte_experimentalbool rte_mcfg_get_single_file_segments (void ); +#ifdef RTE_MALLOC_DEBUG +void +rte_mcfg_malloc_debug_read_lock (void ); + +void +rte_mcfg_malloc_debug_read_unlock (void ); + +void +rte_mcfg_malloc_debug_write_lock (void ); + +void +rte_mcfg_malloc_debug_write_unlock (void ); + +#endif + #ifdef __cplusplus }#endif
lib/librte_eal/include/rte_malloc.h +70 -0
82 lines not on this page · raw message
lib/librte_eal/version.map +13 -0
@@ -133,6 +133,10 @@ DPDK_21 { rte_mcfg_tailq_read_unlock; rte_mcfg_tailq_write_lock; rte_mcfg_tailq_write_unlock; + rte_mcfg_malloc_debug_read_lock; + rte_mcfg_malloc_debug_read_unlock; + rte_mcfg_malloc_debug_write_lock; + rte_mcfg_malloc_debug_write_unlock; rte_mem_lock_page; rte_mem_virt2iova; rte_mem_virt2phy;
@@ -217,6 +221,14 @@ DPDK_21 { rte_vlog; rte_zmalloc; rte_zmalloc_socket; + rte_malloc_debug; + rte_zmalloc_debug; + rte_calloc_debug; + rte_realloc_debug; + rte_malloc_socket_debug; + rte_zmalloc_socket_debug; + rte_calloc_socket_debug; + rte_malloc_validate_all_memory; local: *; };
@@ -319,6 +331,7 @@ EXPERIMENTAL { rte_fbarray_find_rev_biggest_used; rte_intr_callback_unregister_pending; rte_realloc_socket; + rte_realloc_socket_debug; # added in 19.08 rte_intr_ack;
Signature · 1 line
2.17.1
Quoted 36 lines · On Fri, 18 Dec 2020 14:21:09 -0500 Peng Zhihong <[email protected]> wrote:
1. The debugging log in current DPDK
RTE_MALLOC_DEBUGmode is insufficient, which makes it difficult to locate the issues, such as:
a) When a memeory overlflow occur inrte_free, there is a little log information. Even if abort here, we can find which API is core dumped but we still need to read the source code to find out where the requested memory is overflowed.
b) Current DPDK can NOT find that the overflow if the memory has been used and not released.
c) If there are two pieces of continuous memory, when the first block is not released and an overflow is occured and also the second block of memory is covered, a memory overflow will be detected once the second block of memory is released. However, current DPDK can not find the correct point of memory overflow. It only detect the memory overflow of the second block but should dedect the one of first block.
----------------------------------------------------------------------------------
| header cookie | data1 | trailer cookie | header cookie | data2 |trailer cookie |
----------------------------------------------------------------------------------
2. To fix above issues, we can store the requested information When DPDK request memory. Including the requested address and requested momory's file, function and numbers of rows and then put it into a list.-------------------- ---------------------- ---------------------- | struct list_head |---->| struct malloc_info |---->| struct malloc_info | -------------------- ---------------------- ---------------------- The above 3 problems can be solved through this implementation: a) If there is a memory overflow in rte_free, you can traverse the list to find the information of overflow memory and print the overflow memory information. like this: code: 37 char *p = rte_zmalloc(NULL, 64, 0); 38 memset(p, 0, 65); 39 rte_free(p); 40 //rte_malloc_validate_all_memory(); memory error: EAL: Error: Invalid memory malloc memory address 0x17ff2c340 overflow in \ file:../examples/helloworld/main.c function:main line:37
Quoted 6 lines
b)c) Provide a interface to check all memory overflow in function
rte_malloc_validate_all_memory, this function will check all memory on the list. Call this funcation manually at the exit point of business logic, we can find all overflow points in time.Signed-off-by Peng Zhihong <[email protected]>
Good concept, but doesn't this add significant overhead?
Maybe we could make rte_malloc work with existing address sanitizer infrastructure in gcc/clang? That would provide faster and more immediate better diagnostic info.
1. I think this implement doesn't add significant overhead. Overhead only will be occurred in rte_malloc and rte_free.
2. Current existing address sanitizer infrastructure only support libc malloc.
Regards,
Peng,Zhihong
-----Original Message-----
From: Stephen Hemminger <[email protected]>
Sent: Saturday, December 19, 2020 2:54 AM
To: Peng, ZhihongX <[email protected]>
Cc: Wang, Haiyue <[email protected]>; Zhang, Qi Z <[email protected]>; Xing, Beilei <[email protected]>; [email protected]
Subject: Re: [dpdk-dev] [RFC] mem_debug add more log
Quoted 38 lines · On Fri, 18 Dec 2020 14:21:09 -0500 Peng Zhihong <[email protected]> wrote:
1. The debugging log in current DPDK
RTE_MALLOC_DEBUGmode is insufficient, which makes it difficult to locate the issues, such as:
a) When a memeory overlflow occur inrte_free, there is a little log information. Even if abort here, we can find which API is core dumped but we still need to read the source code to find out where the requested memory is overflowed.
b) Current DPDK can NOT find that the overflow if the memory has been used and not released.
c) If there are two pieces of continuous memory, when the first block is not released and an overflow is occured and also the second block of memory is covered, a memory overflow will be detected once the second block of memory is released. However, current DPDK can not find the correct point of memory overflow. It only detect the memory overflow of the second block but should dedect the one of first block.
----------------------------------------------------------------------------------
| header cookie | data1 | trailer cookie | header cookie | data2 |trailer cookie |----------------------------------------------------------------------
------------ 2. To fix above issues, we can store the requested information When DPDK
request memory. Including the requested address and requested momory's file, function and numbers of rows and then put it into a list.-------------------- ---------------------- ---------------------- | struct list_head |---->| struct malloc_info |---->| struct malloc_info | -------------------- ---------------------- ---------------------- The above 3 problems can be solved through this implementation: a) If there is a memory overflow in rte_free, you can traverse the list to find the information of overflow memory and print the overflow memory information. like this: code: 37 char *p = rte_zmalloc(NULL, 64, 0); 38 memset(p, 0, 65); 39 rte_free(p); 40 //rte_malloc_validate_all_memory(); memory error: EAL: Error: Invalid memory malloc memory address 0x17ff2c340 overflow in \ file:../examples/helloworld/main.c function:main line:37
Quoted 6 lines
b)c) Provide a interface to check all memory overflow in function
rte_malloc_validate_all_memory, this function will check all memory on the list. Call this funcation manually at the exit point of business logic, we can find all overflow points in time.Signed-off-by Peng Zhihong <[email protected]>
Good concept, but doesn't this add significant overhead?
Maybe we could make rte_malloc work with existing address sanitizer infrastructure in gcc/clang? That would provide faster and more immediate better diagnostic info.
Quoted 60 lines · ZhihongX
1. I think this implement doesn't add significant overhead. Overhead only will be occurred in
rte_mallocandrte_free.2. Current existing address sanitizer infrastructure only support libc malloc.
Regards,
Peng,Zhihong-----Original Message-----
From: Stephen Hemminger <[email protected]>
Sent: Saturday, December 19, 2020 2:54 AM
To: Peng, ZhihongX <[email protected]>
Cc: Wang, Haiyue <[email protected]>; Zhang, Qi Z <[email protected]>; Xing, Beilei <[email protected]>; [email protected]
Subject: Re: [dpdk-dev] [RFC]mem_debugadd more logQuoted 43 lines · On Fri, 18 Dec 2020 14:21:09 -0500 Peng Zhihong <[email protected]> wrote:
1. The debugging log in current DPDK
RTE_MALLOC_DEBUGmode is insufficient, which makes it difficult to locate the issues, such as:
a) When a memeory overlflow occur inrte_free, there is a little log information. Even if abort here, we can find which API is core dumped but we still need to read the source code to find out where the requested memory is overflowed.
b) Current DPDK can NOT find that the overflow if the memory has been used and not released.
c) If there are two pieces of continuous memory, when the first block is not released and an overflow is occured and also the second block of memory is covered, a memory overflow will be detected once the second block of memory is released. However, current DPDK can not find the correct point of memory overflow. It only detect the memory overflow of the second block but should dedect the one of first block.
----------------------------------------------------------------------------------
| header cookie | data1 | trailer cookie | header cookie | data2 |trailer cookie |----------------------------------------------------------------------
------------ 2. To fix above issues, we can store the requested information When DPDK
request memory. Including the requested address and requested momory's file, function and numbers of rows and then put it into a list.-------------------- ---------------------- ---------------------- | struct list_head |---->| struct malloc_info |---->| struct malloc_info | -------------------- ---------------------- ---------------------- The above 3 problems can be solved through this implementation: a) If there is a memory overflow in rte_free, you can traverse the list to find the information of overflow memory and print the overflow memory information. like this: code: 37 char *p = rte_zmalloc(NULL, 64, 0); 38 memset(p, 0, 65); 39 rte_free(p); 40 //rte_malloc_validate_all_memory(); memory error: EAL: Error: Invalid memory malloc memory address 0x17ff2c340 overflow in \ file:../examples/helloworld/main.c function:main line:37b)c) Provide a interface to check all memory overflow in function
rte_malloc_validate_all_memory, this function will check all memory on the list. Call this funcation manually at the exit point of business logic, we can find all overflow points in time.
Quoted 5 lines
Quoted 1 line
Signed-off-by Peng Zhihong <[email protected]>Good concept, but doesn't this add significant overhead?
Maybe we could make
rte_mallocwork with existing address sanitizer infrastructure in gcc/clang? That would provide faster and more immediate better diagnostic info.
Everybody builds there own custom debug hooks, and some of these are worth sharing. But lots of time debug code becomes a technical debt, creates API/ABI issues and causes more trouble than it is worth.
Therefore my desire is for DPDK to be better supported by standard tools such as valgrind and address sanitizer. The standard tools catch more errors faster and do not create project maintenance workload.
See:
https://github.com/google/sanitizers/wiki/AddressSanitizerAlgorithm
The performance of our simple scheme is better than asan. We are trying the asan solution.
Regards,
Peng,Zhihong
-----Original Message-----
From: Stephen Hemminger <[email protected]>
Sent: Tuesday, December 22, 2020 2:44 AM
To: Peng, ZhihongX <[email protected]>
Cc: Wang, Haiyue <[email protected]>; Zhang, Qi Z <[email protected]>; Xing, Beilei <[email protected]>; [email protected]; Lin, Xueqin <[email protected]>; Yu, PingX <[email protected]>
Subject: Re: [dpdk-dev] [RFC] mem_debug add more log
Quoted 64 lines · ZhihongX
1. I think this implement doesn't add significant overhead. Overhead only will be occurred in
rte_mallocandrte_free.2. Current existing address sanitizer infrastructure only support libc malloc.
Regards,
Peng,Zhihong-----Original Message-----
From: Stephen Hemminger <[email protected]>
Sent: Saturday, December 19, 2020 2:54 AM
To: Peng, ZhihongX <[email protected]>
Cc: Wang, Haiyue <[email protected]>; Zhang, Qi Z <[email protected]>; Xing, Beilei <[email protected]>; [email protected]
Subject: Re: [dpdk-dev] [RFC]mem_debugadd more logQuoted 45 lines · On Fri, 18 Dec 2020 14:21:09 -0500 Peng Zhihong <[email protected]> wrote:
1. The debugging log in current DPDK
RTE_MALLOC_DEBUGmode is insufficient, which makes it difficult to locate the issues, such as:
a) When a memeory overlflow occur inrte_free, there is a little log information. Even if abort here, we can find which API is core dumped but we still need to read the source code to find out where the requested memory is overflowed.
b) Current DPDK can NOT find that the overflow if the memory has been used and not released.
c) If there are two pieces of continuous memory, when the first block is not released and an overflow is occured and also the second block of memory is covered, a memory overflow will be detected once the second block of memory is released. However, current DPDK can not find the correct point of memory overflow. It only detect the memory overflow of the second block but should dedect the one of first block.
----------------------------------------------------------------------------------
| header cookie | data1 | trailer cookie | header cookie |
data2 |trailer cookie |--------------------------------------------------------------------
--
------------ 2. To fix above issues, we can store the requested information When DPDK
request memory. Including the requested address and requested momory's file, function and numbers of rows and then put it into a list.-------------------- ---------------------- ---------------------- | struct list_head |---->| struct malloc_info |---->| struct malloc_info | -------------------- ---------------------- ---------------------- The above 3 problems can be solved through this implementation: a) If there is a memory overflow in rte_free, you can traverse the list to find the information of overflow memory and print the overflow memory information. like this: code: 37 char *p = rte_zmalloc(NULL, 64, 0); 38 memset(p, 0, 65); 39 rte_free(p); 40 //rte_malloc_validate_all_memory(); memory error: EAL: Error: Invalid memory malloc memory address 0x17ff2c340 overflow in \ file:../examples/helloworld/main.c function:main line:37b)c) Provide a interface to check all memory overflow in function
rte_malloc_validate_all_memory, this function will check all memory on the list. Call this funcation manually at the exit point of business logic, we can find all overflow points in time.
Quoted 5 lines
Quoted 1 line
Signed-off-by Peng Zhihong <[email protected]>Good concept, but doesn't this add significant overhead?
Maybe we could make
rte_mallocwork with existing address sanitizer infrastructure in gcc/clang? That would provide faster and more immediate better diagnostic info.
Everybody builds there own custom debug hooks, and some of these are worth sharing.
But lots of time debug code becomes a technical debt, creates API/ABI issues and causes more trouble than it is worth.
Therefore my desire is for DPDK to be better supported by standard tools such as valgrind and address sanitizer. The standard tools catch more errors faster and do not create project maintenance workload.
See:
https://github.com/google/sanitizers/wiki/AddressSanitizerAlgorithm
Quoted 4 lines · ZhihongX
The performance of our simple scheme is better than asan. We are trying the asan solution.
Regards,
Peng,Zhihong
Closing this RFC, not much has changed after 5 years.
Your solution adds locking and only catches small overruns it doesn't address the bigger set of use after free issues.
If you can come up with a faster and more complete solution it would be good to have.