Skip to content
Browse files

If user sets a smaller stack size than our default we should use it S…

…ERVER-2707
  • Loading branch information...
1 parent 3d590b6 commit 5e12acf80501fc5b4c7e925c878c2f8ac398e62d @RedBeard0531 RedBeard0531 committed
Showing with 27 additions and 6 deletions.
  1. +12 −3 db/db.cpp
  2. +15 −3 util/message_server_port.cpp
View
15 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);
View
18 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);

0 comments on commit 5e12acf

Please sign in to comment.
Something went wrong with that request. Please try again.