aboutsummaryrefslogtreecommitdiffstats
path: root/util/system/mincore.cpp
diff options
context:
space:
mode:
authorDevtools Arcadia <arcadia-devtools@yandex-team.ru>2022-02-07 18:08:42 +0300
committerDevtools Arcadia <arcadia-devtools@mous.vla.yp-c.yandex.net>2022-02-07 18:08:42 +0300
commit1110808a9d39d4b808aef724c861a2e1a38d2a69 (patch)
treee26c9fed0de5d9873cce7e00bc214573dc2195b7 /util/system/mincore.cpp
downloadydb-1110808a9d39d4b808aef724c861a2e1a38d2a69.tar.gz
intermediate changes
ref:cde9a383711a11544ce7e107a78147fb96cc4029
Diffstat (limited to 'util/system/mincore.cpp')
-rw-r--r--util/system/mincore.cpp35
1 files changed, 35 insertions, 0 deletions
diff --git a/util/system/mincore.cpp b/util/system/mincore.cpp
new file mode 100644
index 0000000000..8cbae72586
--- /dev/null
+++ b/util/system/mincore.cpp
@@ -0,0 +1,35 @@
+#include "align.h"
+#include "compiler.h"
+#include "info.h"
+#include "mincore.h"
+
+#include <util/generic/yexception.h>
+
+#include <cstring>
+
+#if defined(_unix_)
+ #include <sys/unistd.h>
+ #include <sys/mman.h>
+ #if defined(_android_)
+ #include <sys/syscall.h>
+ #endif
+#endif
+
+void InCoreMemory(const void* addr, size_t len, unsigned char* vec, size_t vecLen) {
+#if defined(_linux_)
+ const size_t pageSize = NSystemInfo::GetPageSize();
+ void* maddr = const_cast<void*>(AlignDown(addr, pageSize));
+ len = AlignUp(len, pageSize);
+ if (vecLen * pageSize < len) {
+ ythrow yexception() << "vector argument for mincore is too small: " << vecLen * pageSize << " < " << len;
+ }
+ if (::mincore(maddr, len, vec)) {
+ ythrow yexception() << LastSystemErrorText();
+ }
+#else
+ // pessimistic assumption: nothing is in core
+ Y_UNUSED(addr);
+ Y_UNUSED(len);
+ ::memset(vec, 0, vecLen);
+#endif
+}