bitmap_find_free_region(9)

πŸ“¦ version 7.3.1, in nixpkgs unstable

πŸ’– bitmap_find_free_region(9) πŸ’–

okay so this is a page from the Kernel API Manual, and bestie, it's literally about grabbing a nice lil chunk of free space out of a bitmap. it's bitmap_find_free_region, and yes she's iconic πŸ’…


✨ NAME ✨

bitmap_find_free_region β€” find a contiguous aligned mem region πŸŽ€


🌸 SYNOPSIS 🌸

int bitmap_find_free_region (unsigned long *bitmap , unsigned int bits ,
int order );

like, that's the whole signature. short king 🫢


πŸ¦‹ ARGUMENTS πŸ¦‹

  • bitmap β€” the array of unsigned longs that correspond to the bitmap. this is the thing you're hunting through, no cap.
  • bits β€” how many bits are in the bitmap, fr fr. that's your total playing field.
  • order β€” the region size you wanna find, expressed as log base 2 of the number of bits. so order is giving "the exponent, not the answer" 😭

πŸ’« DESCRIPTION πŸ’«

so what she does is: find a region of free (zero) bits in a bitmap of bits bits, and then allocate them by setting them to one. periodt. πŸŽ€

and here's the slay part β€” she only considers regions of length a power (order) of two, aligned to that power of two. the way that makes the search algorithm much faster?? obsessed. ⚑ highkey a vibe.

so yeah, aligned-only. that's not a bug, that's the whole point of the speed. don't come for her πŸ’…

πŸ‘‘ RETURN πŸ‘‘

returns the bit offset in bitmap of the allocated region 🌟 β€” or -errno on failure 😭 (yes, negative errno, watch out for it).


πŸ”₯ SEE ALSO πŸ”₯

kernel file ./include/linux/bitmap.h 🧚


🌈 okay that's the whole page, bestie! this one's brought to you from ./include/linux, October 2026, and it's bitmap_find_free_region(9) signing off β€” mwah πŸ’‹βœ¨

πŸ“¦ where this page comes from