背景
压测的时候发现,进程的RSS内存一直在上升,就怀疑是onnxruntime导致的。因此,没加模型推理前,是不存在内存泄漏的。
解决方法
在创建Ort::SessionOptions sopt
后, 额外添加一个配置项 sopt.DisableCpuMemArena()
,可以解决内存泄漏的问题。
泄漏原因
不知道,还没看出来。但估计可能是多线程/进程环境中mem会发送竞争吧。
有个参考说法
Can you also try disabling the memory arena by calling OrtApi::DisableCpuMemArena? If that and memory pattern are disabled ORT will just call malloc/free for each individual request instead of maintaining it's own buffers/cache in an attempt to minimize allocations.
参考
- https://github.com/microsoft/onnxruntime/issues/10982
- [https://github.com/microsoft/onnxruntime/issues/1725])(https://github.com/microsoft/onnxruntime/issues/1725)