Repository navigation
mm: support task heap - #22619
mm: support task heap#22619anjiahao1 wants to merge 7 commits into
Conversation
a1effc7 to
5f8c883
Compare
5f8c883 to
0df419f
Compare
|
0df419f to
9686103
Compare
|
The |
|
The |
9686103 to
df4ca23
Compare
Use MM_TASK_HEAP to control whether a task uses an internal task-specific heap.
Use MM_TASK_HEAPSIZE to define the default heap size for each task.
Additional APIs will be added later to assign a specific heap to a task
Each task will allocate its own task heap from the user heap.
The task heap is initialized when the task is initialized,
and the task's stack is allocated from the task heap.
The pthreads belonging to this task also use the task heap.
This ensures isolation between task heaps.
flat build and protect build can use task heap,
heap view like this:
|-kernal-|------------user heap----------------|
|-task A heap--||-task B heap--|-free-|
|-stack-|-heap-||-stack-|-heap-|
Next:
so if have mpu, We can change mpu region, when switch context,
it can protect task heap
Signed-off-by: anjiahao <anjiahao@xiaomi.com>
The heapsize travels from the spawn attributes into the task initialization so that the new group can size its heap accordingly. nxtask_init() keeps its existing signature for callers that do not pass a heap size, including the Espressif HAL glue that builds against a fixed third-party revision. nxtask_init_with_heapsize() is the entry point for callers that do. Signed-off-by: anjiahao <anjiahao@xiaomi.com>
The region needs to be added to the public user heap umm_addregion call when system starup, it mean add memroy to umm not task heap。 USR_HEAP is task heap when use CONFIG_TASK_HEAP Signed-off-by: anjiahao <anjiahao@xiaomi.com>
The builtin loader ignored the heapsize from the builtin table when CONFIG_MM_TASK_HEAP is enabled, so the task heap size configured in the app table was lost after loading. Copy builtin->heapsize to binp->heapsize so the loader creates the task with the configured heap size. Signed-off-by: anjiahao <anjiahao@xiaomi.com>
The init thread started by nx_start_application always uses the default task heap size. Add CONFIG_INIT_HEAPSIZE so boards can configure the init thread heap independently when MM_TASK_HEAP is enabled. Signed-off-by: anjiahao <anjiahao@xiaomi.com>
A task heapsize of zero now shares the user heap instead of carving and initializing a private one. MM_TASK_HEAP_DEFAULT_SIZE defaults to zero, so spawned tasks without an explicit heapsize share the user heap unless a board sets a nonzero default. group_heap_uninitialize never uninitializes the shared user heap, and task_fork keeps the parent's sharing choice for the child. Signed-off-by: anjiahao <anjiahao@xiaomi.com>
The environment belongs to the task information of the task it describes, which may not be the running task: nxtask_init() copies the environment of the parent. Under the task heap, allocate it from that task's heap rather than the heap of whichever task happens to be running. Signed-off-by: anjiahao <anjiahao@xiaomi.com>
df4ca23 to
a90b5a8
Compare
Summary
Add a per-task-group heap (
CONFIG_MM_TASK_HEAP). A task group may own aprivate heap carved from the user heap, and the user-space allocators
(
USR_HEAPviaumm_getheap()) switch to it for the running task. Theseries is ported from the Vela tree as a sequence of cherry-picks, with
the adaptations required by the current tree folded into the commits.
CONFIG_MM_TASK_HEAPwithMM_TASK_HEAP_DEFAULT_SIZEandMM_TASK_HEAP_DEFAULT_ALIGN. The default size is 0, which shares theuser heap; a board can configure a private default.
ta_heap;struct task_group_sgainstg_heap.group_allocate()sizes the heap, and avfork()childshares the heap of its parent.
group_malloc(),group_realloc(),group_zalloc(),group_free()and
umm_getheap()use the task heap.binfmt/builtinandposix_spawn()propagate the configuredheapsize to the new task.
nxtask_init()keeps its existingsignature, and the new
nxtask_init_with_heapsize()entry point isused by callers that have a heapsize, so out-of-tree callers such as
the pinned Espressif HAL glue keep building.
Impact
New option, disabled by default; existing configurations are unchanged.
Known limitations:
CONFIG_MM_KERNEL_HEAP) mayenable the option, otherwise the
kmm_*allocators would routekernel allocations into the task heap;
BUILD_KERNELis not supported yet;arch/arm64/src/common/arm64_addrenv_mpu.calready containsCONFIG_MM_TASK_HEAPblocks that were never compiled because thesymbol did not exist; enabling the option together with
ARCH_USE_MPUis not covered by this series;lifetime rework and is left for a follow-up.
Testing
cmakeforsim:nsh, and withmakeformps3-an547:nsh,mps3-an547:knshandmps3-an547:knshwithCONFIG_MM_TASK_HEAP=yandCONFIG_MM_TASK_HEAP_DEFAULT_SIZE=65536.makeforqemu-armv7a:citest_knsh(CONFIG_BUILD_KERNEL=y,task heap disabled) to cover the kernel-build path.
qemu-system-arm -M mps3-an547(protected build, kernel +user blob):
nshprompt andhellorun with a 64 KiB per-task heap,no assertion failures.
swapped (TX=49, RX=50) on QEMU 8.x; the defaults in the tree match the
ARM documentation and are left unchanged.