* [Xenomai] [PATCH] Fix unneeded pre-commit of memory pool when CONFIG_XENO_PSHARED set
@ 2017-11-03 16:44 Charles Kiorpes
2017-11-05 14:42 ` Philippe Gerum
0 siblings, 1 reply; 2+ messages in thread
From: Charles Kiorpes @ 2017-11-03 16:44 UTC (permalink / raw)
To: xenomai; +Cc: 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.
Signed-off-by: Charles Kiorpes <ckiorpes@gmail.com>
---
lib/copperplate/heapobj-tlsf.c | 23 ++++++++++++++++++-----
1 file changed, 18 insertions(+), 5 deletions(-)
diff --git a/lib/copperplate/heapobj-tlsf.c b/lib/copperplate/heapobj-tlsf.c
index e24db15..3709852 100644
--- a/lib/copperplate/heapobj-tlsf.c
+++ b/lib/copperplate/heapobj-tlsf.c
@@ -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);
--
2.7.4
^ permalink raw reply related [flat|nested] 2+ messages in thread
* Re: [Xenomai] [PATCH] Fix unneeded pre-commit of memory pool when CONFIG_XENO_PSHARED set
2017-11-03 16:44 [Xenomai] [PATCH] Fix unneeded pre-commit of memory pool when CONFIG_XENO_PSHARED set Charles Kiorpes
@ 2017-11-05 14:42 ` Philippe Gerum
0 siblings, 0 replies; 2+ messages in thread
From: Philippe Gerum @ 2017-11-05 14:42 UTC (permalink / raw)
To: Charles Kiorpes, xenomai
On 11/03/2017 05:44 PM, Charles Kiorpes wrote:
> 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.
>
> Signed-off-by: Charles Kiorpes <ckiorpes@gmail.com>
Merged, thanks.
--
Philippe.
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2017-11-05 14:42 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-11-03 16:44 [Xenomai] [PATCH] Fix unneeded pre-commit of memory pool when CONFIG_XENO_PSHARED set Charles Kiorpes
2017-11-05 14:42 ` Philippe Gerum
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.