malloc: fix storage size for some allocations

The amount of memory to allocate from the system for heap expansion
was calculated in a way that may yield one page more than needed.
This could hit the allocation limit from the system or EAL.
The allocation would fail despite enough memory being available.

In response to mail:
https://inbox.dpdk.org/dev/CAEYuUWCnRZNwxiOHEeTHw0Gy9aFJRLZtvAG9g=smuUvUEMcFXg@mail.gmail.com/

A reproducer has been provided by Dmitry, see:
https://inbox.dpdk.org/dev/20220922015212.03bfde66@sovereign/

Fixes: 07dcbfe010 ("malloc: support multiprocess memory hotplug")
Cc: stable@dpdk.org

Signed-off-by: Fidaullah Noonari <fidaullah.noonari@emumba.com>
Acked-by: Dmitry Kozlyuk <dmitry.kozliuk@gmail.com>
This commit is contained in:
Fidaullah Noonari 2022-07-28 14:41:03 +05:00 committed by David Marchand
parent 479c2b1b5f
commit f92b9ebed0
2 changed files with 2 additions and 2 deletions

View File

@ -402,7 +402,7 @@ try_expand_heap_primary(struct malloc_heap *heap, uint64_t pg_sz,
int n_segs;
bool callback_triggered = false;
alloc_sz = RTE_ALIGN_CEIL(align + elt_size +
alloc_sz = RTE_ALIGN_CEIL(RTE_ALIGN_CEIL(elt_size, align) +
MALLOC_ELEM_OVERHEAD, pg_sz);
n_segs = alloc_sz / pg_sz;

View File

@ -250,7 +250,7 @@ handle_alloc_request(const struct malloc_mp_req *m,
return -1;
}
alloc_sz = RTE_ALIGN_CEIL(ar->align + ar->elt_size +
alloc_sz = RTE_ALIGN_CEIL(RTE_ALIGN_CEIL(ar->elt_size, ar->align) +
MALLOC_ELEM_OVERHEAD, ar->page_sz);
n_segs = alloc_sz / ar->page_sz;