__mt_dup(9)

πŸ“¦ version 7.3.1, in nixpkgs unstable

✨ __mt_dup β€” section 9 kernel API, bestie edition ✨

okay so this is __mt_dup from the kernel API manual (section 9, the kernel-space girlies πŸ’…), and it's literally the glow-up button for an entire maple tree. let's get into it πŸŽ€


🌸 SYNOPSIS 🌸

int __mt_dup (struct maple_tree *mt , struct maple_tree *new , gfp_t gfp
);

three args, one int back, no cap πŸ’–


πŸ¦‹ ARGUMENTS πŸ¦‹

  • mt β€” the source maple tree, aka the one you're copying from πŸ‘‘
  • new β€” the new maple tree, aka the destination glow-up 🌈
  • gfp β€” the GFP_FLAGS you wanna use for allocations, so pick your flags wisely bestie πŸ“

πŸ’œ DESCRIPTION πŸ’œ

so the way this works: it duplicates a maple tree in Depth-First Search (DFS) pre-order traversal. it uses memcpy to copy nodes in the source tree and allocates new child nodes in non-leaf nodes. the new node is exactly the same as the source node except for all the addresses stored in it β€” the way that's efficient fr fr 😭

it will be faster than traversing all elements in the source tree and inserting them one by one into the new tree. ate and left no crumbs πŸ”₯

⚠️ bestie, ground rules: the user needs to ensure that the attributes of the source tree and the new tree are the same, and the new tree needs to be an empty tree, otherwise -EINVAL will be returned. also note that the user needs to manually lock the source tree and the new tree. no auto-locking here, you're on your own πŸ’€

⭐ RETURN ⭐

  • 0 on success β€” slay ✨
  • -ENOMEM if memory could not be allocated 😭
  • -EINVAL if the attributes of the two trees are different or the new tree is not an empty tree πŸ™ˆ

🫢 SEE ALSO 🫢

the whole friend group, no one left out πŸ’– Kernel file ./lib/maple_tree.c, plus 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), mtree_dup(9), __mt_destroy(9), mtree_destroy(9), mt_find(9), mt_find_after(9) 🌟


🧚 and that's the page! brought to you by ./lib, circa October 2026, filed under __mt_dup(9) β€” periodt πŸ’…πŸ‘‘
πŸ“¦ where this page comes from