Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

fork: define a local GFP_VMAP_STACK

The current allocation of VMAP stack memory is using (THREADINFO_GFP &
~__GFP_ACCOUNT) which is a complicated way of saying (GFP_KERNEL |
__GFP_ZERO):

<linux/thread_info.h>:
define THREADINFO_GFP (GFP_KERNEL_ACCOUNT | __GFP_ZERO)
<linux/gfp_types.h>:
define GFP_KERNEL_ACCOUNT (GFP_KERNEL | __GFP_ACCOUNT)

This is an unfortunate side-effect of independent changes blurring the
picture:

commit 19809c2da28aee5860ad9a2eff760730a0710df0 changed (THREADINFO_GFP |
__GFP_HIGHMEM) to just THREADINFO_GFP since highmem became implicit.

commit 9b6f7e163cd0f468d1b9696b785659d3c27c8667 then added stack caching
and rewrote the allocation to (THREADINFO_GFP & ~__GFP_ACCOUNT) as cached
stacks need to be accounted separately. However that code, when it
eventually accounts the memory does this:

ret = memcg_kmem_charge(vm->pages[i], GFP_KERNEL, 0)

so the memory is charged as a GFP_KERNEL allocation.

Define a unique GFP_VMAP_STACK to use
GFP_KERNEL | __GFP_ZERO and move the comment there.

Link: https://lkml.kernel.org/r/20250509-gfp-stack-v1-1-82f6f7efc210@linaro.org
Signed-off-by: Linus Walleij <linus.walleij@linaro.org>
Reported-by: Mateusz Guzik <mjguzik@gmail.com>
Cc: Pasha Tatashin <pasha.tatashin@soleen.com>
Cc: Mike Rapoport (Microsoft) <rppt@kernel.org>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>

authored by

Linus Walleij and committed by
Andrew Morton
f7b0ff2b 449e0b4e

+7 -6
+7 -6
kernel/fork.c
··· 201 201 */ 202 202 #define NR_CACHED_STACKS 2 203 203 static DEFINE_PER_CPU(struct vm_struct *, cached_stacks[NR_CACHED_STACKS]); 204 + /* 205 + * Allocated stacks are cached and later reused by new threads, so memcg 206 + * accounting is performed by the code assigning/releasing stacks to tasks. 207 + * We need a zeroed memory without __GFP_ACCOUNT. 208 + */ 209 + #define GFP_VMAP_STACK (GFP_KERNEL | __GFP_ZERO) 204 210 205 211 struct vm_stack { 206 212 struct rcu_head rcu; ··· 313 307 return 0; 314 308 } 315 309 316 - /* 317 - * Allocated stacks are cached and later reused by new threads, 318 - * so memcg accounting is performed manually on assigning/releasing 319 - * stacks to tasks. Drop __GFP_ACCOUNT. 320 - */ 321 310 stack = __vmalloc_node(THREAD_SIZE, THREAD_ALIGN, 322 - THREADINFO_GFP & ~__GFP_ACCOUNT, 311 + GFP_VMAP_STACK, 323 312 node, __builtin_return_address(0)); 324 313 if (!stack) 325 314 return -ENOMEM;