list_entry_lockless(9)
π list_entry_lockless β bestie's guide to grabbing the struct π
okay so real talk, we're deep in the kernel API manual (section 9, the "kernel internals" girlies know) and today's main character is list_entry_lockless. it's a macro. it's giving "small but mighty". let's get into it π
β¨ SYNOPSIS β¨
list_entry_lockless (ptr , type , member );
no cap, that's the whole call. three args, zero drama. π
πΈ ARGUMENTS πΈ
ptrβ thestruct list_headpointer. this is your starting point, the little node you're turning back into its bigger self. π¦typeβ the type of the struct this is embedded in. i.e., what you want back out of this whole situation. πmemberβ the name of thelist_headwithin the struct. yes, the member. the inner list head that lives inside your bigger struct. she's literally the key that makes the reverse lookup work. π
π₯ DESCRIPTION π₯
so what does this primitive actually do? it gets the struct for this entry, bestie β you hand it the list_head pointer and it hands you back the containing struct. iconic behavior. π«Ά
and the "lockless" part? not just a cute name. this primitive may safely run concurrently with the _rcu list-mutation primitives β think list_add_rcu and friends β so you can be out here traversing while someone else is mutating. slay. β¨
but β and this is the important part, don't skip it β it requires some implicit RCU read-side guarding. the locklessness is not free. you need to already be under some kind of implicit guard, or this is not it. π
two examples the manual gives you:
- running within a special exception-time environment where preemption is disabled and where
lockdepcannot be invoked. π§ - when items are added to the list, but never deleted. π
that's it. those are the vibes. no extra reading, that's what the page says. π
π SEE ALSO π
the whole _rcu friend group lives in the kernel file ./include/linux/rculist.h, and honestly they're all linked below, so let's list them all because we do not gatekeep. π
list_for_each_rcu(9)list_tail_rcu(9)list_add_rcu(9)list_add_tail_rcu(9)list_del_rcu(9)list_bidir_del_rcu(9)hlist_del_init_rcu(9)list_replace_rcu(9)list_splice_rcu(9)__list_splice_init_rcu(9)list_splice_init_rcu(9)list_splice_tail_init_rcu(9)list_entry_rcu(9)list_first_or_null_rcu(9)list_next_or_null_rcu(9)list_for_each_entry_rcu(9)list_for_each_entry_srcu(9)list_for_each_entry_lockless(9)list_for_each_entry_continue_rcu(9)list_for_each_entry_from_rcu(9)hlist_del_rcu(9)hlist_replace_rcu(9)hlists_swap_heads_rcu(9)hlist_add_head_rcu(9)hlist_add_tail_rcu(9)hlist_add_before_rcu(9)hlist_add_behind_rcu(9)hlist_for_each_entry_rcu(9)hlist_for_each_entry_srcu(9)hlist_for_each_entry_rcu_notrace(9)hlist_for_each_entry_rcu_bh(9)hlist_for_each_entry_continue_rcu(9)hlist_for_each_entry_continue_rcu_bh(9)hlist_for_each_entry_from_rcu(9)
iykyk, the hlist girlies and the list girlies both showed up for this one. π
that's the page, bestie!! π shoutout to whoever maintains ./include/linux (october 2026 edition, mwah π) for keeping this list_entry_lockless(9) lore alive and documented. go forth and be lockless responsibly. π¦β¨
π¦ where this page comes from
- nixpkgs unstable: linux-manual 7.3.1
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms