Skip to content

Commit f7b0ff2

Browse files
linuswakpm00
authored andcommitted
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 19809c2 changed (THREADINFO_GFP | __GFP_HIGHMEM) to just THREADINFO_GFP since highmem became implicit. commit 9b6f7e1 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/[email protected] Signed-off-by: Linus Walleij <[email protected]> Reported-by: Mateusz Guzik <[email protected]> Cc: Pasha Tatashin <[email protected]> Cc: Mike Rapoport (Microsoft) <[email protected]> Signed-off-by: Andrew Morton <[email protected]>
1 parent 449e0b4 commit f7b0ff2

File tree

1 file changed

+7
-6
lines changed

1 file changed

+7
-6
lines changed

kernel/fork.c

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -201,6 +201,12 @@ static inline void free_task_struct(struct task_struct *tsk)
201201
*/
202202
#define NR_CACHED_STACKS 2
203203
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)
204210

205211
struct vm_stack {
206212
struct rcu_head rcu;
@@ -307,13 +313,8 @@ static int alloc_thread_stack_node(struct task_struct *tsk, int node)
307313
return 0;
308314
}
309315

310-
/*
311-
* Allocated stacks are cached and later reused by new threads,
312-
* so memcg accounting is performed manually on assigning/releasing
313-
* stacks to tasks. Drop __GFP_ACCOUNT.
314-
*/
315316
stack = __vmalloc_node(THREAD_SIZE, THREAD_ALIGN,
316-
THREADINFO_GFP & ~__GFP_ACCOUNT,
317+
GFP_VMAP_STACK,
317318
node, __builtin_return_address(0));
318319
if (!stack)
319320
return -ENOMEM;

0 commit comments

Comments
 (0)