Skip to content

Commit d82893c

Browse files
soleenakpm00
authored andcommitted
fork: check charging success before zeroing stack
No need to do zero cached stack if memcg charge fails, so move the charging attempt before the memset operation. [[email protected]: rebased] Link: https://lkml.kernel.org/r/[email protected] Signed-off-by: Pasha Tatashin <[email protected]> Link: https://lore.kernel.org/[email protected] Signed-off-by: Linus Walleij <[email protected]> Acked-by: Mike Rapoport (Microsoft) <[email protected]> Signed-off-by: Andrew Morton <[email protected]>
1 parent 90eb270 commit d82893c

File tree

1 file changed

+5
-5
lines changed

1 file changed

+5
-5
lines changed

kernel/fork.c

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -280,6 +280,11 @@ static int alloc_thread_stack_node(struct task_struct *tsk, int node)
280280
if (!vm_area)
281281
continue;
282282

283+
if (memcg_charge_kernel_stack(vm_area)) {
284+
vfree(vm_area->addr);
285+
return -ENOMEM;
286+
}
287+
283288
/* Reset stack metadata. */
284289
kasan_unpoison_range(vm_area->addr, THREAD_SIZE);
285290

@@ -288,11 +293,6 @@ static int alloc_thread_stack_node(struct task_struct *tsk, int node)
288293
/* Clear stale pointers from reused stack. */
289294
memset(stack, 0, THREAD_SIZE);
290295

291-
if (memcg_charge_kernel_stack(vm_area)) {
292-
vfree(vm_area->addr);
293-
return -ENOMEM;
294-
}
295-
296296
tsk->stack_vm_area = vm_area;
297297
tsk->stack = stack;
298298
return 0;

0 commit comments

Comments
 (0)