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.blumenkrantz@gmail.com>
Differential Revision: https://phab.enlightenment.org/D10534
This commit is contained in:
Cedric BAIL 2019-10-25 07:58:31 -07:00
parent 37e258904d
commit 1f445dd12d
1 changed files with 11 additions and 10 deletions

View File

@ -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)