aboutsummaryrefslogtreecommitdiff
path: root/src/zenserver/cache/cachememorylayer.cpp
diff options
context:
space:
mode:
authorDan Engelbrecht <[email protected]>2023-10-17 16:24:05 +0200
committerGitHub <[email protected]>2023-10-17 16:24:05 +0200
commit570cb66257b2c7d90cf90c860eb4f5a90c6446d4 (patch)
tree8caa98c9ae91f55a152452e374a0bb8bdce46a83 /src/zenserver/cache/cachememorylayer.cpp
parentMerge branch 'main' of https://github.com/EpicGames/zen (diff)
downloadzen-570cb66257b2c7d90cf90c860eb4f5a90c6446d4.tar.xz
zen-570cb66257b2c7d90cf90c860eb4f5a90c6446d4.zip
fix mem layer total count (#480)
* fix calculation of ZenCacheMemoryLayer::m_TotalSize
Diffstat (limited to 'src/zenserver/cache/cachememorylayer.cpp')
-rw-r--r--src/zenserver/cache/cachememorylayer.cpp21
1 files changed, 16 insertions, 5 deletions
diff --git a/src/zenserver/cache/cachememorylayer.cpp b/src/zenserver/cache/cachememorylayer.cpp
index 1651ad05a..86938df41 100644
--- a/src/zenserver/cache/cachememorylayer.cpp
+++ b/src/zenserver/cache/cachememorylayer.cpp
@@ -93,10 +93,18 @@ ZenCacheMemoryLayer::Put(std::string_view InBucket, const IoHash& HashKey, const
}
}
- Trim();
-
// Note that since the underlying IoBuffer is retained, the content type is also
- Bucket->Put(HashKey, Value);
+ int64_t Diff = Bucket->Put(HashKey, Value);
+
+ if (Diff > 0)
+ {
+ m_TotalSize.fetch_add(static_cast<uint64_t>(Diff));
+ Trim();
+ }
+ else if (Diff < 0)
+ {
+ m_TotalSize.fetch_sub(static_cast<uint64_t>(-Diff));
+ }
}
bool
@@ -376,7 +384,7 @@ ZenCacheMemoryLayer::CacheBucket::Get(const IoHash& HashKey, ZenCacheValue& OutV
return false;
}
-void
+int64_t
ZenCacheMemoryLayer::CacheBucket::Put(const IoHash& HashKey, const ZenCacheValue& Value)
{
ZEN_TRACE_CPU("Z$::Mem::Bucket::Put");
@@ -404,7 +412,7 @@ ZenCacheMemoryLayer::CacheBucket::Put(const IoHash& HashKey, const ZenCacheValue
else if (m_CacheMap.size() == std::numeric_limits<uint32_t>::max())
{
// No more space in our memory cache!
- return;
+ return 0;
}
else
{
@@ -422,11 +430,14 @@ ZenCacheMemoryLayer::CacheBucket::Put(const IoHash& HashKey, const ZenCacheValue
if (PayloadSize > OldPayloadSize)
{
m_TotalSize.fetch_add(PayloadSize - OldPayloadSize);
+ return PayloadSize - OldPayloadSize;
}
else if (PayloadSize < OldPayloadSize)
{
m_TotalSize.fetch_sub(OldPayloadSize - PayloadSize);
+ return -static_cast<int64_t>(OldPayloadSize - PayloadSize);
}
+ return 0;
}
void