Skip to contentSkip to conversation

xen/malloc: handle correctly page allocation when align > size

PATCH Superseded Julien Grall 2 participants 3 messages Mar 7, 2014 – Mar 9, 2014

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 xen/malloc: handle correctly page allocation when align > size

When align is superior to size, we need to retrieve the order from align during multiple page allocation. I guess it was the goal of the commit fb034f42 "xmalloc: make close-to-PAGE_SIZE allocations more efficient".

---
 xen/common/xmalloc_tlsf.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
xen/common/xmalloc_tlsf.c +1 -1
index d3bdfa7..c957119 100644
@@ -531,7 +531,7 @@ static void *xmalloc_whole_pages(unsigned long size, unsigned long align)
     void *res, *p;
 
     if ( align > size )
-        get_order_from_bytes(align);
+        order = get_order_from_bytes(align);
 
     res = alloc_xenheap_pages(order, 0);
     if ( res == NULL )
Signature · 1 line
1.8.5.3
Reviewed-by on v1 1/1
#1 lore raw
Quoted 4 lines
Quoted 1 line
Quoted 1 line · Julien Grall

When align is superior to size, we need to retrieve the order from align during multiple page allocation. I guess it was the goal of the commit fb034f42 "xmalloc: make close-to-PAGE_SIZE allocations more efficient".

Oh, yes, of course it was. Without that the call is pointless.

Quoted 1 line

Albeit in fact the better change might be to simply use max(size, align) in the initializer of order - no idea why I didn't do it that way.

Out of curiosity: I never expected this code path to be actually taken - what is it that you need this to work correctly?

Jan

Quoted 11 lines
xen/common/xmalloc_tlsf.c +1 -1
@@ -531,7 +531,7 @@ static void *xmalloc_whole_pages(unsigned long size, unsigned long align)
     void *res, *p;
 
     if ( align > size )
-        get_order_from_bytes(align);
+        order = get_order_from_bytes(align);
 
     res = alloc_xenheap_pages(order, 0);
     if ( res == NULL )
#2 lore raw
Quoted 7 lines · Jan Beulich
Quoted 4 lines
Quoted 1 line
Quoted 1 line · Julien Grall

When align is superior to size, we need to retrieve the order from align during multiple page allocation. I guess it was the goal of the commit fb034f42 "xmalloc: make close-to-PAGE_SIZE allocations more efficient".

Oh, yes, of course it was. Without that the call is pointless.

Quoted 7 lines
Quoted 1 line

Albeit in fact the better change might be to simply use max(size, align) in the initializer of order - no idea why I didn't do it that way.

I can send a new version of this page to use max.

Quoted 2 lines

Out of curiosity: I never expected this code path to be actually taken - what is it that you need this to work correctly?

I was looking to the code to decide if the best solution is to use xmalloc or alloc_xenheap_pages directly.

Signature · 1 line
Julien Grall