From: Pavel Charvat Date: Tue, 20 May 2014 11:36:32 +0000 (+0200) Subject: Mempool: Implemented mp_shrink(). X-Git-Tag: v6.0~33 X-Git-Url: http://mj.ucw.cz/gitweb/?a=commitdiff_plain;h=4570bd0b9f62747176322900eb0951db9c96f14a;p=libucw.git Mempool: Implemented mp_shrink(). --- diff --git a/ucw/mempool.c b/ucw/mempool.c index 9e5d62b0..1048686f 100644 --- a/ucw/mempool.c +++ b/ucw/mempool.c @@ -230,6 +230,19 @@ mp_total_size(struct mempool *pool) return pool->total_size; } +void +mp_shrink(struct mempool *pool, u64 min_total_size) +{ + while (1) + { + struct mempool_chunk *chunk = pool->unused; + if (!chunk || pool->total_size - (chunk->size + MP_CHUNK_TAIL) < min_total_size) + break; + pool->unused = chunk->next; + mp_free_chunk(pool, chunk); + } +} + void * mp_alloc_internal(struct mempool *pool, uns size) { diff --git a/ucw/mempool.h b/ucw/mempool.h index 9427a8ac..b44b955a 100644 --- a/ucw/mempool.h +++ b/ucw/mempool.h @@ -137,6 +137,11 @@ void mp_stats(struct mempool *pool, struct mempool_stats *stats); **/ u64 mp_total_size(struct mempool *pool); +/** + * Release unused chunks of memory reserved for further allocation + * requests, but stop if mp_total_size() would drop below @min_total_size. + **/ +void mp_shrink(struct mempool *pool, u64 min_total_size); /*** * [[alloc]]