mt_find(9)

πŸ“¦ version 7.3.1, in nixpkgs unstable

🍁 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:


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