Skip to content

dax: set instance lifespan from prepare to reset#10526

Open
checkupup wants to merge 1 commit intothesofproject:mainfrom
checkupup:main_dax_alloc
Open

dax: set instance lifespan from prepare to reset#10526
checkupup wants to merge 1 commit intothesofproject:mainfrom
checkupup:main_dax_alloc

Conversation

@checkupup
Copy link
Contributor

At present, dax instance is initialized and allocated inner buffer on module_init(), and released on module_free(). The memory requirement for the inner buffer per instance is quite large.

The existing implementation has 2 pipelines containing dax. Even though the host is restricted from processing stream on both pipelines simultaneously, they may coexist with each other under some circumstances e.g. the interim when switching PCM device from one to the other, which may drain out the memory.

This commit changes the timing of instance allocation/deallocation to module_prepare()/reset() respectively. That is, dax instance only occupies the inner buffer memory when processing.

@checkupup
Copy link
Contributor Author

PR that references #10503

@sofci
Copy link
Collaborator

sofci commented Feb 6, 2026

Can one of the admins verify this patch?

reply test this please to run this test once

At present, dax instance is initialized and allocated inner buffer
on module_init(), and released on module_free(). The memory
requirement for the inner buffer per instance is quite large.

The existing implementation has 2 pipelines containing dax. Even
though the host is restricted from processing stream on both
pipelines simultaneously, they may coexist with each other under some
circumstances e.g. the interim when switching PCM device from one to
the other, which may drain out the memory.

This commit changes the timing of instance allocation/deallocation to
module_prepare()/reset() respectively. That is, dax instance only
occupies the inner buffer memory when processing.

Signed-off-by: Johny Lin <johnylin@google.com>
Copy link
Contributor

@johnylin76 johnylin76 left a comment

Choose a reason for hiding this comment

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

LGTM in overall. please help to test them.

struct sof_dax *dax_ctx = module_get_private_data(mod);

/* dax instance will be established on prepare(), and destroyed on reset() */
destroy_instance(mod);
Copy link
Contributor

Choose a reason for hiding this comment

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

maybe also add if (dax_ctx) check to protect these lines

although I'm not sure if it can be reached. We can always be safe.

comp_err(dev, "dax instance initialization failed, ret %d", ret);
goto err;
}
dax_ctx->update_flags |= DAX_ENABLE_MASK;
Copy link
Contributor

Choose a reason for hiding this comment

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

recommend to add a comment here

/* set DAX_ENABLE_MASK bit to trigger the fully update of kcontrol values */

@lgirdwood
Copy link
Member

@checkupup @johnylin76 I think we need to consider that DSPs are quite memory constrained devices and the asynchronous nature of PCM/pipeline creation/destruction within ALSA can easily lead to us with some heap fragmentation, especially when we need to allocate very large continuous buffers (and we had this problem with the key phrase buffer).

e.g. please consider

  1. User plays audio to endpoint 1 with DAX instance 1
  2. User selects endpoint2 with DAX instance 2, DAX 1 then frees memory.
  3. Asynchronous audio event occurs before DAX 2 PCM is ready e.g. incoming call, system notification and allocates memory resources for its pipeline.
  4. DAX instance 2 attempts to allocate large continuous buffer and fails due to event 3 fragmenting heap.

If we can allocate the DAX memory resources at init() (by the 1st DAX instance) and then pass/share the resources between DAX instances then we dont have to worry about the heap fragmentation and other audio events.

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.

4 participants