Opened 13 years ago

Closed 12 years ago

#395 closed defect (fixed)

memalign() does not work as expected

Reported by: Vojtech Horky Owned by: Jakub Jermář
Priority: major Milestone: 0.5.0
Component: helenos/lib/c Version: mainline
Keywords: allocator malloc free memalign Cc:
Blocker for: Depends on:
See also:

Description

This problem was discussed on ML (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().

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.

Attachments (4)

test_memalign.patch (5.5 KB ) - added by Vojtech Horky 13 years ago.
memalign application demonstrating the problem
memalign_bad.png (36.1 KB ) - added by Vojtech Horky 13 years ago.
Screenshot of unexpected behavior
memalign_good.png (40.5 KB ) - added by Vojtech Horky 13 years ago.
Screenshot with "fixed" allocator (i.e. expected behavior)
fix_hint.patch (1.3 KB ) - added by Vojtech Horky 13 years ago.
Hint for fixing the memory allocator - reviewer wanted ;-)

Download all attachments as: .zip

Change History (6)

by Vojtech Horky, 13 years ago

Attachment: test_memalign.patch added

memalign application demonstrating the problem

by Vojtech Horky, 13 years ago

Attachment: memalign_bad.png added

Screenshot of unexpected behavior

by Vojtech Horky, 13 years ago

Attachment: memalign_good.png added

Screenshot with "fixed" allocator (i.e. expected behavior)

by Vojtech Horky, 13 years ago

Attachment: fix_hint.patch added

Hint for fixing the memory allocator - reviewer wanted ;-)

comment:1 by Jakub Jermář, 12 years ago

Milestone: 0.5.00.5.1

No need to have this fixed for 0.5.0, rescheduling for the next release.

comment:2 by Jakub Jermář, 12 years ago

Milestone: 0.5.10.5.0
Resolution: fixed
Status: newclosed

Fixed in mainline,1553.

Note: See TracTickets for help on using tickets.