Skip to contentSkip to conversation

fork: Use this_cpu_try_cmpxchg() in try_release_thread_stack_to_cache()

PATCH Applied Uros Bizjak 1 participant 1 message May 23, 2024

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 fork: Use this_cpu_try_cmpxchg() in try_release_thread_stack_to_cache()

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.

---
 kernel/fork.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
kernel/fork.c +3 -1
index 99076dbe27d8..c9e994d66930 100644
@@ -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;
 	}
Signature · 1 line
2.45.1