diff options
author | Devtools Arcadia <arcadia-devtools@yandex-team.ru> | 2022-02-07 18:08:42 +0300 |
---|---|---|
committer | Devtools Arcadia <arcadia-devtools@mous.vla.yp-c.yandex.net> | 2022-02-07 18:08:42 +0300 |
commit | 1110808a9d39d4b808aef724c861a2e1a38d2a69 (patch) | |
tree | e26c9fed0de5d9873cce7e00bc214573dc2195b7 /util/system/mlock.h | |
download | ydb-1110808a9d39d4b808aef724c861a2e1a38d2a69.tar.gz |
intermediate changes
ref:cde9a383711a11544ce7e107a78147fb96cc4029
Diffstat (limited to 'util/system/mlock.h')
-rw-r--r-- | util/system/mlock.h | 43 |
1 files changed, 43 insertions, 0 deletions
diff --git a/util/system/mlock.h b/util/system/mlock.h new file mode 100644 index 0000000000..f021c0fe67 --- /dev/null +++ b/util/system/mlock.h @@ -0,0 +1,43 @@ +#pragma once + +#include "defaults.h" + +#include <util/generic/flags.h> + +//on some systems (not win, freebd, linux, but darwin (Mac OS X) +//multiple mlock calls on the same address range +//require the corresponding number of munlock calls to actually unlock the pages + +//on some systems you must have privilege and resource limit + +void LockMemory(const void* addr, size_t len); +void UnlockMemory(const void* addr, size_t len); + +enum ELockAllMemoryFlag { + /** Lock all pages which are currently mapped into the address space of the process. */ + LockCurrentMemory = 1, + + /** Lock all pages which will become mapped into the address space of the process in the future. */ + LockFutureMemory = 2, + + /** Since Linux 4.4, with LockCurrentMemory or LockFutureMemory or both, lock only pages that are or once they are present in memory. */ + LockMemoryOnFault = 4, +}; +Y_DECLARE_FLAGS(ELockAllMemoryFlags, ELockAllMemoryFlag) +Y_DECLARE_OPERATORS_FOR_FLAGS(ELockAllMemoryFlags) + +/** + * Performs provided locking operation. + * + * Does nothing on windows. + * + * \param flags Locking operation to perform. + */ +void LockAllMemory(ELockAllMemoryFlags flags); + +/** + * Unlocks whatever was locked with a previous call to `LockAllMemory`. + * + * Does nothing on windows. + */ +void UnlockAllMemory(); |