diff options
| author | Dan Engelbrecht <[email protected]> | 2022-03-17 23:16:57 +0100 |
|---|---|---|
| committer | Dan Engelbrecht <[email protected]> | 2022-03-31 11:28:32 +0200 |
| commit | db802259323abf66bc49186408461db1df3447dd (patch) | |
| tree | 2d36faf094215a6347b6853f130b7fea7f49adaa /zenstore/compactcas.h | |
| parent | WIP - bit assignement for CasDiskLocation (diff) | |
| download | zen-db802259323abf66bc49186408461db1df3447dd.tar.xz zen-db802259323abf66bc49186408461db1df3447dd.zip | |
Use bitpacking for Cas block location
Diffstat (limited to 'zenstore/compactcas.h')
| -rw-r--r-- | zenstore/compactcas.h | 63 |
1 files changed, 26 insertions, 37 deletions
diff --git a/zenstore/compactcas.h b/zenstore/compactcas.h index 5f58ccab1..91c7c6981 100644 --- a/zenstore/compactcas.h +++ b/zenstore/compactcas.h @@ -19,16 +19,35 @@ namespace zen { ////////////////////////////////////////////////////////////////////////// +struct CasLocation +{ + uint32_t BlockIndex; + uint64_t Offset; + uint64_t Size; +}; + #pragma pack(push) #pragma pack(1) struct CasDiskLocation { - // 20 bits blockindex - // 28 bits offset - // 32 bits size + constexpr static uint32_t MaxBlockIndexBits = 20; + constexpr static uint32_t MaxOffsetBits = 28; + constexpr static uint32_t MaxBlockIndex = (1ul << CasDiskLocation::MaxBlockIndexBits) - 1ul; + constexpr static uint32_t MaxOffset = (1ul << CasDiskLocation::MaxOffsetBits) - 1ul; + + explicit CasDiskLocation(const CasLocation& Location) { Init(Location.BlockIndex, Location.Offset, Location.Size); } + + CasDiskLocation() = default; - CasDiskLocation(uint32_t BlockIndex, uint64_t Offset, uint64_t Size) + inline CasLocation operator*() const { return {.BlockIndex = BlockIndex(), .Offset = Offset(), .Size = Size()}; } + +private: + inline uint32_t BlockIndex() const { return (static_cast<uint32_t>(m_BlockIndexAndOffsetHighBits & 0xf) << 16) | m_BlockIndexLowBits; } + inline uint64_t Offset() const { return (static_cast<uint64_t>(m_BlockIndexAndOffsetHighBits & 0xfff0) << 12) | m_OffsetLowBits; } + inline uint64_t Size() const { return m_Size; } + + inline void Init(uint32_t BlockIndex, uint64_t Offset, uint64_t Size) { ZEN_ASSERT(BlockIndex < (1L << 20)); ZEN_ASSERT(Offset < (1L << 28)); @@ -40,40 +59,10 @@ struct CasDiskLocation m_BlockIndexAndOffsetHighBits = static_cast<uint16_t>(((BlockIndex >> 16) & 0xf) | (((Offset >> 16) & 0xfff) << 4)); } - CasDiskLocation() = default; - - inline uint32_t GetBlockIndex() const - { - return (static_cast<uint32_t>(m_BlockIndexAndOffsetHighBits & 0xf) << 16) | m_BlockIndexLowBits; - } - inline uint64_t Offset() const { return (static_cast<uint64_t>(m_BlockIndexAndOffsetHighBits & 0xfff0) << 8) | m_OffsetLowBits; } - inline uint64_t Size() const { return m_Size; } - -private: uint32_t m_Size; uint16_t m_BlockIndexLowBits; uint16_t m_OffsetLowBits; uint16_t m_BlockIndexAndOffsetHighBits; - -#if 0 - // 24 bits blockindex - // 24 bits offset - // 32 bits size - inline uint32_t GetBlockIndex() const - { - return (static_cast<uint32_t>(BlockIndexHighBits) << 16) | BlockIndexLowBits; - } - inline uint32_t Offset() const - { - return (static_cast<uint32_t>(OffsetHighBits) << 16) | OffsetLowBits; - } - - uint32_t Size; - uint16_t BlockIndexLowBits; - uint16_t OffsetLowBits; - uint8_t BlockIndexHighBits; - uint8_t OffsetHighBits; -#endif }; struct CasDiskIndexEntry @@ -134,10 +123,10 @@ private: std::unordered_map<IoHash, CasDiskLocation, IoHash::Hasher> m_LocationMap; RwLock m_InsertLock; // used to serialize inserts - std::unordered_map<uint16_t, std::shared_ptr<ChunkBlock>> m_OpenBlocks; + std::unordered_map<uint32_t, std::shared_ptr<ChunkBlock>> m_OpenBlocks; std::weak_ptr<ChunkBlock> m_CurrentBlock; - uint16_t m_CurrentBlockIndex = 0; - std::atomic_uint32_t m_CurrentInsertOffset{}; + uint32_t m_CurrentBlockIndex = 0; + std::atomic_uint64_t m_CurrentInsertOffset{}; std::atomic_uint64_t m_TotalSize{}; void MakeIndexSnapshot(); |