deepinsight/insightface · error · std::runtime_error
RGA buffer allocation failed
Error message
RGA buffer allocation failed
What it means
In the RGA image processor's buffer cache, when a GetBuffer cache miss occurs a new RGA buffer is allocated via buffer.Allocate(width, height, channels); if the underlying allocation (RGA/malloc/DMA memory) fails, the code throws std::runtime_error("RGA buffer allocation failed"). This aborts the copy/conversion step of the RGA pipeline. It almost always indicates resource exhaustion or dimensions the allocator rejects, not a logic bug in caller code.
Source
Thrown at cpp-package/inspireface/cpp/inspireface/image_process/nexus_processor/image_processor_rga.h:191
last_dst_key_ = key;
}
return it->second;
}
if (buffer_cache_.size() >= 3) { // Keep max 3 buffers in cache
for (auto it = buffer_cache_.begin(); it != buffer_cache_.end();) {
if (!(it->first == last_src_key_) && !(it->first == last_dst_key_)) {
it = buffer_cache_.erase(it);
} else {
++it;
}
}
}
auto& buffer = buffer_cache_[key];
if (!buffer.Allocate(key.width, key.height, key.channels)) {
INSPIRECV_LOG(ERROR) << "Failed to allocate RGA buffer";
throw std::runtime_error("RGA buffer allocation failed");
}
if (is_src) {
last_src_key_ = key;
} else {
last_dst_key_ = key;
}
return buffer;
}
private:
std::unordered_map<BufferKey, RGABuffer, BufferKeyHash> buffer_cache_;
BufferKey last_src_key_{0, 0, 0};
BufferKey last_dst_key_{0, 0, 0};
int32_t aligned_width_{0};
};
View on GitHub (pinned to 7fadd420c2)
Solutions
- Free memory / reduce concurrent load: close other camera or inference processes and retry to see if allocation succeeds.
- Reduce input resolution or reuse a consistent frame size so the buffer cache hits (buffer_cache_[key]) instead of allocating new buffers every frame.
- Check RGA availability and memory: verify /dev/rga exists, the rga driver is loaded, and inspect CMA/DMA heap usage (dmesg | grep -i rga, /proc/meminfo).
- If the leak is repeated cache growth, bound or clear the buffer cache between sessions and report upstream if buffers are never released.
Example fix
// before
auto& proc = ...; // ImageProcessorRGA
proc->CopyImage(img, dst); // may throw std::runtime_error: RGA buffer allocation failed
// after
try {
proc->CopyImage(img, dst);
} catch (const std::runtime_error& e) {
LOG(WARNING) << "RGA allocation failed: " << e.what()
<< " — retrying with downscaled frame";
auto small = img.Resize(img.Width()/2, img.Height()/2);
proc->CopyImage(small, dst);
} Defensive patterns
Strategy: try-catch
Validate before calling
size_t need = (size_t)width * height * channels;
if (need > kMaxRgaBufferBytes) { /* downscale or reject frame before processing */ } Try / catch
try {
processor->CopyImage(src, dst);
} catch (const std::runtime_error& e) {
if (std::string(e.what()).find("RGA buffer") != std::string::npos) {
// free memory / downscale input and retry once
} else throw;
} Prevention
- Normalize input frames to one resolution so buffer_cache_ keys hit instead of allocating new buffers.
- Keep only one active RGA processing pipeline per process where possible.
- Watch CMA/DMA heap usage on Rockchip boards during load testing.
When it happens
Trigger: Requesting a conversion/copy with unusually large width×height×channels so the RGA buffer allocation exceeds available memory; many concurrent streams creating distinct cache keys and fragmenting/exhausting the cache; running on a device where the RGA device (/dev/rga) or its DMA heap is unavailable or out of memory; memory pressure on embedded boards after long uptime or alongside other camera/AI processes.
Common situations: Feeding 4K/high-resolution frames on RK3588/RK3566 boards where CMA or DMA-BUF heap is exhausted; multiple cameras or pipeline instances each allocating new buffer keys because width/height/format differ per frame; OOM conditions on Android/Embedded Linux when InspireFace runs next to other heavy media processes; a first-run failure because the RGA driver isn't loaded.
AI-assisted analysis of deepinsight/insightface@7fadd420c2 (2026-08-28).
Data as JSON: /api/errors/c5b2ff9d30ea4ac5.
Report an issue: GitHub.