Module: xenomai-3
Branch: wip/drivers
Commit: e0e6ae76230e283e81bd0e80ea87dd6612c63a1c
URL:    
http://git.xenomai.org/?p=xenomai-3.git;a=commit;h=e0e6ae76230e283e81bd0e80ea87dd6612c63a1c

Author: Ronny Meeus <ronny.me...@gmail.com>
Date:   Thu Dec 15 12:45:00 2016 +0100

boilerplate/tlsf: limit memory usage to the specified size

Before this patch the system memory pool's (tlsf variant) behavior was
to grow in case allocations were done when depleted. This is a
contradiction with the expected behavior (see mem-pool-size tunable
documentation). When the pool is depleted, an error should be retuned
instead of growing the pool.

This patch solves this bug.

---

 lib/boilerplate/tlsf/tlsf.c |   18 +-----------------
 1 file changed, 1 insertion(+), 17 deletions(-)

diff --git a/lib/boilerplate/tlsf/tlsf.c b/lib/boilerplate/tlsf/tlsf.c
index 207de21..8ee9405 100644
--- a/lib/boilerplate/tlsf/tlsf.c
+++ b/lib/boilerplate/tlsf/tlsf.c
@@ -625,6 +625,7 @@ void *tlsf_malloc(size_t size)
        void *area;
 
        area_size = sizeof(tlsf_t) + BHDR_OVERHEAD * 8; /* Just a safety 
constant */
+       area_size += size;
        area_size = (area_size > DEFAULT_AREA_SIZE) ? area_size : 
DEFAULT_AREA_SIZE;
        area = get_new_area(&area_size);
        if (area == ((void *) ~0))
@@ -709,23 +710,6 @@ void *malloc_ex(size_t size, void *mem_pool)
     /* Searching a free block, recall that this function changes the values of 
fl and sl,
        so they are not longer valid when the function fails */
     b = FIND_SUITABLE_BLOCK(tlsf, &fl, &sl);
-#if USE_MMAP || USE_SBRK
-    if (!b && mem_pool == mp) {        /* Don't grow private pools */
-       size_t area_size;
-       void *area;
-       /* Growing the pool size when needed */
-       area_size = size + BHDR_OVERHEAD * 8;   /* size plus enough room for 
the requered headers. */
-       area_size = (area_size > DEFAULT_AREA_SIZE) ? area_size : 
DEFAULT_AREA_SIZE;
-       area = get_new_area(&area_size);        /* Call sbrk or mmap */
-       if (area == ((void *) ~0))
-           return NULL;        /* Not enough system memory */
-       add_new_area(area, area_size, mem_pool);
-       /* Rounding up the requested size and calculating fl and sl */
-       MAPPING_SEARCH(&size, &fl, &sl);
-       /* Searching a free block */
-       b = FIND_SUITABLE_BLOCK(tlsf, &fl, &sl);
-    }
-#endif
     if (!b)
        return NULL;            /* Not found */
 


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

Reply via email to