v1
2026-09-29
arm64 内核栈大小命令行配置 · v1
为 arm64 增加 cmdline 参数配置内核栈大小,默认 16KB 栈在 4K 页下可占用约 100MB,调小可减少内核内存占用。
原始补丁链接
子 Patch(15)
1/15
fork: Remove assumption that vm_area->nr_pages equals to THREAD_SIZE
删除 fork 中“栈页数必为 THREAD_SIZE/PAGE_SIZE”的 BUG_ON,改用 vm_area->nr_pages 获取实际分配页数,为后续运行时可配且可能小于 THREAD_SIZE 的内核栈铺路。
2/15
fork: Don't assume fully populated stack during reuse
复用内核栈时不再假设 vm_area->nr_pages 等于 THREAD_SIZE,按实际已分配页清零;VA 范围仍为 THREAD_SIZE 但可能仅部分填充。
3/15
fork: Move vm_stack to the beginning of the stack
将用于 RCU 延迟释放的 vm_stack 结构固定放在栈起始处,不再依赖增长方向,避免部分分配栈上回调访问未映射页而 fault。
4/15
fork: Separate vmap stack allocation and free calls
把 vmap 内核栈的 VA 分配/释放与页表填充/拆除拆成独立函数,便于后续实现只填充部分页的栈。
5/15
sched/task_stack: Add helpers for stack high/low
新增 task_stack_low()/high()/size() 助手,隐藏 CONFIG_STACK_GROWSUP 与栈大小差异,替代直接使用 THREAD_SIZE 计算栈地址。
6/15
exit: Don't assume the kernel stack size
check_stack_usage() 改用 task_stack_size() 计算栈使用率,不再假设已分配内核栈等于 THREAD_SIZE。
7/15
usercopy: Don't assume the kernel stack size
check_stack_object() 用 task_stack_low()/task_stack_high() 判断对象是否位于内核栈,不再用 THREAD_SIZE 推算范围。
8/15
mm: kmemleak: Don't assume the kernel stack size
kmemleak_scan_task_stacks() 改用 task_stack_low()/high() 扫描内核栈,避免按 THREAD_SIZE 扫描部分分配栈时越界。
9/15
arm64: Don't assume the kernel stack size
arm64 栈回溯与 panic 代码改用 task_stack_low()/high() 确定内核栈边界,不再假设栈大小为 THREAD_SIZE。
10/15
mm/vmalloc: Add a get_vm_area_node()
新增 get_vm_area_node(),允许调用者指定分配 vm_struct 的 node 和 VA 对齐,供部分填充内核栈预留大于实际映射内存的虚拟地址空间。
11/15
fork: Move vmap stack freeing to work queue
将未进栈缓存的 vmap 栈释放从 call_rcu() 改为 system_percpu_wq 工作队列,使 remove_vm_area() 可在可睡眠上下文执行,为释放部分填充栈做准备。
12/15
sched/task_stack: Introduce ARCH_HAS_VARIABLE_STACK_SIZE
When CONFIG_ARCH_HAS_VARIABLE_STACK_SIZE is enabled, the kernel stack may not be fully populated with the THREAD_SIZE virtual area. Teach task_stack_size() to return the size of the vm area and not a
13/15
fork: Implement partial VMAP stack allocation
When CONFIG_ARCH_HAS_VARIABLE_STACK_SIZE is enabled, architectures can allocate a VMAP stack that is smaller than the full THREAD_SIZE. This introduces arch abstraction arch_vm_stack_pages() which de
14/15
arm64: mm: Relax kernel stack alignment
On the kernel entry it was not possible to use the stack until it was checked for overflow which was done by a clever trick relying on aligning the kernel stack to double it’s size, so if the bit at T
15/15
arm64: mm: Set stack size from the kernel command line
Select CONFIG_ARCH_HAS_VARIABLE_STACK_SIZE for arm64 and override arch_vm_stack_pages() to a value set from the command line, this value have the following properties: - Aligned to page size (doesn’t