Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CVS-154697, Windows implementation for malloc_trim(0) #2854

Closed
Closed
Show file tree
Hide file tree
Changes from 17 commits
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
9b8f83d
CVS-154698, Implement windows specific status codes
18582088138 Nov 18, 2024
e5b13a5
remove redundant code
18582088138 Nov 18, 2024
9e2bf85
fix clang-format check
18582088138 Nov 18, 2024
985a445
CVS-154700, Implement LoadLibrary for windows with GetProcAddress - d…
18582088138 Nov 19, 2024
ecb587b
Merge branch 'win_ovms_cvs154700' of https://github.com/18582088138/x…
18582088138 Nov 19, 2024
6652865
Fix clang-format style check
18582088138 Nov 19, 2024
133a1e1
CVS-154697, Windows implementation for malloc_trim(0)
18582088138 Nov 19, 2024
ed32ee9
Merge branch 'win_ovms_cvs154697' of https://github.com/18582088138/x…
18582088138 Nov 19, 2024
799eee6
Fix clang-format check
18582088138 Nov 19, 2024
3604771
Merge branch 'openvinotoolkit:main' into win_ovms_cvs154697
18582088138 Nov 19, 2024
f036aaf
Merge branch 'openvinotoolkit:main' into win_ovms_cvs154697
18582088138 Nov 22, 2024
a3a4c73
issue fix for base branch
18582088138 Nov 22, 2024
8959c87
Merge branch 'openvinotoolkit:main' into win_ovms_cvs154697
18582088138 Nov 25, 2024
a8b06a7
Merge branch 'main' into win_ovms_cvs154697
18582088138 Nov 27, 2024
e162f4c
Merge branch 'main' into win_ovms_cvs154697
18582088138 Dec 3, 2024
34b6e08
Merge branch 'main' into win_ovms_cvs154697
18582088138 Dec 9, 2024
3af51db
Merge branch 'main' into win_ovms_cvs154697
18582088138 Dec 10, 2024
78702c4
Merge branch 'main' into win_ovms_cvs154697
18582088138 Dec 15, 2024
1b8d57d
Merge branch 'main' into win_ovms_cvs154697
18582088138 Jan 3, 2025
f2557c5
Merge branch 'main' into win_ovms_cvs154697
18582088138 Jan 3, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 24 additions & 1 deletion src/cleaner_utils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,36 @@ namespace ovms {
FunctorSequenceCleaner::FunctorSequenceCleaner(GlobalSequencesViewer& globalSequencesViewer) :
globalSequencesViewer(globalSequencesViewer) {}

#ifdef _WIN32
bool malloc_trim_win() {
HANDLE heap = GetProcessHeap();
if (heap == NULL) {
std::cerr << "Failed to get process heap" << std::endl;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use: SPDLOG_TRACE, SPDLOG_ERROR

return false;
}

ULONG_PTR freed_bytes = HeapCompact(heap, 0);
if (freed_bytes == 0) {
DWORD error = GetLastError();
if (error != 0) {
std::cerr << "HeapCompact failed with error: " << error << std::endl;
return false;
}
}
std::cout << "HeapCompact freed " << freed_bytes << " bytes" << std::endl;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

SPDLOG_INFO

return true;
}
#endif

void FunctorSequenceCleaner::cleanup() {
globalSequencesViewer.removeIdleSequences();
SPDLOG_TRACE("malloc_trim(0)");
#ifdef __linux__
malloc_trim(0);
#endif
#elif _WIN32
// TODO: windows for malloc_trim(0);
malloc_trim_win();
#endif
}

FunctorSequenceCleaner::~FunctorSequenceCleaner() = default;
Expand Down
5 changes: 5 additions & 0 deletions src/cleaner_utils.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,11 @@
namespace ovms {
class GlobalSequencesViewer;
class ModelManager;

#ifdef _WIN32
bool malloc_trim_win();
#endif

struct FunctorSequenceCleaner {
GlobalSequencesViewer& globalSequencesViewer;

Expand Down
6 changes: 5 additions & 1 deletion src/modelinstance.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@

#include "capi_frontend/inferencerequest.hpp"
#include "capi_frontend/inferenceresponse.hpp"
#include "cleaner_utils.hpp"
#include "config.hpp"
#include "customloaderinterface.hpp"
#include "customloaders.hpp"
Expand Down Expand Up @@ -1315,10 +1316,13 @@ void ModelInstance::unloadModelComponents() {
customLoaderInterfacePtr->unloadModel(getName(), getVersion());
}
}

#ifdef __linux__
malloc_trim(0);
#endif
#elif _WIN32
// TODO: windows for malloc_trim(0);
malloc_trim_win();
#endif
}

const std::set<std::string>& ModelInstance::getOptionalInputNames() {
Expand Down