aboutsummaryrefslogtreecommitdiff
path: root/src/zenstore/gc.cpp
diff options
context:
space:
mode:
authorStefan Boberg <[email protected]>2024-12-02 12:21:53 +0100
committerGitHub Enterprise <[email protected]>2024-12-02 12:21:53 +0100
commite6f44577f469e891ed8dab1492a4c53224e0b765 (patch)
tree47334606ce62fb6bf1975cdc09276ced335599f4 /src/zenstore/gc.cpp
parent5.5.15-pre0 (diff)
downloadzen-e6f44577f469e891ed8dab1492a4c53224e0b765.tar.xz
zen-e6f44577f469e891ed8dab1492a4c53224e0b765.zip
added support for dynamic LLM tags (#245)
* added FLLMTag which can be used to register memory tags outside of core * changed `UE_MEMSCOPE` -> `ZEN_MEMSCOPE` for consistency * instrumented some subsystems with dynamic tags
Diffstat (limited to 'src/zenstore/gc.cpp')
-rw-r--r--src/zenstore/gc.cpp30
1 files changed, 30 insertions, 0 deletions
diff --git a/src/zenstore/gc.cpp b/src/zenstore/gc.cpp
index 15dff40f5..f2901c4ee 100644
--- a/src/zenstore/gc.cpp
+++ b/src/zenstore/gc.cpp
@@ -9,6 +9,7 @@
#include <zencore/filesystem.h>
#include <zencore/fmtutils.h>
#include <zencore/logging.h>
+#include <zencore/memory/llm.h>
#include <zencore/scopeguard.h>
#include <zencore/string.h>
#include <zencore/testing.h>
@@ -43,6 +44,14 @@
namespace zen {
+const FLLMTag&
+GetGcTag()
+{
+ static FLLMTag _("gc");
+
+ return _;
+}
+
using namespace std::literals;
namespace fs = std::filesystem;
@@ -633,6 +642,8 @@ KeepUnusedReferences(std::span<const IoHash> SortedUsedReferences, std::span<IoH
void
GcManager::AddGcReferencer(GcReferencer& Referencer)
{
+ ZEN_MEMSCOPE(GetGcTag());
+
RwLock::ExclusiveLockScope _(m_Lock);
m_GcReferencers.push_back(&Referencer);
}
@@ -646,12 +657,14 @@ GcManager::RemoveGcReferencer(GcReferencer& Referencer)
void
GcManager::AddGcReferenceLocker(GcReferenceLocker& ReferenceLocker)
{
+ ZEN_MEMSCOPE(GetGcTag());
RwLock::ExclusiveLockScope _(m_Lock);
m_GcReferencerLockers.push_back(&ReferenceLocker);
}
void
GcManager::RemoveGcReferenceLocker(GcReferenceLocker& ReferenceLocker)
{
+ ZEN_MEMSCOPE(GetGcTag());
RwLock::ExclusiveLockScope _(m_Lock);
std::erase_if(m_GcReferencerLockers, [&](GcReferenceLocker* $) { return $ == &ReferenceLocker; });
}
@@ -659,6 +672,7 @@ GcManager::RemoveGcReferenceLocker(GcReferenceLocker& ReferenceLocker)
void
GcManager::AddGcReferenceStore(GcReferenceStore& ReferenceStore)
{
+ ZEN_MEMSCOPE(GetGcTag());
RwLock::ExclusiveLockScope _(m_Lock);
m_GcReferenceStores.push_back(&ReferenceStore);
}
@@ -676,6 +690,7 @@ GcManager::RemoveGcReferenceStore(GcReferenceStore& ReferenceStore)
GcResult
GcManager::CollectGarbage(const GcSettings& Settings)
{
+ ZEN_MEMSCOPE(GetGcTag());
ZEN_TRACE_CPU("GcV2::CollectGarbage");
GcCtx Ctx{.Settings = Settings, .IsCancelledFlag = m_CancelGC, .Logger = Log()};
@@ -1333,6 +1348,8 @@ GcManager::SetCancelGC(bool CancelFlag)
void
GcManager::AddGcStorage(GcStorage* Storage)
{
+ ZEN_MEMSCOPE(GetGcTag());
+
ZEN_ASSERT(Storage != nullptr);
RwLock::ExclusiveLockScope _(m_Lock);
m_GcStorage.push_back(Storage);
@@ -1348,6 +1365,8 @@ GcManager::RemoveGcStorage(GcStorage* Storage)
void
GcManager::ScrubStorage(ScrubContext& GcCtx)
{
+ ZEN_MEMSCOPE(GetGcTag());
+
RwLock::SharedLockScope _(m_Lock);
for (GcStorage* Storage : m_GcStorage)
@@ -1359,6 +1378,7 @@ GcManager::ScrubStorage(ScrubContext& GcCtx)
GcStorageSize
GcManager::TotalStorageSize() const
{
+ ZEN_MEMSCOPE(GetGcTag());
ZEN_TRACE_CPU("Gc::TotalStorageSize");
RwLock::SharedLockScope _(m_Lock);
@@ -1507,6 +1527,8 @@ GcScheduler::~GcScheduler()
void
GcScheduler::Initialize(const GcSchedulerConfig& Config)
{
+ ZEN_MEMSCOPE(GetGcTag());
+
using namespace std::chrono;
m_Config = Config;
@@ -1571,6 +1593,8 @@ GcScheduler::Initialize(const GcSchedulerConfig& Config)
void
GcScheduler::Shutdown()
{
+ ZEN_MEMSCOPE(GetGcTag());
+
if (static_cast<uint32_t>(GcSchedulerStatus::kStopped) != m_Status)
{
bool GcIsRunning = m_Status == static_cast<uint32_t>(GcSchedulerStatus::kRunning);
@@ -1598,6 +1622,7 @@ GcScheduler::Shutdown()
bool
GcScheduler::TriggerGc(const GcScheduler::TriggerGcParams& Params)
{
+ ZEN_MEMSCOPE(GetGcTag());
std::unique_lock Lock(m_GcMutex);
if (static_cast<uint32_t>(GcSchedulerStatus::kIdle) == m_Status)
{
@@ -1617,6 +1642,7 @@ GcScheduler::TriggerGc(const GcScheduler::TriggerGcParams& Params)
bool
GcScheduler::TriggerScrub(const TriggerScrubParams& Params)
{
+ ZEN_MEMSCOPE(GetGcTag());
std::unique_lock Lock(m_GcMutex);
if (static_cast<uint32_t>(GcSchedulerStatus::kIdle) == m_Status)
@@ -1652,6 +1678,7 @@ GcScheduler::CancelGC()
DiskSpace
GcScheduler::CheckDiskSpace()
{
+ ZEN_MEMSCOPE(GetGcTag());
std::error_code Ec;
DiskSpace Space = DiskSpaceInfo(m_Config.RootDirectory, Ec);
if (Ec)
@@ -1685,6 +1712,7 @@ GcScheduler::CheckDiskSpace()
void
GcScheduler::AppendGCLog(std::string_view Id, GcClock::TimePoint StartTime, const GcSettings& Settings, const GcResult& Result)
{
+ ZEN_MEMSCOPE(GetGcTag());
try
{
std::vector<uint8_t> Blob;
@@ -1784,6 +1812,7 @@ GcScheduler::AppendGCLog(std::string_view Id, GcClock::TimePoint StartTime, cons
GcSchedulerState
GcScheduler::GetState() const
{
+ ZEN_MEMSCOPE(GetGcTag());
GcClock::TimePoint Now = GcClock::Now();
const GcStorageSize TotalSize = m_GcManager.TotalStorageSize();
@@ -1854,6 +1883,7 @@ GcScheduler::GetState() const
void
GcScheduler::SchedulerThread()
{
+ ZEN_MEMSCOPE(GetGcTag());
SetCurrentThreadName("GcScheduler");
std::chrono::seconds WaitTime{0};