Fork us on GitHub Follow us on Facebook Follow us on Twitter

Opened 10 years ago

Closed 9 years ago

#114 closed enhancement (fixed)

memory reservation feature needed

Reported by: Pippijn van Steenhoven Owned by: Jakub Jermář
Priority: major Milestone: 0.5.0
Component: helenos/kernel/generic Version: mainline
Keywords: allocation, malloc, memory, suggestion Cc: martin@…, jakub@…
Blocker for: Depends on:
See also:

Description

The following code works:

main(){ while (malloc (1024 * 1024)); }

but the next code does not:

main(){ while (memset (malloc (1024 * 1024), 0, 1024 * 1024)); }

The full test code I was using is attached.

Attachments (1)

malloc_test.c (280 bytes) - added by Pippijn van Steenhoven 10 years ago.
malloc+memset test

Download all attachments as: .zip

Change History (10)

Changed 10 years ago by Pippijn van Steenhoven

Attachment: malloc_test.c added

malloc+memset test

comment:1 Changed 10 years ago by Martin Decky

And what should be the expected behaviour? In the first example you might be allocating 1 MB chunks (actually the kernel just commits the memory to you), but since you never touch most of the memory, the memory won't be actually assigned to you.

In the second example you actually force the kernel to assign the physical memory to you (in the page fault handler which gets triggered once you touch the memory using memset()). The physical memory runs out and your task gets blocked in the kernel, waiting for any physical memory to be released (by other tasks or possibly the kernel itself).

There has been some discussion recently how to allow the user to modify this kernel behaviour with respect to memory overcommit and deferred blocking in the page fault handler (see the long thread in our mailing list: http://lists.modry.cz/cgi-bin/private/helenos-devel/2009-August/005717.html).

BTW: Isn't there still an unrelated bug in your second code? When the malloc() returns NULL, you should not pass this NULL to memset(). Or am I missing something?

comment:2 Changed 10 years ago by Martin Decky

Cc: martin@… added

comment:3 Changed 10 years ago by Jakub Jermář

Cc: jakub@… added

comment:4 Changed 10 years ago by Jakub Jermář

Summary: memory allocation seems to be brokenmemory reservation feature needed
Type: defectenhancement

I am changing the synopsis and the type of this ticket as this is definitely not a bug, but a call for implementing memory reservations.

comment:5 Changed 10 years ago by Jakub Jermář

Milestone: 0.4.20.5.0

comment:6 Changed 10 years ago by Jakub Jermář

Keywords: suggestion added

comment:7 Changed 9 years ago by Jakub Jermář

Owner: set to Jakub Jermář
Status: newassigned

comment:8 Changed 9 years ago by Jakub Jermář

Milestone: 0.4.30.5.0

comment:9 Changed 9 years ago by Jakub Jermář

Resolution: fixed
Status: assignedclosed

Fixed in changeset:mainline,926.

Please log bugs against the implementation or suggestions on how to further improve it as separate ticket.

Note: See TracTickets for help on using tickets.