Heap library and test case changes
cover Heap library and test case changes
This series fixed a heap free list management issue which was captured by unit test failure.
It also includes fixes of the unit test.
Ruifeng Wang (4):
eal: fix list index for 256 byte element
eal: simplify check condition
test/malloc: fix missing free
test/malloc: fix case expectation
app/test/test_malloc.c | 21 +++++++++++---------- lib/eal/common/malloc_elem.c | 2 +- lib/eal/common/malloc_heap.c | 2 +- 3 files changed, 13 insertions(+), 12 deletions(-)
Signature · 1 line
2.25.1
PATCH 1/4 eal: fix list index for 256 byte element
Elements with 2^8B size should fall into index 1 of the list.
--- lib/eal/common/malloc_elem.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
lib/eal/common/malloc_elem.c +1 -1
@@ -382,7 +382,7 @@ malloc_elem_free_list_index(size_t size)size_t log2;size_t index; -if (size <= (1UL <<MALLOC_MINSIZE_LOG2 )) +if (size < (1UL <<MALLOC_MINSIZE_LOG2 ))return 0 ;/* Find next power of 2 > size. */
Signature · 1 line
2.25.1
Re: [PATCH 1/4] eal: fix list index for 256 byte element
Quoted 8 lines · Ruifeng Wang
Elements with 2^8B size should fall into index 1 of the list.
Signed-off-by Ruifeng Wang <[email protected]>---
Signature · 2 lines
Thanks, Anatoly
PATCH 2/4 eal: simplify check condition
In reply to Ruifeng WangThe alt_elem is initialized to null. Checking only size hint flag is sufficient to return a proper value.
Removed the redundant check.
--- lib/eal/common/malloc_heap.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
lib/eal/common/malloc_heap.c +1 -1
@@ -168,7 +168,7 @@ find_suitable_element(struct malloc_heap *heap, size_t size, } } -if ((alt_elem !=NULL ) && (flags &RTE_MEMZONE_SIZE_HINT_ONLY )) +if (flags &RTE_MEMZONE_SIZE_HINT_ONLY )return alt_elem;return NULL ;
Signature · 1 line
2.25.1
Re: [PATCH 2/4] eal: simplify check condition
Quoted 7 lines · Ruifeng Wang
The
alt_elemis initialized to null. Checking only size hint flag is sufficient to return a proper value.
Removed the redundant check.Signed-off-by Ruifeng Wang <[email protected]>Reviewed-by Feifei Wang <[email protected]>---
Signature · 2 lines
Thanks, Anatoly
PATCH 3/4 test/malloc: fix missing free
In reply to Ruifeng WangFree the allocated buffer before returning.
--- app/test/test_malloc.c | 1 + 1 file changed, 1 insertion(+)
app/test/test_malloc.c +1 -0
@@ -937,6 +937,7 @@ test_alloc_single_socket(int32_t socket)if (mem ==NULL )return -1 ;if (addr_to_socket (mem) != desired_socket) { +rte_free (mem);return -1 ; }rte_free (mem);
Signature · 1 line
2.25.1
Re: [PATCH 3/4] test/malloc: fix missing free
Quoted 8 lines · Ruifeng Wang
Free the allocated buffer before returning.
Fixes a40a1f8231b4 ("app: various tests update")Signed-off-by Ruifeng Wang <[email protected]>Reviewed-by Feifei Wang <[email protected]>---
Signature · 2 lines
Thanks, Anatoly
PATCH 4/4 test/malloc: fix case expectation
In reply to Ruifeng WangThe case expects all stats to be equal. Therefor the conditions in check should be logically or'ed.
--- app/test/test_malloc.c | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-)
app/test/test_malloc.c +10 -10
@@ -302,11 +302,11 @@ test_multi_alloc_statistics(void)rte_malloc_get_socket_stats (socket,&post_stats);/* Check statistics reported are correct */ /* All post stats should be equal to pre stats after alloc freed */ -if ((post_stats.heap_totalsz_bytes != pre_stats.heap_totalsz_bytes) && - (post_stats.heap_freesz_bytes!=pre_stats.heap_freesz_bytes) && - (post_stats.heap_allocsz_bytes!=pre_stats.heap_allocsz_bytes)&& - (post_stats.alloc_count!=pre_stats.alloc_count)&& - (post_stats.free_count!=pre_stats.free_count)) { +if ((post_stats.heap_totalsz_bytes != pre_stats.heap_totalsz_bytes) || + (post_stats.heap_freesz_bytes != pre_stats.heap_freesz_bytes) || + (post_stats.heap_allocsz_bytes != pre_stats.heap_allocsz_bytes) || + (post_stats.alloc_count != pre_stats.alloc_count) || + (post_stats.free_count != pre_stats.free_count)) {printf ("Malloc statistics are incorrect - freed alloc\n" );return -1 ; }
@@ -363,11 +363,11 @@ test_multi_alloc_statistics(void)return -1 ; } -if ((post_stats.heap_totalsz_bytes != pre_stats.heap_totalsz_bytes) && - (post_stats.heap_freesz_bytes!=pre_stats.heap_freesz_bytes) && - (post_stats.heap_allocsz_bytes!=pre_stats.heap_allocsz_bytes)&& - (post_stats.alloc_count!=pre_stats.alloc_count)&& - (post_stats.free_count!=pre_stats.free_count)) { +if ((post_stats.heap_totalsz_bytes != pre_stats.heap_totalsz_bytes) || + (post_stats.heap_freesz_bytes != pre_stats.heap_freesz_bytes) || + (post_stats.heap_allocsz_bytes != pre_stats.heap_allocsz_bytes) || + (post_stats.alloc_count != pre_stats.alloc_count) || + (post_stats.free_count != pre_stats.free_count)) {printf ("Malloc statistics are incorrect - freed alloc\n" );return -1 ; }
Signature · 1 line
2.25.1
Re: [PATCH 4/4] test/malloc: fix case expectation
Quoted 9 lines · Ruifeng Wang
The case expects all stats to be equal. Therefor the conditions in check should be logically or'ed.
Fixes a40a1f8231b4 ("app: various tests update")Signed-off-by Ruifeng Wang <[email protected]>Reviewed-by Feifei Wang <[email protected]>---
Signature · 2 lines
Thanks, Anatoly
Thomas Monjalon
Applied19/05/2023 06:29, Ruifeng Wang:
Quoted 9 lines
This series fixed a heap free list management issue which was captured by unit test failure.
It also includes fixes of the unit test.Ruifeng Wang (4):
eal: fix list index for 256 byte element
eal: simplify check condition
test/malloc: fix missing free
test/malloc: fix case expectation
Applied, thanks.