kmemdup(9)

πŸ“¦ version 7.3.1, in nixpkgs unstable

✨ kmemdup β€” the kernel's very own copy machine πŸ’–

okay so picture this: you've got a chunk of memory and you literally just need another one exactly like it. same bytes, same energy, brand new home. that's kmemdup, bestie. it's in the Kernel API Manual (section 9, the cool one) and it's giving "duplicate region of memory" 🫢


🌸 SYNOPSIS 🌸

void * kmemdup (const void *src , size_t len , gfp_t gfp );

three arguments, one very cute little pointer coming back at you. no cap ✨


πŸŽ€ ARGUMENTS πŸŽ€

  • src β€” the memory region you wanna duplicate. your original, your blueprint, your main character πŸ¦‹
  • len β€” how long that region is. gotta tell her the size, she's not a mind reader πŸ’…
  • gfp β€” the GFP mask to use. that's the allocation vibes you're handing over to the memory gods 🌈

πŸ‘‘ RETURN πŸ‘‘

you get back a shiny newly allocated copy of src β€” or NULL if something went wrong (error case, we don't love her but she exists 😭).

and here's the tea: the result is physically contiguous. fr fr. contiguous memory, no scattering, all snuggled together 🧚

⭐ important bestie note: when you're done, free it with kfree. don't just leave her hanging, that's rude πŸ’€

🌟 SEE ALSO 🌟

all the siblings and cousins, in the kernel file ./mm/util.c β€” go say hi 🫢

kfree_const(9), __kmemdup_nul(9), kstrdup(9), kstrdup_const(9), kstrndup(9), kmemdup_array(9), kvmemdup(9), kmemdup_nul(9), memdup_user(9), vmemdup_user(9), strndup_user(9), memdup_user_nul(9), randomize_page(9), __account_locked_vm(9), account_locked_vm(9), __vmalloc_array(9), vmalloc_array(9), __vcalloc(9), vcalloc(9), folio_mapping(9), folio_copy(9), get_cmdline(9), mem_dump_obj(9), compat_set_desc_from_vma(9), __compat_vma_mmap(9), compat_vma_mmap(9), snapshot_page(9), mmap_action_prepare(9), mmap_action_complete(9), folio_pte_batch(9), page_range_contiguous(9)


and that's the whole vibe, bestie πŸ’œ this lil page lives in ./mm, dated October 2026, and it's part of the Kernel API Manual, section 9. slay, go duplicate some memory responsibly βœ¨πŸŽ€πŸ”₯

πŸ“¦ where this page comes from