mirror of
https://git.rwth-aachen.de/acs/public/villas/node/
synced 2025-03-09 00:00:00 +01:00
memory: Added a fallback to use mmap without hugepages in case mmap with hugepages fails; in case the fallback is used, a warning is provided to the user
This commit is contained in:
parent
5c179a6609
commit
aaf20934fd
1 changed files with 21 additions and 2 deletions
|
@ -72,8 +72,27 @@ static struct memory_allocation * memory_hugepage_alloc(struct memory_type *m, s
|
|||
|
||||
ma->address = mmap(NULL, ma->length, prot, flags, -1, 0);
|
||||
if (ma->address == MAP_FAILED) {
|
||||
free(ma);
|
||||
return NULL;
|
||||
//try again without hugepages as fallback solution, warn the user
|
||||
|
||||
prot= PROT_READ | PROT_WRITE;
|
||||
//same flags as above without hugepages
|
||||
flags = MAP_PRIVATE | MAP_ANONYMOUS;
|
||||
#ifdef __linux__
|
||||
if(getuid() == 0){
|
||||
flags |= MAP_LOCKED;
|
||||
}
|
||||
#endif
|
||||
//length has to be aligned with pagesize
|
||||
ma->length = ALIGN(len, getpagesize());
|
||||
//try mmap again
|
||||
ma->address = mmap(NULL, ma->length, prot, flags, -1, 0);
|
||||
if(ma->address == MAP_FAILED){
|
||||
free(ma);
|
||||
return NULL;
|
||||
}
|
||||
else{
|
||||
warn("memory_hugepage_alloc: hugepage could not be mapped, mapped without hugepages instead!");
|
||||
}
|
||||
}
|
||||
|
||||
return ma;
|
||||
|
|
Loading…
Add table
Reference in a new issue