Skip to content

Commit

Permalink
thread_pthread.c: precise stack size
Browse files Browse the repository at this point in the history
* thread_pthread.c (ruby_init_stack): round stack limit to page size
  boundary to calculate stack size more precisely.  [ruby-dev:46174]
  [Bug ruby#7084]

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@37080 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
  • Loading branch information
nobu committed Oct 4, 2012
1 parent cbe3646 commit fab7e66
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 2 deletions.
6 changes: 6 additions & 0 deletions ChangeLog
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
Thu Oct 4 11:43:28 2012 Nobuyoshi Nakada <[email protected]>

* thread_pthread.c (ruby_init_stack): round stack limit to page size
boundary to calculate stack size more precisely. [ruby-dev:46174]
[Bug #7084]

Wed Oct 3 19:51:57 2012 Narihiro Nakamura <[email protected]>

* gc.c: Use the non-recursive marking instead of recursion. The
Expand Down
12 changes: 10 additions & 2 deletions thread_pthread.c
Original file line number Diff line number Diff line change
Expand Up @@ -649,14 +649,22 @@ ruby_init_stack(volatile VALUE *addr
STACK_GROW_DIR_DETECTION;
get_stack(&stackaddr, &size);
space = STACK_DIR_UPPER((char *)addr - (char *)stackaddr, (char *)stackaddr - (char *)addr);
native_main_thread.stack_maxsize = size - space;
#elif defined(HAVE_GETRLIMIT)
int pagesize = getpagesize();
struct rlimit rlim;
if (getrlimit(RLIMIT_STACK, &rlim) == 0) {
size = (size_t)rlim.rlim_cur;
}
space = size > 5 * 1024 * 1024 ? 1024 * 1024 : size / 5;
addr = native_main_thread.stack_start;
if (IS_STACK_DIR_UPPER()) {
space = ((size_t)((char *)addr + size) / pagesize) * pagesize - (size_t)addr;
}
else {
space = (size_t)addr - ((size_t)((char *)addr - size) / pagesize + 1) * pagesize;
}
native_main_thread.stack_maxsize = space;
#endif
native_main_thread.stack_maxsize = size - space;
}
}

Expand Down

0 comments on commit fab7e66

Please sign in to comment.