newlib: clamp max heap size on MMU systems

Previously, newlib claimed all free physical memory in the
system.

Now, the kernel manages this, allowing for memory to be
used via k_mem_map() calls.

Establish an upper bound to how much newlib will try to
claim on system startup, instead of trying to take all
of it, allowing other parts of the system to also map
anonymous memory.

Signed-off-by: Andrew Boie <andrew.p.boie@intel.com>
This commit is contained in:
Andrew Boie 2021-01-14 10:35:51 -08:00 committed by Anas Nashif
commit e2b62b8abb
2 changed files with 12 additions and 1 deletions

View file

@ -52,6 +52,16 @@ config NEWLIB_LIBC_NANO
The newlib-nano library for ARM embedded processors is a part of the
GNU Tools for ARM Embedded Processors.
config NEWLIB_LIBC_MAX_MAPPED_REGION_SIZE
int "Maximum memory mapped for newlib heap"
depends on MMU
default 1048576
help
On MMU-based systems, indicates the maximum amount of memory which
will be used for the newlib malloc() heap. The actual amount of
memory used will be the minimum of this value and the amount of
free physical memory at kernel boot.
config NEWLIB_LIBC_ALIGNED_HEAP_SIZE
int "Newlib aligned heap size"
depends on MPU_REQUIRES_POWER_OF_TWO_ALIGNMENT

View file

@ -99,7 +99,8 @@ static int malloc_prepare(const struct device *unused)
ARG_UNUSED(unused);
#ifdef CONFIG_MMU
max_heap_size = k_mem_free_get();
max_heap_size = MIN(CONFIG_NEWLIB_LIBC_MAX_MAPPED_REGION_SIZE,
k_mem_free_get());
if (max_heap_size != 0) {
heap_base = k_mem_map(max_heap_size, K_MEM_PERM_RW);