list_entry_lockless(9)

πŸ“¦ version 7.3.1, in nixpkgs unstable

πŸ’– 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 β€” the struct list_head pointer. 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 the list_head within 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:

  1. running within a special exception-time environment where preemption is disabled and where lockdep cannot be invoked. 🧚
  2. 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. 🌈

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