From 591f7252320481d1c230adc1cb0c988902a47c05 Mon Sep 17 00:00:00 2001 From: Ming-Hung Tsai Date: Tue, 5 Sep 2017 01:05:19 +0800 Subject: [PATCH] [space map disk] reduce the lock counts to speed up free block searching (#84) Avoid repetitively acquiring/releasing the bitmap while finding a free block --- persistent-data/space-maps/disk.cc | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/persistent-data/space-maps/disk.cc b/persistent-data/space-maps/disk.cc index 67f3f09..8aef71a 100644 --- a/persistent-data/space-maps/disk.cc +++ b/persistent-data/space-maps/disk.cc @@ -120,12 +120,7 @@ namespace { ref_t lookup(unsigned b) const { read_ref rr = tm_.read_lock(ie_.blocknr_, validator_); - void const *bits = bitmap_data(rr); - ref_t b1 = test_bit_le(bits, b * 2); - ref_t b2 = test_bit_le(bits, b * 2 + 1); - ref_t result = b2 ? 1 : 0; - result |= b1 ? 2 : 0; - return result; + return __lookup_raw(bitmap_data(rr), b); } void insert(unsigned b, ref_t n) { @@ -158,8 +153,10 @@ namespace { } boost::optional find_free(unsigned begin, unsigned end) { + read_ref rr = tm_.read_lock(ie_.blocknr_, validator_); + void const *bits = bitmap_data(rr); for (unsigned i = max(begin, ie_.none_free_before_); i < end; i++) - if (lookup(i) == 0) + if (__lookup_raw(bits, i) == 0) return boost::optional(i); return boost::optional(); @@ -193,6 +190,14 @@ namespace { return h + 1; } + ref_t __lookup_raw(void const *bits, unsigned b) const { + ref_t b1 = test_bit_le(bits, b * 2); + ref_t b2 = test_bit_le(bits, b * 2 + 1); + ref_t result = b2 ? 1 : 0; + result |= b1 ? 2 : 0; + return result; + } + transaction_manager &tm_; bcache::validator::ptr validator_;