User: Password:
|
|
Subscribe / Log in / New account

Blocking on allocation failure - WTF?

Blocking on allocation failure - WTF?

Posted Mar 10, 2011 14:39 UTC (Thu) by epa (subscriber, #39769)
In reply to: Blocking on allocation failure - WTF? by alonz
Parent article: Delaying the OOM killer

What you miss is that in modern Linux, malloc() practically never fails.
Right, but here is an instance where it does fail to allocate memory. It is known that the memory is not available right now (although of course it might become available at some point in the future). The malloc() API has provision for letting that be known to the application, by returning null. If the application wants to just hang until memory becomes available, that can easily be implemented in user-space (perhaps at the cost of a little busy-waiting or sleeping); but on the other hand if the application would like to find out when no more memory is available and do something, it's impossible to implement that on top of a malloc() interface that just blocks indefinitely.


(Log in to post comments)

Blocking on allocation failure - WTF?

Posted Mar 11, 2011 14:22 UTC (Fri) by droundy (subscriber, #4559) [Link]

The point is that malloc never does block indefinitely with overcommit enabled. It (essentially) always succeeds, and what blocks indefinitely is when you try to write to that shiny new virtual address space that was provided to you by malloc. At this point, the kernel realizes that there aren't any pages to provide you with, but it's too late for malloc to do anything to help you out, since malloc already succeeded.


Copyright © 2017, Eklektix, Inc.
Comments and public postings are copyrighted by their creators.
Linux is a registered trademark of Linus Torvalds