[PATCH slab/for-next v2 06/14] kernel/fork: specify SLAB_MAY_ACCOUNT for thread_stack cache
Harry Yoo (Meta)
harry at kernel.org
Wed Nov 25 21:37:07 UTC 2026
When THREAD_SIZE < PAGE_SIZE, thread stacks are allocated from a slab
cache with THREADINFO_GFP, which includes __GFP_ACCOUNT. Specify
SLAB_MAY_ACCOUNT when the object may be charged to a memcg.
__GFP_ACCOUNT without SLAB_MAY_ACCOUNT will not be allowed.
Path (e.g. ppc64le, 64K pages, !VMAP_STACK): copy_process()
-> dup_task_struct() -> alloc_thread_stack_node()
-> kmem_cache_alloc_node(thread_stack_cache, THREADINFO_GFP)
Cc: Kees Cook <kees at kernel.org>
Cc: David Hildenbrand <david at kernel.org>
Cc: Lorenzo Stoakes <ljs at kernel.org>
Cc: "Liam R. Howlett" <liam at infradead.org>
Cc: Mike Rapoport <rppt at kernel.org>
Cc: Michal Hocko <mhocko at suse.com>
Cc: Ingo Molnar <mingo at redhat.com>
Cc: Peter Zijlstra <peterz at infradead.org>
Cc: Juri Lelli <juri.lelli at redhat.com>
Cc: Vincent Guittot <vincent.guittot at linaro.org>
Cc: Dietmar Eggemann <dietmar.eggemann at arm.com>
Cc: Steven Rostedt <rostedt at goodmis.org>
Cc: Ben Segall <bsegall at google.com>
Cc: Mel Gorman <mgorman at suse.de>
Cc: Valentin Schneider <vschneid at redhat.com>
Cc: K Prateek Nayak <kprateek.nayak at amd.com>
Signed-off-by: Harry Yoo (Meta) <harry at kernel.org>
---
kernel/fork.c | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)
diff --git a/kernel/fork.c b/kernel/fork.c
index 5efceb8d58a7..d0e49a81e7cf 100644
--- a/kernel/fork.c
+++ b/kernel/fork.c
@@ -459,7 +459,8 @@ static void free_thread_stack(struct task_struct *tsk)
void thread_stack_cache_init(void)
{
thread_stack_cache = kmem_cache_create_usercopy("thread_stack",
- THREAD_SIZE, THREAD_SIZE, 0, 0,
+ THREAD_SIZE, THREAD_SIZE,
+ SLAB_MAY_ACCOUNT, 0,
THREAD_SIZE, NULL);
BUG_ON(thread_stack_cache == NULL);
}
--
2.54.0
More information about the Linux-security-module-archive
mailing list