fix(heap): revert DMA pool MALLOC_CAP_DEFAULT caps

This commit is contained in:
wuzhenghui
2026-08-27 19:46:48 +08:00
parent d41a3436b1
commit 68eea51d27
6 changed files with 31 additions and 26 deletions

View File

@@ -104,7 +104,7 @@ config SPIRAM_MALLOC_RESERVE_INTERNAL
that the internal memory is entirely filled up. This causes allocations that are specifically done in
internal memory, for example the stack for new tasks or memory to service DMA or have memory that's
also available when SPI cache is down, to fail. This option reserves a pool specifically for requests
like that; a normal malloc() can fall back to the pool only after all other internal are exhausted.
like that; the memory in this pool is not given out when a normal malloc() is called.
Set this to 0 to disable this feature.

View File

@@ -488,7 +488,7 @@ esp_err_t esp_psram_extram_reserve_dma_pool(size_t size)
return ESP_ERR_NO_MEM;
}
uint32_t caps[] = {0, MALLOC_CAP_DMA | MALLOC_CAP_INTERNAL, MALLOC_CAP_DEFAULT | MALLOC_CAP_8BIT | MALLOC_CAP_32BIT};
uint32_t caps[] = {0, MALLOC_CAP_DMA | MALLOC_CAP_INTERNAL, MALLOC_CAP_8BIT | MALLOC_CAP_32BIT};
esp_err_t e = heap_caps_add_region_with_caps(caps, (intptr_t)dma_heap, (intptr_t)dma_heap + next_size - 1);
if (e != ESP_OK) {
return e;

View File

@@ -1,5 +1,5 @@
/*
* SPDX-FileCopyrightText: 2022-2026 Espressif Systems (Shanghai) CO LTD
* SPDX-FileCopyrightText: 2022-2025 Espressif Systems (Shanghai) CO LTD
*
* SPDX-License-Identifier: Apache-2.0
*/
@@ -37,11 +37,6 @@ esp_err_t esp_psram_extram_add_to_heap_allocator(void);
/**
* @brief Reserve a pool of internal memory for specific DMA/internal allocations
*
* Carves out @p size bytes from the regular internal heaps and registers the
* region as separate heap pool with new priority-based caps: medium priority for
* MALLOC_CAP_DMA | MALLOC_CAP_INTERNAL, and low priority for MALLOC_CAP_DEFAULT.
* malloc() uses the pool only after other internal heaps are exhausted.
*
* @param size Size of reserved pool in bytes
*
* @return

View File

@@ -1,5 +1,5 @@
/*
* SPDX-FileCopyrightText: 2022-2026 Espressif Systems (Shanghai) CO LTD
* SPDX-FileCopyrightText: 2022-2023 Espressif Systems (Shanghai) CO LTD
*
* SPDX-License-Identifier: Unlicense OR CC0-1.0
*/
@@ -64,6 +64,30 @@ TEST_CASE("Malloc/overwrite, then free all available DRAM", "[heap]")
TEST_ASSERT(m1==m2);
}
#if CONFIG_SPIRAM_USE_MALLOC
#if (CONFIG_SPIRAM_MALLOC_RESERVE_INTERNAL > 1024)
TEST_CASE("Check if reserved DMA pool still can allocate even when malloc()'ed memory is exhausted", "[heap]")
{
char** dmaMem=malloc(sizeof(char*)*512);
assert(dmaMem);
int m=tryAllocMem();
int i=0;
for (i=0; i<512; i++) {
dmaMem[i]=heap_caps_malloc(1024, MALLOC_CAP_DMA);
if (dmaMem[i]==NULL) break;
}
for (int j=0; j<i; j++) free(dmaMem[j]);
free(dmaMem);
tryAllocMemFree();
printf("Could allocate %dK of DMA memory after allocating all of %dK of normal memory.\n", i, m);
TEST_ASSERT(i);
}
#endif
#endif
/* As you see, we are desperately trying to outsmart the compiler, so that it
* doesn't warn about oversized allocations in the next two unit tests.
* To be removed when we switch to GCC 8.2 and add
@@ -152,7 +176,7 @@ TEST_CASE("test get allocated size", "[heap]")
const size_t aligned_size = (alloc_sizes[i] + 3) & ~3;
const size_t real_size = heap_caps_get_allocated_size(ptr_array[i]);
printf("initial size: %d, requested size : %d, allocated size: %d\n", alloc_sizes[i], aligned_size, real_size);
TEST_ASSERT(aligned_size <= real_size);
TEST_ASSERT_EQUAL(aligned_size, real_size);
heap_caps_free(ptr_array[i]);
}