summaryrefslogtreecommitdiffstats
path: root/src/vppinfra/linux/mem.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/mem.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/mem.c')
-rw-r--r--src/vppinfra/linux/mem.c35
1 files changed, 35 insertions, 0 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)
{