summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMathias Stearn <mathias@10gen.com>2011-08-12 16:27:33 -0400
committerMathias Stearn <mathias@10gen.com>2011-08-12 16:28:36 -0400
commit94ce2d93733dcbc515a1325d759b8312962279db (patch)
treed8dc3e9e0a5ee47cb8aec2f7d2c733ea08de35f1
parentf95d8d5594077358e7932a1781dad56f1dd7ad66 (diff)
downloadmongo-r1.9.2.tar.gz
If user sets a smaller stack size than our default we should use it SERVER-2707r1.9.2
-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);