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

Function LockMemory

util/system/mlock.cpp:22–47  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

20#include <limits>
21
22void LockMemory(const void* addr, size_t len) {
23#if defined(_unix_)
24 if (0 == len) {
25 return;
26 }
27 Y_ASSERT(static_cast<ssize_t>(len) > 0);
28 const size_t pageSize = NSystemInfo::GetPageSize();
29 const char* begin = AlignDown(static_cast<const char*>(addr), pageSize);
30 const char* end = AlignUp(static_cast<const char*>(addr) + len, pageSize);
31 if (mlock(begin, end - begin)) {
32 ythrow yexception() << LastSystemErrorText();
33 }
34#elif defined(_win_)
35 HANDLE hndl = GetCurrentProcess();
36 SIZE_T min, max;
37 if (!GetProcessWorkingSetSize(hndl, &min, &max)) {
38 ythrow yexception() << LastSystemErrorText();
39 }
40 if (!SetProcessWorkingSetSize(hndl, min + len, max + len)) {
41 ythrow yexception() << LastSystemErrorText();
42 }
43 if (!VirtualLock((LPVOID)addr, len)) {
44 ythrow yexception() << LastSystemErrorText();
45 }
46#endif
47}
48
49void UnlockMemory(const void* addr, size_t len) {
50#if defined(_unix_)

Callers 2

TMappedBlobBaseMethod · 0.85
Y_UNIT_TESTFunction · 0.85

Calls 3

AlignDownFunction · 0.70
AlignUpFunction · 0.70
GetPageSizeFunction · 0.50

Tested by

no test coverage detected