}
ch->next = pool->first_chunk;
pool->first_chunk = ch;
+ pool->num_chunks++;
return p;
}
+u64
+ep_total_size(struct eltpool *pool)
+{
+ return (u64)pool->num_chunks * pool->chunk_size + sizeof(*pool);
+}
+
#ifdef TEST
#include <stdio.h>
uns chunk_size;
uns elts_per_chunk;
uns num_allocated; // Just for debugging
+ uns num_chunks;
};
struct eltpool_chunk {
struct eltpool *ep_new(uns elt_size, uns elts_per_chunk);
void ep_delete(struct eltpool *pool);
void *ep_alloc_slow(struct eltpool *pool);
+u64 ep_total_size(struct eltpool *pool);
static inline void *
ep_alloc(struct eltpool *pool)
mp_stats_chain(pool->unused, stats, 2);
}
+u64
+mp_total_size(struct mempool *pool)
+{
+ struct mempool_stats stats;
+ mp_stats(pool, &stats);
+ return stats.total_size;
+}
+
void *
mp_alloc_internal(struct mempool *pool, uns size)
{
/* Statistics (see mp_stats()) */
struct mempool_stats {
- uns total_size; /* Real allocated size in bytes */
+ u64 total_size; /* Real allocated size in bytes */
uns chain_count[3]; /* Number of allocated chunks in small/big/unused chains */
uns chain_size[3]; /* Size of allocated chunks in small/big/unused chains */
};
/* Compute some statistics for debug purposes. See the definition of the mempool_stats structure. */
void mp_stats(struct mempool *pool, struct mempool_stats *stats);
+u64 mp_total_size(struct mempool *pool);
/*** Allocation routines ***/