diff --git a/src/Common/AsynchronousMetrics.cpp b/src/Common/AsynchronousMetrics.cpp index b24d9bcc301..0b9be18c84e 100644 --- a/src/Common/AsynchronousMetrics.cpp +++ b/src/Common/AsynchronousMetrics.cpp @@ -9,6 +9,7 @@ #include #include #include +#include #include #include #include @@ -90,6 +91,9 @@ AsynchronousMetrics::AsynchronousMetrics( openFileIfExists("/sys/fs/cgroup/cpu/cpu.cfs_quota_us", cgroupcpu_cfs_quota); } + openFileIfExists("/proc/sys/vm/max_map_count", vm_max_map_count); + openFileIfExists("/proc/self/maps", vm_maps); + openSensors(); openBlockDevices(); openEDAC(); @@ -1423,6 +1427,55 @@ void AsynchronousMetrics::update(TimePoint update_time, bool force_update) } } + if (vm_max_map_count) + { + try + { + vm_max_map_count->rewind(); + + uint64_t max_map_count = 0; + readText(max_map_count, *vm_max_map_count); + new_values["VMMaxMapCount"] = { max_map_count, "The maximum number of memory mappings a process may have (/proc/sys/vm/max_map_count)."}; + } + catch (...) + { + tryLogCurrentException(__PRETTY_FUNCTION__); + openFileIfExists("/proc/sys/vm/max_map_count", vm_max_map_count); + } + } + + if (vm_maps) + { + try + { + vm_maps->rewind(); + + uint64_t num_maps = 0; + while (!vm_maps->eof()) + { + char * next_pos = find_first_symbols<'\n'>(vm_maps->position(), vm_maps->buffer().end()); + vm_maps->position() = next_pos; + + if (!vm_maps->hasPendingData()) + continue; + + if (*vm_maps->position() == '\n') + { + ++num_maps; + ++vm_maps->position(); + } + } + new_values["VMNumMaps"] = { num_maps, + "The current number of memory mappings of the process (/proc/self/maps)." + " If it is close to the maximum (VMMaxMapCount), you should increase the limit for vm.max_map_count in /etc/sysctl.conf"}; + } + catch (...) + { + tryLogCurrentException(__PRETTY_FUNCTION__); + openFileIfExists("/proc/self/maps", vm_maps); + } + } + try { for (size_t i = 0, size = thermal.size(); i < size; ++i) diff --git a/src/Common/AsynchronousMetrics.h b/src/Common/AsynchronousMetrics.h index 305e8136b8a..4b3d28e80c5 100644 --- a/src/Common/AsynchronousMetrics.h +++ b/src/Common/AsynchronousMetrics.h @@ -123,6 +123,9 @@ private: std::optional cgroupcpu_cfs_quota TSA_GUARDED_BY(data_mutex); std::optional cgroupcpu_max TSA_GUARDED_BY(data_mutex); + std::optional vm_max_map_count TSA_GUARDED_BY(data_mutex); + std::optional vm_maps TSA_GUARDED_BY(data_mutex); + std::vector> thermal TSA_GUARDED_BY(data_mutex); std::unordered_map