mtree_alloc_cyclic(9)

πŸ“¦ version 7.3.1, in nixpkgs unstable

✨ mtree_alloc_cyclic(9) ✨

okay so this is a page from the Kernel API Manual and honestly? it's giving "let me find a little spot in the tree for your entry" energy and i'm obsessed πŸ’…


🌸 NAME 🌸

mtree_alloc_cyclic β€” bestie, this is literally the "find somewhere to store this entry in the tree" function πŸŽ€


πŸ¦‹ SYNOPSIS πŸ¦‹

int mtree_alloc_cyclic (struct maple_tree *mt , unsigned long *startp ,
void *entry , unsigned long range_lo , unsigned long range_hi , unsigned
long *next , gfp_t gfp );

like, that's the whole vibe right there ✨


πŸ’– ARGUMENTS πŸ’–

  • mt β€” the maple tree 🌳 (yes queen, THE tree)
  • startp β€” pointer to ID, no cap
  • entry β€” the entry you're storing, the main character fr
  • range_lo β€” lower bound of the range we're searching πŸ“
  • range_hi β€” upper bound of the range we're searching 🌈
  • next β€” pointer to the next ID to allocate πŸ‘‘
  • gfp β€” the GFP_FLAGS to use for allocations 🧚

πŸ”₯ DESCRIPTION πŸ”₯

so what it does is: it finds an empty entry in mt after next, stores the new index into the id pointer, stores the entry at that index, and then updates next. literally a whole little glow-up sequence πŸ’«

⚠️ important bestie: mt must be initialized with the MT_FLAGS_ALLOC_RANGE flag. no flag, no vibes 😭

⭐ CONTEXT ⭐

any context at all β€” she's flexible like that 🫢. it takes and releases the mt.lock. it may sleep if the gfp flags permit 😴


πŸ’€ RETURN πŸ’€

  • 0 β€” allocation succeeded without wrapping, slay ✨
  • 1 β€” allocation succeeded after wrapping, still ate πŸ’…
  • -ENOMEM β€” memory could not be allocated, tragic, we hate to see it 😭
  • -EINVAL β€” mt cannot be used, not it 🚩
  • -EBUSY β€” there are no free entries, the tree is FULL, respectfully πŸ’€

πŸ‘‘ SEE ALSO πŸ‘‘

kernel file ./lib/maple_tree.c and the whole friend group:

like, that's the entire group chat, everyone showed up 🫢✨


πŸ’– that's the whole page bestie, hope it ate πŸ’–

this iconic little slice of documentation lives in ./lib, dated October 2026, and you can find her filed under mtree_alloc_cyclic(9) β€” periodt πŸŒŸπŸŽ€

πŸ“¦ where this page comes from