summaryrefslogtreecommitdiffstats
path: root/src/vppinfra/linux/sysfs.c
diff options
context:
space:
mode:
authorDamjan Marion <damarion@cisco.com>2018-10-24 12:56:32 +0200
committerDave Barach <openvpp@barachs.net>2018-10-24 13:26:41 +0000
commit9787f5f90a6802e39fa7954c344ba89b03a6c4af (patch)
tree0035506066ab4cadec411fc19d8af6f3f5481705 /src/vppinfra/linux/sysfs.c
parenta35fc46c0ae6e6d21b35413bdc993171265fd4e5 (diff)
vppinfra: autodetect default hugepage size
Change-Id: I5ff713ad0b254c74c5622e3b9425cca365b5ee97 Signed-off-by: Damjan Marion <damarion@cisco.com>
Diffstat (limited to 'src/vppinfra/linux/sysfs.c')
-rw-r--r--src/vppinfra/linux/sysfs.c29
1 files changed, 21 insertions, 8 deletions
diff --git a/src/vppinfra/linux/sysfs.c b/src/vppinfra/linux/sysfs.c
index 199e6bbfd69..c45897fc83b 100644
--- a/src/vppinfra/linux/sysfs.c
+++ b/src/vppinfra/linux/sysfs.c
@@ -22,8 +22,6 @@
#include <fcntl.h>
#include <dirent.h>
-#define DEFAULT_HUGETLB_SIZE 2048
-
clib_error_t *
clib_sysfs_write (char *file_name, char *fmt, ...)
{
@@ -121,8 +119,12 @@ 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;
+ uword page_size;
+
+ if (log2_page_size == 0)
+ log2_page_size = min_log2 (clib_mem_get_default_hugepage_size ());
+
+ page_size = 1ULL << (log2_page_size - 10);
p = format (p, "/sys/devices/system/node/node%u%c", numa_node, 0);
@@ -168,8 +170,14 @@ clib_sysfs_get_xxx_hugepages (char *type, int numa_node,
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;
+
+ uword page_size;
+
+ if (log2_page_size == 0)
+ log2_page_size = min_log2 (clib_mem_get_default_hugepage_size ());
+
+ page_size = 1ULL << (log2_page_size - 10);
+
p = format (p, "/sys/devices/system/node/node%u%c", numa_node, 0);
@@ -232,8 +240,13 @@ clib_sysfs_prealloc_hugepages (int numa_node, int log2_page_size, int nr)
{
clib_error_t *error = 0;
int n, needed;
- int page_size = log2_page_size ? 1ULL << (log2_page_size - 10) :
- DEFAULT_HUGETLB_SIZE;
+ uword page_size;
+
+ if (log2_page_size == 0)
+ log2_page_size = min_log2 (clib_mem_get_default_hugepage_size ());
+
+ page_size = 1ULL << (log2_page_size - 10);
+
error = clib_sysfs_get_free_hugepages (numa_node, log2_page_size, &n);
if (error)
return error;