[erlang-questions] Hipe and memory alignment (Yikes! erts_alloc() returned misaligned address)
Mikael Pettersson
mikpe@REDACTED
Wed Aug 4 23:19:31 CEST 2010
Paul Guyot writes:
> Hello,
>
> When running erl with native (hipe) code on some platforms (FreeBSD amd64), one quickly encounters messages such as:
>
> Yikes! erts_alloc() returned misaligned address 0x8016a512c
>
> This message seems to come from hipe_bifs:alloc_data/2. The allocator is the system allocator, which on unix platform is malloc, and malloc does not necessarily return aligned blocks (on MacOS X, it does, but not on FreeBSD).
>
> Does it really matter? (hipe_bifs:alloc_data/2 is only called from hipe_unified_loader:create_data_segment/3).
> If it doesn't, can we remove the log line?
> If it does, can we replace the allocator with another one that always return aligned blocks?
Of course alignment matters, otherwise you'd only be able to store
char arrays in malloc:d areas without risking alignment faults or
poor performance. That's true even on x86/amd64.
Upper levels (hipe_unified_loader and initially the hipe compiler)
describe the required alignment and size of the data segment, and
the alignment is a function of the type of data stored there.
Now, it is possible that the alignment is wrong, esp. if the data
segment for whatever reason turns out to be tiny. Please rebuild
the erlang VM with the following patch and do what you normally do
to trigger the Yikes! message. It should tell us a little bit more
about the allocation parameters.
FWIW, I've never heard of anyone being able to trigger this warning
before.
/Mikael
--- otp_src_R14A/erts/emulator/hipe/hipe_bif0.c.~1~ 2010-02-19 19:04:06.000000000 +0100
+++ otp_src_R14A/erts/emulator/hipe/hipe_bif0.c 2010-08-04 23:02:40.000000000 +0200
@@ -442,7 +442,8 @@ BIF_RETTYPE hipe_bifs_alloc_data_2(BIF_A
nrbytes = unsigned_val(BIF_ARG_2);
block = erts_alloc(ERTS_ALC_T_HIPE, nrbytes);
if ((unsigned long)block & (align-1))
- fprintf(stderr, "Yikes! erts_alloc() returned misaligned address %p\r\n", block);
+ fprintf(stderr, "Yikes! erts_alloc() returned %p for align %lu nrbytes %lu\r\n",
+ block, (unsigned long)align, (unsigned long)nrbytes);
BIF_RET(address_to_term(block, BIF_P));
}
More information about the erlang-questions
mailing list