diff mbox series

[RFC,07/14] fork: use the first page in stack to store vm_stack in cached_stacks

Message ID 20240311164638.2015063-8-pasha.tatashin@soleen.com (mailing list archive)
State New
Headers show
Series Dynamic Kernel Stacks | expand

Commit Message

Pasha Tatashin March 11, 2024, 4:46 p.m. UTC
vmap stack are stored in a per-cpu cache_stacks in order to reduce
number of allocations and free calls. However, the stacks ared stored
using the buttom address of the stack. Since stacks normally grow down,
this is a problem with dynamic stacks, as the lower pages might not
even be allocated. Instead of the first available page from vm_area.

Signed-off-by: Pasha Tatashin <pasha.tatashin@soleen.com>
---
 kernel/fork.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)
diff mbox series

Patch

diff --git a/kernel/fork.c b/kernel/fork.c
index 41e0baee79d2..3004e6ce6c65 100644
--- a/kernel/fork.c
+++ b/kernel/fork.c
@@ -217,9 +217,10 @@  static void thread_stack_free_rcu(struct rcu_head *rh)
 
 static void thread_stack_delayed_free(struct task_struct *tsk)
 {
-	struct vm_stack *vm_stack = tsk->stack;
+	struct vm_struct *vm_area = tsk->stack_vm_area;
+	struct vm_stack *vm_stack = page_address(vm_area->pages[0]);
 
-	vm_stack->stack_vm_area = tsk->stack_vm_area;
+	vm_stack->stack_vm_area = vm_area;
 	call_rcu(&vm_stack->rcu, thread_stack_free_rcu);
 }