Skip to content

Conversation

@softwarecki
Copy link
Collaborator

Platforms based on xtensa have a non-coherent cache between cores. Before releasing a memory block, it is necessary to invalidate the cache. This memory block can be allocated by another core and performing cache writeback by the previous owner will destroy current content of the main memory.

Invalidate cache when freeing allocated memory block.

The memory block allocated by the allocator may be larger than a requested one. If the allocated block size exceeds the memory page size, only enough pages are mapped to satisfy the request. Thanks to this optimization, it don't map memory pages that will not be used. When freeing memory, the allocator knows only size of the allocated block. Information about the
number of pages actually mapped isn't stored anywhere.

Before unmapping memory, determine the number of mapped pages to avoid error when trying to unmap unmapped memory.

Platforms based on xtensa have a non-coherent cache between cores. Before
releasing a memory block, it is necessary to invalidate the cache. This
memory block can be allocated by another core and performing cache
writeback by the previous owner will destroy current content of the main
memory.

Invalidate cache when freeing allocated memory block.

Signed-off-by: Adrian Warecki <adrian.warecki@intel.com>
Copy link
Member

@lgirdwood lgirdwood left a comment

Choose a reason for hiding this comment

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

@softwarecki LGTM (just have an open on naming) , btw do we need to perform any cache operation on the heap region metadata after the free() ?
@andyross pls review.

@softwarecki
Copy link
Collaborator Author

@lgirdwood:

cache operation on the heap region metadata

Metadata is stored in a separate location, not in a unallocated memory.
But it is a very good point!!! I'm afraid all book keeping should be placed in non-cacheable memory or use cache invalidate/flush... It smells like a more changes is coming...

The memory block allocated by the allocator may be larger than a requested
one. If the allocated block size exceeds the memory page size, only enough
pages are mapped to satisfy the request. Thanks to this optimization, it
don't map memory pages that will not be used. When freeing memory,
the allocator knows only size of the allocated block. Information about the
number of pages actually mapped isn't stored anywhere.

Before unmapping memory, determine the number of mapped pages to avoid
error when trying to unmap unmapped memory.

Signed-off-by: Adrian Warecki <adrian.warecki@intel.com>
@softwarecki softwarecki marked this pull request as ready for review October 4, 2024 12:01
Copy link
Contributor

@tmleman tmleman left a comment

Choose a reason for hiding this comment

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

LGTM, I would only consider whether it's worth using the CONFIG_INCOHERENT config here.

@kv2019i
Copy link
Collaborator

kv2019i commented Oct 7, 2024

Ready to go when CI passes, @softwarecki can you check the Intel internal CI fail?

@softwarecki
Copy link
Collaborator Author

SOFCI TEST

@kv2019i kv2019i merged commit eaddf53 into thesofproject:main Oct 8, 2024
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.

5 participants