X-Git-Url: https://git.kernel.dk/?a=blobdiff_plain;f=smalloc.c;h=125e07bf1d21a6d4c49ba0c5cbb79a44efe20df0;hb=dc54b6ca3209c2da3df30e96d097f6de29d56d24;hp=c97bcbaae5bb429cfa807f32edfc4fa9d216867b;hpb=23380ef29cdf6eaba8bafaf1c3e51e82610ad5ad;p=fio.git diff --git a/smalloc.c b/smalloc.c index c97bcbaa..125e07bf 100644 --- a/smalloc.c +++ b/smalloc.c @@ -338,15 +338,23 @@ void sfree(void *ptr) log_err("smalloc: ptr %p not from smalloc pool\n", ptr); } -static unsigned int firstfree(struct pool *pool) +static unsigned int find_best_index(struct pool *pool) { - unsigned int i; + unsigned int i; + + assert(pool->free_blocks); - for (i = 0; i < pool->nr_blocks; i++) - if (pool->bitmap[i] != -1U) - return i; + 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; + } + } - assert(0); + return i; } static void *__smalloc_pool(struct pool *pool, size_t size) @@ -363,16 +371,11 @@ static void *__smalloc_pool(struct pool *pool, size_t size) if (nr_blocks > pool->free_blocks) goto fail; - for (i = pool->next_non_full; pool->bitmap[i] == -1U; i++) - if (i == pool->nr_blocks - 1) { - i = firstfree(pool); - break; - } - - pool->next_non_full = i; + 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;