From d45a2a81541c53eca39706d54d97c076d944a52e Mon Sep 17 00:00:00 2001 From: "Raasz, Pawel" Date: Wed, 13 Nov 2024 12:35:16 +0000 Subject: [PATCH] On Linux return not used memory to system on compiled model dtor --- src/inference/src/cpp/compiled_model.cpp | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/src/inference/src/cpp/compiled_model.cpp b/src/inference/src/cpp/compiled_model.cpp index c780bbee1e991d..d675cba4714887 100644 --- a/src/inference/src/cpp/compiled_model.cpp +++ b/src/inference/src/cpp/compiled_model.cpp @@ -8,6 +8,10 @@ #include "openvino/runtime/icompiled_model.hpp" #include "openvino/runtime/properties.hpp" +#if defined(OPENVINO_GNU_LIBC) && !defined(__ANDROID__) +# include +#endif + #define OV_COMPILED_MODEL_CALL_STATEMENT(...) \ if (_impl == nullptr) \ OPENVINO_THROW("CompiledModel was not initialized."); \ @@ -23,6 +27,12 @@ namespace ov { CompiledModel::~CompiledModel() { _impl = {}; +#if defined(OPENVINO_GNU_LIBC) && !defined(__ANDROID__) + // Linux memory margent doesn't return system memory immediate after release. + // It depends on memory chunk size and allocation history. + // Try return memory from a process to system now to reduce memory usage and not wait to the end of the process. + malloc_trim(0); +#endif } CompiledModel::CompiledModel(const std::shared_ptr& impl, const std::shared_ptr& so)