STRUCT GPU_BUDDY(9)

๐Ÿ“ฆ version 7.3.1, in nixpkgs unstable

๐ŸŒธ struct gpu_buddy(9) ๐ŸŒธ

okay bestie, welcome to the struct gpu_buddy(9) page from the Kernel API Manual โ€” yes that's the manual name, no I'm not gonna make you read it twice ๐Ÿ’… this is the GPU binary buddy allocator and it's lowkey iconic.


โœจ NAME โœจ

struct gpu_buddy โ€” the GPU binary buddy allocator, aka the thing that hands out memory in tidy little power-of-two chunks ๐ŸŽ€


๐Ÿฆ‹ SYNOPSIS ๐Ÿฆ‹

struct gpu_buddy {
    unsigned int n_roots;
    unsigned int max_order;
    u64 chunk_size;
    u64 size;
    u64 avail;
    u64 clear_avail;
  #ifdef CONFIG_LOCKDEP;
    struct lockdep_map *lock_dep_map;
  #endif;
 };

like, that's the whole vibe right there, no notes โœจ


๐ŸŽ€ Members ๐ŸŽ€

  • n_roots โ€” how many root blocks live in the roots array. that's it, that's the number ๐Ÿซถ
  • max_order โ€” the maximum block order, which is the log2 of (largest block size / chunk_size). math girlie moment ๐Ÿงฎ
  • chunk_size โ€” the smallest allocation granularity, in bytes. important: it must be at least SZ_4K. no cap, that's a hard requirement ๐Ÿ’€
  • size โ€” the total size, in bytes, of the address space this allocator is managing ๐Ÿ‘‘
  • avail โ€” the total free space currently available for allocation, in bytes. the "how much can I still spend" field ๐Ÿ’ธ
  • clear_avail โ€” free space available in the clear tree (that's the zeroed memory), in bytes. key detail: this is a subset of avail, not extra on top ๐Ÿ™ˆ
  • lock_dep_map โ€” annotates the gpu_buddy API with a lock provided by the driver. it's giving lockdep realness ๐Ÿ”’
heads up, lock_dep_map only exists when CONFIG_LOCKDEP is defined, per the #ifdef up in the synopsis โญ

๐Ÿ’– Description ๐Ÿ’–

so the buddy allocator gives you efficient power-of-two memory allocation with fast alloc and free operations โ€” literally the whole point. it's super commonly used for GPU memory management, where allocations can get split into power-of-two block sizes. that's the aesthetic ๐Ÿฆ‹

Locking is on you, bestie. the user handles it. a simple mutex wrapped around gpu_buddy_alloc_blocks and gpu_buddy_free_block/gpu_buddy_free_list should suffice โ€” that's straight from the page, so don't come for me ๐Ÿ˜ญ


๐ŸŒˆ SEE ALSO ๐ŸŒˆ

kernel file ./include/linux/gpu_buddy.h โ€” go read it, it ate ๐Ÿ”ฅ


and that's the page!! sign-off time: this one came out of ./include/linux and it's dated October 2026 โญ that's the source and the date, bestie, we're done here ๐Ÿ’œ ๐ŸŽ€ ๐Ÿซถ

๐Ÿ“ฆ where this page comes from