diff mbox series

[API-NEXT,v1,3/3] linux-gen: shm: use global init max memory

Message ID 1517500809-452-4-git-send-email-odpbot@yandex.ru
State Superseded
Headers show
Series [API-NEXT,v1,1/3] validation: shm: test capa and maximum reservation | expand

Commit Message

Github ODP bot Feb. 1, 2018, 4 p.m. UTC
From: Petri Savolainen <petri.savolainen@linaro.org>


Use global init parameter to allow application to use more than
512 MB of shared memory.

Signed-off-by: Petri Savolainen <petri.savolainen@linaro.org>

---
/** Email created from pull request 446 (psavol:next-global-init-shm-size-2)
 ** https://github.com/Linaro/odp/pull/446
 ** Patch: https://github.com/Linaro/odp/pull/446.patch
 ** Base sha: 5718327018debbb02aacb464493504c95fbe57a3
 ** Merge commit sha: 5beffee2f03442764ec79a301dd6608c8e82c8b4
 **/
 platform/linux-generic/_ishm.c                | 16 ++++++++++++----
 platform/linux-generic/include/odp_internal.h |  4 +++-
 platform/linux-generic/odp_init.c             |  2 +-
 platform/linux-generic/odp_shared_memory.c    |  3 ++-
 4 files changed, 18 insertions(+), 7 deletions(-)
diff mbox series

Patch

diff --git a/platform/linux-generic/_ishm.c b/platform/linux-generic/_ishm.c
index 81d77edc0..ab112acea 100644
--- a/platform/linux-generic/_ishm.c
+++ b/platform/linux-generic/_ishm.c
@@ -258,7 +258,7 @@  static void *alloc_fragment(uintptr_t size, int block_index, intptr_t align,
 	ishm_fragment_t *rem_fragmnt;
 	uintptr_t border;/* possible start of new fragment (next alignement)  */
 	intptr_t left;	 /* room remaining after, if the segment is allocated */
-	uintptr_t remainder = ODP_CONFIG_ISHM_VA_PREALLOC_SZ;
+	uintptr_t remainder = odp_global_data.shm_max_memory;
 
 	/*
 	 * search for the best bit, i.e. search for the unallocated fragment
@@ -1436,7 +1436,7 @@  int _odp_ishm_cleanup_files(const char *dirpath)
 	return 0;
 }
 
-int _odp_ishm_init_global(void)
+int _odp_ishm_init_global(const odp_init_t *init)
 {
 	void *addr;
 	void *spce_addr;
@@ -1444,7 +1444,15 @@  int _odp_ishm_init_global(void)
 	uid_t uid;
 	char *hp_dir = odp_global_data.hugepage_info.default_huge_page_dir;
 	uint64_t align;
+	uint64_t max_memory = ODP_CONFIG_ISHM_VA_PREALLOC_SZ;
+	uint64_t internal   = ODP_CONFIG_ISHM_VA_PREALLOC_SZ / 8;
 
+	/* user requested memory size + some extra for internal use */
+	if (init && init->shm.max_memory)
+		max_memory = init->shm.max_memory + internal;
+
+	odp_global_data.shm_max_memory = max_memory;
+	odp_global_data.shm_max_size   = max_memory - internal;
 	odp_global_data.main_pid = getpid();
 	odp_global_data.shm_dir = getenv("ODP_SHM_DIR");
 	if (odp_global_data.shm_dir) {
@@ -1507,7 +1515,7 @@  int _odp_ishm_init_global(void)
 	 *reserve the address space for _ODP_ISHM_SINGLE_VA reserved blocks,
 	 * only address space!
 	 */
-	spce_addr = _odp_ishmphy_book_va(ODP_CONFIG_ISHM_VA_PREALLOC_SZ, align);
+	spce_addr = _odp_ishmphy_book_va(max_memory, align);
 	if (!spce_addr) {
 		ODP_ERR("unable to reserve virtual space\n.");
 		goto init_glob_err3;
@@ -1516,7 +1524,7 @@  int _odp_ishm_init_global(void)
 	/* use the first fragment descriptor to describe to whole VA space: */
 	ishm_ftbl->fragment[0].block_index   = -1;
 	ishm_ftbl->fragment[0].start = spce_addr;
-	ishm_ftbl->fragment[0].len   = ODP_CONFIG_ISHM_VA_PREALLOC_SZ;
+	ishm_ftbl->fragment[0].len   = max_memory;
 	ishm_ftbl->fragment[0].prev  = NULL;
 	ishm_ftbl->fragment[0].next  = NULL;
 	ishm_ftbl->used_fragmnts   = &ishm_ftbl->fragment[0];
diff --git a/platform/linux-generic/include/odp_internal.h b/platform/linux-generic/include/odp_internal.h
index a21e93c8b..444e1163b 100644
--- a/platform/linux-generic/include/odp_internal.h
+++ b/platform/linux-generic/include/odp_internal.h
@@ -44,6 +44,8 @@  typedef struct {
 struct odp_global_data_s {
 	char *shm_dir; /*< directory for odp mmaped files */
 	int   shm_dir_from_env; /*< overload default with env */
+	uint64_t shm_max_memory;
+	uint64_t shm_max_size;
 	pid_t main_pid;
 	char uid[UID_MAXLEN];
 	odp_log_func_t log_fn;
@@ -129,7 +131,7 @@  int _odp_int_name_tbl_term_global(void);
 int _odp_fdserver_init_global(void);
 int _odp_fdserver_term_global(void);
 
-int _odp_ishm_init_global(void);
+int _odp_ishm_init_global(const odp_init_t *init);
 int _odp_ishm_init_local(void);
 int _odp_ishm_term_global(void);
 int _odp_ishm_term_local(void);
diff --git a/platform/linux-generic/odp_init.c b/platform/linux-generic/odp_init.c
index be75a530b..a2d9d52ff 100644
--- a/platform/linux-generic/odp_init.c
+++ b/platform/linux-generic/odp_init.c
@@ -66,7 +66,7 @@  int odp_init_global(odp_instance_t *instance,
 	}
 	stage = SYSINFO_INIT;
 
-	if (_odp_ishm_init_global()) {
+	if (_odp_ishm_init_global(params)) {
 		ODP_ERR("ODP ishm init failed.\n");
 		goto init_failed;
 	}
diff --git a/platform/linux-generic/odp_shared_memory.c b/platform/linux-generic/odp_shared_memory.c
index c322c7eb0..c9b04dfdb 100644
--- a/platform/linux-generic/odp_shared_memory.c
+++ b/platform/linux-generic/odp_shared_memory.c
@@ -12,6 +12,7 @@ 
 #include <odp/api/shared_memory.h>
 #include <odp/api/plat/strong_types.h>
 #include <_ishm_internal.h>
+#include <odp_internal.h>
 #include <string.h>
 
 ODP_STATIC_ASSERT(ODP_CONFIG_SHM_BLOCKS >= ODP_CONFIG_POOLS,
@@ -47,7 +48,7 @@  int odp_shm_capability(odp_shm_capability_t *capa)
 	memset(capa, 0, sizeof(odp_shm_capability_t));
 
 	capa->max_blocks = ODP_CONFIG_SHM_BLOCKS;
-	capa->max_size = 0;
+	capa->max_size = odp_global_data.shm_max_size;
 	capa->max_align = 0;
 
 	return 0;