diff options
author | ko1 <ko1@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2012-12-19 22:29:18 +0000 |
---|---|---|
committer | ko1 <ko1@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2012-12-19 22:29:18 +0000 |
commit | 87e1616048edca270c86ab7e5d8b8599e1df79de (patch) | |
tree | 97ab05b808201a66b21d7cacbc5702769507abcf /cont.c | |
parent | 5d92f6ec05be5df5f89f81fb926ad08faf22ee03 (diff) | |
download | ruby-87e1616048edca270c86ab7e5d8b8599e1df79de.tar.gz |
* 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 'cont.c')
-rw-r--r-- | cont.c | 12 |
1 files changed, 2 insertions, 10 deletions
@@ -47,12 +47,6 @@ #define RB_PAGE_SIZE (pagesize) #define RB_PAGE_MASK (~(RB_PAGE_SIZE - 1)) static long pagesize; - - #if SIZEOF_VOIDP==8 - #define FIBER_MACHINE_STACK_ALLOCATION_SIZE (0x20000) - #else - #define FIBER_MACHINE_STACK_ALLOCATION_SIZE (0x10000) - #endif #endif /*FIBER_USE_NATIVE*/ #define CAPTURE_JUST_VALID_VM_STACK 1 @@ -631,7 +625,7 @@ fiber_setcontext(rb_fiber_t *newfib, rb_fiber_t *oldfib) rb_thread_t *th = GET_THREAD(), *sth = &newfib->cont.saved_thread; if (newfib->status != RUNNING) { - fiber_initialize_machine_stack_context(newfib, FIBER_MACHINE_STACK_ALLOCATION_SIZE); + fiber_initialize_machine_stack_context(newfib, th->vm->default_params.fiber_machine_stack_size); } /* restore thread context */ @@ -1002,8 +996,6 @@ rb_cont_call(int argc, VALUE *argv, VALUE contval) * */ -#define FIBER_VM_STACK_SIZE (4 * 1024) - static const rb_data_type_t fiber_data_type = { "fiber", {fiber_mark, fiber_free, fiber_memsize,}, @@ -1054,7 +1046,7 @@ fiber_init(VALUE fibval, VALUE proc) fiber_link_join(fib); - th->stack_size = FIBER_VM_STACK_SIZE; + th->stack_size = th->vm->default_params.fiber_vm_stack_size / sizeof(VALUE); th->stack = ALLOC_N(VALUE, th->stack_size); th->cfp = (void *)(th->stack + th->stack_size); |