mt_find(9)
π mt_find(9) β the Kernel API Manual, bestie edition
okay so this is mt_find, from the Kernel API Manual, and it is literally the "find me something in this maple tree" girlie. Search from the start until you hit an entry, that's the whole vibe. β¨
πΈ NAME πΈ
mt_find β Search from the start up until an entry is found.
π SYNOPSIS π
void * mt_find (struct maple_tree *mt , unsigned long *index , unsigned
long max );
π ARGUMENTS π
mtβ The maple tree. the main character, the tree in question π³indexβ Pointer which contains the start location of the search. also where the answer comes back to, so yeah, she's doing double duty π«Άmaxβ The maximum value of the search range. the ceiling, the limit, the "don't go past this" line π₯
π¦ DESCRIPTION π¦
So the way this works: it takes the RCU read lock internally to protect the search. and here's the part you need to internalize, bestie β that lock does not protect the returned pointer after you drop the RCU read lock. like, it protects the search itself, not the thing you walk away holding. no cap, this matters.
See also: Documentation/core-api/maple_tree.rst β go read it, it's giving essential lore π
In case that an entry is found, index is updated to point to the next possible entry, independent of whether the found entry is occupying a single index or a range of indices. so it always moves you forward to the next candidate, whether the thing you found was a solo index or a whole range. slay, that's consistent. π
π§ RETURN π§
The entry at or after the index, or NULL. that's it, that's the deal β entry or nothing π
π SEE ALSO π
Kernel file ./lib/maple_tree.c, plus the whole friend group:
mas_prealloc_calc(9)mas_wr_preallocate(9)mas_insert(9)mas_alloc_cyclic(9)mas_walk(9)mte_dead_walk(9)mt_free_walk(9)mas_store(9)mas_store_gfp(9)mas_store_prealloc(9)mas_preallocate(9)mas_next(9)mas_next_range(9)mt_next(9)mas_prev(9)mas_prev_range(9)mt_prev(9)mas_pause(9)mas_find_setup(9)mas_find(9)mas_find_range(9)mas_find_rev_setup(9)mas_find_rev(9)mas_find_range_rev(9)mas_erase(9)mas_nomem(9)mas_nomem_nofail(9)mtree_load(9)mtree_store_range(9)mtree_store(9)mtree_insert_range(9)mtree_insert(9)mtree_alloc_cyclic(9)mtree_erase(9)__mt_dup(9)mtree_dup(9)__mt_destroy(9)mtree_destroy(9)mt_find_after(9)
ngl the RCU thing is the one that bites people, so if you only remember one line from this whole page make it the "does not protect the returned pointer" one. mwah. ππ
okay that's the page!! this whole thing lives in ./lib and it's dated October 2026 β so yeah, future girlie behavior, but we stay informed. π bye bestie, go find your entries π
πΈ
π¦ 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