Skip to content

Commit

Permalink
[core] On Linux try return not used memory to system on compile model…
Browse files Browse the repository at this point in the history
… destructor (openvinotoolkit#27534)

### Details:
- Optimize Linux process using OV memory consumption by returning not
used memory to the system when compiled model is destroyed.
- It should optimize memory usage by C++ and Python applications, as
Linux avoid reclaim memory until process end especially for small chunks
of allocations.

### Tickets:
 - CVS-149497
  • Loading branch information
praasz authored and NishantPrabhuFujitsu committed Nov 26, 2024
1 parent b07018f commit dc2da37
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions src/inference/src/cpp/compiled_model.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@
#include "openvino/runtime/icompiled_model.hpp"
#include "openvino/runtime/properties.hpp"

#if defined(OPENVINO_GNU_LIBC) && !defined(__ANDROID__)
# include <malloc.h>
#endif

#define OV_COMPILED_MODEL_CALL_STATEMENT(...) \
if (_impl == nullptr) \
OPENVINO_THROW("CompiledModel was not initialized."); \
Expand All @@ -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<ov::ICompiledModel>& impl, const std::shared_ptr<void>& so)
Expand Down

0 comments on commit dc2da37

Please sign in to comment.