Improve memory tracking (#1631)
This commit is contained in:
parent
0a7a7bc0d1
commit
23dff58d22
@ -1,4 +1,4 @@
|
|||||||
// Copyright 2023 Memgraph Ltd.
|
// Copyright 2024 Memgraph Ltd.
|
||||||
//
|
//
|
||||||
// Use of this software is governed by the Business Source License
|
// Use of this software is governed by the Business Source License
|
||||||
// included in the file licenses/BSL.txt; by using this file, you agree to be bound by the terms of the Business Source
|
// included in the file licenses/BSL.txt; by using this file, you agree to be bound by the terms of the Business Source
|
||||||
@ -36,14 +36,22 @@ namespace memgraph::memory {
|
|||||||
|
|
||||||
void QueriesMemoryControl::UpdateThreadToTransactionId(const std::thread::id &thread_id, uint64_t transaction_id) {
|
void QueriesMemoryControl::UpdateThreadToTransactionId(const std::thread::id &thread_id, uint64_t transaction_id) {
|
||||||
auto accessor = thread_id_to_transaction_id.access();
|
auto accessor = thread_id_to_transaction_id.access();
|
||||||
accessor.insert({thread_id, transaction_id});
|
auto elem = accessor.find(thread_id);
|
||||||
|
if (elem == accessor.end()) {
|
||||||
|
accessor.insert({thread_id, {transaction_id, 1}});
|
||||||
|
} else {
|
||||||
|
elem->transaction_id.cnt++;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void QueriesMemoryControl::EraseThreadToTransactionId(const std::thread::id &thread_id, uint64_t transaction_id) {
|
void QueriesMemoryControl::EraseThreadToTransactionId(const std::thread::id &thread_id, uint64_t transaction_id) {
|
||||||
auto accessor = thread_id_to_transaction_id.access();
|
auto accessor = thread_id_to_transaction_id.access();
|
||||||
auto elem = accessor.find(thread_id);
|
auto elem = accessor.find(thread_id);
|
||||||
MG_ASSERT(elem != accessor.end() && elem->transaction_id == transaction_id);
|
MG_ASSERT(elem != accessor.end() && elem->transaction_id == transaction_id);
|
||||||
accessor.remove(thread_id);
|
elem->transaction_id.cnt--;
|
||||||
|
if (elem->transaction_id.cnt == 0) {
|
||||||
|
accessor.remove(thread_id);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void QueriesMemoryControl::TrackAllocOnCurrentThread(size_t size) {
|
void QueriesMemoryControl::TrackAllocOnCurrentThread(size_t size) {
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
// Copyright 2023 Memgraph Ltd.
|
// Copyright 2024 Memgraph Ltd.
|
||||||
//
|
//
|
||||||
// Use of this software is governed by the Business Source License
|
// Use of this software is governed by the Business Source License
|
||||||
// included in the file licenses/BSL.txt; by using this file, you agree to be bound by the terms of the Business Source
|
// included in the file licenses/BSL.txt; by using this file, you agree to be bound by the terms of the Business Source
|
||||||
@ -78,9 +78,20 @@ class QueriesMemoryControl {
|
|||||||
bool IsThreadTracked();
|
bool IsThreadTracked();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
struct TransactionId {
|
||||||
|
uint64_t id;
|
||||||
|
uint64_t cnt;
|
||||||
|
|
||||||
|
bool operator<(const TransactionId &other) const { return id < other.id; }
|
||||||
|
bool operator==(const TransactionId &other) const { return id == other.id; }
|
||||||
|
|
||||||
|
bool operator<(uint64_t other) const { return id < other; }
|
||||||
|
bool operator==(uint64_t other) const { return id == other; }
|
||||||
|
};
|
||||||
|
|
||||||
struct ThreadIdToTransactionId {
|
struct ThreadIdToTransactionId {
|
||||||
std::thread::id thread_id;
|
std::thread::id thread_id;
|
||||||
uint64_t transaction_id;
|
TransactionId transaction_id;
|
||||||
|
|
||||||
bool operator<(const ThreadIdToTransactionId &other) const { return thread_id < other.thread_id; }
|
bool operator<(const ThreadIdToTransactionId &other) const { return thread_id < other.thread_id; }
|
||||||
bool operator==(const ThreadIdToTransactionId &other) const { return thread_id == other.thread_id; }
|
bool operator==(const ThreadIdToTransactionId &other) const { return thread_id == other.thread_id; }
|
||||||
@ -98,6 +109,9 @@ class QueriesMemoryControl {
|
|||||||
|
|
||||||
bool operator<(uint64_t other) const { return transaction_id < other; }
|
bool operator<(uint64_t other) const { return transaction_id < other; }
|
||||||
bool operator==(uint64_t other) const { return transaction_id == other; }
|
bool operator==(uint64_t other) const { return transaction_id == other; }
|
||||||
|
|
||||||
|
bool operator<(TransactionId other) const { return transaction_id < other.id; }
|
||||||
|
bool operator==(TransactionId other) const { return transaction_id == other.id; }
|
||||||
};
|
};
|
||||||
|
|
||||||
utils::SkipList<ThreadIdToTransactionId> thread_id_to_transaction_id;
|
utils::SkipList<ThreadIdToTransactionId> thread_id_to_transaction_id;
|
||||||
|
Loading…
Reference in New Issue
Block a user