Skip to contentSkip to conversation

malloc: respect SIZE_HINT_ONLY when looking for the biggest free elem

PATCH In review Darek Stojaczyk 3 participants 3 messages Oct 7, 2018 – Oct 28, 2018

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 malloc: respect SIZE_HINT_ONLY when looking for the biggest free elem

RTE_MEMZONE_SIZE_HINT_ONLY wasn't checked in any way, causing size hints to be parsed as hard requirements. This resulted in some allocations being failed prematurely.

Fixes 68b6092bd3c7 ("malloc: allow reserving biggest element")
---
 lib/librte_eal/common/malloc_heap.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
lib/librte_eal/common/malloc_heap.c +3 -1
index ac7bbb3ba..d2a8bd8dc 100644
@@ -165,7 +165,9 @@ find_biggest_element(struct malloc_heap *heap, size_t *size,
 		for (elem = LIST_FIRST(&heap->free_head[idx]);
 				!!elem; elem = LIST_NEXT(elem, free_list)) {
 			size_t cur_size;
-			if (!check_hugepage_sz(flags, elem->msl->page_sz))
+			if ((flags & RTE_MEMZONE_SIZE_HINT_ONLY) == 0 &&
+					!check_hugepage_sz(flags,
+						elem->msl->page_sz))
 				continue;
 			if (contig) {
 				cur_size =
Signature · 1 line
2.17.1
Reviewed-by on v1 1/1
#1 lore raw
Quoted 18 lines · Darek Stojaczyk

RTE_MEMZONE_SIZE_HINT_ONLY wasn't checked in any way, causing size hints to be parsed as hard requirements. This resulted in some allocations being failed prematurely.

Fixes 68b6092bd3c7 ("malloc: allow reserving biggest element")
---
  lib/librte_eal/common/malloc_heap.c | 4 +++-
  1 file changed, 3 insertions(+), 1 deletion(-)
lib/librte_eal/common/malloc_heap.c +0 -0
index ac7bbb3ba..d2a8bd8dc 100644

lib/librte_eal/common/malloc_heap.c find_biggest_element(struct malloc_heap *heap, size_t *size, · line 171

Quoted 8 lines
lib/librte_eal/common/malloc_heap.c +3 -1
@@ -165,7 +165,9 @@ find_biggest_element(struct malloc_heap *heap, size_t *size,
  		for (elem = LIST_FIRST(&heap->free_head[idx]);
  				!!elem; elem = LIST_NEXT(elem, free_list)) {
  			size_t cur_size;
-			if (!check_hugepage_sz(flags, elem->msl->page_sz))
+			if ((flags & RTE_MEMZONE_SIZE_HINT_ONLY) == 0 &&
+					!check_hugepage_sz(flags,
+						elem->msl->page_sz))
  				continue;

Although to be frank, the whole concept of "reserving biggest available memzone" is currently broken because of dynamic memory allocation. There is currently no way to allocate "as many hugepages as you can", so we're only looking at memory already allocated, which in the general case is less than page size long (unless you use legacy mode or memory preallocation switches).

Signature · 2 lines
Thanks,
Anatoly
#2 lore raw

08/10/2018 11:02, Burakov, Anatoly:

Quoted 30 lines · Darek Stojaczyk
Quoted 18 lines

RTE_MEMZONE_SIZE_HINT_ONLY wasn't checked in any way, causing size hints to be parsed as hard requirements. This resulted in some allocations being failed prematurely.

Fixes 68b6092bd3c7 ("malloc: allow reserving biggest element")
---
  lib/librte_eal/common/malloc_heap.c | 4 +++-
  1 file changed, 3 insertions(+), 1 deletion(-)
lib/librte_eal/common/malloc_heap.c +0 -0
index ac7bbb3ba..d2a8bd8dc 100644

lib/librte_eal/common/malloc_heap.c find_biggest_element(struct malloc_heap *heap, size_t *size, · line 171

Quoted 8 lines
lib/librte_eal/common/malloc_heap.c +3 -1
@@ -165,7 +165,9 @@ find_biggest_element(struct malloc_heap *heap, size_t *size,
  		for (elem = LIST_FIRST(&heap->free_head[idx]);
  				!!elem; elem = LIST_NEXT(elem, free_list)) {
  			size_t cur_size;
-			if (!check_hugepage_sz(flags, elem->msl->page_sz))
+			if ((flags & RTE_MEMZONE_SIZE_HINT_ONLY) == 0 &&
+					!check_hugepage_sz(flags,
+						elem->msl->page_sz))
  				continue;
Quoted 6 lines

Although to be frank, the whole concept of "reserving biggest available memzone" is currently broken because of dynamic memory allocation. There is currently no way to allocate "as many hugepages as you can", so we're only looking at memory already allocated, which in the general case is less than page size long (unless you use legacy mode or memory preallocation switches).

Applied anyway, thanks