diff options
author | Tor Egge <Tor.Egge@online.no> | 2021-12-08 23:49:48 +0100 |
---|---|---|
committer | Tor Egge <Tor.Egge@online.no> | 2021-12-08 23:49:48 +0100 |
commit | f5b7a486d9907f47c4d3b8cb4fb9514407fe4c30 (patch) | |
tree | dc9d46d67beea35fd13563419811f934331a3c6b /vespalib | |
parent | 2853733d3227818dd83e006e63a3c915679a7b53 (diff) |
Integrate CompactionStrategy with AddressSpace and MemoryUsage.
Diffstat (limited to 'vespalib')
3 files changed, 45 insertions, 13 deletions
diff --git a/vespalib/src/vespa/vespalib/datastore/compaction_spec.h b/vespalib/src/vespa/vespalib/datastore/compaction_spec.h index 5bc2d838f9a..b346df68452 100644 --- a/vespalib/src/vespa/vespalib/datastore/compaction_spec.h +++ b/vespalib/src/vespa/vespalib/datastore/compaction_spec.h @@ -21,6 +21,7 @@ public: _compact_address_space(compact_address_space_) { } + bool compact() const noexcept { return _compact_memory || _compact_address_space; } bool compact_memory() const noexcept { return _compact_memory; } bool compact_address_space() const noexcept { return _compact_address_space; } }; diff --git a/vespalib/src/vespa/vespalib/datastore/compaction_strategy.cpp b/vespalib/src/vespa/vespalib/datastore/compaction_strategy.cpp index 43da1837427..2dbd501f78e 100644 --- a/vespalib/src/vespa/vespalib/datastore/compaction_strategy.cpp +++ b/vespalib/src/vespa/vespalib/datastore/compaction_strategy.cpp @@ -1,10 +1,31 @@ // Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. #include "compaction_strategy.h" +#include "compaction_spec.h" +#include <vespa/vespalib/util/memoryusage.h> +#include <vespa/vespalib/util/address_space.h> #include <iostream> namespace vespalib::datastore { +bool +CompactionStrategy::should_compact_memory(const MemoryUsage& memory_usage) const +{ + return should_compact_memory(memory_usage.usedBytes(), memory_usage.deadBytes()); +} + +bool +CompactionStrategy::should_compact_address_space(const AddressSpace& address_space) const +{ + return should_compact_address_space(address_space.used(), address_space.dead()); +} + +CompactionSpec +CompactionStrategy::should_compact(const MemoryUsage& memory_usage, const AddressSpace& address_space) const +{ + return CompactionSpec(should_compact_memory(memory_usage), should_compact_address_space(address_space)); +} + std::ostream& operator<<(std::ostream& os, const CompactionStrategy& compaction_strategy) { os << "{maxDeadBytesRatio=" << compaction_strategy.getMaxDeadBytesRatio() << diff --git a/vespalib/src/vespa/vespalib/datastore/compaction_strategy.h b/vespalib/src/vespa/vespalib/datastore/compaction_strategy.h index 06d54786122..df7ca1657cb 100644 --- a/vespalib/src/vespa/vespalib/datastore/compaction_strategy.h +++ b/vespalib/src/vespa/vespalib/datastore/compaction_strategy.h @@ -4,16 +4,36 @@ #include <iosfwd> +namespace vespalib { + +class AddressSpace; +class MemoryUsage; + +} + namespace vespalib::datastore { +class CompactionSpec; + /* * Class describing compaction strategy for a compactable data structure. */ class CompactionStrategy { +public: + static constexpr size_t DEAD_BYTES_SLACK = 0x10000u; + static constexpr size_t DEAD_ADDRESS_SPACE_SLACK = 0x10000u; private: double _maxDeadBytesRatio; // Max ratio of dead bytes before compaction double _maxDeadAddressSpaceRatio; // Max ratio of dead address space before compaction + bool should_compact_memory(size_t used_bytes, size_t dead_bytes) const { + return ((dead_bytes >= DEAD_BYTES_SLACK) && + (dead_bytes > used_bytes * getMaxDeadBytesRatio())); + } + bool should_compact_address_space(size_t used_address_space, size_t dead_address_space) const { + return ((dead_address_space >= DEAD_ADDRESS_SPACE_SLACK) && + (dead_address_space > used_address_space * getMaxDeadAddressSpaceRatio())); + } public: CompactionStrategy() noexcept : _maxDeadBytesRatio(0.05), @@ -33,19 +53,9 @@ public: } bool operator!=(const CompactionStrategy & rhs) const { return !(operator==(rhs)); } - static constexpr size_t DEAD_BYTES_SLACK = 0x10000u; - - bool should_compact_memory(size_t used_bytes, size_t dead_bytes) const { - return ((dead_bytes >= DEAD_BYTES_SLACK) && - (dead_bytes > used_bytes * getMaxDeadBytesRatio())); - } - - static constexpr size_t DEAD_ADDRESS_SPACE_SLACK = 0x10000u; - - bool should_compact_address_space(size_t used_address_space, size_t dead_address_space) const { - return ((dead_address_space >= DEAD_ADDRESS_SPACE_SLACK) && - (dead_address_space > used_address_space * getMaxDeadAddressSpaceRatio())); - } + bool should_compact_memory(const MemoryUsage& memory_usage) const; + bool should_compact_address_space(const AddressSpace& address_space) const; + CompactionSpec should_compact(const MemoryUsage& memory_usage, const AddressSpace& address_space) const; }; std::ostream& operator<<(std::ostream& os, const CompactionStrategy& compaction_strategy); |