Skip to contentSkip to conversation

Fix unneeded pre-commit of memory pool when CONFIG_XENO_PSHARED set

PATCH Applied Charles Kiorpes 2 participants 2 messages Nov 3, 2017 – Nov 5, 2017

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 Fix unneeded pre-commit of memory pool when CONFIG_XENO_PSHARED set

When CONFIG_XENO_PSHARED is set, heapobj_pkg_init_private() was causing unneeded pages to be locked into memory by performing a temporary allocation of the size of the entire memory pool.

This patch reduces the size of this temporary allocation to a single page when CONFIG_XENO_PSHARED is set.

---
 lib/copperplate/heapobj-tlsf.c | 23 ++++++++++++++++++-----
 1 file changed, 18 insertions(+), 5 deletions(-)
lib/copperplate/heapobj-tlsf.c +18 -5
index e24db15..3709852 100644
@@ -19,6 +19,7 @@
 #include <errno.h>
 #include <stdio.h>
 #include <stdint.h>
+#include <unistd.h>
 #include "boilerplate/tlsf/tlsf.h"
 #include "copperplate/heapobj.h"
 #include "copperplate/debug.h"
@@ -76,7 +77,12 @@ int heapobj_init_array_private(struct heapobj *hobj, const char *name,
 
 int heapobj_pkg_init_private(void)
 {
-	size_t size;
+	#ifdef CONFIG_XENO_PSHARED
+		size_t alloc_size = sysconf(_SC_PAGE_SIZE);
+	#else
+		size_t alloc_size = __copperplate_setup_data.mem_pool;
+	#endif
+	size_t available_size;
 	void *mem;
 
 	/*
@@ -88,14 +94,21 @@ int heapobj_pkg_init_private(void)
 	 * We include 1k of additional memory to cope with the
 	 * per-block overhead for an undefined number of individual
 	 * allocation requests. Ugly.
+	 *
+	 * CAUTION: in pshared mode, private heaps are subsidiary
+	 * storage pools, so no need to pre-commit as much memory as
+	 * we will be preallocating for the main shared pool,
+	 * especially with memory locking in effect. In that case,
+	 * creating a temporary single-page pool is enough to figure
+	 * out the allocation overhead.
 	 */
-	mem = tlsf_malloc(__copperplate_setup_data.mem_pool);
-	size = init_memory_pool(__copperplate_setup_data.mem_pool, mem);
-	if (size == (size_t)-1)
+	mem = tlsf_malloc(alloc_size);
+	available_size = init_memory_pool(alloc_size, mem);
+	if (available_size == (size_t)-1)
 		panic("cannot initialize TLSF memory manager");
 
 	destroy_memory_pool(mem);
-	tlsf_pool_overhead = __copperplate_setup_data.mem_pool - size;
+	tlsf_pool_overhead = alloc_size - available_size;
 	tlsf_pool_overhead = (tlsf_pool_overhead + 1024) & ~15;
 	tlsf_free(mem);
 
Signature · 1 line
2.7.4
#1 lore raw
Quoted 5 lines · Charles Kiorpes

When CONFIG_XENO_PSHARED is set, heapobj_pkg_init_private() was causing unneeded pages to be locked into memory by performing a temporary allocation of the size of the entire memory pool.

This patch reduces the size of this temporary allocation to a single page when CONFIG_XENO_PSHARED is set.

Merged, thanks.

Signature · 1 line
Philippe.