aboutsummaryrefslogtreecommitdiffstats
path: root/src/vppinfra/linux
diff options
context:
space:
mode:
Diffstat (limited to 'src/vppinfra/linux')
-rw-r--r--src/vppinfra/linux/mem.c35
-rw-r--r--src/vppinfra/linux/sysfs.c29
2 files changed, 56 insertions, 8 deletions
diff --git a/src/vppinfra/linux/mem.c b/src/vppinfra/linux/mem.c
index 2fbda966bc0..6a551ec0554 100644
--- a/src/vppinfra/linux/mem.c
+++ b/src/vppinfra/linux/mem.c
@@ -46,6 +46,41 @@
#define F_SEAL_WRITE 0x0008 /* prevent writes */
#endif
+
+uword
+clib_mem_get_page_size (void)
+{
+ return getpagesize ();
+}
+
+uword
+clib_mem_get_default_hugepage_size (void)
+{
+ unformat_input_t input;
+ static u32 size = 0;
+ int fd;
+
+ if (size)
+ goto done;
+
+ if ((fd = open ("/proc/meminfo", 0)) == -1)
+ return 0;
+
+ unformat_init_clib_file (&input, fd);
+
+ while (unformat_check_input (&input) != UNFORMAT_END_OF_INPUT)
+ {
+ if (unformat (&input, "Hugepagesize:%_%u kB", &size))
+ ;
+ else
+ unformat_skip_line (&input);
+ }
+ unformat_free (&input);
+ close (fd);
+done:
+ return 1024ULL * size;
+}
+
u64
clib_mem_vm_get_page_size (int fd)
{
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;