diff --git a/src/blockstore/blockstore_heap.cpp b/src/blockstore/blockstore_heap.cpp index 654882bc..de1adc1a 100644 --- a/src/blockstore/blockstore_heap.cpp +++ b/src/blockstore/blockstore_heap.cpp @@ -834,13 +834,18 @@ int blockstore_heap_t::allocate_entry(uint32_t entry_size, uint32_t *block_num, last_allocated_block = UINT32_MAX; } } - if (last_allocated_block == UINT32_MAX && meta_nearfull.size() > 0) + if (last_allocated_block == UINT32_MAX) { // Then into nearfull blocks - auto most_free = *std::prev(meta_nearfull.end()); - if ((most_free >> 32) >= entry_size) + for (uint32_t b = meta_alloc->find(META_ALLOC_LEVELS-1); b != UINT32_MAX; b = meta_alloc->next(b)) { - last_allocated_block = (uint32_t)most_free; + auto & inf = block_info.at(b); + auto free_space = dsk->meta_block_size - inf.used_space; + if (free_space >= entry_size) + { + last_allocated_block = b; + break; + } } } if (last_allocated_block == UINT32_MAX) @@ -1317,14 +1322,6 @@ void blockstore_heap_t::modify_alloc(uint32_t block_num, std::function= META_ALLOC_LEVELS-1 ? 1 : -1); } - if (old_pos == META_ALLOC_LEVELS-1 || new_pos == META_ALLOC_LEVELS-1) - { - // block is nearfull -> free space between minimum and maximum entry size - if (old_pos == META_ALLOC_LEVELS-1) - meta_nearfull.erase(block_num | (((uint64_t)(dsk->meta_block_size-old_used)) << 32)); - if (new_pos == META_ALLOC_LEVELS-1) - meta_nearfull.insert(block_num | (((uint64_t)(dsk->meta_block_size-new_used)) << 32)); - } } void blockstore_heap_t::start_block_write(uint32_t block_num) diff --git a/src/blockstore/blockstore_heap.h b/src/blockstore/blockstore_heap.h index 41d1a4d2..4575a920 100644 --- a/src/blockstore/blockstore_heap.h +++ b/src/blockstore/blockstore_heap.h @@ -139,7 +139,6 @@ class blockstore_heap_t std::vector block_info; allocator_t *data_alloc = NULL; multilist_index_t *meta_alloc = NULL; - std::set meta_nearfull; uint32_t meta_nearfull_blocks = 0; uint64_t meta_used_space = 0; multilist_alloc_t *buffer_alloc = NULL; diff --git a/src/blockstore/multilist.cpp b/src/blockstore/multilist.cpp index 6cd3a3bd..6b9f5f42 100644 --- a/src/blockstore/multilist.cpp +++ b/src/blockstore/multilist.cpp @@ -300,6 +300,11 @@ uint32_t multilist_index_t::find(uint32_t wanted_used) return heads[wanted_used]; } +uint32_t multilist_index_t::next(uint32_t pos) +{ + return nexts[pos]; +} + void multilist_index_t::change(uint32_t pos, uint32_t old_used, uint32_t new_used) { if (new_used == old_used) diff --git a/src/blockstore/multilist.h b/src/blockstore/multilist.h index 58b25f5a..3c80eafa 100644 --- a/src/blockstore/multilist.h +++ b/src/blockstore/multilist.h @@ -32,6 +32,7 @@ struct multilist_index_t // used should be always < max_used multilist_index_t(uint32_t count, uint32_t max_used, uint32_t init_used); uint32_t find(uint32_t wanted_used); + uint32_t next(uint32_t pos); void change(uint32_t pos, uint32_t old_used, uint32_t new_used); void print(); };