Skip to contentSkip to conversation

Heap library and test case changes

PATCH Applied Ruifeng Wang 3 participants 10 messages May 19, 2023 – Jun 5, 2023

lore
Share & tools
lore
#0 lore raw

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
#1 lore raw

PATCH 1/4 eal: fix list index for 256 byte element

Elements with 2^8B size should fall into index 1 of the list.

Fixes f62f4a375ff4 ("malloc: optimize 4K allocations")
---
 lib/eal/common/malloc_elem.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
lib/eal/common/malloc_elem.c +1 -1
index 35a2313d04..619c040aa3 100644
@@ -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
#3 lore raw

PATCH 2/4 eal: simplify check condition

In reply to Ruifeng Wang

The 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
index d25bdc98f9..fa709ac567 100644
@@ -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
#5 lore raw

PATCH 3/4 test/malloc: fix missing free

In reply to Ruifeng Wang

Free the allocated buffer before returning.

Fixes a40a1f8231b4 ("app: various tests update")
---
 app/test/test_malloc.c | 1 +
 1 file changed, 1 insertion(+)
app/test/test_malloc.c +1 -0
index de40e50611..f144b89d88 100644
@@ -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
#7 lore raw

PATCH 4/4 test/malloc: fix case expectation

In reply to 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")
---
 app/test/test_malloc.c | 20 ++++++++++----------
 1 file changed, 10 insertions(+), 10 deletions(-)
app/test/test_malloc.c +10 -10
index f144b89d88..ff081dd931 100644
@@ -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
#9 lore raw
In reply to Ruifeng Wang

19/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.