Bug #5901
closedOpenBSD "[FATAL] failed to allocate memory"
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
Updated by kosaki (Motohiro KOSAKI) almost 13 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) almost 13 years ago
- Status changed from Open to Assigned
- Assignee set to authorNari (Narihiro Nakamura)
Updated by kernigh (George Koehler) almost 13 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) almost 13 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) almost 13 years ago
- File smaller-heap-3.diff smaller-heap-3.diff added
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)
Updated by authorNari (Narihiro Nakamura) almost 13 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.