From 4a8039c26c7cc5aaa9b4485315879fba8fadacf7 Mon Sep 17 00:00:00 2001 From: Matias Elo Date: Wed, 14 Nov 2018 14:28:53 +0200 Subject: linux-gen: ishm: add config option for selecting huge page usage limit Add configuration option for selecting huge page usage limit in kilobytes. Memory reservations larger than this value are done using huge pages (if available), whereas smaller reservations are done using normal pages to conserve memory. The default value is still 64 kilobytes. Signed-off-by: Matias Elo Reviewed-by: Bill Fischofer Signed-off-by: Maxim Uvarov --- config/odp-linux-generic.conf | 5 +++++ platform/linux-generic/odp_ishm.c | 30 ++++++++++++++++++------------ 2 files changed, 23 insertions(+), 12 deletions(-) diff --git a/config/odp-linux-generic.conf b/config/odp-linux-generic.conf index 8f39ff7cf..895f996bb 100644 --- a/config/odp-linux-generic.conf +++ b/config/odp-linux-generic.conf @@ -34,6 +34,11 @@ shm: { # because the current implementation won't work properly otherwise. num_cached_hp = 0 + # Huge page usage limit in kilobytes. Memory reservations larger than + # this value are done using huge pages (if available). Smaller + # reservations are done using normal pages to conserve memory. + huge_page_limit_kb = 64 + # Amount of memory pre-reserved for ODP_SHM_SINGLE_VA usage in kilobytes single_va_size_kb = 131072 } diff --git a/platform/linux-generic/odp_ishm.c b/platform/linux-generic/odp_ishm.c index eea527db8..eceadd99e 100644 --- a/platform/linux-generic/odp_ishm.c +++ b/platform/linux-generic/odp_ishm.c @@ -113,13 +113,6 @@ */ #define ISHM_NB_FRAGMNTS (ISHM_MAX_NB_BLOCKS * 2 + 1) -/* - * Memory reservations larger than ISHM_HUGE_PAGE_LIMIT (bytes) are allocated - * using huge pages (if available). Smaller reservations are done using normal - * pages to conserve memory. - */ -#define ISHM_HUGE_PAGE_LIMIT (64 * 1024) - /* * when a memory block is to be exported outside its ODP instance, * an block 'attribute file' is created in /dev/shm/odp--shm-. @@ -190,6 +183,8 @@ typedef struct ishm_block { typedef struct { odp_spinlock_t lock; uint64_t dev_seq; /* used when creating device names */ + /* limit for reserving memory using huge pages */ + uint64_t huge_page_limit; uint32_t odpthread_cnt; /* number of running ODP threads */ ishm_block_t block[ISHM_MAX_NB_BLOCKS]; void *single_va_start; /* start of single VA memory */ @@ -1101,7 +1096,7 @@ int _odp_ishm_reserve(const char *name, uint64_t size, int fd, /* Otherwise, Try first huge pages when possible and needed: */ if ((fd < 0) && page_hp_size && ((flags & _ODP_ISHM_USE_HP) || - size > ISHM_HUGE_PAGE_LIMIT)) { + size > ishm_tbl->huge_page_limit)) { /* at least, alignment in VA should match page size, but user * can request more: If the user requirement exceeds the page * size then we have to make sure the block will be mapped at @@ -1636,23 +1631,33 @@ int _odp_ishm_init_global(const odp_init_t *init) void *addr; void *spce_addr = NULL; int i; - int single_va_size_kb = 0; + int val_kb; uid_t uid; char *hp_dir = odp_global_ro.hugepage_info.default_huge_page_dir; uint64_t max_memory; uint64_t internal; + uint64_t huge_page_limit; if (!_odp_libconfig_lookup_ext_int("shm", NULL, "single_va_size_kb", - &single_va_size_kb)) { + &val_kb)) { ODP_ERR("Unable to read single VA size from config\n"); return -1; } - ODP_DBG("Shm single VA size: %dkB\n", single_va_size_kb); + ODP_DBG("Shm single VA size: %dkB\n", val_kb); - max_memory = single_va_size_kb * 1024; + max_memory = val_kb * 1024; internal = max_memory / 8; + if (!_odp_libconfig_lookup_ext_int("shm", NULL, "huge_page_limit_kb", + &val_kb)) { + ODP_ERR("Unable to read huge page usage limit from config\n"); + return -1; + } + huge_page_limit = (uint64_t)val_kb * 1024; + + ODP_DBG("Shm huge page usage limit: %dkB\n", val_kb); + /* user requested memory size + some extra for internal use */ if (init && init->shm.max_memory) max_memory = init->shm.max_memory + internal; @@ -1703,6 +1708,7 @@ int _odp_ishm_init_global(const odp_init_t *init) memset(ishm_tbl, 0, sizeof(ishm_table_t)); ishm_tbl->dev_seq = 0; ishm_tbl->odpthread_cnt = 0; + ishm_tbl->huge_page_limit = huge_page_limit; odp_spinlock_init(&ishm_tbl->lock); /* allocate space for the internal shared mem fragment table: */ -- cgit v1.2.3