kmalloc_size_roundup(9)

πŸ“¦ version 7.3.1, in nixpkgs unstable

πŸ’– kmalloc_size_roundup(9) πŸ’–

okay bestie, welcome to the Kernel API Manual β€” today’s main character is kmalloc_size_roundup, and it’s giving β€œsmall function, very useful bucket math” energy ✨


🌸 NAME 🌸

kmalloc_size_roundup β€” Report allocation bucket size for the given size. That’s the whole vibe, no cap.


✨ SYNOPSIS ✨

size_t kmalloc_size_roundup (size_t size );

πŸŽ€ ARGUMENTS πŸŽ€

  • size β€” Number of bytes to round up from. That’s literally the assignment, bestie. πŸ’…

πŸ’… DESCRIPTION πŸ’…

okay so this returns the number of bytes that would be available in a kmalloc allocation of size bytes. For example, a 126 byte request would be rounded up to the next sized kmalloc bucket, 128 bytes. Slay? Slay. πŸ”₯

This is strictly for the general-purpose kmalloc-based allocations, and is not for the pre-sized kmem_cache_alloc-based allocations. Important distinction β€” do not mix those up, bestie. πŸ’€

Use this to kmalloc the full bucket size ahead of time instead of using ksize to query the size after an allocation. It’s giving β€œplan ahead, icon” energy. 🫢


πŸ¦‹ SEE ALSO πŸ¦‹

Kernel file ./include/linux/slab.h β€” plus the whole squad, periodt:


mwah πŸ’‹ this little page comes from ./include/linux, is dated October 2026, and lives in the Kernel API Manual β€” kmalloc_size_roundup(9), signing off! 🫢✨

πŸ“¦ where this page comes from