Merge pull request #133 from mingnus/master
Improve performance, and remove unused code
This commit is contained in:
commit
47da81b6b7
@ -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();
|
||||
|
||||
|
@ -47,18 +47,6 @@ namespace persistent_data {
|
||||
b_.put();
|
||||
}
|
||||
|
||||
template <uint32_t BlockSize>
|
||||
typename block_manager<BlockSize>::read_ref const &
|
||||
block_manager<BlockSize>::read_ref::operator =(read_ref const &rhs)
|
||||
{
|
||||
if (this != &rhs) {
|
||||
b_ = rhs.b_;
|
||||
b_.get();
|
||||
}
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
template <uint32_t BlockSize>
|
||||
block_address
|
||||
block_manager<BlockSize>::read_ref::get_location() const
|
||||
@ -112,18 +100,6 @@ namespace persistent_data {
|
||||
}
|
||||
}
|
||||
|
||||
template <uint32_t BlockSize>
|
||||
typename block_manager<BlockSize>::write_ref const &
|
||||
block_manager<BlockSize>::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 <uint32_t BlockSize>
|
||||
void *
|
||||
block_manager<BlockSize>::write_ref::data()
|
||||
|
@ -153,11 +153,27 @@ namespace {
|
||||
}
|
||||
|
||||
boost::optional<unsigned> find_free(unsigned begin, unsigned end) {
|
||||
begin = max(begin, ie_.none_free_before_);
|
||||
if (begin >= end)
|
||||
return boost::optional<unsigned>();
|
||||
|
||||
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<unsigned>(i);
|
||||
|
||||
// specify the search range inside the bitmap, in 64-bit unit
|
||||
le64 const *w = reinterpret_cast<le64 const *>(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<unsigned>();
|
||||
}
|
||||
@ -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<uint64_t>(*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_;
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user