summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJens Axboe <axboe@kernel.dk>2019-07-31 15:27:27 -0600
committerJens Axboe <axboe@kernel.dk>2019-07-31 15:29:48 -0600
commit66b182f90c3f08dcbd0592ce70cb350ca5ac0cc0 (patch)
tree4f00f690be21c0184034c602f2821aeb4b91cf5d
parent82a90566caf08964064e74241e5eb5e42c6fb189 (diff)
downloadfio-66b182f90c3f08dcbd0592ce70cb350ca5ac0cc0.tar.gz
fio-66b182f90c3f08dcbd0592ce70cb350ca5ac0cc0.tar.bz2
smalloc: cleanup firstfree()
Signed-off-by: Jens Axboe <axboe@kernel.dk>
-rw-r--r--smalloc.c30
1 files changed, 15 insertions, 15 deletions
diff --git a/smalloc.c b/smalloc.c
index 0d7054a4..125e07bf 100644
--- a/smalloc.c
+++ b/smalloc.c
@@ -338,18 +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;
- assert(0);
+ for (j = 0; j < pool->nr_blocks; j++)
+ if (pool->bitmap[j] != -1U)
+ return j;
+ }
+ }
- /* we will never get here but this fixes a compiler warning */
- return -1U;
+ return i;
}
static void *__smalloc_pool(struct pool *pool, size_t size)
@@ -366,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;