Hacker News new | ask | show | jobs
by dent9876543 668 days ago
Do you mean that my process might get killed [by the OOM killer] if /another process/ fails to get more backing pages?

Or are you suggesting that there is some other failure path that results in my process getting killed if my own malloc() fails to get pages? (That seems wrong. Should simply return NULL in that case, no?)

1 comments

> Do you mean that my process might get killed [by the OOM killer] if /another process/ fails to get more backing pages?

It can be your process or some other process, depending on the OOM killer weights and heuristics.

> Or are you suggesting that there is some other failure path that results in my process getting killed if my own malloc() fails to get pages? (That seems wrong. Should simply return NULL in that case, no?)

No, malloc() in Linux will never return NULL for small allocations. What happens is that glibc will try to get more pages for its heap by calling mmap(). The call to mmap() will result in the OOM killer waking up and freeing some memory.

It then can kill some other process, and your process mmap() will succeed, or it can kill your process, and in this case mmap() never returns.