Skip to contentSkip to conversation

epoll: Use try_cmpxchg in list_add_tail_lockless

PATCH Applied Uros Bizjak 1 participant 1 message Jul 14, 2022 VFS

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 epoll: Use try_cmpxchg in list_add_tail_lockless

Use try_cmpxchg instead of cmpxchg (*ptr, old, new) == old in list_add_tail_lockless. 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.

Cc Alexander Viro <[email protected]>
---
 fs/eventpoll.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
fs/eventpoll.c +1 -1
index e2daa940ebce..6705cb965fbe 100644
@@ -1065,7 +1065,7 @@ static inline bool list_add_tail_lockless(struct list_head *new,
 	 * added to the list from another CPU: the winner observes
 	 * new->next == new.
 	 */
-	if (cmpxchg(&new->next, new, head) != new)
+	if (!try_cmpxchg(&new->next, &new, head))
 		return false;
 
 	/*
Signature · 1 line
2.35.3