mtree_insert_range(9)
π NAME π
mtree_insert_range β bestie, this is the one that drops an entry into a range [first, last] only if there's no value there already. Like, it's not gonna fight something that's already occupying the spot. No cap. β¨
(Oh and hey, we're in the Kernel API Manual today β kernel girlies rise up π«Ά)
β¨ SYNOPSIS β¨
int mtree_insert_range (struct maple_tree *mt , unsigned long first ,
unsigned long last , void *entry , gfp_t gfp );
π ARGUMENTS π
mtβ the maple tree itself, the main character we're all here for π³πfirstβ where the range startslastβ where the range ends, and yes it's inclusive πentryβ the thing you want to store, your precious little payload πgfpβ theGFP_FLAGSused for allocations β¨
π¦ DESCRIPTION π¦
Okay so real talk: last is inclusive. Not "inclusive-ish", not "kinda", literally inclusive. So this is the math you want, iykyk:
last = first + length - 1
Write that down, bestie, because off-by-one errors are not the vibe π
πΈ RETURN πΈ
0β slayed, it worked β¨-EEXISTSβ nope, the range is already occupied, someone got there first π-EINVALβ invalid request, like... what were you even trying to do π-ENOMEMβ couldn't allocate memory, the allocations said "not today" π
π SEE ALSO π
Kernel file ./lib/maple_tree.c β and the whole friend group, fr fr:
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(9),mtree_alloc_cyclic(9),mtree_erase(9),__mt_dup(9),mtree_dup(9),__mt_destroy(9),mtree_destroy(9),mt_find(9),mt_find_after(9)
Reminder bestie: last = inclusive. Do NOT come crying to me when you forget. π«Ά
Okay that's the whole page β from ./lib, the October 2026 edition, mwah π go forth and insert those ranges responsibly π₯
π¦ 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