summaryrefslogtreecommitdiff
path: root/thread_pthread.c
diff options
context:
space:
mode:
authorko1 <ko1@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2012-12-19 22:29:18 +0000
committerko1 <ko1@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2012-12-19 22:29:18 +0000
commit87e1616048edca270c86ab7e5d8b8599e1df79de (patch)
tree97ab05b808201a66b21d7cacbc5702769507abcf /thread_pthread.c
parent5d92f6ec05be5df5f89f81fb926ad08faf22ee03 (diff)
* vm.c: support variable VM/Machine stack sizes.
Specified by the following environment variaables: - RUBY_THREAD_VM_STACK_SIZE: vm stack size used at thread creation. default: 128KB (32bit CPU) or 256KB (64bit CPU). - RUBY_THREAD_MACHINE_STACK_SIZE: machine stack size used at thread creation. default: 512KB or 1024KB. - RUBY_FIBER_VM_STACK_SIZE: vm stack size used at fiber creation. default: 64KB or 128KB. - RUBY_FIBER_MACHINE_STACK_SIZE: machine stack size used at fiber creation. default: 256KB or 256KB. This values are specified at launched timing. You can not change these values at running time. Environ variables are only *hints* because: - They are aligned to 4KB. - They have minimum values (depend on OSs). - Machine stack settings are ignored by some OSs. Default values especially fiber stack sizes are increased. This change affect Fiber's behavior: (1) You can run more complex program on a Fiber. (2) You can not make many (thousands) Fibers because of lack of address space (on 32bit CPU). If (2) bothers you, (a) Use 64bit CPU with big memory, or (b) Specify RUBY_FIBER_(VM|MACHINE)_STACK_SIZE correctly. You need to choose correct stack size carefully. These values are completely rely on systems (OS/compiler and so on). * vm_core.h (rb_vm_t::default_params): add to record above settings. * vm.c (RubyVM::DEFAULT_PARAMS): add new constant to see above setting. * thread_pthread.c: support RUBY_THREAD_MACHINE_STACK_SIZE. * cont.c: support RUBY_FIBER_(VM|MACHINE)_STACK_SIZE. * test/ruby/test_fiber.rb: add tests for above. * test/ruby/test_thread.rb: ditto. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@38478 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'thread_pthread.c')
-rw-r--r--thread_pthread.c41
1 files changed, 19 insertions, 22 deletions
diff --git a/thread_pthread.c b/thread_pthread.c
index d60cb41e28..cbf75aa3e1 100644
--- a/thread_pthread.c
+++ b/thread_pthread.c
@@ -584,26 +584,6 @@ static struct {
#endif
} native_main_thread;
-
-enum {
-#ifdef __SYMBIAN32__
- RUBY_STACK_MIN_LIMIT = 64 * 1024, /* 64KB: Let's be slightly more frugal on mobile platform */
-#else
- RUBY_STACK_MIN_LIMIT = 512 * 1024, /* 512KB */
-#endif
- RUBY_STACK_SPACE_LIMIT = 1024 * 1024,
- RUBY_STACK_SPACE_RATIO = 5
-};
-#ifdef PTHREAD_STACK_MIN
-#define RUBY_STACK_MIN ((RUBY_STACK_MIN_LIMIT < PTHREAD_STACK_MIN) ? \
- PTHREAD_STACK_MIN * 2 : RUBY_STACK_MIN_LIMIT)
-#else
-#define RUBY_STACK_MIN (RUBY_STACK_MIN_LIMIT)
-#endif
-#define RUBY_STACK_MIN_SPACE RUBY_STACK_MIN/RUBY_STACK_SPACE_RATIO
-#define RUBY_STACK_SPACE ((RUBY_STACK_MIN_SPACE > RUBY_STACK_SPACE_LIMIT) ? \
- RUBY_STACK_SPACE_LIMIT : RUBY_STACK_MIN_SPACE)
-
#ifdef STACK_END_ADDRESS
extern void *STACK_END_ADDRESS;
#endif
@@ -830,6 +810,23 @@ use_cached_thread(rb_thread_t *th)
return result;
}
+enum {
+ RUBY_STACK_SPACE_LIMIT = 1024 * 1024, /* 1024KB */
+ RUBY_STACK_SPACE_RATIO = 5
+};
+
+static size_t
+space_size(size_t stack_size)
+{
+ size_t space_size = stack_size / RUBY_STACK_SPACE_RATIO;
+ if (space_size > RUBY_STACK_SPACE_LIMIT) {
+ return RUBY_STACK_SPACE_LIMIT;
+ }
+ else {
+ return space_size;
+ }
+}
+
static int
native_thread_create(rb_thread_t *th)
{
@@ -840,8 +837,8 @@ native_thread_create(rb_thread_t *th)
}
else {
pthread_attr_t attr;
- const size_t stack_size = RUBY_STACK_MIN;
- const size_t space = RUBY_STACK_SPACE;
+ const size_t stack_size = th->vm->default_params.thread_machine_stack_size;
+ const size_t space = space_size(stack_size);
th->machine_stack_maxsize = stack_size - space;
#ifdef __ia64