Module: xenomai-2.4
Branch: master
Commit: 912dc2f84c02cb1468e6c4d63037751e05936445
URL:    
http://git.xenomai.org/?p=xenomai-2.4.git;a=commit;h=912dc2f84c02cb1468e6c4d63037751e05936445

Author: Gilles Chanteperdrix <gilles.chanteperd...@xenomai.org>
Date:   Thu May 28 00:07:09 2009 +0200

Fix computation of heap overhead

---

 include/nucleus/heap.h |   22 +++++++++++++++++-----
 ksrc/nucleus/heap.c    |    2 +-
 2 files changed, 18 insertions(+), 6 deletions(-)

diff --git a/include/nucleus/heap.h b/include/nucleus/heap.h
index be2d70f..d04aeed 100644
--- a/include/nucleus/heap.h
+++ b/include/nucleus/heap.h
@@ -126,11 +126,23 @@ static inline size_t xnheap_align(size_t size, size_t al)
        return ((size+al-1)&(~(al-1)));
 }
 
-static inline size_t xnheap_overhead(size_t hsize, size_t psize)
+static inline size_t xnheap_external_overhead(size_t hsize, size_t psize)
 {
-       size_t m = psize / sizeof(struct xnpagemap);
-       size_t q = (size_t)xnarch_llimd(hsize - sizeof(xnextent_t), m, m + 1);
-       return xnheap_align(hsize - q, XNHEAP_MINALIGNSZ);
+       size_t pages = (hsize + psize - 1) / psize;
+       return xnheap_align(sizeof(xnextent_t)
+                           + pages * sizeof(struct xnpagemap), psize);
+}
+
+static inline size_t xnheap_internal_overhead(size_t hsize, size_t psize)
+{
+       /* o = (h - o) * m / p + e
+          o * p = (h - o) * m + e * p
+          o * (p + m) = h * m + e * p
+          o = (h * m + e *p) / (p + m)
+       */
+       return xnheap_align((sizeof(xnextent_t) * psize
+                            + sizeof(struct xnpagemap) * hsize)
+                           / (psize + sizeof(struct xnpagemap)), psize);
 }
 
 #define xnmalloc(size)     xnheap_alloc(&kheap,size)
@@ -156,7 +168,7 @@ static inline size_t xnheap_rounded_size(size_t hsize, 
size_t psize)
         */
        if (hsize < 2 * psize)
                hsize = 2 * psize;
-       hsize += xnheap_overhead(hsize, psize);
+       hsize += xnheap_external_overhead(hsize, psize);
        return xnheap_align(hsize, psize);
 }
 
diff --git a/ksrc/nucleus/heap.c b/ksrc/nucleus/heap.c
index 69cd277..3b93d8e 100644
--- a/ksrc/nucleus/heap.c
+++ b/ksrc/nucleus/heap.c
@@ -200,7 +200,7 @@ int xnheap_init(xnheap_t *heap,
         * static_part + pmapsize rounded to the minimum alignment
         * size.
        */
-       hdrsize = xnheap_overhead(heapsize, pagesize);
+       hdrsize = xnheap_internal_overhead(heapsize, pagesize);
 
        /* Compute the page shiftmask from the page size (i.e. log2 value). */
        for (pageshift = 0, shiftsize = pagesize;


_______________________________________________
Xenomai-git mailing list
Xenomai-git@gna.org
https://mail.gna.org/listinfo/xenomai-git

Reply via email to