* [PATCH v4] fork: Clean-up ifdef logic around stack allocation
@ 2025-06-18 13:34 Linus Walleij
0 siblings, 0 replies; only message in thread
From: Linus Walleij @ 2025-06-18 13:34 UTC (permalink / raw)
To: Andrew Morton, linux-mm, Pasha Tatashin, Mateusz Guzik; +Cc: Linus Walleij
From: Pasha Tatashin <pasha.tatashin@soleen.com>
There is unneeded OR in the ifdef functions that are used to allocate
and free kernel stacks based on direct map or vmap. Adding dynamic stack
support would complicate this logic even further.
Therefore, clean up by Changing the order so OR is no longer needed.
Signed-off-by: Pasha Tatashin <pasha.tatashin@soleen.com>
Link: https://lore.kernel.org/20240311164638.2015063-3-pasha.tatashin@soleen.com
Signed-off-by: Linus Walleij <linus.walleij@linaro.org>
---
This patch set consists of outtakes from a 1 year+ old
patch set from Pasha, which all stand on their own.
See:
https://lore.kernel.org/all/20240311164638.2015063-1-pasha.tatashin@soleen.com/
These are good cleanups for readability
so I split these off, rebased on v6.15-rc1, addressed review
comments and send them separately.
All mentions of dynamic stack are removed from the patch
set as we have no idea whether that will go anywhere.
This is mostly MM related so when the patches are ready
I expect they would land in Andrew's patch stack.
---
Changes in v4:
- Drop the two queued patches.
- Resend the remaining patch for the ifdef logic.
- Link to v3: https://lore.kernel.org/r/20250509-fork-fixes-v3-0-e6c69dd356f2@linaro.org
Changes in v3:
- Drop patches 3 and 5.
- Patch 3 probably only makes sense in the context of
implementing dynamic stack sizing.
- Patch 5 is better addressed after adding the per-arch helper
clear_pahes() to clear more than one page in a go, so I
will wait for this to happen and propose an updated version
at that point.
- Link to v2: https://lore.kernel.org/r/20250507-fork-fixes-v2-0-82ab1e42cde3@linaro.org
Changes in v2:
- Fix subject on patch 2/5
- Fix bisect problem in BUG() guard in patch 2/5
- Move back to using a local nr_pages variable in
patch 3/5 for performance concerns.
- Use preferred patch augment format.
- Link to v1: https://lore.kernel.org/r/20250506-fork-fixes-v1-0-bd35b63f0f1b@linaro.org
---
kernel/fork.c | 22 +++++++++++-----------
1 file changed, 11 insertions(+), 11 deletions(-)
diff --git a/kernel/fork.c b/kernel/fork.c
index 6616d173307a92a238fd5b8b74c97b90d551c968..bd8c21d64746163ef22baac6cf7e190fcaca3591 100644
--- a/kernel/fork.c
+++ b/kernel/fork.c
@@ -188,13 +188,7 @@ static inline void free_task_struct(struct task_struct *tsk)
kmem_cache_free(task_struct_cachep, tsk);
}
-/*
- * Allocate pages if THREAD_SIZE is >= PAGE_SIZE, otherwise use a
- * kmemcache based allocator.
- */
-# if THREAD_SIZE >= PAGE_SIZE || defined(CONFIG_VMAP_STACK)
-
-# ifdef CONFIG_VMAP_STACK
+#ifdef CONFIG_VMAP_STACK
/*
* vmalloc() is a bit slow, and calling vfree() enough times will force a TLB
* flush. Try to minimize the number of calls by caching stacks.
@@ -344,7 +338,13 @@ static void free_thread_stack(struct task_struct *tsk)
tsk->stack_vm_area = NULL;
}
-# else /* !CONFIG_VMAP_STACK */
+#else /* !CONFIG_VMAP_STACK */
+
+/*
+ * Allocate pages if THREAD_SIZE is >= PAGE_SIZE, otherwise use a
+ * kmemcache based allocator.
+ */
+#if THREAD_SIZE >= PAGE_SIZE
static void thread_stack_free_rcu(struct rcu_head *rh)
{
@@ -376,8 +376,7 @@ static void free_thread_stack(struct task_struct *tsk)
tsk->stack = NULL;
}
-# endif /* CONFIG_VMAP_STACK */
-# else /* !(THREAD_SIZE >= PAGE_SIZE || defined(CONFIG_VMAP_STACK)) */
+#else /* !(THREAD_SIZE >= PAGE_SIZE) */
static struct kmem_cache *thread_stack_cache;
@@ -416,7 +415,8 @@ void thread_stack_cache_init(void)
BUG_ON(thread_stack_cache == NULL);
}
-# endif /* THREAD_SIZE >= PAGE_SIZE || defined(CONFIG_VMAP_STACK) */
+#endif /* THREAD_SIZE >= PAGE_SIZE */
+#endif /* CONFIG_VMAP_STACK */
/* SLAB cache for signal_struct structures (tsk->signal) */
static struct kmem_cache *signal_cachep;
---
base-commit: cbc68827edcaac2df9aae2f58f9f6eb8a1256620
change-id: 20250504-fork-fixes-9378b6c57873
Best regards,
--
Linus Walleij <linus.walleij@linaro.org>
^ permalink raw reply [flat|nested] only message in thread
only message in thread, other threads:[~2025-06-18 13:34 UTC | newest]
Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2025-06-18 13:34 [PATCH v4] fork: Clean-up ifdef logic around stack allocation Linus Walleij
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox