summaryrefslogtreecommitdiff
path: root/vm_core.h
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 /vm_core.h
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 'vm_core.h')
-rw-r--r--vm_core.h27
1 files changed, 23 insertions, 4 deletions
diff --git a/vm_core.h b/vm_core.h
index 8cc48bc00d..87076f3e08 100644
--- a/vm_core.h
+++ b/vm_core.h
@@ -393,8 +393,30 @@ typedef struct rb_vm_struct {
struct RArray at_exit;
VALUE *defined_strings;
+
+ /* params */
+ struct { /* size in byte */
+ size_t thread_vm_stack_size;
+ size_t thread_machine_stack_size;
+ size_t fiber_vm_stack_size;
+ size_t fiber_machine_stack_size;
+ } default_params;
} rb_vm_t;
+/* default values */
+
+#define RUBY_VM_SIZE_ALIGN 4096
+
+#define RUBY_VM_THREAD_VM_STACK_SIZE ( 32 * 1024 * sizeof(VALUE)) /* 128 KB or 256 KB */
+#define RUBY_VM_THREAD_VM_STACK_SIZE_MIN ( 2 * 1024 * sizeof(VALUE)) /* 8 KB or 16 KB */
+#define RUBY_VM_THREAD_MACHINE_STACK_SIZE ( 128 * 1024 * sizeof(VALUE)) /* 512 KB or 1024 KB */
+#define RUBY_VM_THREAD_MACHINE_STACK_SIZE_MIN ( 16 * 1024 * sizeof(VALUE)) /* 64 KB or 128 KB */
+
+#define RUBY_VM_FIBER_VM_STACK_SIZE ( 16 * 1024 * sizeof(VALUE)) /* 64 KB or 128 KB */
+#define RUBY_VM_FIBER_VM_STACK_SIZE_MIN ( 2 * 1024 * sizeof(VALUE)) /* 8 KB or 16 KB */
+#define RUBY_VM_FIBER_MACHINE_STACK_SIZE ( 64 * 1024 * sizeof(VALUE)) /* 256 KB or 512 KB */
+#define RUBY_VM_FIBER_MACHINE_STACK_SIZE_MIN ( 16 * 1024 * sizeof(VALUE)) /* 64 KB or 128 KB */
+
#ifndef VM_DEBUG_BP_CHECK
#define VM_DEBUG_BP_CHECK 1
#endif
@@ -469,7 +491,7 @@ typedef struct rb_thread_struct {
/* execution information */
VALUE *stack; /* must free, must mark */
- unsigned long stack_size;
+ size_t stack_size; /* size in word (byte size / sizeof(VALUE)) */
rb_control_frame_t *cfp;
int safe_level;
int raised_flag;
@@ -620,9 +642,6 @@ RUBY_EXTERN VALUE rb_mRubyVMFrozenCore;
#pragma GCC visibility pop
#endif
-/* each thread has this size stack : 128KB */
-#define RUBY_VM_THREAD_STACK_SIZE (128 * 1024)
-
#define GetProcPtr(obj, ptr) \
GetCoreDataFromValue((obj), rb_proc_t, (ptr))