void *p3 = rte_malloc_socket("add2", size,align, socket);
if (!p3)
return -1;
+
rte_malloc_get_socket_stats(socket,&second_stats);
+ rte_free(p2);
+ rte_free(p3);
+
+ /* After freeing both allocations check stats return to original */
+ rte_malloc_get_socket_stats(socket, &post_stats);
+
/*
* Check that no new blocks added after small allocations
* i.e. < RTE_MALLOC_MEMZONE_SIZE
return -1;
}
- /* 2 Free blocks smaller 11M, larger 11M + (11M - 2048) */
- if (second_stats.greatest_free_size !=
- (rte_str_to_size(MALLOC_MEMZONE_SIZE) * 2) -
- 2048 - trailer_size) {
+ /* Make sure that we didn't touch our greatest chunk: 2 * 11M) */
+ if (second_stats.greatest_free_size != pre_stats.greatest_free_size) {
printf("Incorrect heap statistics: Greatest free size \n");
return -1;
}
printf("Incorrect heap statistics: Free size \n");
return -1;
}
- rte_free(p2);
- rte_free(p3);
- /* After freeing both allocations check stats return to original */
- rte_malloc_get_socket_stats(socket, &post_stats);
+
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)&&
static int
test_memzone_size_alloc(void)
{
- void *p1 = rte_malloc("BIG", rte_str_to_size(MALLOC_MEMZONE_SIZE) - 128, 64);
+ void *p1 = rte_malloc("BIG", (size_t)(rte_str_to_size(MALLOC_MEMZONE_SIZE) - 128), 64);
if (!p1)
return -1;
rte_free(p1);
find_suitable_element(struct malloc_heap *heap, size_t size,
unsigned align, struct malloc_elem **prev)
{
- struct malloc_elem *elem = heap->free_head;
+ struct malloc_elem *elem, *min_elem, *min_prev;
+ size_t min_sz;
+
+ elem = heap->free_head;
+ min_elem = NULL;
+ min_prev = NULL;
+ min_sz = (size_t) SIZE_MAX;
*prev = NULL;
+
while(elem){
- if (malloc_elem_can_hold(elem, size, align))
- break;
- *prev = elem;
+ if (malloc_elem_can_hold(elem, size, align)) {
+ if (min_sz > elem->size) {
+ min_elem = elem;
+ *prev = min_prev;
+ min_sz = elem->size;
+ }
+ }
+ min_prev = elem;
elem = elem->next_free;
}
- return elem;
+ return (min_elem);
}
/*