From: Anatoly Burakov Date: Mon, 11 Jun 2018 20:55:42 +0000 (+0100) Subject: mem: allocate in reverse to reduce fragmentation X-Git-Url: http://git.droids-corp.org/?a=commitdiff_plain;h=179f916e88e4a0fdd5ad4d20e226771d3d271c41;p=dpdk.git mem: allocate in reverse to reduce fragmentation Currently, all hugepages are allocated from lower VA address to higher VA address, while malloc heap allocates from higher VA address to lower VA address. This results in heap fragmentation over time due to multiple reserves leaving small space below the allocated elements. Fix this by allocating VA memory from the top, thereby reducing fragmentation and lowering overall memory usage. Signed-off-by: Anatoly Burakov --- diff --git a/lib/librte_eal/linuxapp/eal/eal_memalloc.c b/lib/librte_eal/linuxapp/eal/eal_memalloc.c index 81c94d54e8..36278d9ee7 100644 --- a/lib/librte_eal/linuxapp/eal/eal_memalloc.c +++ b/lib/librte_eal/linuxapp/eal/eal_memalloc.c @@ -703,7 +703,8 @@ alloc_seg_walk(const struct rte_memseg_list *msl, void *arg) need = wa->n_segs; /* try finding space in memseg list */ - cur_idx = rte_fbarray_find_next_n_free(&cur_msl->memseg_arr, 0, need); + cur_idx = rte_fbarray_find_prev_n_free(&cur_msl->memseg_arr, + cur_msl->memseg_arr.len - 1, need); if (cur_idx < 0) return 0; start_idx = cur_idx;