summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMathias Stearn <mathias@10gen.com>2011-08-12 16:07:56 -0400
committerMathias Stearn <mathias@10gen.com>2011-08-12 16:07:56 -0400
commit5e12acf80501fc5b4c7e925c878c2f8ac398e62d (patch)
treed3da59bc2fb294434ecb88d554991a08d9e02757
parent3d590b6dd6fc1d7135bf41fb954158db59e5ae30 (diff)
downloadmongo-5e12acf80501fc5b4c7e925c878c2f8ac398e62d.tar.gz
If user sets a smaller stack size than our default we should use it SERVER-2707
-rw-r--r--db/db.cpp15
-rw-r--r--util/message_server_port.cpp18
2 files changed, 27 insertions, 6 deletions
diff --git a/db/db.cpp b/db/db.cpp
index 6b2535d6bf8..4f4575ce5f8 100644
--- a/db/db.cpp
+++ b/db/db.cpp
@@ -46,6 +46,7 @@
# include "../util/ntservice.h"
#else
# include <sys/file.h>
+# include <sys/resource.h>
#endif
namespace mongo {
@@ -116,9 +117,17 @@ namespace mongo {
pthread_attr_setdetachstate(&attrs, PTHREAD_CREATE_DETACHED);
static const size_t STACK_SIZE = 4*1024*1024;
- pthread_attr_setstacksize(&attrs, (DEBUG_BUILD
- ? (STACK_SIZE / 2)
- : STACK_SIZE));
+
+ struct rlimit limits;
+ assert(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 at least 1MB" << endl;
+ }
pthread_t thread;
int failed = pthread_create(&thread, &attrs, (void*(*)(void*)) &connThread, mp);
diff --git a/util/message_server_port.cpp b/util/message_server_port.cpp
index d4fcd77513b..409b0c7795f 100644
--- a/util/message_server_port.cpp
+++ b/util/message_server_port.cpp
@@ -26,6 +26,10 @@
#include "../db/lasterror.h"
#include "../db/stats/counters.h"
+#ifdef __linux__
+# include <sys/resource.h>
+#endif
+
namespace mongo {
namespace pms {
@@ -113,9 +117,17 @@ namespace mongo {
pthread_attr_setdetachstate(&attrs, PTHREAD_CREATE_DETACHED);
static const size_t STACK_SIZE = 4*1024*1024;
- pthread_attr_setstacksize(&attrs, (DEBUG_BUILD
- ? (STACK_SIZE / 2)
- : STACK_SIZE));
+
+ struct rlimit limits;
+ assert(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 at least 1MB" << endl;
+ }
pthread_t thread;
int failed = pthread_create(&thread, &attrs, (void*(*)(void*)) &pms::threadRun, p);