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 <[email protected]>
Cc: Andrew Morton <[email protected]>
---
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