r/programming • • Apr 14 '21

[RFC] Rust support for Linux Kernel

https://lkml.org/lkml/2021/4/14/1023
730 Upvotes

308 comments sorted by

View all comments

Show parent comments

5

u/StillNoNumb Apr 15 '21

I think you misunderstood the parent comment. They make no such claim nor did they suggest something along these lines.

1

u/phySi0 Apr 16 '21 edited Apr 16 '21

Regarding userspace [emphasis mine]: Yes, the behaviour you describe (return NULL on allocation failure/when out of memory) would be correct. However, at least in Linux you are pretty much guaranteed this will never happen. In Detail: If the system truly is out of memory and you try to allocate more, the kernel might invoke the OOM killer, i.e. choose a program to terminate in order to regain some memory. If the sacrificed program happens to be the one that requested more memory in the first place, it would just never see the result of the malloc call. As a result, as a programmer you can assume (at least on Linux) that malloc never fails. [emphasis mine]

I’m not saying he explicitly said there’s a functional difference, but that is the implication here.

I’m saying you can say malloc never fails, but that’s cold comfort when your program gets OOM-killed because of a malloc.

I also don’t think the OP has to explicitly say that there’s a functional difference for me to think it’s worth making the opposite point myself.