Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 20 additions & 2 deletions zephyr/lib/alloc.c
Original file line number Diff line number Diff line change
Expand Up @@ -625,6 +625,13 @@ void *rmalloc_align(uint32_t flags, size_t bytes, uint32_t alignment)
ptr = heap_alloc_aligned(heap, alignment, bytes);
}

#if CONFIG_VIRTUAL_HEAP
if (!ptr && heap == &sof_heap && virtual_buffers_heap) {
tr_warn(&zephyr_tr, "system heap allocation of %zu failed, trying VMH", bytes);
ptr = virtual_heap_alloc(virtual_buffers_heap, flags, bytes, alignment);

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's not very obvious how the free is matched, but it seems this is ok as rfree() does a "is_virtual_heap_pointer(ptr)". If you need to respin, maybe worth a comment (not a showstopper, rfree() is in the same file, so people can look it up as well).

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

rballoc()s counterpart is rfree() - that's universal, and of course not a single bit confusing ;-)

}
#endif

return ptr;
}
EXPORT_SYMBOL(rmalloc_align);
Expand Down Expand Up @@ -781,10 +788,21 @@ void *z_impl_sof_heap_alloc(struct k_heap *heap, uint32_t flags, size_t bytes,
heap = &sof_heap;
}

void *ptr;

if (flags & SOF_MEM_FLAG_COHERENT)
return heap_alloc_aligned(heap, alignment, bytes);
ptr = heap_alloc_aligned(heap, alignment, bytes);
else
ptr = (__sparse_force void *)heap_alloc_aligned_cached(heap, alignment, bytes);

return (__sparse_force void *)heap_alloc_aligned_cached(heap, alignment, bytes);
#if CONFIG_VIRTUAL_HEAP
if (!ptr && heap == &sof_heap && virtual_buffers_heap) {
tr_warn(&zephyr_tr, "system heap allocation of %zu failed, trying VMH", bytes);
ptr = virtual_heap_alloc(virtual_buffers_heap, flags, bytes, alignment);
}
#endif

return ptr;
}

void z_impl_sof_heap_free(struct k_heap *heap, void *addr)
Expand Down
Loading