From db44b5b9280c115ef9cdfc76b78cf7c3515ab29f Mon Sep 17 00:00:00 2001 From: Joe Thornber Date: Tue, 11 Apr 2017 09:40:08 +0100 Subject: [PATCH] [space-map-disk] Keep track of the allocated prefix so we can start searching in a better place. --- persistent-data/space-maps/disk.cc | 22 +++++++++++++++++++--- 1 file changed, 19 insertions(+), 3 deletions(-) diff --git a/persistent-data/space-maps/disk.cc b/persistent-data/space-maps/disk.cc index caeaca3..050137f 100644 --- a/persistent-data/space-maps/disk.cc +++ b/persistent-data/space-maps/disk.cc @@ -260,6 +260,7 @@ namespace { indexes_(indexes), nr_blocks_(0), nr_allocated_(0), + search_start_(0), ref_counts_(tm_, ref_count_traits::ref_counter()) { } @@ -271,6 +272,7 @@ namespace { indexes_(indexes), nr_blocks_(root.nr_blocks_), nr_allocated_(root.nr_allocated_), + search_start_(0), ref_counts_(tm_, root.ref_count_root_, ref_count_traits::ref_counter()) { } @@ -308,8 +310,11 @@ namespace { if (old == 0) nr_allocated_++; - else if (c == 0) + else if (c == 0) { + if (b < search_start_) + search_start_ = b; nr_allocated_--; + } } void commit() { @@ -317,23 +322,31 @@ namespace { } void inc(block_address b) { + if (b == search_start_) + search_start_++; + // FIXME: 2 get_counts ref_t old = get_count(b); set_count(b, old + 1); } void dec(block_address b) { + // FIXME: 2 get_counts ref_t old = get_count(b); set_count(b, old - 1); } - // FIXME: keep track of the lowest free block so we - // can start searching from a suitable place. maybe_block find_free(span_iterator &it) { for (maybe_span ms = it.first(); ms; ms = it.next()) { block_address begin = ms->first; block_address end = ms->second; + if (end < search_start_) + continue; + + if (begin < search_start_) + begin = search_start_; + block_address begin_index = begin / ENTRIES_PER_BLOCK; block_address end_index = div_up(end, ENTRIES_PER_BLOCK); @@ -347,6 +360,8 @@ namespace { boost::optional maybe_b = bm.find_free(bit_begin, bit_end); if (maybe_b) { block_address b = (index * ENTRIES_PER_BLOCK) + *maybe_b; + if (b) + search_start_ = b - 1; return b; } } @@ -526,6 +541,7 @@ namespace { index_store::ptr indexes_; block_address nr_blocks_; block_address nr_allocated_; + block_address search_start_; btree<1, ref_count_traits> ref_counts_; };