Project

General

Profile

Actions

Bug #5901

closed

OpenBSD "[FATAL] failed to allocate memory"

Added by kernigh (George Koehler) over 12 years ago. Updated about 12 years ago.

Status:
Closed
Target version:
-
ruby -v:
ruby 2.0.0dev (2012-01-16 trunk 34316) [x86_64-openbsd5.0]
Backport:
[ruby-core:42158]

Description

=begin
Ruby trunk fails to build with OpenBSD. During the build, miniruby fails with message
[FATAL] failed to allocate memory

OpenBSD has a broken posix_memalign(). Ruby fails in gc.c, because posix_memalign() fails and aligned_malloc() returns NULL. OpenBSD's manual for posix_memalign ((URL:http://xrl.us/bmow7c)) says:

BUGS
Only alignments up to the page size can be specified.

Ruby wants alignment of 16 kilobytes, but my page size is only 4 kilobytes.

I tried to edit gc.c. My first attempt (bad-fix-never-apply.diff) was good enough to build Ruby, but it did not always work, and some tests failed. So I reverted gc.c and tried again.

My second attempt (smaller-heap-for-openbsd.diff) was much simpler. I changed the values of HEAP_ALIGN*, shrinking the heap size from 16 kilobytes to 4 kilobytes, which is not larger than my page size. More tests pass. The only failures in 'make test' are in bootstraptest/test_thread.rb. Those tests seem to create an infinite loop in Ruby, and I needed to kill -9 those processes. Some tests in 'make test-all' failed the same way, with the infinite loop.
=end


Files

bad-patch-never-apply.diff (2.66 KB) bad-patch-never-apply.diff bad patch! do not use! kernigh (George Koehler), 01/17/2012 09:03 AM
smaller-heap-for-openbsd.diff (671 Bytes) smaller-heap-for-openbsd.diff better fix -- if OpenBSD, set HEAP_SIZE to 4 kilobytes kernigh (George Koehler), 01/17/2012 09:03 AM
smaller-heap-3.diff (887 Bytes) smaller-heap-3.diff patch by Narihiro Nakamura, but migrated to svn r34399 kernigh (George Koehler), 01/31/2012 06:27 AM

Related issues 1 (0 open1 closed)

Related to Ruby master - Feature #5839: Proposal: Bitmap Marking GCClosedmatz (Yukihiro Matsumoto)01/04/2012Actions

Updated by kosaki (Motohiro KOSAKI) over 12 years ago

You don't have to edit gc.c. Instead, please make a workaround in configure.in. We only need aligned alloc, and don't exactly need posix_memalign.

Updated by naruse (Yui NARUSE) about 12 years ago

  • Status changed from Open to Assigned
  • Assignee set to authorNari (Narihiro Nakamura)

Updated by kernigh (George Koehler) about 12 years ago

Motohiro KOSAKI wrote:

You don't have to edit gc.c. Instead, please make a workaround in configure.in. We only need aligned alloc, and don't exactly need posix_memalign.

Even if configure.in would check that posix_memalign is broken, there seems to be no other way to do aligned alloc for OpenBSD. One would need to edit gc.c to do something different for OpenBSD.

Updated by authorNari (Narihiro Nakamura) about 12 years ago

Hi.

I make the following patch. Is it acceptable?

diff --git a/configure.in b/configure.in
index 085dfcf..f41ef3b 100644
--- a/configure.in
+++ b/configure.in
@@ -1292,6 +1292,13 @@ main() {
CFLAGS="$save_CFLAGS"])
AC_DEFINE_UNQUOTED(GC_MARK_STACKFRAME_WORD, $rb_cv_gc_mark_stackframe_word)

+AS_CASE(["$target_os"],
+[openbsd*], [

  • AC_DEFINE_UNQUOTED(HEAP_ALIGN_LOG, 12)
  • AC_DEFINE_UNQUOTED(HEAP_ALIGN, 0x1000)
  • AC_DEFINE_UNQUOTED(HEAP_ALIGN_MASK, 0x0fff)
  • ])

dnl Checks for library functions.
AC_TYPE_GETGROUPS
diff --git a/gc.c b/gc.c
index 4c906e7..b90cf35 100644
--- a/gc.c
+++ b/gc.c
@@ -536,10 +536,13 @@ rb_objspace_free(rb_objspace_t *objspace)
}
#endif

-/* tiny heap size: 16KB /
+#ifndef HEAP_ALIGN_LOG
+/
default tiny heap size: 16KB */
#define HEAP_ALIGN_LOG 14
#define HEAP_ALIGN 0x4000
#define HEAP_ALIGN_MASK 0x3fff
+#endif
+
#define REQUIRED_SIZE_BY_MALLOC (sizeof(size_t) * 5)
#define HEAP_SIZE (HEAP_ALIGN - REQUIRED_SIZE_BY_MALLOC)

Updated by kernigh (George Koehler) about 12 years ago

I reverted my own changes. Then I tried to apply patch by Narihiro Nakamura, but I got patch conflict with svn r34399. After I solved conflict, I can compile and run Ruby, 'make test' passes all tests, and 'make test-all' has 0 failures and 0 errors. My system is OpenBSD 5.0/amd64.

After I solved conflict, patch looks like this:

Index: configure.in

--- configure.in (revision 34399)
+++ configure.in (working copy)
@@ -1292,7 +1292,12 @@
CFLAGS="$save_CFLAGS"])
AC_DEFINE_UNQUOTED(GC_MARK_STACKFRAME_WORD, $rb_cv_gc_mark_stackframe_word)

+AS_CASE(["$target_os"],
+[openbsd*], [

  • AC_DEFINE_UNQUOTED(HEAP_ALIGN_LOG, 12)

  • ])

dnl Checks for library functions.
AC_TYPE_GETGROUPS
AC_TYPE_SIGNAL
Index: gc.c

--- gc.c (revision 34399)
+++ gc.c (working copy)
@@ -536,8 +536,11 @@
}
#endif

-/* tiny heap size: 16KB /
+#ifndef HEAP_ALIGN_LOG
+/
default tiny heap size: 16KB */
#define HEAP_ALIGN_LOG 14
+#endif
+
#define HEAP_ALIGN (1UL << HEAP_ALIGN_LOG)
#define HEAP_ALIGN_MASK (~(~0UL << HEAP_ALIGN_LOG))
#define REQUIRED_SIZE_BY_MALLOC (sizeof(size_t) * 5)

Actions #6

Updated by authorNari (Narihiro Nakamura) about 12 years ago

  • Status changed from Assigned to Closed
  • % Done changed from 0 to 100

This issue was solved with changeset r34404.
George, thank you for reporting this issue.
Your contribution to Ruby is greatly appreciated.
May Ruby be with you.


  • configure.in (HEAP_ALIGN_LOG): HEAP_ALIGN_LOG should be page
    size in OpenBSD. [ruby-core:42158][Bug #5901]

  • gc.c : avoid to redefine.

Actions

Also available in: Atom PDF

Like0
Like0Like0Like0Like0Like0Like0