mem: find most little element from heap
Allocations now return the most little element from heap matching size constraint instead of the first one available. Signed-off-by: Intel
This commit is contained in:
parent
286bd05bf7
commit
e0c8475561
@ -393,8 +393,15 @@ test_multi_alloc_statistics(void)
|
||||
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
|
||||
@ -420,10 +427,8 @@ test_multi_alloc_statistics(void)
|
||||
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;
|
||||
}
|
||||
@ -432,10 +437,7 @@ test_multi_alloc_statistics(void)
|
||||
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)&&
|
||||
@ -450,7 +452,7 @@ test_multi_alloc_statistics(void)
|
||||
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);
|
||||
|
@ -153,15 +153,27 @@ static struct malloc_elem *
|
||||
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);
|
||||
}
|
||||
|
||||
/*
|
||||
|
@ -43,6 +43,7 @@
|
||||
#include <rte_memzone.h>
|
||||
#include <rte_tailq.h>
|
||||
#include <rte_eal.h>
|
||||
#include <rte_eal_memconfig.h>
|
||||
#include <rte_branch_prediction.h>
|
||||
#include <rte_debug.h>
|
||||
#include <rte_launch.h>
|
||||
@ -54,7 +55,6 @@
|
||||
#include <rte_malloc.h>
|
||||
#include "malloc_elem.h"
|
||||
#include "malloc_heap.h"
|
||||
#include "malloc_heap.c"
|
||||
|
||||
|
||||
/* Free the memory space back to heap */
|
||||
|
Loading…
Reference in New Issue
Block a user