From mboxrd@z Thu Jan 1 00:00:00 1970 From: cakturk@gmail.com (Cihangir Akturk) Date: Sat, 28 Feb 2015 22:12:23 +0200 Subject: ACCESS_ONCE usage inside llist_add_batch function Message-ID: <20150228201223.GA2291@lg> To: kernelnewbies@lists.kernelnewbies.org List-Id: kernelnewbies.lists.kernelnewbies.org Reading the lib/llist.c file in the kernel sources, I came across the llist_add_bach function defined like this; bool llist_add_batch(struct llist_node *new_first, struct llist_node *new_last, struct llist_head *head) { struct llist_node *first; do { new_last->next = first = ACCESS_ONCE(head->first); } while (cmpxchg(&head->first, first, new_first) != first); return !first; } One thing bugging my mind is the ACCESS_ONCE macro. Is it really needed here ? I mean I would write this function with ACCES_ONCE moved outside the loop like as follows; bool llist_add_batch(struct llist_node *new_first, struct llist_node *new_last, struct llist_head *head) { struct llist_node *first, *old; old = ACCESS_ONCE(head->first); for (;;) { first = old; new_last->next = old; old = cmpxchg(&head->first, first, new_first); if (old == first) break; } return !first; } I think that it may be faster to just use the return value of cmpxchg. But I am not sure about this. Is my understanding correct ?