mirror of
https://git.rwth-aachen.de/acs/public/villas/node/
synced 2025-03-09 00:00:00 +01:00
allow for running without superuser privilges (closes #227)
This commit is contained in:
parent
1bdd597be1
commit
623e3cd8ca
2 changed files with 21 additions and 10 deletions
23
lib/memory.c
23
lib/memory.c
|
@ -27,6 +27,7 @@
|
|||
|
||||
#include <sys/time.h>
|
||||
#include <sys/resource.h>
|
||||
#include <sys/mman.h>
|
||||
|
||||
#include <villas/log.h>
|
||||
#include <villas/memory.h>
|
||||
|
@ -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;
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue