summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--util/net/message_server_port.cpp20
1 files changed, 16 insertions, 4 deletions
diff --git a/util/net/message_server_port.cpp b/util/net/message_server_port.cpp
index ae5293373f4..ca0b13dae07 100644
--- a/util/net/message_server_port.cpp
+++ b/util/net/message_server_port.cpp
@@ -28,6 +28,10 @@
#include "../../db/lasterror.h"
#include "../../db/stats/counters.h"
+#ifdef __linux__ // TODO: consider making this ifndef _WIN32
+# include <sys/resource.h>
+#endif
+
namespace mongo {
namespace pms {
@@ -127,10 +131,18 @@ namespace mongo {
pthread_attr_init(&attrs);
pthread_attr_setdetachstate(&attrs, PTHREAD_CREATE_DETACHED);
- static const size_t STACK_SIZE = 1024*1024;
- pthread_attr_setstacksize(&attrs, (DEBUG_BUILD
- ? (STACK_SIZE / 2)
- : STACK_SIZE));
+ static const size_t STACK_SIZE = 1024*1024; // if we change this we need to update the warning
+
+ struct rlimit limits;
+ verify(15887, getrlimit(RLIMIT_STACK, &limits) == 0);
+ if (limits.rlim_cur > STACK_SIZE) {
+ pthread_attr_setstacksize(&attrs, (DEBUG_BUILD
+ ? (STACK_SIZE / 2)
+ : STACK_SIZE));
+ } else if (limits.rlim_cur < 1024*1024) {
+ warning() << "Stack size set to " << (limits.rlim_cur/1024) << "KB. We suggest 1MB" << endl;
+ }
+
pthread_t thread;
int failed = pthread_create(&thread, &attrs, (void*(*)(void*)) &pms::threadRun, p);