[#25936] [Bug:1.9] [rubygems] $LOAD_PATH includes bin directory — Nobuyoshi Nakada <nobu@...>

Hi,

10 messages 2009/10/05

[#25943] Disabling tainting — Tony Arcieri <tony@...>

Would it make sense to have a flag passed to the interpreter on startup that

16 messages 2009/10/05

[#26028] [Bug #2189] Math.atanh(1) & Math.atanh(-1) should not raise an error — Marc-Andre Lafortune <redmine@...>

Bug #2189: Math.atanh(1) & Math.atanh(-1) should not raise an error

14 messages 2009/10/10

[#26222] [Bug #2250] IO::for_fd() objects' finalization dangerously closes underlying fds — Mike Pomraning <redmine@...>

Bug #2250: IO::for_fd() objects' finalization dangerously closes underlying fds

11 messages 2009/10/22

[#26244] [Bug #2258] Kernel#require inside rb_require() inside rb_protect() inside SysV context fails — Suraj Kurapati <redmine@...>

Bug #2258: Kernel#require inside rb_require() inside rb_protect() inside SysV context fails

24 messages 2009/10/22

[#26361] [Feature #2294] [PATCH] ruby_bind_stack() to embed Ruby in coroutine — Suraj Kurapati <redmine@...>

Feature #2294: [PATCH] ruby_bind_stack() to embed Ruby in coroutine

42 messages 2009/10/27

[#26371] [Bug #2295] segmentation faults — tomer doron <redmine@...>

Bug #2295: segmentation faults

16 messages 2009/10/27

[ruby-core:26211] Ruby 1.9.1 embedding and GC

From: Roman Shterenzon <romanbsd@...>
Date: 2009-10-21 12:44:19 UTC
List: ruby-core #26211
Good day,

I'm trying to embed a Ruby 1.9.1 interpreter, and I'd like to disable to GC, and only run it manually (say, every 1000 requests).
The problem is, that somehow it's not disabled, and after an attempt to allocate memory the interpreter exits.
I tried to understand the code, but I'm a bit lost. What I'm doing wrong here?

The ruby version is:
ruby 1.9.1p281 (2009-08-09 revision 24476) [i386-darwin10.0.0]

My code:
-----
RUBY_INIT_STACK;
ruby_init();
ruby_init_loadpath();
ruby_script(service_file);
rb_define_module("Gem");
rb_gc_disable();
Init_prelude();
int error;
rb_protect((VALUE (*)(VALUE))rb_require, (VALUE)service_file, &error);
-----

The gdb backtrace (line 193 in ruby_handler.c is Array allocation):
(gdb) bt
#0  0x00007fff84fb5183 in exit ()
#1  0x0000000100233b0b in garbage_collect_with_gvl (objspace=0x10036d9c0) at gc.c:602
#2  0x0000000100233b71 in vm_xmalloc (objspace=0x10036d9c0, size=80) at gc.c:623
#3  0x0000000100204f3a in ary_new (klass=<value temporarily unavailable, due to optimizations>, len=10) at array.c:301
#4  0x000000010006d03b in ruby_init_request_data (req=0x1028ff800) at ruby_handler.c:193
...
(gdb) up 
#1  0x0000000100233b0b in garbage_collect_with_gvl (objspace=0x10036d9c0) at gc.c:602
602    exit(EXIT_FAILURE);
(gdb) list
597    return (int)rb_thread_call_with_gvl(gc_with_gvl, (void *)objspace);
598}
599else {
600    /* no ruby thread */
601    fprintf(stderr, "[FATAL] failed to allocate memory\n");
602    exit(EXIT_FAILURE);
603}
604    }
605}
606
(gdb) up
#2  0x0000000100233b71 in vm_xmalloc (objspace=0x10036d9c0, size=80) at gc.c:623
623garbage_collect_with_gvl(objspace);
(gdb) list
618    size += sizeof(size_t);
619#endif
620
621    if ((ruby_gc_stress && !ruby_disable_gc_stress) ||
622(malloc_increase+size) > malloc_limit) {
623garbage_collect_with_gvl(objspace);
624    }
625    mem = malloc(size);
626    if (!mem) {
627if (garbage_collect_with_gvl(objspace)) {
(gdb)


Another question, which might be related, is that if I don't disable GC, then I see this error:
[BUG] object allocation during garbage collection phase

And I assumed, that if I control the allocation and GC, then I can avoid triggering this bug, but perhaps there's a better workaround or solution.

Thank you very much in advance,

--Roman


      

In This Thread

Prev Next