Compare commits

...

6 Commits

Author SHA1 Message Date
Antonio Filipovic
c77d84ef6d Merge branch 'master' into add-gc-for-query-memory-tracker 2023-11-22 10:11:07 +01:00
antoniofilipovic
186be4c213 link mg-memory 2023-11-14 16:19:41 +01:00
antoniofilipovic
4e06e769f1 revert back on isTransactionTracked 2023-11-14 15:57:46 +01:00
antoniofilipovic
311c129bfc clear only under main lock 2023-11-14 15:47:33 +01:00
antoniofilipovic
fe577aab18 resolve conflict 2023-11-14 15:14:58 +01:00
antoniofilipovic
9a3ce1ef01 add gc for query memory tracker 2023-11-06 16:45:00 +01:00
3 changed files with 29 additions and 1 deletions

View File

@@ -154,6 +154,12 @@ inline int &Get_Thread_Tracker() {
bool QueriesMemoryControl::IsThreadTracked() { return Get_Thread_Tracker() == 1; }
void QueriesMemoryControl::ResetTrackings() {
Get_Thread_Tracker() = 0;
transaction_id_to_tracker.clear();
thread_id_to_transaction_id.clear();
}
#endif
void StartTrackingCurrentThreadTransaction(uint64_t transaction_id) {
@@ -190,6 +196,12 @@ void TryStopTrackingOnTransaction(uint64_t transaction_id) {
#endif
}
void CleanTracker() {
#if USE_JEMALLOC
GetQueriesMemoryControl().ResetTrackings();
#endif
}
#if USE_JEMALLOC
bool IsTransactionTracked(uint64_t transaction_id) {
return GetQueriesMemoryControl().CheckTransactionIdTrackerExists(transaction_id);

View File

@@ -77,6 +77,12 @@ class QueriesMemoryControl {
bool IsThreadTracked();
// This method resets all the trackings.
// Method is not thread-safe so it should
// be called when there is global lock
// to not create new transactions
void ResetTrackings();
private:
struct ThreadIdToTransactionId {
std::thread::id thread_id;
@@ -127,6 +133,11 @@ void TryStartTrackingOnTransaction(uint64_t transaction_id, size_t limit);
// Does nothing if jemalloc is not enabled. Does nothing if tracker doesn't exist
void TryStopTrackingOnTransaction(uint64_t transaction_id);
// This method requires lock on global storage
// It will clean all trackers which may accidentally have left in system
// It will reset any tracking on arenas
void CleanTracker();
// Is transaction with given id tracked in memory tracker
bool IsTransactionTracked(uint64_t transaction_id);

View File

@@ -11,6 +11,7 @@
#include "storage/v2/inmemory/storage.hpp"
#include "dbms/constants.hpp"
#include "memory/query_memory_control.hpp"
#include "memory/global_memory_control.hpp"
#include "storage/v2/durability/durability.hpp"
#include "storage/v2/durability/snapshot.hpp"
@@ -1243,7 +1244,11 @@ void InMemoryStorage::CollectGarbage(std::unique_lock<utils::ResourceLock> main_
if (!gc_guard.owns_lock()) {
return;
}
if constexpr (force) {
if (main_guard.owns_lock()) {
memgraph::memory::CleanTracker();
}
}
uint64_t oldest_active_start_timestamp = commit_log_->OldestActive();
// Deltas from previous GC runs or from aborts can be cleaned up here