From 2bc0c12afc214d31d0c4bbbdf27df46c3e2050c3 Mon Sep 17 00:00:00 2001 From: Vojislav Stojkovic Date: Tue, 21 Sep 2021 10:59:15 -0700 Subject: SERVER-51233 Warn on startup if vm.max_map_count is too low --- src/mongo/db/startup_warnings_mongod.cpp | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/src/mongo/db/startup_warnings_mongod.cpp b/src/mongo/db/startup_warnings_mongod.cpp index bcbdd49355a..80fda5e69f1 100644 --- a/src/mongo/db/startup_warnings_mongod.cpp +++ b/src/mongo/db/startup_warnings_mongod.cpp @@ -44,6 +44,7 @@ #include "mongo/db/startup_warnings_common.h" #include "mongo/db/storage/storage_options.h" #include "mongo/logv2/log.h" +#include "mongo/transport/service_entry_point.h" #include "mongo/util/processinfo.h" #include "mongo/util/str.h" #include "mongo/util/version.h" @@ -281,6 +282,29 @@ void logMongodStartupWarnings(const StorageGlobalParams& storageParams, "Failed to read " TRANSPARENT_HUGE_PAGES_DIR "/defrag", "error"_attr = transparentHugePagesDefragResult.getStatus().reason()); } + + // Check if vm.max_map_count is high enough, as per SERVER-51233 + { + size_t maxConns = svcCtx->getServiceEntryPoint()->maxOpenSessions(); + size_t requiredMapCount = 2 * maxConns; + + std::fstream f("/proc/sys/vm/max_map_count", ios_base::in); + size_t val; + f >> val; + + if (val < requiredMapCount) { + LOGV2_WARNING_OPTIONS(5123300, + {logv2::LogTag::kStartupWarnings}, + "** WARNING: Maximum number of memory map areas per process is " + "too low. Current value of vm.max_map_count is {currentValue}, " + "recommended minimum is {recommendedMinimum} for currently " + "configured maximum connections ({maxConns})", + "vm.max_map_count is too low", + "currentValue"_attr = val, + "recommendedMinimum"_attr = requiredMapCount, + "maxConns"_attr = maxConns); + } + } #endif // __linux__ #ifndef _WIN32 -- cgit v1.2.1