Autonomy Software C++ 24.5.1
Welcome to the Autonomy Software repository of the Mars Rover Design Team (MRDT) at Missouri University of Science and Technology (Missouri S&T)! API reference contains the source code and other resources for the development of the autonomy software for our Mars rover. The Autonomy Software project aims to compete in the University Rover Challenge (URC) by demonstrating advanced autonomous capabilities and robust navigation algorithms.
Loading...
Searching...
No Matches
duckdb::BufferPool::MemoryUsage Struct Reference

Public Types

using MemoryUsageCounters = array<atomic<int64_t>, MEMORY_TAG_COUNT + 1>

Public Member Functions

idx_t GetUsedMemory (MemoryUsageCaches cache)
idx_t GetUsedMemory (MemoryTag tag, MemoryUsageCaches cache)
idx_t GetUsedMemory (idx_t index, MemoryUsageCaches cache)
void UpdateUsedMemory (MemoryTag tag, int64_t size)

Public Attributes

MemoryUsageCounters memory_usage
 global memory usage counters
array< MemoryUsageCounters, MEMORY_USAGE_CACHE_COUNT > memory_usage_caches
 cache memory usage to improve performance

Static Public Attributes

static constexpr idx_t MEMORY_USAGE_CACHE_COUNT = 64
 The maximum difference between memory statistics and actual usage is 2MB (64 * 32k).
static constexpr idx_t MEMORY_USAGE_CACHE_THRESHOLD = 32 << 10
static constexpr idx_t TOTAL_MEMORY_USAGE_INDEX = MEMORY_TAG_COUNT

Constructor & Destructor Documentation

◆ MemoryUsage()

duckdb::BufferPool::MemoryUsage::MemoryUsage ( )
387741 {
387742 for (auto &v : memory_usage) {
387743 v = 0;
387744 }
387745 for (auto &cache : memory_usage_caches) {
387746 for (auto &v : cache) {
387747 v = 0;
387748 }
387749 }
387750}
uint32_t v
MemoryUsageCounters memory_usage
global memory usage counters
Definition duckdb.cpp:114009
array< MemoryUsageCounters, MEMORY_USAGE_CACHE_COUNT > memory_usage_caches
cache memory usage to improve performance
Definition duckdb.cpp:114011

Member Function Documentation

◆ GetUsedMemory() [1/3]

idx_t duckdb::BufferPool::MemoryUsage::GetUsedMemory ( MemoryUsageCaches cache)
inline
114015 {
114016 return GetUsedMemory(TOTAL_MEMORY_USAGE_INDEX, cache);
114017 }

◆ GetUsedMemory() [2/3]

idx_t duckdb::BufferPool::MemoryUsage::GetUsedMemory ( MemoryTag tag,
MemoryUsageCaches cache )
inline
114019 {
114020 return GetUsedMemory((idx_t)tag, cache);
114021 }
uint64_t idx_t
a saner size_t for loop indices etc
Definition duckdb.hpp:237

◆ GetUsedMemory() [3/3]

idx_t duckdb::BufferPool::MemoryUsage::GetUsedMemory ( idx_t index,
MemoryUsageCaches cache )
inline
114023 {
114024 if (cache == MemoryUsageCaches::NO_FLUSH) {
114025 auto used_memory = memory_usage[index].load(std::memory_order_relaxed);
114026 return used_memory > 0 ? static_cast<idx_t>(used_memory) : 0;
114027 }
114028 int64_t cached = 0;
114029 for (auto &cache : memory_usage_caches) {
114030 cached += cache[index].exchange(0, std::memory_order_relaxed);
114031 }
114032 auto used_memory = memory_usage[index].fetch_add(cached, std::memory_order_relaxed) + cached;
114033 return used_memory > 0 ? static_cast<idx_t>(used_memory) : 0;
114034 }
index
::int64_t int64_t

◆ UpdateUsedMemory()

void duckdb::BufferPool::MemoryUsage::UpdateUsedMemory ( MemoryTag tag,
int64_t size )
387752 {
387753 auto tag_idx = (idx_t)tag;
387754 if ((idx_t)AbsValue(size) < MEMORY_USAGE_CACHE_THRESHOLD) {
387755 // update cache and update global counter when cache exceeds threshold
387756 // Get corresponding cache slot based on current CPU core index
387757 // Two threads may access the same cache simultaneously,
387758 // ensuring correctness through atomic operations
387760 auto &cache = memory_usage_caches[cache_idx];
387761 auto new_tag_size = cache[tag_idx].fetch_add(size, std::memory_order_relaxed) + size;
387762 if ((idx_t)AbsValue(new_tag_size) >= MEMORY_USAGE_CACHE_THRESHOLD) {
387763 // cached tag memory usage exceeds threshold
387764 auto tag_size = cache[tag_idx].exchange(0, std::memory_order_relaxed);
387765 memory_usage[tag_idx].fetch_add(tag_size, std::memory_order_relaxed);
387766 }
387767 auto new_total_size = cache[TOTAL_MEMORY_USAGE_INDEX].fetch_add(size, std::memory_order_relaxed) + size;
387768 if ((idx_t)AbsValue(new_total_size) >= MEMORY_USAGE_CACHE_THRESHOLD) {
387769 // cached total memory usage exceeds threshold
387770 auto total_size = cache[TOTAL_MEMORY_USAGE_INDEX].exchange(0, std::memory_order_relaxed);
387771 memory_usage[TOTAL_MEMORY_USAGE_INDEX].fetch_add(total_size, std::memory_order_relaxed);
387772 }
387773 } else {
387774 // update global counter
387775 memory_usage[tag_idx].fetch_add(size, std::memory_order_relaxed);
387776 memory_usage[TOTAL_MEMORY_USAGE_INDEX].fetch_add(size, std::memory_order_relaxed);
387777 }
387778}
static idx_t GetEstimatedCPUId()
Definition duckdb.cpp:335387
GOpaque< Size > size(const GMat &src)
static constexpr idx_t MEMORY_USAGE_CACHE_COUNT
The maximum difference between memory statistics and actual usage is 2MB (64 * 32k).
Definition duckdb.cpp:114003

The documentation for this struct was generated from the following file: