cedric pushed a commit to branch master.

http://git.enlightenment.org/core/efl.git/commit/?id=1f445dd12db8cfeb8c4d9c5334ca9ba490bef9f3

commit 1f445dd12db8cfeb8c4d9c5334ca9ba490bef9f3
Author: Cedric BAIL <cedric.b...@free.fr>
Date:   Fri Oct 25 07:58:31 2019 -0700

    eina: change default policy of Chained Mempool to recycle memory right away.
    
    Until now, Chained Mempool would first empty its pool and the started to
    recycle memory. Now it does always try to recycle first. This should limit
    memory fragmentation to some extend.
    
    Reviewed-by: Mike Blumenkrantz <michael.blumenkra...@gmail.com>
    Differential Revision: https://phab.enlightenment.org/D10534
---
 .../eina/mp/chained_pool/eina_chained_mempool.c     | 21 +++++++++++----------
 1 file changed, 11 insertions(+), 10 deletions(-)

diff --git a/src/modules/eina/mp/chained_pool/eina_chained_mempool.c 
b/src/modules/eina/mp/chained_pool/eina_chained_mempool.c
index 6d4facf74d..f70339e080 100644
--- a/src/modules/eina/mp/chained_pool/eina_chained_mempool.c
+++ b/src/modules/eina/mp/chained_pool/eina_chained_mempool.c
@@ -182,16 +182,10 @@ _eina_chained_mempool_usage_cmp(const Eina_Inlist *l1, 
const Eina_Inlist *l2)
 static void *
 _eina_chained_mempool_alloc_in(Chained_Mempool *pool, Chained_Pool *p)
 {
-  void *mem;
+  void *mem = NULL;
 
-  if (p->last)
-    {
-      mem = p->last;
-      p->last += pool->item_alloc;
-      if (p->last >= p->limit)
-        p->last = NULL;
-    }
-  else
+  // Let's try to first recycle memory
+  if (p->base)
     {
 #ifndef NVALGRIND
       VALGRIND_MAKE_MEM_DEFINED(p->base, pool->item_alloc);
@@ -199,6 +193,13 @@ _eina_chained_mempool_alloc_in(Chained_Mempool *pool, 
Chained_Pool *p)
       // Request a free pointer
       mem = eina_trash_pop(&p->base);
     }
+  else if (p->last)
+    {
+      mem = p->last;
+      p->last += pool->item_alloc;
+      if (p->last >= p->limit)
+        p->last = NULL;
+    }
 
   // move to end - it just filled up
   if (!p->base && !p->last)
@@ -306,7 +307,7 @@ eina_chained_mempool_malloc(void *data, EINA_UNUSED 
unsigned int size)
 
    // we have reached the end of the list - no free pools
    if (!p)
-     {
+      {
        //new chain created ,point it to be the first_fill chain
         pool->first_fill = _eina_chained_mp_pool_new(pool);
         if (!pool->first_fill)

-- 


Reply via email to