Conversation
Add vmh_log_alloc_stats() which prints only a single-line summary of total allocated/free bytes; call it on every successful allocation in virtual_heap_alloc() instead of the verbose vmh_log_stats(). Both functions are compiled only when CONFIG_SYS_MEM_BLOCKS_RUNTIME_STATS is set. This matches the debug capability in place for plain heap allocs. Signed-off-by: Kai Vehmanen <kai.vehmanen@linux.intel.com>
Add a single-line LOG_INF to z_impl_vregion_alloc_align() reporting the lifetime allocator's used and free bytes after each successful allocation. Gated on CONFIG_SYS_HEAP_RUNTIME_STATS. Signed-off-by: Kai Vehmanen <kai.vehmanen@linux.intel.com>
Add a debug overlay file to enable alloc heap debugging, with prints of memory usage via logging subsystem. This is added as a separate file as this creates a notable increase in logging traffic and is not something one wants enabled in all builds (e.g. depends on the logging backend bandwidth). Signed-off-by: Kai Vehmanen <kai.vehmanen@linux.intel.com>
There was a problem hiding this comment.
Copilot review overview
🟡 Changes recommended
Invalid vregion states can query uninitialized heap metadata, and the overlay does not reliably enable its INFO-level logs.
Review effort: Balanced
Findings: 3
Open (4)
What changed in this PR
Adds allocation-time diagnostics across SOF heap implementations and a unified debugging overlay.
Changes:
- Logs vregion allocation statistics.
- Adds aggregate virtual-heap usage logging after allocations.
- Provides an overlay enabling runtime heap statistics.
| File | Description |
|---|---|
zephyr/lib/vregion.c |
Logs lifetime and interim heap usage. |
zephyr/lib/regions_mm.c |
Aggregates virtual-heap allocator statistics. |
zephyr/lib/alloc.c |
Logs statistics after virtual-heap allocations. |
zephyr/include/sof/lib/regions_mm.h |
Declares the statistics helper. |
app/debug_heap_allocs.conf |
Enables runtime statistics options. |
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
| CONFIG_SYS_HEAP_RUNTIME_STATS=y | ||
| CONFIG_SYS_MEM_BLOCKS_RUNTIME_STATS=y |
| #if CONFIG_SYS_HEAP_RUNTIME_STATS | ||
| if (vr->type == VREGION_MEM_TYPE_LIFETIME) { | ||
| LOG_INF("lifetime alloc of %zu, used %zu, free %zu", | ||
| size, vr->lifetime.used, | ||
| vr->lifetime.size - vr->lifetime.used); |
| } else { | ||
| struct sys_memory_stats stats; | ||
|
|
||
| sys_heap_runtime_stats_get(&vr->interim.heap.heap, &stats); |
| heap->logged = true; | ||
| } | ||
|
|
||
| void vmh_log_alloc_stats(struct vmh_heap *heap) |
PR 11264: test resultsRun date: 2026-10-05 10:11 UTC Tested commit: b5363b4af9edfd891b15fa66ec0f0d048d20ab88 |
| } else { | ||
| struct sys_memory_stats stats; | ||
|
|
||
| sys_heap_runtime_stats_get(&vr->interim.heap.heap, &stats); | ||
|
|
||
| LOG_INF("interim alloc of %zu, used %u, free %u, max %u", | ||
| size, stats.allocated_bytes, stats.free_bytes, stats.max_allocated_bytes); | ||
|
|
||
| } |
There was a problem hiding this comment.
Is it possible to get here with vr->type == VREGION_MEM_TYPE_INVALID? switch in line 503 suggests so. In that case these structures are probably not correctly populated.
| struct sys_memory_stats stats; | ||
|
|
||
| sys_heap_runtime_stats_get(&vr->interim.heap.heap, &stats); | ||
|
|
||
| LOG_INF("interim alloc of %zu, used %u, free %u, max %u", | ||
| size, stats.allocated_bytes, stats.free_bytes, stats.max_allocated_bytes); |
There was a problem hiding this comment.
sys_heap_runtime_stats_get can return -EINVAL. You can initialize stats to avoid printing garbage in the log.


A series to help debugging heap usage issues. We already have infra to print logs for each alloc, but these were not documented for developers and didn't cover all the heaps (especially not newer "virtual heap" and "vregion").
This series add similar debugging for all major heap implementations (print out usage stats at each alloc), and adds an overlay to enable these all with a single overlay file.