MCPcopy Create free account
hub / github.com/catboost/catboost / UnlockMemory

Function UnlockMemory

util/system/mlock.cpp:49–74  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

47}
48
49void UnlockMemory(const void* addr, size_t len) {
50#if defined(_unix_)
51 if (0 == len) {
52 return;
53 }
54 Y_ASSERT(static_cast<ssize_t>(len) > 0);
55 const size_t pageSize = NSystemInfo::GetPageSize();
56 const char* begin = AlignDown(static_cast<const char*>(addr), pageSize);
57 const char* end = AlignUp(static_cast<const char*>(addr) + len, pageSize);
58 if (munlock(begin, end - begin)) {
59 ythrow yexception() << LastSystemErrorText();
60 }
61#elif defined(_win_)
62 HANDLE hndl = GetCurrentProcess();
63 SIZE_T min, max;
64 if (!GetProcessWorkingSetSize(hndl, &min, &max)) {
65 ythrow yexception() << LastSystemErrorText();
66 }
67 if (!SetProcessWorkingSetSize(hndl, min - len, max - len)) {
68 ythrow yexception() << LastSystemErrorText();
69 }
70 if (!VirtualUnlock((LPVOID)addr, len)) {
71 ythrow yexception() << LastSystemErrorText();
72 }
73#endif
74}
75
76void LockAllMemory(ELockAllMemoryFlags flags) {
77 Y_UNUSED(flags);

Callers 1

~TMappedBlobBaseMethod · 0.85

Calls 3

AlignDownFunction · 0.70
AlignUpFunction · 0.70
GetPageSizeFunction · 0.50

Tested by

no test coverage detected