From cb0a77e2ae7a35a6409067e04805d0364b9139f8 Mon Sep 17 00:00:00 2001 From: Ming-Hung Tsai Date: Fri, 28 Feb 2020 22:18:35 +0800 Subject: [PATCH 1/2] [block-manager] remove unused copy-assignment operator block_cache::block is non-copyable, and so are the containing structures. --- persistent-data/block.h | 4 ---- persistent-data/block.tcc | 24 ------------------------ 2 files changed, 28 deletions(-) diff --git a/persistent-data/block.h b/persistent-data/block.h index d5127c2..393c60f 100644 --- a/persistent-data/block.h +++ b/persistent-data/block.h @@ -64,8 +64,6 @@ namespace persistent_data { read_ref(read_ref const &rhs); virtual ~read_ref(); - read_ref const &operator =(read_ref const &rhs); - block_address get_location() const; void const *data() const; @@ -82,8 +80,6 @@ namespace persistent_data { write_ref(write_ref const &rhs); ~write_ref(); - write_ref const &operator =(write_ref const &rhs); - using read_ref::data; void *data(); diff --git a/persistent-data/block.tcc b/persistent-data/block.tcc index e743360..792c658 100644 --- a/persistent-data/block.tcc +++ b/persistent-data/block.tcc @@ -47,18 +47,6 @@ namespace persistent_data { b_.put(); } - template - typename block_manager::read_ref const & - block_manager::read_ref::operator =(read_ref const &rhs) - { - if (this != &rhs) { - b_ = rhs.b_; - b_.get(); - } - - return *this; - } - template block_address block_manager::read_ref::get_location() const @@ -112,18 +100,6 @@ namespace persistent_data { } } - template - typename block_manager::write_ref const & - block_manager::write_ref::operator =(write_ref const &rhs) - { - if (&rhs != this) { - read_ref::operator =(rhs); - ref_count_ = rhs.ref_count_; - if (ref_count_) - (*ref_count_)++; - } - } - template void * block_manager::write_ref::data() From 7a1c6dc4bf0b9383bca39171b185341a0afdb014 Mon Sep 17 00:00:00 2001 From: Ming-Hung Tsai Date: Wed, 31 Oct 2018 18:10:51 +0800 Subject: [PATCH 2/2] [space-map-disk] improve performance of finding a free bitmap entry * Simply test the raw bitmap entries against zero, to avoid time-consumed reference-count value extraction. * Improve the way of iterating entries inside a bitmap: Extract 64-bit of bitmap entries at once, and use bitwise shift to iterate through the entries. --- persistent-data/space-maps/disk.cc | 35 +++++++++++++++++++++++++++--- 1 file changed, 32 insertions(+), 3 deletions(-) diff --git a/persistent-data/space-maps/disk.cc b/persistent-data/space-maps/disk.cc index 4492a3c..7d2e466 100644 --- a/persistent-data/space-maps/disk.cc +++ b/persistent-data/space-maps/disk.cc @@ -153,11 +153,27 @@ namespace { } boost::optional find_free(unsigned begin, unsigned end) { + begin = max(begin, ie_.none_free_before_); + if (begin >= end) + return boost::optional(); + 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_raw(bits, i) == 0) - return boost::optional(i); + + // specify the search range inside the bitmap, in 64-bit unit + le64 const *w = reinterpret_cast(bits); + le64 const *le64_begin = w + (begin >> 5); // w + div_down(begin, 32) + le64 const *le64_end = w + ((end + 31) >> 5); // w + div_up(end, 32) + + for (le64 const *ptr = le64_begin; ptr < le64_end; ptr++) { + // specify the search range among a 64-bit of entries + unsigned entry_begin = (ptr == le64_begin) ? (begin & 0x1F) : 0; + unsigned entry_end = ((ptr == le64_end - 1) && (end & 0x1F)) ? + (end & 0x1F) : 32; + int i; + if ((i = find_free_entry(ptr, entry_begin, entry_end)) >= 0) + return ((ptr - w) << 5) + i; + } return boost::optional(); } @@ -198,6 +214,19 @@ namespace { return result; } + // find a free entry (a 2-bit pair) among the specified range in the input bits + int find_free_entry(le64 const* bits, unsigned entry_begin, unsigned entry_end) { + uint64_t v = to_cpu(*bits); + v >>= (entry_begin * 2); + for (; entry_begin < entry_end; entry_begin++) { + if (!(v & 0x3)) { + return entry_begin; + } + v = v >> 2; + } + return -1; + } + transaction_manager &tm_; bcache::validator::ptr validator_;