[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <20240311164638.2015063-6-pasha.tatashin@soleen.com>
Date: Mon, 11 Mar 2024 16:46:29 +0000
From: Pasha Tatashin <pasha.tatashin@...een.com>
To: linux-kernel@...r.kernel.org,
linux-mm@...ck.org,
akpm@...ux-foundation.org,
x86@...nel.org,
bp@...en8.de,
brauner@...nel.org,
bristot@...hat.com,
bsegall@...gle.com,
dave.hansen@...ux.intel.com,
dianders@...omium.org,
dietmar.eggemann@....com,
eric.devolder@...cle.com,
hca@...ux.ibm.com,
hch@...radead.org,
hpa@...or.com,
jacob.jun.pan@...ux.intel.com,
jgg@...pe.ca,
jpoimboe@...nel.org,
jroedel@...e.de,
juri.lelli@...hat.com,
kent.overstreet@...ux.dev,
kinseyho@...gle.com,
kirill.shutemov@...ux.intel.com,
lstoakes@...il.com,
luto@...nel.org,
mgorman@...e.de,
mic@...ikod.net,
michael.christie@...cle.com,
mingo@...hat.com,
mjguzik@...il.com,
mst@...hat.com,
npiggin@...il.com,
peterz@...radead.org,
pmladek@...e.com,
rick.p.edgecombe@...el.com,
rostedt@...dmis.org,
surenb@...gle.com,
tglx@...utronix.de,
urezki@...il.com,
vincent.guittot@...aro.org,
vschneid@...hat.com,
pasha.tatashin@...een.com
Subject: [RFC 05/14] fork: check charging success before zeroing stack
No need to do zero cahced stack if memcg charge fails, so move the
charging attempt before the memset operation.
Signed-off-by: Pasha Tatashin <pasha.tatashin@...een.com>
---
kernel/fork.c | 10 +++++-----
1 file changed, 5 insertions(+), 5 deletions(-)
diff --git a/kernel/fork.c b/kernel/fork.c
index a35f4008afa0..6a2f2c85e09f 100644
--- a/kernel/fork.c
+++ b/kernel/fork.c
@@ -271,6 +271,11 @@ static int alloc_thread_stack_node(struct task_struct *tsk, int node)
if (!vm_area)
continue;
+ if (memcg_charge_kernel_stack(vm_area)) {
+ vfree(vm_area->addr);
+ return -ENOMEM;
+ }
+
/* Reset stack metadata. */
kasan_unpoison_range(vm_area->addr, THREAD_SIZE);
@@ -279,11 +284,6 @@ static int alloc_thread_stack_node(struct task_struct *tsk, int node)
/* Clear stale pointers from reused stack. */
memset(stack, 0, THREAD_SIZE);
- if (memcg_charge_kernel_stack(vm_area)) {
- vfree(vm_area->addr);
- return -ENOMEM;
- }
-
tsk->stack_vm_area = vm_area;
tsk->stack = stack;
return 0;
--
2.44.0.278.ge034bb2e1d-goog
Powered by blists - more mailing lists