]> mj.ucw.cz Git - libucw.git/commitdiff
Mempool: Fixed bug in mp_stats().
authorPavel Charvat <pchar@ucw.cz>
Fri, 30 May 2014 12:26:46 +0000 (14:26 +0200)
committerPavel Charvat <pchar@ucw.cz>
Fri, 30 May 2014 12:26:46 +0000 (14:26 +0200)
ucw/mempool.c

index a66615ab79a05dd3dca005eac2ca8fc01f3adbf1..47e07fbcb6c1c0d39fbc07cf407c6a8373648685 100644 (file)
@@ -200,12 +200,18 @@ mp_flush(struct mempool *pool)
 }
 
 static void
-mp_stats_chain(struct mempool_chunk *chunk, struct mempool_stats *stats, uns idx)
+mp_stats_chain(struct mempool *pool, struct mempool_chunk *chunk, struct mempool_stats *stats, uns idx)
 {
   while (chunk)
     {
       stats->chain_size[idx] += chunk->size + MP_CHUNK_TAIL;
       stats->chain_count[idx]++;
+      if (idx < 2)
+       {
+         stats->used_size += chunk->size;
+         if ((byte *)pool == (byte *)chunk - chunk->size)
+           stats->used_size -= sizeof(*pool);
+       }
       chunk = chunk->next;
     }
   stats->total_size += stats->chain_size[idx];
@@ -215,14 +221,12 @@ void
 mp_stats(struct mempool *pool, struct mempool_stats *stats)
 {
   bzero(stats, sizeof(*stats));
-  mp_stats_chain(pool->state.last[0], stats, 0);
-  mp_stats_chain(pool->state.last[1], stats, 1);
-  mp_stats_chain(pool->unused, stats, 2);
+  mp_stats_chain(pool, pool->state.last[0], stats, 0);
+  mp_stats_chain(pool, pool->state.last[1], stats, 1);
+  mp_stats_chain(pool, pool->unused, stats, 2);
+  stats->used_size -= pool->state.free[0] + pool->state.free[1];
   ASSERT(stats->total_size == pool->total_size);
-  stats->used_size = stats->chain_size[0] + stats->chain_size[1]
-    - MP_CHUNK_TAIL * (stats->chain_count[0] + stats->chain_count[1])
-    - pool->state.free[0] - pool->state.free[1] - sizeof(*pool);
-  ASSERT(stats->used_size < stats->total_size);
+  ASSERT(stats->used_size <= stats->total_size);
 }
 
 u64