kunit_kmalloc_array(9)

πŸ“¦ version 7.3.1, in nixpkgs unstable

πŸ’… kunit_kmalloc_array β€” Kernel API Manual, bestie edition πŸŽ€

okay so you're reading the kunit_kmalloc_array(9) page, welcome, this one's actually so good. it lives in the Kernel API Manual and honestly it's giving "small function, huge convenience" energy. let's get into it ✨


✨ NAME ✨

kunit_kmalloc_array β€” literally like kmalloc_array() except the allocation is test managed. no cap. that's the whole vibe. 🫢


🌸 SYNOPSIS 🌸

void * kunit_kmalloc_array (struct kunit *test , size_t n , size_t size
, gfp_t gfp );

look at her. four args, returns a void *. iconic signature tbh πŸ’…


πŸ¦‹ ARGUMENTS πŸ¦‹

  • test β€” the test context object. your main character struct, the whole test revolves around her πŸ‘‘
  • n β€” number of elements. like, how many of the thing do you want πŸ“
  • size β€” the size in bytes of the desired memory. yes, bytes, not vibes 😭
  • gfp β€” flags passed to the underlying kmalloc. forwarding them straight through, no edits, no notes πŸ’–

⭐ DESCRIPTION ⭐

okay so it's just like kmalloc_array(...), except the allocation is managed by the test case and gets automatically cleaned up after the test case concludes. so you don't have to remember to free it, she remembers for you. that's the whole slay πŸ”₯

if you want the deeper lore on how that cleanup actually works, go see kunit_add_action for more information. iykyk 🧚

⚠️ note that some internal context data is also allocated with GFP_KERNEL, regardless of the gfp you passed in. so like, don't assume your flags cover everything bestie, that's not the deal here πŸ’€

🌈 SEE ALSO 🌈

so many friends, we love a connected ecosystem πŸ’œ first up, the kernel file ./include/kunit/test.h and enum kunit_status(9), plus these:


okay that's the whole page, you ate that πŸ’… this one came from ./include/kunit, October 2026 (Kernel API Manual), and honestly? go forth and let the test manage your memory for you. periodt. πŸŽ€βœ¨πŸ¦‹

πŸ“¦ where this page comes from