﻿id	summary	reporter	owner	description	type	status	priority	milestone	component	version	resolution	keywords	cc	field_blocks	field_dependson	field_seealso
395	memalign() does not work as expected	Vojtech Horky	Jakub Jermář	"This problem was discussed on ML ([http://lists.modry.cz/cgi-bin/private/helenos-devel/2011-June/007484.html initial post]), information here is rather a summary.

In current mainline (1302), `memalign()` fails to satisfy a request even when there is evidently enough memory to satisfy it. The attached patch adds a `memalign` program to HelenOS that tries to allocate blocks of growing size using `malloc()` and `memalign()`.

{{{
#!c
for (i = 0; i < 30; i++) {
   void *ptr = malloc(1 << i); // or memalign(1 << i, 32)
   // if ptr != NULL, access it and free it
   // print i if allocation was successful
}
}}}

The expected behavior is that both functions would be able to allocate blocks of (more or less) similar sizes. For example, when `malloc()` is able to allocate 8M, `memalign()` shall be able to allocate at least 4M.

However, as the attached screenshots prove, `memalign()` starts to return `NULL` much earlier than `malloc()` and moreover, this ""upper boundary"" is not consistent through repeated runs.

It is apparent that this is some problem inside libc memory allocator but the root cause is not known. One possible suspect is rounding/aligning inside allocation routines. The second patch fixes the `memalign` application somehow but I am not sure whether it really fixes the root cause and whether the rounding is not an overkill.

"	defect	closed	major	0.5.0	helenos/lib/c	mainline	fixed	allocator malloc free memalign				
