Implement a Buddy Allocator for GPU Video Memory

Last updated: November 29, 2026

Quick Overview

Implement a buddy allocator over a power-of-two VRAM region with a minimum block size. Support alloc(size) returning an offset or None, and free(offset) that merges a freed block with its buddy whenever the buddy is also free.

AMD
Software Engineering Fundamentals
Software Engineer
AMD
November 29, 2026
Software Engineer
Onsite
Software Engineering Fundamentals
Hard

0

0

0 solved


Implement a buddy allocator over a power-of-two VRAM region with a minimum block size. Support alloc(size) returning an offset or None, and free(offset) that merges a freed block with its buddy whenever the buddy is also free.

An onsite systems question in the style of AMD's Linux amdgpu and ROCm runtime teams; the kernel's DRM subsystem uses a buddy allocator for VRAM. The interviewer checks the XOR buddy trick, correct split and merge logic, fragmentation awareness and robustness against bad frees.

What the Interviewer Expects
  • Round requests up to a power-of-two order not below the minimum block
  • Keep one free list per order
  • Split larger blocks down, returning the upper halves to free lists
  • Find the buddy with offset XOR block size
  • Merge repeatedly up the orders on free
  • Detect double free and invalid offsets
Key Topics to Cover
memory allocators
bit manipulation
fragmentation
operating systems
How to Approach This
  1. Apply SOLID principles. Single Responsibility makes code testable, Open/Closed makes it extensible.
  2. Choose data structures based on access patterns, not familiarity.
  3. Prefer immutable data and message passing over shared mutable state for concurrency.
  4. Design APIs with RESTful conventions, versioning, meaningful errors, and pagination from day one.
Possible Follow-up Questions
  • How much internal fragmentation can a buddy allocator cause, and how would you reduce it for 65 KiB requests?
  • How would you make this thread-safe without one global lock?
  • How would you support allocations that must be physically contiguous versus ones that can be scattered across pages?
  • How would you prefer CPU-visible VRAM for some allocations?
Sharpen Your Skills on Codemia

Practice similar problems with our interactive workspace, get AI feedback, and track your progress.

Practice System Design Problems
Sample Answer
Requirements

BuddyAllocator(total_size, min_block), both powers of two. alloc(size) returns the offset of a block of at least size bytes, aligned to its own size, or None if no block fits. `free_block(offs...

High-Level Design

Blocks have order o, size 2**o. Keep a set of free offsets per order and a map from allocated offset to order. To allocate, compute the needed order, find the smallest order with a free block, the...


Submit Your Answer
Markdown supported

Related Questions