[space-map-disk] optimise updating a ref count

This commit is contained in:
Joe Thornber 2017-04-11 10:48:49 +01:00
parent db44b5b928
commit 8f25e1b234

View File

@ -292,20 +292,29 @@ namespace {
return count; return count;
} }
void set_count(block_address b, ref_t c) { template <typename Mut>
ref_t old = get_count(b); void modify_count(block_address b, Mut const &m) {
check_block(b);
if (c == old) index_entry ie = indexes_->find_ie(b / ENTRIES_PER_BLOCK);
return; bitmap bm(tm_, ie, bitmap_validator_);
ref_t old = bm.lookup(b % ENTRIES_PER_BLOCK);
if (old == 3)
old = lookup_ref_count(b);
ref_t c = m(old);
if (c > 2) { if (c > 2) {
if (old < 3) if (old < 3) {
insert_bitmap(b, 3); bm.insert(b % ENTRIES_PER_BLOCK, 3);
indexes_->save_ie(b / ENTRIES_PER_BLOCK, bm.get_ie());
}
insert_ref_count(b, c); insert_ref_count(b, c);
} else { } else {
if (old > 2) if (old > 2)
remove_ref_count(b); remove_ref_count(b);
insert_bitmap(b, c); bm.insert(b % ENTRIES_PER_BLOCK, c);
indexes_->save_ie(b / ENTRIES_PER_BLOCK, bm.get_ie());
} }
if (old == 0) if (old == 0)
@ -317,23 +326,44 @@ namespace {
} }
} }
struct override {
override(ref_t new_value)
: new_value_(new_value) {
}
ref_t operator()(ref_t old) const {
return new_value_;
}
ref_t new_value_;
};
void set_count(block_address b, ref_t c) {
override m(c);
modify_count(b, m);
}
void commit() { void commit() {
indexes_->commit_ies(); indexes_->commit_ies();
} }
static ref_t inc_mutator(ref_t c) {
return c + 1;
}
static ref_t dec_mutator(ref_t c) {
return c - 1;
}
void inc(block_address b) { void inc(block_address b) {
if (b == search_start_) if (b == search_start_)
search_start_++; search_start_++;
// FIXME: 2 get_counts modify_count(b, inc_mutator);
ref_t old = get_count(b);
set_count(b, old + 1);
} }
void dec(block_address b) { void dec(block_address b) {
// FIXME: 2 get_counts modify_count(b, dec_mutator);
ref_t old = get_count(b);
set_count(b, old - 1);
} }
maybe_block find_free(span_iterator &it) { maybe_block find_free(span_iterator &it) {