diff options
| author | Per Larsson <[email protected]> | 2021-12-10 15:29:18 +0100 |
|---|---|---|
| committer | Per Larsson <[email protected]> | 2021-12-10 15:29:18 +0100 |
| commit | 370d0134a7f755b1e39fbba5c9482ecc9ff3a0fe (patch) | |
| tree | 7329dc070434ccc265be6a7651274366d8c9fc06 | |
| parent | Set GC default enabled and interval set to zero (off). (diff) | |
| download | zen-370d0134a7f755b1e39fbba5c9482ecc9ff3a0fe.tar.xz zen-370d0134a7f755b1e39fbba5c9482ecc9ff3a0fe.zip | |
Added size to GcStorage.
| -rw-r--r-- | zenserver/cache/structuredcache.cpp | 4 | ||||
| -rw-r--r-- | zenserver/cache/structuredcachestore.cpp | 24 | ||||
| -rw-r--r-- | zenserver/cache/structuredcachestore.h | 26 | ||||
| -rw-r--r-- | zenstore/CAS.cpp | 6 | ||||
| -rw-r--r-- | zenstore/compactcas.cpp | 4 | ||||
| -rw-r--r-- | zenstore/compactcas.h | 6 | ||||
| -rw-r--r-- | zenstore/filecas.cpp | 10 | ||||
| -rw-r--r-- | zenstore/filecas.h | 10 | ||||
| -rw-r--r-- | zenstore/include/zenstore/gc.h | 10 |
9 files changed, 50 insertions, 50 deletions
diff --git a/zenserver/cache/structuredcache.cpp b/zenserver/cache/structuredcache.cpp index cf3915363..e74030e07 100644 --- a/zenserver/cache/structuredcache.cpp +++ b/zenserver/cache/structuredcache.cpp @@ -1192,8 +1192,8 @@ HttpStructuredCacheService::HandleStatsRequest(zen::HttpServerRequest& Request) const uint64_t MissCount = m_CacheStats.MissCount; const uint64_t TotalCount = HitCount + MissCount; - const CasStoreSize CasSize = m_CidStore.CasSize(); - const ZenCacheSize CacheSize = m_CacheStore.TotalSize(); + const CasStoreSize CasSize = m_CidStore.CasSize(); + const GcStorageSize CacheSize = m_CacheStore.StorageSize(); Cbo.BeginObject("cache"); Cbo.BeginObject("size"); diff --git a/zenserver/cache/structuredcachestore.cpp b/zenserver/cache/structuredcachestore.cpp index 64e597d53..f74bb05c1 100644 --- a/zenserver/cache/structuredcachestore.cpp +++ b/zenserver/cache/structuredcachestore.cpp @@ -200,10 +200,10 @@ ZenCacheStore::CollectGarbage(GcContext& GcCtx) m_DiskLayer.CollectGarbage(GcCtx); } -ZenCacheSize -ZenCacheStore::TotalSize() const +GcStorageSize +ZenCacheStore::StorageSize() const { - return {.MemorySize = m_MemLayer.TotalSize(), .DiskSize = m_DiskLayer.TotalSize()}; + return {.DiskSize = m_DiskLayer.TotalSize(), .MemorySize = m_MemLayer.TotalSize()}; } ////////////////////////////////////////////////////////////////////////// @@ -472,7 +472,7 @@ struct ZenCacheDiskLayer::CacheBucket void CollectGarbage(GcContext& GcCtx); inline bool IsOk() const { return m_IsOk; } - inline uint64_t TotalSize() const { return m_TotalSize; } + inline uint64_t TotalSize() const { return m_TotalSize.load(std::memory_order::relaxed); } private: std::filesystem::path m_BucketDir; @@ -1544,7 +1544,7 @@ TEST_CASE("zcache.size") const size_t Count = 16; ScopedTemporaryDirectory TempDir; - ZenCacheSize CacheSize; + GcStorageSize CacheSize; { CasGc Gc; @@ -1561,7 +1561,7 @@ TEST_CASE("zcache.size") Zcs.Put("test_bucket-{}"_format(Bucket), IoHash::HashBuffer(&Key, sizeof(uint32_t)), {.Value = Buffer}); } - CacheSize = Zcs.TotalSize(); + CacheSize = Zcs.StorageSize(); CHECK_EQ(CacheValue.GetSize() * Count, CacheSize.DiskSize); CHECK_EQ(CacheValue.GetSize() * Count, CacheSize.MemorySize); } @@ -1570,7 +1570,7 @@ TEST_CASE("zcache.size") CasGc Gc; ZenCacheStore Zcs(Gc, TempDir.Path() / "cache"); - const ZenCacheSize SerializedSize = Zcs.TotalSize(); + const GcStorageSize SerializedSize = Zcs.StorageSize(); CHECK_EQ(SerializedSize.MemorySize, 0); CHECK_EQ(SerializedSize.DiskSize, CacheSize.DiskSize); @@ -1578,7 +1578,7 @@ TEST_CASE("zcache.size") { Zcs.DropBucket("test_bucket-{}"_format(Bucket)); } - CHECK_EQ(0, Zcs.TotalSize().DiskSize); + CHECK_EQ(0, Zcs.StorageSize().DiskSize); } } @@ -1587,7 +1587,7 @@ TEST_CASE("zcache.size") const size_t Count = 16; ScopedTemporaryDirectory TempDir; - ZenCacheSize CacheSize; + GcStorageSize CacheSize; { CasGc Gc; @@ -1604,7 +1604,7 @@ TEST_CASE("zcache.size") Zcs.Put("test_bucket-{}"_format(Bucket), IoHash::HashBuffer(&Key, sizeof(uint32_t)), {.Value = Buffer}); } - CacheSize = Zcs.TotalSize(); + CacheSize = Zcs.StorageSize(); CHECK_EQ(CacheValue.GetSize() * Count, CacheSize.DiskSize); CHECK_EQ(0, CacheSize.MemorySize); } @@ -1613,7 +1613,7 @@ TEST_CASE("zcache.size") CasGc Gc; ZenCacheStore Zcs(Gc, TempDir.Path() / "cache"); - const ZenCacheSize SerializedSize = Zcs.TotalSize(); + const GcStorageSize SerializedSize = Zcs.StorageSize(); CHECK_EQ(SerializedSize.MemorySize, 0); CHECK_EQ(SerializedSize.DiskSize, CacheSize.DiskSize); @@ -1621,7 +1621,7 @@ TEST_CASE("zcache.size") { Zcs.DropBucket("test_bucket-{}"_format(Bucket)); } - CHECK_EQ(0, Zcs.TotalSize().DiskSize); + CHECK_EQ(0, Zcs.StorageSize().DiskSize); } } } diff --git a/zenserver/cache/structuredcachestore.h b/zenserver/cache/structuredcachestore.h index 437d06267..14670f88d 100644 --- a/zenserver/cache/structuredcachestore.h +++ b/zenserver/cache/structuredcachestore.h @@ -143,27 +143,21 @@ private: ZenCacheDiskLayer& operator=(const ZenCacheDiskLayer&) = delete; }; -struct ZenCacheSize -{ - uint64_t MemorySize{}; - uint64_t DiskSize{}; -}; - -class ZenCacheStore : public GcStorage, public GcContributor +class ZenCacheStore final : public GcStorage, public GcContributor { public: ZenCacheStore(CasGc& Gc, const std::filesystem::path& RootDir); ~ZenCacheStore(); - bool Get(std::string_view Bucket, const IoHash& HashKey, ZenCacheValue& OutValue); - void Put(std::string_view Bucket, const IoHash& HashKey, const ZenCacheValue& Value); - bool DropBucket(std::string_view Bucket); - void Flush(); - void Scrub(ScrubContext& Ctx); - virtual void GatherReferences(GcContext& GcCtx) override; - virtual void CollectGarbage(GcContext& GcCtx) override; - ZenCacheSize TotalSize() const; - uint64_t DiskLayerThreshold() const { return m_DiskLayerSizeThreshold; } + bool Get(std::string_view Bucket, const IoHash& HashKey, ZenCacheValue& OutValue); + void Put(std::string_view Bucket, const IoHash& HashKey, const ZenCacheValue& Value); + bool DropBucket(std::string_view Bucket); + void Flush(); + void Scrub(ScrubContext& Ctx); + uint64_t DiskLayerThreshold() const { return m_DiskLayerSizeThreshold; } + virtual void GatherReferences(GcContext& GcCtx) override; + virtual void CollectGarbage(GcContext& GcCtx) override; + virtual GcStorageSize StorageSize() const override; private: std::filesystem::path m_RootDir; diff --git a/zenstore/CAS.cpp b/zenstore/CAS.cpp index 40846e368..18abd2cf5 100644 --- a/zenstore/CAS.cpp +++ b/zenstore/CAS.cpp @@ -324,9 +324,9 @@ CasImpl::GarbageCollect(GcContext& GcCtx) CasStoreSize CasImpl::TotalSize() const { - const uint64_t Tiny = m_TinyStrategy.TotalSize(); - const uint64_t Small = m_SmallStrategy.TotalSize(); - const uint64_t Large = m_LargeStrategy.TotalSize(); + const uint64_t Tiny = m_TinyStrategy.StorageSize().DiskSize; + const uint64_t Small = m_SmallStrategy.StorageSize().DiskSize; + const uint64_t Large = m_LargeStrategy.StorageSize().DiskSize; return {.TinySize = Tiny, .SmallSize = Small, .LargeSize = Large, .TotalSize = Tiny + Small + Large}; } diff --git a/zenstore/compactcas.cpp b/zenstore/compactcas.cpp index f3fcbca28..6149873ad 100644 --- a/zenstore/compactcas.cpp +++ b/zenstore/compactcas.cpp @@ -579,7 +579,7 @@ TEST_CASE("cas.compact.totalsize") ZEN_ASSERT(InsertResult.New); } - const uint64_t TotalSize = Cas.TotalSize(); + const uint64_t TotalSize = Cas.StorageSize().DiskSize; CHECK_EQ(kChunkSize * kChunkCount, TotalSize); } @@ -588,7 +588,7 @@ TEST_CASE("cas.compact.totalsize") CasContainerStrategy Cas(CasConfig, Gc); Cas.Initialize("test", 16, false); - const uint64_t TotalSize = Cas.TotalSize(); + const uint64_t TotalSize = Cas.StorageSize().DiskSize; CHECK_EQ(kChunkSize * kChunkCount, TotalSize); } } diff --git a/zenstore/compactcas.h b/zenstore/compactcas.h index 1d3a2beff..f3a933718 100644 --- a/zenstore/compactcas.h +++ b/zenstore/compactcas.h @@ -80,7 +80,7 @@ static_assert(sizeof(CasDiskIndexEntry) == 32); * */ -struct CasContainerStrategy : public GcStorage +struct CasContainerStrategy final : public GcStorage { CasContainerStrategy(const CasStoreConfiguration& Config, CasGc& Gc); ~CasContainerStrategy(); @@ -93,8 +93,8 @@ struct CasContainerStrategy : public GcStorage void Initialize(const std::string_view ContainerBaseName, uint64_t Alignment, bool IsNewStore); void Flush(); void Scrub(ScrubContext& Ctx); - void CollectGarbage(GcContext& GcCtx); - uint64_t TotalSize() const { return m_TotalSize; } + virtual void CollectGarbage(GcContext& GcCtx) override; + virtual GcStorageSize StorageSize() const override { return {.DiskSize = m_TotalSize.load(std::memory_order::relaxed)}; } private: void OpenContainer(bool IsNewStore); diff --git a/zenstore/filecas.cpp b/zenstore/filecas.cpp index 62600eae6..bfad34c86 100644 --- a/zenstore/filecas.cpp +++ b/zenstore/filecas.cpp @@ -248,8 +248,8 @@ FileCasStrategy::InsertChunk(IoBuffer Chunk, const IoHash& ChunkHash) if (Success) { - m_TotalSize.fetch_add(static_cast<int64_t>(Chunk.Size())); - m_CasLog.Append({.Key = ChunkHash, .Size = static_cast<int64_t>(Chunk.Size())}); + m_TotalSize.fetch_add(Chunk.Size(), std::memory_order::relaxed); + m_CasLog.Append({.Key = ChunkHash, .Size = Chunk.Size()}); return CasStore::InsertResult{.New = true}; } @@ -354,8 +354,8 @@ FileCasStrategy::InsertChunk(const void* const ChunkData, const size_t ChunkSize // *after* the lock is released due to the initialization order PayloadFile.Close(); - m_TotalSize.fetch_add(static_cast<int64_t>(ChunkSize)); - m_CasLog.Append({.Key = ChunkHash, .Size = static_cast<int64_t>(ChunkSize)}); + m_TotalSize.fetch_add(ChunkSize, std::memory_order::relaxed); + m_CasLog.Append({.Key = ChunkHash, .Size = ChunkSize}); return {.New = true}; } @@ -409,7 +409,7 @@ FileCasStrategy::DeleteChunk(const IoHash& ChunkHash, std::error_code& Ec) if (!Ec) { m_TotalSize.fetch_sub(FileSize); - m_CasLog.Append({.Key = ChunkHash, .Flags = FileCasIndexEntry::kTombStone, .Size = static_cast<int64_t>(FileSize)}); + m_CasLog.Append({.Key = ChunkHash, .Flags = FileCasIndexEntry::kTombStone, .Size = FileSize}); } } diff --git a/zenstore/filecas.h b/zenstore/filecas.h index f64c3061a..a229ba6f1 100644 --- a/zenstore/filecas.h +++ b/zenstore/filecas.h @@ -26,7 +26,7 @@ class BasicFile; /** CAS storage strategy using a file-per-chunk storage strategy */ -struct FileCasStrategy : public GcStorage +struct FileCasStrategy final : public GcStorage { FileCasStrategy(const CasStoreConfiguration& Config, CasGc& Gc); ~FileCasStrategy(); @@ -38,9 +38,9 @@ struct FileCasStrategy : public GcStorage bool HaveChunk(const IoHash& ChunkHash); void FilterChunks(CasChunkSet& InOutChunks); void Flush(); - virtual void CollectGarbage(GcContext& GcCtx) override; void Scrub(ScrubContext& Ctx); - uint64_t TotalSize() const { return static_cast<uint64_t>(m_TotalSize); } + virtual void CollectGarbage(GcContext& GcCtx) override; + virtual GcStorageSize StorageSize() const override { return {.DiskSize = m_TotalSize.load(std::memory_order::relaxed)}; } private: const CasStoreConfiguration& m_Config; @@ -48,7 +48,7 @@ private: RwLock m_ShardLocks[256]; // TODO: these should be spaced out so they don't share cache lines spdlog::logger& m_Log; spdlog::logger& Log() { return m_Log; } - std::atomic_int64_t m_TotalSize{}; + std::atomic_uint64_t m_TotalSize{}; bool m_IsInitialized = false; struct FileCasIndexEntry @@ -59,7 +59,7 @@ private: IoHash Key; uint32_t Flags = 0; - int64_t Size = 0; + uint64_t Size = 0; }; static_assert(sizeof(FileCasIndexEntry) == 32); diff --git a/zenstore/include/zenstore/gc.h b/zenstore/include/zenstore/gc.h index 5a6afc8da..2ea35b131 100644 --- a/zenstore/include/zenstore/gc.h +++ b/zenstore/include/zenstore/gc.h @@ -96,16 +96,22 @@ protected: CasGc& m_Gc; }; +struct GcStorageSize +{ + uint64_t DiskSize{}; + uint64_t MemorySize{}; +}; + /** GC storage provider */ - class GcStorage { public: GcStorage(CasGc& Gc); ~GcStorage(); - virtual void CollectGarbage(GcContext& GcCtx) = 0; + virtual void CollectGarbage(GcContext& GcCtx) = 0; + virtual GcStorageSize StorageSize() const = 0; private: CasGc& m_Gc; |