From 1ccfb3c387773f3b7b396ad2a775dc08b00e8109 Mon Sep 17 00:00:00 2001 From: Stefan Boberg Date: Tue, 17 Dec 2024 14:45:27 +0100 Subject: Miscellaneous minor LLM fixes (#268) With this change, LLM tags are assigned using the name,parent tuple rather than just by name only. This allows tag hierarchies like `cache/store` and `project/store` which would previously get collapsed into the first pair seen when registering the `store` tag. This PR also adds some more LLM tag annotations to more accurately associate memory allocations with subsystems In addition, this PR also tweaks the frequency of timer marker events to increase the resolution in Insights and avoid some cases of Insights deciding that marker events are too far apart since we don't allocate as frequently as UE tends to. --- src/zencore/memory/llm.cpp | 4 +++- src/zencore/memtrack/memorytrace.cpp | 4 ++-- src/zenstore/cache/cachedisklayer.cpp | 2 ++ src/zenstore/compactcas.cpp | 3 ++- 4 files changed, 9 insertions(+), 4 deletions(-) (limited to 'src') diff --git a/src/zencore/memory/llm.cpp b/src/zencore/memory/llm.cpp index fe4853d49..61fa29a66 100644 --- a/src/zencore/memory/llm.cpp +++ b/src/zencore/memory/llm.cpp @@ -15,6 +15,7 @@ static const int32_t TagNamesBaseIndex = 256; static const int32_t TrackedTagNameCount = 256; static const char* TagNames[TrackedTagNameCount]; static uint32_t TagNameHashes[TrackedTagNameCount]; +static int32_t ParentTags[TrackedTagNameCount]; static RwLock TableLock; @@ -46,7 +47,7 @@ FLLMTag::AssignAndAnnounceNewTag(const char* TagName) for (int TagIndex = 0; TagIndex <= CurrentMaxTagIndex; ++TagIndex) { - if (TagNameHashes[TagIndex] == TagNameHash) + if (TagNameHashes[TagIndex] == TagNameHash && ParentTags[TagIndex] == m_ParentTag) { m_Tag = TagIndex + TagNamesBaseIndex; // could verify the string matches here to catch hash collisions @@ -64,6 +65,7 @@ FLLMTag::AssignAndAnnounceNewTag(const char* TagName) { TagNameHashes[TagIndex] = TagNameHash; TagNames[TagIndex] = TagName; + ParentTags[TagIndex] = m_ParentTag; } else { diff --git a/src/zencore/memtrack/memorytrace.cpp b/src/zencore/memtrack/memorytrace.cpp index 7089c356a..e4ae8148e 100644 --- a/src/zencore/memtrack/memorytrace.cpp +++ b/src/zencore/memtrack/memorytrace.cpp @@ -41,8 +41,8 @@ void MemoryTrace_EnableTracePump(); //////////////////////////////////////////////////////////////////////////////// namespace { -// Controls how often time markers are emitted (default: every 4095 allocations). -constexpr uint32_t MarkerSamplePeriod = (4 << 10) - 1; +// Controls how often time markers are emitted (must be POW2-1 as this is used as a mask) +constexpr uint32_t MarkerSamplePeriod = 128 - 1; // Number of shifted bits to SizeLower constexpr uint32_t SizeShift = 3; diff --git a/src/zenstore/cache/cachedisklayer.cpp b/src/zenstore/cache/cachedisklayer.cpp index 9f09713ee..cbc1d6e83 100644 --- a/src/zenstore/cache/cachedisklayer.cpp +++ b/src/zenstore/cache/cachedisklayer.cpp @@ -1267,6 +1267,7 @@ ZenCacheDiskLayer::CacheBucket::EndPutBatch(PutBatchHandle* Batch) noexcept size_t IndexOffset = 0; m_BlockStore.WriteChunks(Batch->Buffers, m_Configuration.PayloadAlignment, [&](std::span Locations) { + ZEN_MEMSCOPE(GetCacheDiskTag()); std::vector DiskEntries; { RwLock::ExclusiveLockScope IndexLock(m_IndexLock); @@ -2679,6 +2680,7 @@ ZenCacheDiskLayer::CacheBucket::PutInlineCacheValue(const IoHash& HashKey, Value.Value.Size(), m_Configuration.PayloadAlignment, [&](const BlockStoreLocation& BlockStoreLocation) { + ZEN_MEMSCOPE(GetCacheDiskTag()); ZEN_TRACE_CPU("Z$::Bucket::UpdateLocation"); DiskLocation Location(BlockStoreLocation, m_Configuration.PayloadAlignment, EntryFlags); m_SlogFile.Append({.Key = HashKey, .Location = Location}); diff --git a/src/zenstore/compactcas.cpp b/src/zenstore/compactcas.cpp index 30cf998f8..2be0542db 100644 --- a/src/zenstore/compactcas.cpp +++ b/src/zenstore/compactcas.cpp @@ -199,6 +199,7 @@ CasContainerStrategy::InsertChunk(const void* ChunkData, size_t ChunkSize, const // reads, insert and GC. m_BlockStore.WriteChunk(ChunkData, ChunkSize, m_PayloadAlignment, [&](const BlockStoreLocation& Location) { + ZEN_MEMSCOPE(GetCasContainerTag()); ZEN_TRACE_CPU("CasContainer::UpdateLocation"); BlockStoreDiskLocation DiskLocation(Location, m_PayloadAlignment); const CasDiskIndexEntry IndexEntry{.Key = ChunkHash, .Location = DiskLocation}; @@ -232,7 +233,6 @@ CasContainerStrategy::InsertChunks(std::span Chunks, std::span ZEN_ASSERT(Chunks.size() == ChunkHashes.size()); std::vector Result(Chunks.size()); std::vector NewChunkIndexes; - Result.reserve(Chunks.size()); { RwLock::SharedLockScope _(m_LocationMapLock); for (size_t ChunkIndex = 0; ChunkIndex < ChunkHashes.size(); ChunkIndex++) @@ -264,6 +264,7 @@ CasContainerStrategy::InsertChunks(std::span Chunks, std::span size_t ChunkOffset = 0; m_BlockStore.WriteChunks(Datas, m_PayloadAlignment, [&](std::span Locations) { + ZEN_MEMSCOPE(GetCasContainerTag()); std::vector IndexEntries; for (const BlockStoreLocation& Location : Locations) { -- cgit v1.2.3