lsa: optimise disabling reclamation and invalidation counter

Most of the lsa gory details are hidden in utils/logalloc.cc. That
includes the actual implementation of a lsa region: region_impl.

However, there is code in the hot path that often accesses the
_reclaiming_enabled member as well as its base class
allocation_strategy.

In order to optimise those accesses another class is introduced:
basic_region_impl that inherits from allocation_strategy and is a base
of region_impl. It is defined in utils/logalloc.hh so that it is
publicly visible and its member functions are inlineable from anywhere
in the code. This class is supposed to be as small as possible, but
contain all members and functions that are accessed from the fast path
and should be inlined.
This commit is contained in:
Paweł Dziepak
2018-01-24 15:14:18 +00:00
committed by Tomasz Grabiec
parent d825ae37bf
commit dcd79af8ed
2 changed files with 43 additions and 41 deletions

View File

@@ -940,7 +940,7 @@ segment::occupancy() const {
// Per-segment metadata is kept in a separate array, managed by segment_pool
// object.
//
class region_impl : public allocation_strategy {
class region_impl final : public basic_region_impl {
// Serialized object descriptor format:
// byte0 byte1 ... byte[n-1]
// bit0-bit5: ULEB64 significand
@@ -1079,7 +1079,6 @@ private:
// occupancy. We could actually just present this as a scalar as well and never use occupancies,
// but consistency is good.
size_t _evictable_space = 0;
bool _reclaiming_enabled = true;
bool _evictable = false;
uint64_t _id;
eviction_fn _eviction_fn;
@@ -1493,14 +1492,6 @@ public:
return _id;
}
void set_reclaiming_enabled(bool enabled) {
_reclaiming_enabled = enabled;
}
bool reclaiming_enabled() const {
return _reclaiming_enabled;
}
// Returns true if this pool is evictable, so that evict_some() can be called.
bool is_evictable() const {
return _evictable && _reclaiming_enabled;
@@ -1592,14 +1583,21 @@ region::region(region_group& group)
: _impl(make_shared<impl>(this, &group)) {
}
region_impl& region::get_impl() {
return *static_cast<region_impl*>(_impl.get());
}
const region_impl& region::get_impl() const {
return *static_cast<const region_impl*>(_impl.get());
}
region::region(region&& other) {
this->_impl = std::move(other._impl);
this->_impl->_region = this;
get_impl()._region = this;
}
region& region::operator=(region&& other) {
this->_impl = std::move(other._impl);
this->_impl->_region = this;
get_impl()._region = this;
return *this;
}
@@ -1607,53 +1605,37 @@ region::~region() {
}
occupancy_stats region::occupancy() const {
return _impl->occupancy();
return get_impl().occupancy();
}
region_group* region::group() {
return _impl->group();
return get_impl().group();
}
void region::merge(region& other) noexcept {
if (_impl != other._impl) {
_impl->merge(*other._impl);
get_impl().merge(other.get_impl());
other._impl = _impl;
}
}
void region::full_compaction() {
_impl->full_compaction();
get_impl().full_compaction();
}
memory::reclaiming_result region::evict_some() {
if (_impl->is_evictable()) {
return _impl->evict_some();
if (get_impl().is_evictable()) {
return get_impl().evict_some();
}
return memory::reclaiming_result::reclaimed_nothing;
}
void region::make_evictable(eviction_fn fn) {
_impl->make_evictable(std::move(fn));
get_impl().make_evictable(std::move(fn));
}
const eviction_fn& region::evictor() const {
return _impl->evictor();
}
allocation_strategy& region::allocator() {
return *_impl;
}
const allocation_strategy& region::allocator() const {
return *_impl;
}
void region::set_reclaiming_enabled(bool compactible) {
_impl->set_reclaiming_enabled(compactible);
}
bool region::reclaiming_enabled() const {
return _impl->reclaiming_enabled();
return get_impl().evictor();
}
std::ostream& operator<<(std::ostream& out, const occupancy_stats& stats) {

View File

@@ -533,6 +533,19 @@ public:
friend std::ostream& operator<<(std::ostream&, const occupancy_stats&);
};
class basic_region_impl : public allocation_strategy {
protected:
bool _reclaiming_enabled = true;
public:
void set_reclaiming_enabled(bool enabled) {
_reclaiming_enabled = enabled;
}
bool reclaiming_enabled() const {
return _reclaiming_enabled;
}
};
//
// Log-structured allocator region.
//
@@ -552,7 +565,10 @@ class region {
public:
using impl = region_impl;
private:
shared_ptr<impl> _impl;
shared_ptr<basic_region_impl> _impl;
private:
region_impl& get_impl();
const region_impl& get_impl() const;
public:
region();
explicit region(region_group& group);
@@ -563,8 +579,12 @@ public:
occupancy_stats occupancy() const;
allocation_strategy& allocator();
const allocation_strategy& allocator() const;
allocation_strategy& allocator() {
return *_impl;
}
const allocation_strategy& allocator() const {
return *_impl;
}
region_group* group();
@@ -582,10 +602,10 @@ public:
// Changes the reclaimability state of this region. When region is not
// reclaimable, it won't be considered by tracker::reclaim(). By default region is
// reclaimable after construction.
void set_reclaiming_enabled(bool);
void set_reclaiming_enabled(bool e) { _impl->set_reclaiming_enabled(e); }
// Returns the reclaimability state of this region.
bool reclaiming_enabled() const;
bool reclaiming_enabled() const { return _impl->reclaiming_enabled(); }
// Returns a value which is increased when this region is either compacted or
// evicted from, which invalidates references into the region.