diff --git a/bolt/runtime/common.h b/bolt/runtime/common.h --- a/bolt/runtime/common.h +++ b/bolt/runtime/common.h @@ -422,6 +422,16 @@ return ret; } +int __munlock(void *addr, size_t length) { + int ret; + __asm__ __volatile__("movq $0x96, %%rax\n" + "syscall\n" + : "=a"(ret) + : "D"(addr), "S"(length) + : "cc", "rcx", "r11", "memory"); + return ret; +} + #define _UTSNAME_LENGTH 65 struct UtsNameTy { diff --git a/bolt/runtime/hugify.cpp b/bolt/runtime/hugify.cpp --- a/bolt/runtime/hugify.cpp +++ b/bolt/runtime/hugify.cpp @@ -157,6 +157,10 @@ return; } + if (__munlock(From, (To - From)) == -1) { + char Msg[] = "[hugify] failed to unlock memory\n"; + reportError(Msg, sizeof(Msg)); + } if (__madvise(From, (To - From), 14 /* MADV_HUGEPAGE */) == -1) { char Msg[] = "[hugify] failed to allocate large page\n"; // TODO: allow user to control the failure behavior.