RADIX-TREE SYNCHRONIZATION(9)
β¨ RADIX-TREE SYNCHRONIZATION β¨
okay so bestie, welcome to Radix-tree synchronization(9) from the Kernel API Manual β yes we're doing kernel internals today and honestly the way this whole page is structured?? obsessed π
π«Ά the vibe check
The radix-tree API is extremely clear about one thing: you provide all synchronisation. Not the API, not the tree, not some helpful little helper. You. (With specific exceptions, noted below β we'll get there, don't spiral πΈ)
Also management of lifetimes? That's yours too. Synchronization of access to the data items being stored in the tree, and management of their lifetimes must be completely managed by API users. Periodt.
For API usage, in general:
- any function _modifying_ the tree or tags (inserting or deleting items, setting or clearing tags) must exclude other modifications, and exclude any functions reading the tree π₯
- any function _reading_ the tree or tags (looking up items or tags, gang lookups) must exclude modifications to the tree, but may occur concurrently with other readers β
π the exceptions (the iconic ones)
The notable exceptions to this rule are the following functions:
__radix_tree_lookupradix_tree_lookupradix_tree_lookup_slotradix_tree_tag_getradix_tree_gang_lookupradix_tree_gang_lookup_tagradix_tree_gang_lookup_tag_slotradix_tree_tagged
The first 7 functions are able to be called locklessly, using RCU π€ The caller must ensure calls to these functions are made within rcu_read_lock regions. Other readers (lock-free or otherwise) and modifications may be running concurrently.
It is still required that the caller manage the synchronization and lifetimes of the items π«Ά So if RCU lock-free lookups are used, typically this would mean that the items have their own locks, or are amenable to lock-free access; and that the items are freed by RCU (or only freed after having been deleted from the radix tree and a synchronize_rcu grace period).
π lowkey important footnote:rcu_assign_pointerandrcu_dereferenceare not needed to control access to data items when inserting into or looking up from the radix tree.
π the radix_tree_tag_get situation (read this one fr fr)
Note that the value returned by radix_tree_tag_get may not be relied upon if only the RCU read lock is held. Functions to set/clear tags and to delete nodes running concurrently with it may affect its result such that two consecutive reads in the same locked section may return different values π
So like⦠don't trust it blindly. If reliability is required, modification functions must also be excluded from concurrency. That's the whole deal, no cap.
π and one chill one
radix_tree_tagged is able to be called without locking or RCU. No locks, no RCU, no stress. Iconic behaviour honestly π
π SEE ALSO π
- Kernel file
./include/linux/radix-tree.h struct radix_tree_iter(9)radix_tree_deref_slot(9)radix_tree_deref_slot_protected(9)radix_tree_deref_retry(9)radix_tree_exception(9)radix_tree_iter_init(9)radix_tree_next_chunk(9)radix_tree_iter_lookup(9)radix_tree_iter_retry(9)radix_tree_iter_resume(9)radix_tree_chunk_size(9)radix_tree_next_slot(9)radix_tree_for_each_slot(9)radix_tree_for_each_tagged(9)
that's the whole page bestie, go forth and lock correctly π§π β source ./include/linux, dated October 2026, and it's Radix-tree synchronization(9) all the way down. mwah π
π¦ 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