diff --git a/lib/memory.c b/lib/memory.c index 4da9df6c3..2d3fe823b 100644 --- a/lib/memory.c +++ b/lib/memory.c @@ -27,6 +27,7 @@ #include #include +#include #include #include @@ -70,10 +71,14 @@ int memory_init(int hugepages) int memory_lock(size_t lock) { -#if defined(__linux__) && defined(__x86_64__) int ret; + +#ifdef __linux__ + +#ifndef __arm__ struct rlimit l; + /* Increase ressource limit for locked memory */ ret = getrlimit(RLIMIT_MEMLOCK, &l); if (ret) return ret; @@ -81,11 +86,10 @@ int memory_lock(size_t lock) if (l.rlim_cur < lock) { if (l.rlim_max < lock) { if (getuid() != 0) { - warning("Failed to in increase ressource limit of locked memory from %lu to %zu bytes", l.rlim_cur, lock); - warning("Please re-run as super-user or raise manually via:"); + warning("Failed to in increase ressource limit of locked memory. Please increase manually by running as root:"); warning(" $ ulimit -Hl %zu", lock); - return -1; + goto out; } l.rlim_max = lock; @@ -99,7 +103,16 @@ int memory_lock(size_t lock) debug(LOG_MEM | 2, "Increased ressource limit of locked memory to %zd bytes", lock); } -#endif +#endif /* __arm__ */ +out: +#ifdef _POSIX_MEMLOCK + /* Lock all current and future memory allocations */ + ret = mlockall(MCL_CURRENT | MCL_FUTURE); + if (ret) { + return -1; +#endif /* _POSIX_MEMLOCK */ + +#endif /* __linux__ */ return 0; } diff --git a/lib/memory/hugepage.c b/lib/memory/hugepage.c index 7d4f592fe..276cdca25 100644 --- a/lib/memory/hugepage.c +++ b/lib/memory/hugepage.c @@ -65,10 +65,8 @@ int memory_hugepage_init(int hugepages) debug(LOG_MEM | 2, "Increased number of reserved hugepages from %d to %d", pagecnt, hugepages); } else { - warning("Failed to reserved hugepages. Please re-run as super-user or reserve manually via:"); + warning("Failed to reserved hugepages. Please reserve manually by running as root:"); warning(" $ echo %d > /proc/sys/vm/nr_hugepages", hugepages); - - return -1; } } #endif @@ -81,7 +79,7 @@ static struct memory_allocation * memory_hugepage_alloc(struct memory_type *m, s { static bool use_huge = true; - int ret, flags, fd; + int flags, fd; size_t sz; struct memory_allocation *ma = alloc(sizeof(struct memory_allocation)); @@ -120,7 +118,7 @@ retry: if (use_huge) { ma->address = mmap(NULL, ma->length, PROT_READ | PROT_WRITE, flags, fd, 0); if (ma->address == MAP_FAILED) { if (use_huge) { - warning("Failed to map hugepages, try with normal pages instead"); + warning("Failed to map hugepages, try with normal pages instead!"); use_huge = false; goto retry; }