eta: use struct jobs_eta_packed
[fio.git] / smalloc.c
index c1ae08bd26fa3e67e294c99430a364508e6c46fc..125e07bf1d21a6d4c49ba0c5cbb79a44efe20df0 100644 (file)
--- a/smalloc.c
+++ b/smalloc.c
@@ -338,6 +338,25 @@ void sfree(void *ptr)
        log_err("smalloc: ptr %p not from smalloc pool\n", ptr);
 }
 
+static unsigned int find_best_index(struct pool *pool)
+{
+       unsigned int i;
+
+       assert(pool->free_blocks);
+
+       for (i = pool->next_non_full; pool->bitmap[i] == -1U; i++) {
+               if (i == pool->nr_blocks - 1) {
+                       unsigned int j;
+
+                       for (j = 0; j < pool->nr_blocks; j++)
+                               if (pool->bitmap[j] != -1U)
+                                       return j;
+               }
+       }
+
+       return i;
+}
+
 static void *__smalloc_pool(struct pool *pool, size_t size)
 {
        size_t nr_blocks;
@@ -352,15 +371,16 @@ static void *__smalloc_pool(struct pool *pool, size_t size)
        if (nr_blocks > pool->free_blocks)
                goto fail;
 
-       i = pool->next_non_full;
+       pool->next_non_full = find_best_index(pool);
+
        last_idx = 0;
        offset = -1U;
+       i = pool->next_non_full;
        while (i < pool->nr_blocks) {
                unsigned int idx;
 
                if (pool->bitmap[i] == -1U) {
                        i++;
-                       pool->next_non_full = i;
                        last_idx = 0;
                        continue;
                }