* [PATCH] fork: Use this_cpu_try_cmpxchg() in try_release_thread_stack_to_cache()
@ 2024-05-23 7:35 Uros Bizjak
0 siblings, 0 replies; only message in thread
From: Uros Bizjak @ 2024-05-23 7:35 UTC (permalink / raw)
To: linux-kernel; +Cc: Uros Bizjak, Andrew Morton
Use this_cpu_try_cmpxchg() instead of
this_cpu_cmpxchg (*ptr, old, new) == old in
try_release_thread_stack_to_cache. x86 CMPXCHG instruction returns
success in ZF flag, so this change saves a compare after cmpxchg
(and related move instruction in front of cmpxchg).
No functional change intended.
Signed-off-by: Uros Bizjak <ubizjak@gmail.com>
Cc: Andrew Morton <akpm@linux-foundation.org>
---
kernel/fork.c | 4 +++-
1 file changed, 3 insertions(+), 1 deletion(-)
diff --git a/kernel/fork.c b/kernel/fork.c
index 99076dbe27d8..c9e994d66930 100644
--- a/kernel/fork.c
+++ b/kernel/fork.c
@@ -205,7 +205,9 @@ static bool try_release_thread_stack_to_cache(struct vm_struct *vm)
unsigned int i;
for (i = 0; i < NR_CACHED_STACKS; i++) {
- if (this_cpu_cmpxchg(cached_stacks[i], NULL, vm) != NULL)
+ struct vm_struct *tmp = NULL;
+
+ if (!this_cpu_try_cmpxchg(cached_stacks[i], &tmp, vm))
continue;
return true;
}
--
2.45.1
^ permalink raw reply related [flat|nested] only message in thread
only message in thread, other threads:[~2024-05-23 7:35 UTC | newest]
Thread overview: (only message) (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-05-23 7:35 [PATCH] fork: Use this_cpu_try_cmpxchg() in try_release_thread_stack_to_cache() Uros Bizjak
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.