diff options
| author | Dan Engelbrecht <[email protected]> | 2024-09-17 15:05:40 +0200 |
|---|---|---|
| committer | GitHub Enterprise <[email protected]> | 2024-09-17 15:05:40 +0200 |
| commit | d020b6522b2d962db67f8a66410e74d61cf3da24 (patch) | |
| tree | 44985edb66e5405df2d3a57c291490b2a0485337 /src/zenstore/include | |
| parent | Running the public github release mirroring as part of creating the release (... (diff) | |
| download | zen-d020b6522b2d962db67f8a66410e74d61cf3da24.tar.xz zen-d020b6522b2d962db67f8a66410e74d61cf3da24.zip | |
gc performance improvements (#160)
* optimized ValidateCbUInt
* optimized iohash comparision
* replace unordered set/map with tsl/robin set/map in blockstore
* increase max buffer size when writing cache bucket sidecar
* only store meta data for files < 4Gb
* faster ReadAttachmentsFromMetaData
* remove memcpy call in BlockStoreDiskLocation
* only write cache bucket state to disk if GC deleted anything
Diffstat (limited to 'src/zenstore/include')
| -rw-r--r-- | src/zenstore/include/zenstore/blockstore.h | 47 | ||||
| -rw-r--r-- | src/zenstore/include/zenstore/cache/cachedisklayer.h | 4 |
2 files changed, 22 insertions, 29 deletions
diff --git a/src/zenstore/include/zenstore/blockstore.h b/src/zenstore/include/zenstore/blockstore.h index 8f67c1c0f..29c53cf22 100644 --- a/src/zenstore/include/zenstore/blockstore.h +++ b/src/zenstore/include/zenstore/blockstore.h @@ -6,7 +6,10 @@ #include <zencore/zencore.h> #include <zenutil/basicfile.h> -#include <unordered_map> +ZEN_THIRD_PARTY_INCLUDES_START +#include <tsl/robin_map.h> +ZEN_THIRD_PARTY_INCLUDES_END + #include <unordered_set> namespace zen { @@ -29,8 +32,8 @@ struct BlockStoreDiskLocation { constexpr static uint32_t MaxBlockIndexBits = 20; constexpr static uint32_t MaxOffsetBits = 28; - constexpr static uint32_t MaxBlockIndex = (1ul << BlockStoreDiskLocation::MaxBlockIndexBits) - 1ul; - constexpr static uint32_t MaxOffset = (1ul << BlockStoreDiskLocation::MaxOffsetBits) - 1ul; + constexpr static uint32_t MaxBlockIndex = (1ul << MaxBlockIndexBits) - 1ul; + constexpr static uint32_t MaxOffset = (1ul << MaxOffsetBits) - 1ul; BlockStoreDiskLocation(const BlockStoreLocation& Location, uint32_t OffsetAlignment) { @@ -41,26 +44,15 @@ struct BlockStoreDiskLocation inline BlockStoreLocation Get(uint32_t OffsetAlignment) const { - uint64_t PackedOffset = 0; - memcpy(&PackedOffset, &m_Offset, sizeof m_Offset); - return {.BlockIndex = static_cast<uint32_t>(PackedOffset >> MaxOffsetBits), - .Offset = static_cast<uint32_t>((PackedOffset & MaxOffset) * OffsetAlignment), - .Size = GetSize()}; + return {.BlockIndex = GetBlockIndex(), .Offset = GetOffset(OffsetAlignment), .Size = GetSize()}; } inline uint32_t GetBlockIndex() const { - uint64_t PackedOffset = 0; - memcpy(&PackedOffset, &m_Offset, sizeof m_Offset); - return static_cast<std::uint32_t>(PackedOffset >> MaxOffsetBits); + return (m_OffsetAndSize1 >> MaxOffsetBits) + (static_cast<uint32_t>(m_OffsetAndSize2) << (32u - MaxOffsetBits)); } - inline uint32_t GetOffset(uint32_t OffsetAlignment) const - { - uint64_t PackedOffset = 0; - memcpy(&PackedOffset, &m_Offset, sizeof m_Offset); - return static_cast<uint32_t>((PackedOffset & MaxOffset) * OffsetAlignment); - } + inline uint32_t GetOffset(uint32_t OffsetAlignment) const { return ((m_OffsetAndSize1)&0x0fffffffu) * OffsetAlignment; } inline uint32_t GetSize() const { return m_Size; } @@ -73,13 +65,14 @@ private: ZEN_ASSERT(Offset <= MaxOffset); ZEN_ASSERT(Size <= std::numeric_limits<std::uint32_t>::max()); - m_Size = static_cast<uint32_t>(Size); - uint64_t PackedOffset = (static_cast<uint64_t>(BlockIndex) << MaxOffsetBits) + Offset; - memcpy(&m_Offset[0], &PackedOffset, sizeof m_Offset); + m_Size = static_cast<uint32_t>(Size); + m_OffsetAndSize1 = (Offset & 0x0fffffffu) + (BlockIndex << MaxOffsetBits); + m_OffsetAndSize2 = static_cast<uint16_t>((BlockIndex >> (32u - MaxOffsetBits)) & 0xffffu); } uint32_t m_Size; - uint8_t m_Offset[6]; + uint32_t m_OffsetAndSize1; + uint16_t m_OffsetAndSize2; }; static_assert(sizeof(BlockStoreDiskLocation) == 10); @@ -146,8 +139,8 @@ public: uint64_t DiskUsage; uint32_t EntryCount; }; - typedef std::unordered_map<uint32_t, BlockUsageInfo> BlockUsageMap; - typedef std::unordered_map<uint32_t, uint32_t> BlockEntryCountMap; + typedef tsl::robin_map<uint32_t, BlockUsageInfo> BlockUsageMap; + typedef tsl::robin_map<uint32_t, uint32_t> BlockEntryCountMap; void Initialize(const std::filesystem::path& BlocksBasePath, uint64_t MaxBlockSize, uint64_t MaxBlockCount); @@ -212,7 +205,7 @@ private: static std::filesystem::path GetBlockPath(const std::filesystem::path& BlocksBasePath, const uint32_t BlockIndex); uint32_t GetFreeBlockIndex(uint32_t StartProbeIndex, RwLock::ExclusiveLockScope&, std::filesystem::path& OutBlockPath) const; - std::unordered_map<uint32_t, Ref<BlockStoreFile>> m_ChunkBlocks; + tsl::robin_map<uint32_t, Ref<BlockStoreFile>> m_ChunkBlocks; mutable RwLock m_InsertLock; // used to serialize inserts Ref<BlockStoreFile> m_WriteBlock; @@ -290,9 +283,9 @@ public: } private: - std::unordered_map<uint32_t, size_t> m_BlockIndexToChunkMapIndex; // Maps to which vector in BlockKeepChunks to use for a block - std::vector<std::vector<size_t>> m_KeepChunks; // One vector per block index with index into ChunkLocations - std::vector<BlockStoreLocation> m_ChunkLocations; + tsl::robin_map<uint32_t, size_t> m_BlockIndexToChunkMapIndex; // Maps to which vector in BlockKeepChunks to use for a block + std::vector<std::vector<size_t>> m_KeepChunks; // One vector per block index with index into ChunkLocations + std::vector<BlockStoreLocation> m_ChunkLocations; }; void blockstore_forcelink(); diff --git a/src/zenstore/include/zenstore/cache/cachedisklayer.h b/src/zenstore/include/zenstore/cache/cachedisklayer.h index 0afc80953..b0b8b4cf3 100644 --- a/src/zenstore/include/zenstore/cache/cachedisklayer.h +++ b/src/zenstore/include/zenstore/cache/cachedisklayer.h @@ -302,7 +302,7 @@ public: }; struct BucketMetaData { - uint64_t RawSize = 0; // 8 + uint32_t RawSize = 0; // 4 IoHash RawHash; // 20 operator bool() const { return RawSize != 0 || RawHash != IoHash::Zero; }; @@ -314,7 +314,7 @@ public: }; #pragma pack(pop) static_assert(sizeof(BucketPayload) == 20u); - static_assert(sizeof(BucketMetaData) == 28u); + static_assert(sizeof(BucketMetaData) == 24u); static_assert(sizeof(AccessTime) == 4u); using IndexMap = tsl::robin_map<IoHash, PayloadIndex, IoHash::Hasher>; |