diff --git a/zephyr/lib/regions_mm.c b/zephyr/lib/regions_mm.c index f60f8875a1c9..94e39a0910e6 100644 --- a/zephyr/lib/regions_mm.c +++ b/zephyr/lib/regions_mm.c @@ -617,6 +617,16 @@ int vmh_free(struct vmh_heap *heap, void *ptr) if (retval) return retval; + /* 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. The cache is invalidated by the + * sys_mm_drv_unmap_region function, when a memory page is unmapped. There is no need to + * invalidate it when releasing buffers of at least a page in size. + */ + if (size_to_free < CONFIG_MM_DRV_PAGE_SIZE) + sys_cache_data_invd_range(ptr, size_to_free); + return vmh_unmap_region(heap->physical_blocks_allocators[mem_block_iter], ptr, size_to_free); }