https://bugs.ruby-lang.org/https://bugs.ruby-lang.org/favicon.ico?17113305112021-01-26T08:56:21ZRuby Issue Tracking SystemRuby master - Bug #17583: Segfault on large stack(RUBY_THREAD_VM_STACK_SIZE)https://bugs.ruby-lang.org/issues/17583?journal_id=901012021-01-26T08:56:21Zyoshiokatsuneo (Tsuneo Yoshioka)yoshiokatsuneo@gmail.com
<ul><li><strong>ruby -v</strong> changed from <i>3.0.0</i> to <i>ruby 3.0.0p0 (2020-12-25 revision 95aff21468) [x86_64-linux]</i></li></ul> Ruby master - Bug #17583: Segfault on large stack(RUBY_THREAD_VM_STACK_SIZE)https://bugs.ruby-lang.org/issues/17583?journal_id=901032021-01-26T09:04:08Zyoshiokatsuneo (Tsuneo Yoshioka)yoshiokatsuneo@gmail.com
<ul><li><strong>Description</strong> updated (<a title="View differences" href="/journals/90103/diff?detail_id=59034">diff</a>)</li></ul> Ruby master - Bug #17583: Segfault on large stack(RUBY_THREAD_VM_STACK_SIZE)https://bugs.ruby-lang.org/issues/17583?journal_id=901042021-01-26T09:04:25Zyoshiokatsuneo (Tsuneo Yoshioka)yoshiokatsuneo@gmail.com
<ul><li><strong>Description</strong> updated (<a title="View differences" href="/journals/90104/diff?detail_id=59035">diff</a>)</li></ul> Ruby master - Bug #17583: Segfault on large stack(RUBY_THREAD_VM_STACK_SIZE)https://bugs.ruby-lang.org/issues/17583?journal_id=901092021-01-26T15:35:06Znobu (Nobuyoshi Nakada)nobu@ruby-lang.org
<ul></ul><p>Seems <code>mark_object_ary</code> broken?<br>
This should be the array of arrays.</p>
<pre><code>* thread #1, queue = 'com.apple.main-thread', stop reason = EXC_BAD_ACCESS (code=1, address=0x10)
frame #0: 0x00000001007698a9 miniruby`lookup_method_table(klass=108645493675760, id=3281) at vm_method.c:699:33
696 lookup_method_table(VALUE klass, ID id)
697 {
698 st_data_t body;
-> 699 struct rb_id_table *m_tbl = RCLASS_M_TBL(klass);
700
701 if (rb_id_table_lookup(m_tbl, id, &body)) {
702 return (rb_method_entry_t *) body;
Target 0: (miniruby) stopped.
(lldb) p ruby_current_vm_ptr->mark_object_ary
(VALUE) $0 = 108645493686200
(lldb) rp ruby_current_vm_ptr->mark_object_ary
bits [ ]
T_ARRAY: len=1 (ownership) capa=128
(const VALUE *) $2 = 0x0000619000001e80 {
(const VALUE) [0] = 0x000062d0000ebf68
}
(lldb) rp $2[0]
bits [ ]
T_STRING: (const char [73]) $4 = " def self.verify_compaction_references(toward: nil, double_heap: false)\n"
</code></pre> Ruby master - Bug #17583: Segfault on large stack(RUBY_THREAD_VM_STACK_SIZE)https://bugs.ruby-lang.org/issues/17583?journal_id=901292021-01-28T15:43:10Zxtkoba (Tee KOBAYASHI)
<ul></ul><p>The crash threshold of <code>RUBY_THREAD_VM_STACK_SIZE</code> seems to coincide with the default value of <code>GC_MALLOC_LIMIT_MIN</code> (which is 16MB).</p>
<p>I think something is messed up by GC in an early stage of initialization. In fact, the crash seems to disappear when the function <code>garbage_collect</code> is made to do nothing other than returning <code>TRUE</code>.</p> Ruby master - Bug #17583: Segfault on large stack(RUBY_THREAD_VM_STACK_SIZE)https://bugs.ruby-lang.org/issues/17583?journal_id=901672021-01-29T18:31:17Zko1 (Koichi Sasada)
<ul><li><strong>Status</strong> changed from <i>Open</i> to <i>Assigned</i></li><li><strong>Assignee</strong> set to <i>ko1 (Koichi Sasada)</i></li></ul> Ruby master - Bug #17583: Segfault on large stack(RUBY_THREAD_VM_STACK_SIZE)https://bugs.ruby-lang.org/issues/17583?journal_id=906972021-03-02T09:18:48Zxtkoba (Tee KOBAYASHI)
<ul></ul><p>Bug <a class="issue tracker-1 status-5 priority-4 priority-default closed" title="Bug: Large RUBY_THREAD_VM_STACK_SIZE causes segmentation fault (again) (Closed)" href="https://bugs.ruby-lang.org/issues/17668">#17668</a> seems to be a duplicate of this bug.</p>
<p>As I wrote in <a href="#note-5">#note-5</a>, this issue seems to be caused by running GC during initialization. If so, a straightforward workaround would be to suppress GC during init:</p>
<pre><code class="diff syntaxhl" data-language="diff"><span class="gd">--- a/eval.c
</span><span class="gi">+++ b/eval.c
</span><span class="p">@@ -99,6 +99,8 @@</span>
return state;
}
<span class="gi">+extern int suppress_garbage_collection;
+
</span> /*!
* Calls ruby_setup() and check error.
*
<span class="p">@@ -107,6 +109,7 @@</span>
void
ruby_init(void)
{
<span class="gi">+ suppress_garbage_collection = 1;
</span> int state = ruby_setup();
if (state) {
if (RTEST(ruby_debug))
<span class="p">@@ -365,6 +368,7 @@</span>
int
ruby_run_node(void *n)
{
<span class="gi">+ suppress_garbage_collection = 0;
</span> rb_execution_context_t *ec = GET_EC();
int status;
if (!ruby_executable_node(n, &status)) {
<span class="gd">--- a/gc.c
</span><span class="gi">+++ b/gc.c
</span><span class="p">@@ -8214,11 +8214,15 @@</span>
#endif
}
<span class="gi">+int suppress_garbage_collection;
+
</span> static int
garbage_collect(rb_objspace_t *objspace, int reason)
{
int ret;
<span class="gi">+ if (suppress_garbage_collection) return TRUE;
+
</span> RB_VM_LOCK_ENTER();
{
#if GC_PROFILE_MORE_DETAIL
</code></pre>
<p>An alternative workaround would be to set <code>GC_ENABLE_LAZY_SWEEP</code> to 0, but this is not good because it disables lazy sweeping throughout the entire lifecycle. It would be better if we could suppress lazy sweeping during initialization only.</p> Ruby master - Bug #17583: Segfault on large stack(RUBY_THREAD_VM_STACK_SIZE)https://bugs.ruby-lang.org/issues/17583?journal_id=907342021-03-03T22:45:07Zjeremyevans0 (Jeremy Evans)merch-redmine@jeremyevans.net
<ul><li><strong>Has duplicate</strong> <i><a class="issue tracker-1 status-5 priority-4 priority-default closed" href="/issues/17668">Bug #17668</a>: Large RUBY_THREAD_VM_STACK_SIZE causes segmentation fault (again)</i> added</li></ul> Ruby master - Bug #17583: Segfault on large stack(RUBY_THREAD_VM_STACK_SIZE)https://bugs.ruby-lang.org/issues/17583?journal_id=908092021-03-09T09:10:20Znobu (Nobuyoshi Nakada)nobu@ruby-lang.org
<ul></ul><p>Does this work?<br>
<a href="https://github.com/nobu/ruby/tree/disable-gc-while-VM-bootsrap" class="external">https://github.com/nobu/ruby/tree/disable-gc-while-VM-bootsrap</a></p> Ruby master - Bug #17583: Segfault on large stack(RUBY_THREAD_VM_STACK_SIZE)https://bugs.ruby-lang.org/issues/17583?journal_id=917442021-04-28T23:52:40Zjeremyevans0 (Jeremy Evans)merch-redmine@jeremyevans.net
<ul></ul><p>nobu (Nobuyoshi Nakada) wrote in <a href="#note-9">#note-9</a>:</p>
<blockquote>
<p>Does this work?<br>
<a href="https://github.com/nobu/ruby/tree/disable-gc-while-VM-bootsrap" class="external">https://github.com/nobu/ruby/tree/disable-gc-while-VM-bootsrap</a></p>
</blockquote>
<p><a class="user active user-mention" href="https://bugs.ruby-lang.org/users/4">@nobu (Nobuyoshi Nakada)</a> I tested it and it fixes the problem on OpenBSD/amd64.</p> Ruby master - Bug #17583: Segfault on large stack(RUBY_THREAD_VM_STACK_SIZE)https://bugs.ruby-lang.org/issues/17583?journal_id=927192021-07-01T19:34:36Zjeremyevans0 (Jeremy Evans)merch-redmine@jeremyevans.net
<ul></ul><p>nobu (Nobuyoshi Nakada) wrote in <a href="#note-9">#note-9</a>:</p>
<blockquote>
<p>Does this work?<br>
<a href="https://github.com/nobu/ruby/tree/disable-gc-while-VM-bootsrap" class="external">https://github.com/nobu/ruby/tree/disable-gc-while-VM-bootsrap</a></p>
</blockquote>
<p>Since it worked for me, I rebased this tree on master and submitted a pull request for it: <a href="https://github.com/ruby/ruby/pull/4617" class="external">https://github.com/ruby/ruby/pull/4617</a></p> Ruby master - Bug #17583: Segfault on large stack(RUBY_THREAD_VM_STACK_SIZE)https://bugs.ruby-lang.org/issues/17583?journal_id=927272021-07-02T01:50:37Znobu (Nobuyoshi Nakada)nobu@ruby-lang.org
<ul><li><strong>Status</strong> changed from <i>Assigned</i> to <i>Closed</i></li></ul><p>Applied in changeset <a class="changeset" title="Keep GC disabled until VM bootstrap has done [Bug #17583]" href="https://bugs.ruby-lang.org/projects/ruby-master/repository/git/revisions/8ebb5e23ebc5f1675e3479b9a29f124dc458226b">git|8ebb5e23ebc5f1675e3479b9a29f124dc458226b</a>.</p>
<hr>
<p>Keep GC disabled until VM bootstrap has done [Bug <a class="issue tracker-1 status-5 priority-4 priority-default closed" title="Bug: Segfault on large stack(RUBY_THREAD_VM_STACK_SIZE) (Closed)" href="https://bugs.ruby-lang.org/issues/17583">#17583</a>]</p> Ruby master - Bug #17583: Segfault on large stack(RUBY_THREAD_VM_STACK_SIZE)https://bugs.ruby-lang.org/issues/17583?journal_id=930642021-07-31T01:02:55Zciel (T Yamada)
<ul></ul><p>Hi, could you backport this to Ruby 3.0?</p> Ruby master - Bug #17583: Segfault on large stack(RUBY_THREAD_VM_STACK_SIZE)https://bugs.ruby-lang.org/issues/17583?journal_id=1002322022-11-24T10:56:08Zhsbt (Hiroshi SHIBATA)hsbt@ruby-lang.org
<ul><li><strong>Backport</strong> changed from <i>2.5: UNKNOWN, 2.6: UNKNOWN, 2.7: UNKNOWN, 3.0: UNKNOWN</i> to <i>2.5: UNKNOWN, 2.6: UNKNOWN, 2.7: UNKNOWN, 3.0: REQUIRED</i></li></ul> Ruby master - Bug #17583: Segfault on large stack(RUBY_THREAD_VM_STACK_SIZE)https://bugs.ruby-lang.org/issues/17583?journal_id=1002332022-11-24T11:02:45Zusa (Usaku NAKAMURA)usa@garbagecollect.jp
<ul><li><strong>Backport</strong> changed from <i>2.5: UNKNOWN, 2.6: UNKNOWN, 2.7: UNKNOWN, 3.0: REQUIRED</i> to <i>2.5: UNKNOWN, 2.6: UNKNOWN, 2.7: UNKNOWN, 3.0: DONE</i></li></ul><p>mergerd into ruby_3_0 at 5fb3cf4</p>