aboutsummaryrefslogtreecommitdiffstats
path: root/src/vppinfra/linux
diff options
context:
space:
mode:
Diffstat (limited to 'src/vppinfra/linux')
-rw-r--r--src/vppinfra/linux/mem.c3
-rw-r--r--src/vppinfra/linux/sysfs.c33
-rw-r--r--src/vppinfra/linux/sysfs.h10
3 files changed, 27 insertions, 19 deletions
diff --git a/src/vppinfra/linux/mem.c b/src/vppinfra/linux/mem.c
index 253ae87845b..2fbda966bc0 100644
--- a/src/vppinfra/linux/mem.c
+++ b/src/vppinfra/linux/mem.c
@@ -221,8 +221,7 @@ clib_mem_vm_ext_alloc (clib_mem_vm_alloc_t * a)
if (a->flags & CLIB_MEM_VM_F_HUGETLB_PREALLOC)
{
- err = clib_sysfs_prealloc_hugepages (a->numa_node,
- 1 << (log2_page_size - 10),
+ err = clib_sysfs_prealloc_hugepages (a->numa_node, log2_page_size,
n_pages);
if (err)
goto error;
diff --git a/src/vppinfra/linux/sysfs.c b/src/vppinfra/linux/sysfs.c
index 5f611e6a341..199e6bbfd69 100644
--- a/src/vppinfra/linux/sysfs.c
+++ b/src/vppinfra/linux/sysfs.c
@@ -22,6 +22,8 @@
#include <fcntl.h>
#include <dirent.h>
+#define DEFAULT_HUGETLB_SIZE 2048
+
clib_error_t *
clib_sysfs_write (char *file_name, char *fmt, ...)
{
@@ -114,11 +116,13 @@ clib_sysfs_link_to_name (char *link)
}
clib_error_t *
-clib_sysfs_set_nr_hugepages (int numa_node, int page_size, int nr)
+clib_sysfs_set_nr_hugepages (int numa_node, int log2_page_size, int nr)
{
clib_error_t *error = 0;
struct stat sb;
u8 *p = 0;
+ int page_size = log2_page_size ? 1ULL << (log2_page_size - 10) :
+ DEFAULT_HUGETLB_SIZE;
p = format (p, "/sys/devices/system/node/node%u%c", numa_node, 0);
@@ -159,11 +163,13 @@ done:
static clib_error_t *
clib_sysfs_get_xxx_hugepages (char *type, int numa_node,
- int page_size, int *val)
+ int log2_page_size, int *val)
{
clib_error_t *error = 0;
struct stat sb;
u8 *p = 0;
+ int page_size = log2_page_size ? 1ULL << (log2_page_size - 10) :
+ DEFAULT_HUGETLB_SIZE;
p = format (p, "/sys/devices/system/node/node%u%c", numa_node, 0);
@@ -203,41 +209,44 @@ done:
}
clib_error_t *
-clib_sysfs_get_free_hugepages (int numa_node, int page_size, int *v)
+clib_sysfs_get_free_hugepages (int numa_node, int log2_page_size, int *v)
{
- return clib_sysfs_get_xxx_hugepages ("free", numa_node, page_size, v);
+ return clib_sysfs_get_xxx_hugepages ("free", numa_node, log2_page_size, v);
}
clib_error_t *
-clib_sysfs_get_nr_hugepages (int numa_node, int page_size, int *v)
+clib_sysfs_get_nr_hugepages (int numa_node, int log2_page_size, int *v)
{
- return clib_sysfs_get_xxx_hugepages ("nr", numa_node, page_size, v);
+ return clib_sysfs_get_xxx_hugepages ("nr", numa_node, log2_page_size, v);
}
clib_error_t *
-clib_sysfs_get_surplus_hugepages (int numa_node, int page_size, int *v)
+clib_sysfs_get_surplus_hugepages (int numa_node, int log2_page_size, int *v)
{
- return clib_sysfs_get_xxx_hugepages ("surplus", numa_node, page_size, v);
+ return clib_sysfs_get_xxx_hugepages ("surplus", numa_node, log2_page_size,
+ v);
}
clib_error_t *
-clib_sysfs_prealloc_hugepages (int numa_node, int page_size, int nr)
+clib_sysfs_prealloc_hugepages (int numa_node, int log2_page_size, int nr)
{
clib_error_t *error = 0;
int n, needed;
- error = clib_sysfs_get_free_hugepages (numa_node, page_size, &n);
+ int page_size = log2_page_size ? 1ULL << (log2_page_size - 10) :
+ DEFAULT_HUGETLB_SIZE;
+ error = clib_sysfs_get_free_hugepages (numa_node, log2_page_size, &n);
if (error)
return error;
needed = nr - n;
if (needed <= 0)
return 0;
- error = clib_sysfs_get_nr_hugepages (numa_node, page_size, &n);
+ error = clib_sysfs_get_nr_hugepages (numa_node, log2_page_size, &n);
if (error)
return error;
clib_warning ("pre-allocating %u additional %uK hugepages on numa node %u",
needed, page_size, numa_node);
- return clib_sysfs_set_nr_hugepages (numa_node, page_size, n + needed);
+ return clib_sysfs_set_nr_hugepages (numa_node, log2_page_size, n + needed);
}
diff --git a/src/vppinfra/linux/sysfs.h b/src/vppinfra/linux/sysfs.h
index 6c80cf95dbb..5f5eec2d07a 100644
--- a/src/vppinfra/linux/sysfs.h
+++ b/src/vppinfra/linux/sysfs.h
@@ -25,15 +25,15 @@ clib_error_t *clib_sysfs_read (char *file_name, char *fmt, ...);
u8 *clib_sysfs_link_to_name (char *link);
clib_error_t *clib_sysfs_set_nr_hugepages (int numa_node,
- int page_size, int nr);
+ int log2_page_size, int nr);
clib_error_t *clib_sysfs_get_nr_hugepages (int numa_node,
- int page_size, int *v);
+ int log2_page_size, int *v);
clib_error_t *clib_sysfs_get_free_hugepages (int numa_node,
- int page_size, int *v);
+ int log2_page_size, int *v);
clib_error_t *clib_sysfs_get_surplus_hugepages (int numa_node,
- int page_size, int *v);
+ int log2_page_size, int *v);
clib_error_t *clib_sysfs_prealloc_hugepages (int numa_node,
- int page_size, int nr);
+ int log2_page_size, int nr);
#endif /* included_linux_sysfs_h */