Skip to content

Commit 96c8a13

Browse files
committed
heap: try VMH when system heap is exhausted
This is a temporary measure before removing VMH and increasing the system heap for Linux configurations. Currently the system heap allocations can fail in cases when multiple (tyipcally more than 5) streams are started. These are rather extreme testing scenarios, unlikely to occur in real use-cases, but to give them a chance to succeed try to fall back to VMH in such cases. Signed-off-by: Guennadi Liakhovetski <guennadi.liakhovetski@linux.intel.com>
1 parent 158518d commit 96c8a13

1 file changed

Lines changed: 20 additions & 2 deletions

File tree

‎zephyr/lib/alloc.c‎

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -625,6 +625,13 @@ void *rmalloc_align(uint32_t flags, size_t bytes, uint32_t alignment)
625625
ptr = heap_alloc_aligned(heap, alignment, bytes);
626626
}
627627

628+
#if CONFIG_VIRTUAL_HEAP
629+
if (!ptr && heap == &sof_heap && virtual_buffers_heap) {
630+
tr_warn(&zephyr_tr, "system heap allocation of %zu failed, trying VMH", bytes);
631+
ptr = virtual_heap_alloc(virtual_buffers_heap, flags, bytes, alignment);
632+
}
633+
#endif
634+
628635
return ptr;
629636
}
630637
EXPORT_SYMBOL(rmalloc_align);
@@ -781,10 +788,21 @@ void *z_impl_sof_heap_alloc(struct k_heap *heap, uint32_t flags, size_t bytes,
781788
heap = &sof_heap;
782789
}
783790

791+
void *ptr;
792+
784793
if (flags & SOF_MEM_FLAG_COHERENT)
785-
return heap_alloc_aligned(heap, alignment, bytes);
794+
ptr = heap_alloc_aligned(heap, alignment, bytes);
795+
else
796+
ptr = (__sparse_force void *)heap_alloc_aligned_cached(heap, alignment, bytes);
786797

787-
return (__sparse_force void *)heap_alloc_aligned_cached(heap, alignment, bytes);
798+
#if CONFIG_VIRTUAL_HEAP
799+
if (!ptr && heap == &sof_heap && virtual_buffers_heap) {
800+
tr_warn(&zephyr_tr, "system heap allocation of %zu failed, trying VMH", bytes);
801+
ptr = virtual_heap_alloc(virtual_buffers_heap, flags, bytes, alignment);
802+
}
803+
#endif
804+
805+
return ptr;
788806
}
789807

790808
void z_impl_sof_heap_free(struct k_heap *heap, void *addr)

0 commit comments

Comments
 (0)