mtree_alloc_cyclic(9)
β¨ 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 capentryβ the entry you're storing, the main character frrange_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β theGFP_FLAGSto 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:mtmust be initialized with theMT_FLAGS_ALLOC_RANGEflag. 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βmtcannot 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:
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_erase(9)__mt_dup(9)mtree_dup(9)__mt_destroy(9)mtree_destroy(9)mt_find(9)mt_find_after(9)
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
- 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