Skip to content

Conversation

@lyakh
Copy link
Collaborator

@lyakh lyakh commented Aug 21, 2025

Supposedly at least in the beginning we'll only want to move DP module allocations to private heaps, so this will be modified

@lgirdwood
Copy link
Member

@lyakh PR title should be per user domain heap rather then per module and we can define which module belong in which domain via topology.

@lyakh lyakh changed the title [DRAFT][WiP] per module heap [DRAFT][WiP] per user domain heap Aug 21, 2025
Jyri Sarha and others added 18 commits August 22, 2025 16:24
Do not allocate module memory containers one by one, but allocate them
in chunks.

The bookkeeping of allocated resources is done using containers that
are allocated from heap. This effectively doubles the amount of heap
allocations. This is not very efficient especially since the containers
are only 20 bytes in size.

This commit changes the allocation of containers so that they are
always allocated in chunks of 16 containers, or what is selected with
MODULE_MEMORY_API_CONTAINER_CHUNK_SIZE Kconfig option. The unused
containers are not freed when the associated resource is
freed. Instead the unused containers are kept in free containers
list. All the containers are freed when mod_free_all() is called, for
instance when the module unloads.

Signed-off-by: Jyri Sarha <jyri.sarha@linux.intel.com>
Add heap usage high water mark to module_adapter_heap_usage() and
shell's "sof module_heap_usage" command.

Signed-off-by: Jyri Sarha <jyri.sarha@linux.intel.com>
Add src/audio/data_blob.c to mixer cmocka test sources to fix the
dependency problem from adding comp_data_blob_handler_new_ext() to
audio/module_adapter/module/generic.c.

Signed-off-by: Jyri Sarha <jyri.sarha@linux.intel.com>
Add mod_data_blob_handler_new() to module API. The function is
otherwise the same as comp_data_blob_handler_new(), but it takes a
module pointer as the first argument, and the blob handler is
automatically freed when the module unloads.

The handler allocated with mod_data_blob_handler_new() should not be
freed with comp_data_blob_handler_free(), mod_data_blob_handler_free()
should be used.

Signed-off-by: Jyri Sarha <jyri.sarha@linux.intel.com>
Add module API versions of fast_get() and fast_put(). The SRAM copies
reserved with mod_fast_get() are released automatically when the
module unloads, and those SRAM copies should not be freed with the
regular fast_put().

Signed-off-by: Jyri Sarha <jyri.sarha@linux.intel.com>
Add safeguard to mod_alloc() and friends that checks that they are
always called from the same thread (e.g. no locking needed).

The checking code has to be also behind defined(__ZEPHYR__) to keep
cmocka tests working.

Signed-off-by: Jyri Sarha <jyri.sarha@linux.intel.com>
Take mod_fast_get() and mod_fast_put() into use.

Signed-off-by: Jyri Sarha <jyri.sarha@linux.intel.com>
Allocate all memory through module API mod_alloc() and friends
and remove all redundant rfree() calls from module unload
functions and init error branches.

Signed-off-by: Jyri Sarha <jyri.sarha@linux.intel.com>
Allocate all memory, blob handlers, and fast_get() buffers through
module API mod_alloc() and friends and remove all redundant rfree(),
comp_data_blob_handler_free(), and fast_put() calls from module unload
functions and init error branches.

Signed-off-by: Jyri Sarha <jyri.sarha@linux.intel.com>
Allocate all memory through module API mod_alloc() and friends
and remove all redundant rfree() calls from module unload
functions and init error branches.

NOTE: copier_dai.c and copier_host.c still have their shared memory
allocated through the old API. This is to be fixed once we have
decided on how the shared memory allocations should work in
user-space.

Signed-off-by: Jyri Sarha <jyri.sarha@linux.intel.com>
Allocate all memory through module API mod_alloc() and friends
and remove all redundant rfree() calls from module unload
functions and init error branches.

Signed-off-by: Jyri Sarha <jyri.sarha@linux.intel.com>
Allocate all memory, blob handlers, and fast_get() buffers through
module API mod_alloc() and friends and remove all redundant rfree(),
comp_data_blob_handler_free(), and fast_put() calls from module unload
functions and init error branches.

Signed-off-by: Jyri Sarha <jyri.sarha@linux.intel.com>
Allocate all memory, blob handlers, and fast_get() buffers through
module API mod_alloc() and friends and remove all redundant rfree(),
comp_data_blob_handler_free(), and fast_put() calls from module unload
functions and init error branches.

Signed-off-by: Jyri Sarha <jyri.sarha@linux.intel.com>
Split comp_alloc() into two parts - allocation and initialisation to
be able to re-use the initialisation code with a different allocation
method.

Signed-off-by: Guennadi Liakhovetski <guennadi.liakhovetski@linux.intel.com>
Add sof_heap_alloc() and sof_heap_free() to allocate and free memory
on a private heap.

Signed-off-by: Guennadi Liakhovetski <guennadi.liakhovetski@linux.intel.com>
We want to be able to serve all module memory allocations from a
private heap. This commit creates such a heap for DP scheduled
modules and moves struct comp_dev and struct processing_module to it.

Signed-off-by: Guennadi Liakhovetski <guennadi.liakhovetski@linux.intel.com>
Move mod_alloc() allocations, including the container pool, to the
module local heap.

Signed-off-by: Guennadi Liakhovetski <guennadi.liakhovetski@linux.intel.com>
Stream parameters are only used by respective modules, move them to
the module's own heap.

Signed-off-by: Guennadi Liakhovetski <guennadi.liakhovetski@linux.intel.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants