STRUCT GPU_BUDDY(9)
๐ธ 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 therootsarray. 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 leastSZ_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 ofavail, not extra on top ๐lock_dep_mapโ annotates thegpu_buddyAPI with a lock provided by the driver. it's giving lockdep realness ๐
heads up,lock_dep_maponly exists whenCONFIG_LOCKDEPis defined, per the#ifdefup 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 ๐ฅ
GPU_BUDDY_RANGE_ALLOCATION(9)GPU_BUDDY_TOPDOWN_ALLOCATION(9)GPU_BUDDY_CONTIGUOUS_ALLOCATION(9)GPU_BUDDY_CLEAR_ALLOCATION(9)GPU_BUDDY_CLEARED(9)GPU_BUDDY_TRIM_DISABLE(9)struct gpu_buddy_block(9)gpu_buddy_driver_set_lock(9)gpu_buddy_driver_lock_held(9)
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
- nixpkgs unstable: linux-manual 7.3.1
- ๐ girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms