summaryrefslogtreecommitdiff
path: root/db/db.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'db/db.cpp')
-rw-r--r--db/db.cpp15
1 files changed, 12 insertions, 3 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);