summaryrefslogtreecommitdiffstats
path: root/vespamalloc
diff options
context:
space:
mode:
authorHenning Baldersheim <balder@yahoo-inc.com>2023-10-19 09:32:14 +0000
committerHenning Baldersheim <balder@yahoo-inc.com>2023-10-19 09:32:14 +0000
commite9d279e50c9bb9558ae3a9a753c4a25dee7dbd6b (patch)
treebb2b6a65d6edda802e7c45fe8cc9d66268ff27e9 /vespamalloc
parent5b7c19edd26fef82201873b18e76a625c9934b0f (diff)
Track size on mmap/unmap
Diffstat (limited to 'vespamalloc')
-rw-r--r--vespamalloc/src/vespamalloc/malloc/mmappool.cpp13
-rw-r--r--vespamalloc/src/vespamalloc/malloc/mmappool.h1
2 files changed, 7 insertions, 7 deletions
diff --git a/vespamalloc/src/vespamalloc/malloc/mmappool.cpp b/vespamalloc/src/vespamalloc/malloc/mmappool.cpp
index ca728547548..cee709ed0ed 100644
--- a/vespamalloc/src/vespamalloc/malloc/mmappool.cpp
+++ b/vespamalloc/src/vespamalloc/malloc/mmappool.cpp
@@ -11,6 +11,7 @@ MMapPool::MMapPool()
: _page_size(getpagesize()),
_huge_flags((getenv("VESPA_USE_HUGEPAGES") != nullptr) ? MAP_HUGETLB : 0),
_peakBytes(0ul),
+ _currentBytes(0ul),
_count(0),
_mutex(),
_mappings()
@@ -29,9 +30,7 @@ MMapPool::getNumMappings() const {
size_t
MMapPool::getMmappedBytes() const {
std::lock_guard guard(_mutex);
- size_t sum(0);
- std::for_each(_mappings.begin(), _mappings.end(), [&sum](const auto & e){ sum += e.second._sz; });
- return sum;
+ return _currentBytes;
}
size_t
@@ -83,11 +82,10 @@ MMapPool::mmap(size_t sz) {
std::lock_guard guard(_mutex);
auto [it, inserted] = _mappings.insert(std::make_pair(buf, MMapInfo(mmapId, sz)));
ASSERT_STACKTRACE(inserted);
- size_t sum(0);
- std::for_each(_mappings.begin(), _mappings.end(), [&sum](const auto & e){ sum += e.second._sz; });
- _peakBytes = std::max(_peakBytes, sum);
+ _currentBytes += sz;
+ _peakBytes = std::max(_peakBytes, _currentBytes);
if (sz >= _G_bigBlockLimit) {
- fprintf(_G_logFile, "%ld mappings of accumulated size %ld\n", _mappings.size(), sum);
+ fprintf(_G_logFile, "%ld mappings of accumulated size %ld\n", _mappings.size(), _currentBytes);
}
}
return buf;
@@ -106,6 +104,7 @@ MMapPool::unmap(void * ptr) {
}
sz = found->second._sz;
_mappings.erase(found);
+ _currentBytes -= sz;
}
int munmap_ok = ::munmap(ptr, sz);
ASSERT_STACKTRACE(munmap_ok == 0);
diff --git a/vespamalloc/src/vespamalloc/malloc/mmappool.h b/vespamalloc/src/vespamalloc/malloc/mmappool.h
index fe02b33f82f..0a3dd5d0a0a 100644
--- a/vespamalloc/src/vespamalloc/malloc/mmappool.h
+++ b/vespamalloc/src/vespamalloc/malloc/mmappool.h
@@ -30,6 +30,7 @@ private:
const size_t _page_size;
const int _huge_flags;
size_t _peakBytes;
+ size_t _currentBytes;
std::atomic<size_t> _count;
std::atomic<bool> _has_hugepage_failure_just_happened;
mutable std::mutex _mutex;