aboutsummaryrefslogtreecommitdiff
path: root/src/zenstore/include
diff options
context:
space:
mode:
authorDan Engelbrecht <[email protected]>2023-12-01 07:57:13 -0500
committerGitHub <[email protected]>2023-12-01 13:57:13 +0100
commit2755b0dbfd47237e018048598e9c85c71b9a0736 (patch)
treeca1e55c43555fc2ff43455f8dfc4ac28daebe42b /src/zenstore/include
parentadd separate PreCache step for GcReferenceChecker (#578) (diff)
downloadzen-2755b0dbfd47237e018048598e9c85c71b9a0736.tar.xz
zen-2755b0dbfd47237e018048598e9c85c71b9a0736.zip
use 32 bit offset and size in BlockStoreLocation (#581)
- Improvement: Reduce memory usage in GC and diskbucket flush
Diffstat (limited to 'src/zenstore/include')
-rw-r--r--src/zenstore/include/zenstore/blockstore.h26
1 files changed, 13 insertions, 13 deletions
diff --git a/src/zenstore/include/zenstore/blockstore.h b/src/zenstore/include/zenstore/blockstore.h
index dcd4b5e87..919684e41 100644
--- a/src/zenstore/include/zenstore/blockstore.h
+++ b/src/zenstore/include/zenstore/blockstore.h
@@ -16,8 +16,8 @@ namespace zen {
struct BlockStoreLocation
{
uint32_t BlockIndex;
- uint64_t Offset;
- uint64_t Size;
+ uint32_t Offset;
+ uint32_t Size;
inline auto operator<=>(const BlockStoreLocation& Rhs) const = default;
};
@@ -32,19 +32,19 @@ struct BlockStoreDiskLocation
constexpr static uint32_t MaxBlockIndex = (1ul << BlockStoreDiskLocation::MaxBlockIndexBits) - 1ul;
constexpr static uint32_t MaxOffset = (1ul << BlockStoreDiskLocation::MaxOffsetBits) - 1ul;
- BlockStoreDiskLocation(const BlockStoreLocation& Location, uint64_t OffsetAlignment)
+ BlockStoreDiskLocation(const BlockStoreLocation& Location, uint32_t OffsetAlignment)
{
Init(Location.BlockIndex, Location.Offset / OffsetAlignment, Location.Size);
}
BlockStoreDiskLocation() = default;
- inline BlockStoreLocation Get(uint64_t OffsetAlignment) const
+ inline BlockStoreLocation Get(uint32_t OffsetAlignment) const
{
uint64_t PackedOffset = 0;
memcpy(&PackedOffset, &m_Offset, sizeof m_Offset);
- return {.BlockIndex = static_cast<std::uint32_t>(PackedOffset >> MaxOffsetBits),
- .Offset = (PackedOffset & MaxOffset) * OffsetAlignment,
+ return {.BlockIndex = static_cast<uint32_t>(PackedOffset >> MaxOffsetBits),
+ .Offset = static_cast<uint32_t>((PackedOffset & MaxOffset) * OffsetAlignment),
.Size = GetSize()};
}
@@ -55,14 +55,14 @@ struct BlockStoreDiskLocation
return static_cast<std::uint32_t>(PackedOffset >> MaxOffsetBits);
}
- inline uint64_t GetOffset(uint64_t OffsetAlignment) const
+ inline uint32_t GetOffset(uint32_t OffsetAlignment) const
{
uint64_t PackedOffset = 0;
memcpy(&PackedOffset, &m_Offset, sizeof m_Offset);
- return (PackedOffset & MaxOffset) * OffsetAlignment;
+ return static_cast<uint32_t>((PackedOffset & MaxOffset) * OffsetAlignment);
}
- inline uint64_t GetSize() const { return m_Size; }
+ inline uint32_t GetSize() const { return m_Size; }
inline auto operator<=>(const BlockStoreDiskLocation& Rhs) const = default;
@@ -150,7 +150,7 @@ public:
void Close();
- void WriteChunk(const void* Data, uint64_t Size, uint64_t Alignment, const WriteChunkCallback& Callback);
+ void WriteChunk(const void* Data, uint64_t Size, uint32_t Alignment, const WriteChunkCallback& Callback);
IoBuffer TryGetChunk(const BlockStoreLocation& Location) const;
void Flush(bool ForceNewBlock);
@@ -160,7 +160,7 @@ public:
const ReclaimSnapshotState& Snapshot,
const std::vector<BlockStoreLocation>& ChunkLocations,
const ChunkIndexArray& KeepChunkIndexes,
- uint64_t PayloadAlignment,
+ uint32_t PayloadAlignment,
bool DryRun,
const ReclaimCallback& ChangeCallback = [](const MovedChunksArray&, const ChunkIndexArray&) {},
const ClaimDiskReserveCallback& DiskReserveCallback = []() { return 0; });
@@ -171,7 +171,7 @@ public:
void CompactBlocks(
const BlockStoreCompactState& CompactState,
- uint64_t PayloadAlignment,
+ uint32_t PayloadAlignment,
const CompactCallback& ChangeCallback = [](const MovedChunksArray&, uint64_t) { return true; },
const ClaimDiskReserveCallback& DiskReserveCallback = []() { return 0; });
@@ -189,7 +189,7 @@ private:
mutable RwLock m_InsertLock; // used to serialize inserts
Ref<BlockStoreFile> m_WriteBlock;
- std::uint64_t m_CurrentInsertOffset = 0;
+ std::uint32_t m_CurrentInsertOffset = 0;
std::atomic_uint32_t m_WriteBlockIndex{};
std::vector<uint32_t> m_ActiveWriteBlocks;