aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDamjan Marion <damarion@cisco.com>2021-09-21 11:38:04 +0200
committerAndrew Yourtchenko <ayourtch@gmail.com>2021-09-22 08:29:23 +0000
commitff011b256012157e2b7ccf2b9298a24b1322c770 (patch)
tree15d6ea44f0b5697f260efa8030d1865aa4e8431f
parent266929f2e498a8748edd8fc6ba5ef4e28226d04c (diff)
vppinfra: make default hugepage size configurable
i.e. memory { default-hugepage-size 1G } Type: improvement Change-Id: I822afb51712ae92f4e4992b8ffa33dcb15ccaef1 Signed-off-by: Damjan Marion <damarion@cisco.com>
-rw-r--r--src/vpp/conf/startup.conf2
-rw-r--r--src/vpp/vnet/main.c8
-rw-r--r--src/vppinfra/linux/mem.c38
-rw-r--r--src/vppinfra/mem.h18
4 files changed, 29 insertions, 37 deletions
diff --git a/src/vpp/conf/startup.conf b/src/vpp/conf/startup.conf
index d96a4307231..ee10faa8683 100644
--- a/src/vpp/conf/startup.conf
+++ b/src/vpp/conf/startup.conf
@@ -51,6 +51,8 @@ socksvr {
## special keyword 'default-hugepage' will use system default hugepage
## size
# main-heap-page-size 1G
+ ## Set the default huge page size.
+ # default-hugepage-size 1G
#}
cpu {
diff --git a/src/vpp/vnet/main.c b/src/vpp/vnet/main.c
index bf1eb7a1d1d..695c358f765 100644
--- a/src/vpp/vnet/main.c
+++ b/src/vpp/vnet/main.c
@@ -111,6 +111,7 @@ main (int argc, char *argv[])
u8 *sizep;
u32 size;
clib_mem_page_sz_t main_heap_log2_page_sz = CLIB_MEM_PAGE_SZ_DEFAULT;
+ clib_mem_page_sz_t default_log2_hugepage_sz = CLIB_MEM_PAGE_SZ_UNKNOWN;
unformat_input_t input, sub_input;
u8 *s = 0, *v = 0;
int main_core = 1;
@@ -291,6 +292,10 @@ defaulted:
unformat_log2_page_size,
&main_heap_log2_page_sz))
;
+ else if (unformat (&sub_input, "default-hugepage-size %U",
+ unformat_log2_page_size,
+ &default_log2_hugepage_sz))
+ ;
else
{
fformat (stderr, "unknown 'memory' config input '%U'\n",
@@ -329,6 +334,9 @@ defaulted:
/* Figure out which numa runs the main thread */
__os_numa_index = clib_get_current_numa_node ();
+ if (default_log2_hugepage_sz != CLIB_MEM_PAGE_SZ_UNKNOWN)
+ clib_mem_set_log2_default_hugepage_size (default_log2_hugepage_sz);
+
/* and use the main heap as that numa's numa heap */
clib_mem_set_per_numa_heap (main_heap);
vlib_main_init ();
diff --git a/src/vppinfra/linux/mem.c b/src/vppinfra/linux/mem.c
index 036890f9c8d..3b752cf43cf 100644
--- a/src/vppinfra/linux/mem.c
+++ b/src/vppinfra/linux/mem.c
@@ -75,40 +75,6 @@ map_unlock ()
clib_atomic_release (&clib_mem_main.map_lock);
}
-__clib_export uword
-clib_mem_get_default_hugepage_size (void)
-{
- unformat_input_t input;
- static u32 size = 0;
- int fd;
-
- if (size)
- goto done;
-
- /*
- * If the kernel doesn't support hugepages, /proc/meminfo won't
- * say anything about it. Use the regular page size as a default.
- */
- size = clib_mem_get_page_size () / 1024;
-
- 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;
-}
-
static clib_mem_page_sz_t
legacy_get_log2_default_hugepage_size (void)
{
@@ -156,6 +122,8 @@ clib_mem_main_init ()
else /* likely kernel older than 4.14 */
mm->log2_default_hugepage_sz = legacy_get_log2_default_hugepage_size ();
+ mm->log2_sys_default_hugepage_sz = mm->log2_default_hugepage_sz;
+
/* numa nodes */
va = mmap (0, page_size, PROT_READ | PROT_WRITE, MAP_PRIVATE |
MAP_ANONYMOUS, -1, 0);
@@ -270,7 +238,7 @@ clib_mem_vm_create_fd (clib_mem_page_sz_t log2_page_size, char *fmt, ...)
if (log2_page_size == mm->log2_page_sz)
log2_page_size = CLIB_MEM_PAGE_SZ_DEFAULT;
- else if (log2_page_size == mm->log2_default_hugepage_sz)
+ else if (log2_page_size == mm->log2_sys_default_hugepage_sz)
log2_page_size = CLIB_MEM_PAGE_SZ_DEFAULT_HUGE;
switch (log2_page_size)
diff --git a/src/vppinfra/mem.h b/src/vppinfra/mem.h
index 1cab0ae7252..dfe8de93626 100644
--- a/src/vppinfra/mem.h
+++ b/src/vppinfra/mem.h
@@ -130,9 +130,12 @@ typedef struct
/* log2 system page size */
clib_mem_page_sz_t log2_page_sz;
- /* log2 system default hugepage size */
+ /* log2 default hugepage size */
clib_mem_page_sz_t log2_default_hugepage_sz;
+ /* log2 system default hugepage size */
+ clib_mem_page_sz_t log2_sys_default_hugepage_sz;
+
/* bitmap of available numa nodes */
u32 numa_node_bitmap;
@@ -470,15 +473,26 @@ clib_mem_get_page_size (void)
return 1ULL << clib_mem_main.log2_page_sz;
}
+static_always_inline void
+clib_mem_set_log2_default_hugepage_size (clib_mem_page_sz_t log2_page_sz)
+{
+ clib_mem_main.log2_default_hugepage_sz = log2_page_sz;
+}
+
static_always_inline clib_mem_page_sz_t
clib_mem_get_log2_default_hugepage_size ()
{
return clib_mem_main.log2_default_hugepage_sz;
}
+static_always_inline uword
+clib_mem_get_default_hugepage_size (void)
+{
+ return 1ULL << clib_mem_main.log2_default_hugepage_sz;
+}
+
int clib_mem_vm_create_fd (clib_mem_page_sz_t log2_page_size, char *fmt, ...);
uword clib_mem_get_fd_page_size (int fd);
-uword clib_mem_get_default_hugepage_size (void);
clib_mem_page_sz_t clib_mem_get_fd_log2_page_size (int fd);
uword clib_mem_vm_reserve (uword start, uword size,
clib_mem_page_sz_t log2_page_sz);