Commit f2f4ca8e authored by Sonja Happ's avatar Sonja Happ

memory: init page size for mmap even if number of hugepages is equal to 0

parent b1130135
......@@ -60,4 +60,4 @@ extern struct memory_type *memory_default;
struct memory_type * memory_ib(struct node *n, struct memory_type *parent);
struct memory_type * memory_managed(void *ptr, size_t len);
int memory_hugepage_init(int hugepages);
int memory_mmap_init(int hugepages);
......@@ -44,18 +44,9 @@ int memory_init(int hugepages)
info("Initialize memory sub-system: #hugepages=%d", hugepages);
if (hugepages > 0) {
ret = memory_hugepage_init(hugepages);
if (ret)
return ret;
memory_default = &memory_mmap_hugetlb;
}
else {
memory_default = &memory_mmap;
warning("Hugepage allocator disabled.");
}
ret = memory_mmap_init(hugepages);
if (ret < 0)
return ret;
size_t lock = kernel_get_hugepage_size() * hugepages;
......
......@@ -45,32 +45,36 @@ using namespace villas::utils;
static size_t pgsz = -1;
static size_t hugepgsz = -1;
int memory_hugepage_init(int hugepages)
int memory_mmap_init(int hugepages)
{
pgsz = kernel_get_page_size();
if (pgsz < 0)
return -1;
hugepgsz = kernel_get_hugepage_size();
if (hugepgsz < 0)
return -1;
if (hugepages > 0) {
hugepgsz = kernel_get_hugepage_size();
if (hugepgsz < 0)
return -1;
#if defined(__linux__) && defined(__x86_64__)
int pagecnt;
pagecnt = kernel_get_nr_hugepages();
if (pagecnt < hugepages) {
if (getuid() == 0) {
kernel_set_nr_hugepages(hugepages);
debug(LOG_MEM | 2, "Increased number of reserved hugepages from %d to %d", pagecnt, hugepages);
}
else {
warning("Failed to reserved hugepages. Please reserve manually by running as root:");
warning(" $ echo %d > /proc/sys/vm/nr_hugepages", hugepages);
}
}
int pagecnt;
pagecnt = kernel_get_nr_hugepages();
if (pagecnt < hugepages) {
if (getuid() == 0) {
kernel_set_nr_hugepages(hugepages);
debug(LOG_MEM | 2, "Increased number of reserved hugepages from %d to %d", pagecnt, hugepages);
} else {
warning("Failed to reserved hugepages. Please reserve manually by running as root:");
warning(" $ echo %d > /proc/sys/vm/nr_hugepages", hugepages);
}
}
#endif
memory_default = &memory_mmap_hugetlb;
} else {
warning("Hugepage allocator disabled.");
memory_default = &memory_mmap;
}
return 0;
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment